Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW resource phone, email & maxusers #28185

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/resource.lang
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ ImportDataset_resource_1=Resources

ErrorResourcesAlreadyInUse=Some resources are in use
ErrorResourceUseInEvent=%s used in %s event

MaxUsers=Maximum users (places, seats, etc.)
66 changes: 48 additions & 18 deletions htdocs/resource/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
$address = GETPOST('address', 'alpha');
$zip = GETPOST('zipcode', 'alpha');
$town = GETPOST('town', 'alpha');
$country_id = GETPOSTINT('country_id');
$state_id = GETPOSTINT('state_id');
$description = GETPOST('description', 'restricthtml');
$phone = GETPOST('phone', 'alpha');
$email = GETPOST('email', 'alpha');
$max_users = GETPOSTINT('max_users');
$confirm = GETPOST('confirm', 'aZ09');
$fk_code_type_resource = GETPOST('fk_code_type_resource', 'aZ09');
$country_id = GETPOSTINT('country_id');
$state_id = GETPOSTINT('state_id');

// Protection if external user
if ($user->socid > 0) {
Expand Down Expand Up @@ -106,10 +109,13 @@
$object->address = $address;
$object->zip = $zip;
$object->town = $town;
$object->description = $description;
$object->fk_code_type_resource = $fk_code_type_resource;
$object->country_id = $country_id;
$object->country_id = $country_id;
$object->state_id = $state_id;
$object->description = $description;
$object->phone = $phone;
$object->email = $email;
$object->max_users = $max_users;
$object->fk_code_type_resource = $fk_code_type_resource;

// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
Expand All @@ -120,7 +126,7 @@
$result = $object->create($user);
if ($result > 0) {
// Creation OK
setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs');
setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null);
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
Expand Down Expand Up @@ -150,10 +156,13 @@
$object->address = $address;
$object->zip = $zip;
$object->town = $town;
$object->description = $description;
$object->fk_code_type_resource = $fk_code_type_resource;
$object->country_id = $country_id;
$object->state_id = $state_id;
$object->description = $description;
$object->phone = $phone;
$object->email = $email;
$object->max_users = $max_users;
$object->fk_code_type_resource = $fk_code_type_resource;

// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
Expand Down Expand Up @@ -186,7 +195,7 @@
$result = $object->delete($id);

if ($result >= 0) {
setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null, 'mesgs');
setEventMessages($langs->trans('RessourceSuccessfullyDeleted'), null);
header('Location: '.DOL_URL_ROOT.'/resource/list.php');
exit;
} else {
Expand Down Expand Up @@ -220,7 +229,7 @@

if ($action == 'create' || $action == 'edit') {
if (!$user->hasRight('resource', 'write')) {
accessforbidden('', 0, 1);
accessforbidden('', 0);
}

// Create/Edit object
Expand All @@ -233,7 +242,7 @@

// Ref
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("ResourceFormLabel_ref").'</td>';
print '<td><input class="minwidth200" name="ref" value="'.($ref ? $ref : $object->ref).'" autofocus="autofocus"></td></tr>';
print '<td><input class="minwidth200" name="ref" value="'.($ref ?: $object->ref).'" autofocus="autofocus"></td></tr>';

// Address
print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
Expand All @@ -257,7 +266,7 @@

// Origin country
print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
print $form->select_country($object->country_id, 'country_id');
print $form->select_country($object->country_id);
if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
Expand Down Expand Up @@ -290,10 +299,31 @@
print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
print '<td>';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor('description', ($description ? $description : $object->description), '', '200', 'dolibarr_notes', false);
$doleditor = new DolEditor('description', ($description ?: $object->description), '', '200', 'dolibarr_notes', false);
$doleditor->Create();
print '</td></tr>';

// Phone
print '<td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
print '<input type="tel" name="phone" id="phone" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
print '</tr>';

// Email
print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_email', 'class="pictofixedwidth"');
print '<input type="email" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
print '</tr>';

// Max users
print '<tr><td>'.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0).'</td>';
print '<td>';
print img_picto('', 'object_user', 'class="pictofixedwidth"');
print '<input type="number" name="max_users" id="max_users" value="'.(GETPOSTISSET('max_users') ? GETPOSTINT('max_users') : $object->max_users).'"></td>';
print '</tr>';

// Other attributes
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
Expand Down Expand Up @@ -326,7 +356,7 @@

$linkback = '<a href="'.DOL_URL_ROOT.'/resource/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&id='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
dol_banner_tab($object, 'ref', $linkback, 1, 'ref');


print '<div class="fichecenter">';
Expand All @@ -353,13 +383,13 @@
print '</td>';
print '</tr>';

// Origin country code
// Max users
print '<tr>';
print '<td>'.$langs->trans("CountryOrigin").'</td>';
print '<td>'.$langs->trans("MaxUsers").'</td>';
print '<td>';
print getCountry($object->country_id, 0, $db);
print $object->max_users;
print '</td>';

print '</tr>';

// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
Expand Down
102 changes: 79 additions & 23 deletions htdocs/resource/class/dolresource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,46 @@ class Dolresource extends CommonObject
public $zip;

/**
* @var string yown
* @var string town
*/
public $town;

/**
* @var string ID
* @var int ID country
*/
public $fk_code_type_resource;
public $fk_country;

public $type_label;
/**
* @var int ID state
*/
public $fk_state;

/**
* @var string description
*/
public $description;

/**
* @var int ID country
* @var string telephone number
*/
public $fk_country;
public $phone;

/**
* @var int ID state
* @var string email address
*/
public $fk_state;
public $email;

/**
* @var int Maximum users
*/
public $max_users;

/**
* @var string ID
*/
public $fk_code_type_resource;

public $type_label;

// Variable for a link of resource

Expand Down Expand Up @@ -143,7 +158,21 @@ public function create(User $user, int $no_trigger = 0)
$error = 0;

// Clean parameters
$new_resource_values = [$this->ref, $this->address, $this->zip, $this->town, $this->description, $this->country_id, $this->state_id, $this->fk_code_type_resource, $this->note_public, $this->note_private];
$new_resource_values = [
$this->ref,
$this->address,
$this->zip,
$this->town,
$this->country_id,
$this->state_id,
$this->description,
$this->phone,
$this->email,
$this->max_users,
$this->fk_code_type_resource,
$this->note_public,
$this->note_private
];
foreach ($new_resource_values as $key => $value) {
if (isset($value)) {
$new_resource_values[$key] = trim($value);
Expand All @@ -157,9 +186,12 @@ public function create(User $user, int $no_trigger = 0)
$sql .= "address,";
$sql .= "zip,";
$sql .= "town,";
$sql .= "description,";
$sql .= "fk_country,";
$sql .= "fk_state,";
$sql .= "description,";
$sql .= "phone,";
$sql .= "email,";
$sql .= "max_users,";
$sql .= "fk_code_type_resource,";
$sql .= "note_public,";
$sql .= "note_private";
Expand Down Expand Up @@ -234,9 +266,12 @@ public function fetch($id, $ref = '')
$sql .= " t.address,";
$sql .= " t.zip,";
$sql .= " t.town,";
$sql .= " t.description,";
$sql .= " t.fk_country,";
$sql .= " t.fk_state,";
$sql .= " t.description,";
$sql .= " t.phone,";
$sql .= " t.email,";
$sql .= " t.max_users,";
$sql .= " t.fk_code_type_resource,";
$sql .= " t.note_public,";
$sql .= " t.note_private,";
Expand All @@ -262,11 +297,14 @@ public function fetch($id, $ref = '')
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;
$this->description = $obj->description;
$this->country_id = $obj->fk_country;
$this->state_id = $obj->fk_state;
$this->description = $obj->description;
$this->phone = $obj->phone;
$this->email = $obj->email;
$this->max_users = $obj->max_users;
$this->fk_code_type_resource = $obj->fk_code_type_resource;
$this->note_public = $obj->note_public;
$this->note_public = $obj->note_public;
$this->note_private = $obj->note_private;
$this->type_label = $obj->type_label;

Expand Down Expand Up @@ -310,18 +348,27 @@ public function update($user = null, $notrigger = 0)
if (isset($this->town)) {
$this->town = trim($this->town);
}
if (isset($this->fk_code_type_resource)) {
$this->fk_code_type_resource = trim($this->fk_code_type_resource);
}
if (isset($this->description)) {
$this->description = trim($this->description);
}
if (!is_numeric($this->country_id)) {
$this->country_id = 0;
}
if (!is_numeric($this->state_id)) {
$this->state_id = 0;
}
if (isset($this->description)) {
$this->description = trim($this->description);
}
if (isset($this->phone)) {
$this->phone = trim($this->phone);
}
if (isset($this->email)) {
$this->email = trim($this->email);
}
if (!is_numeric($this->max_users)) {
$this->max_users = 0;
}
if (isset($this->fk_code_type_resource)) {
$this->fk_code_type_resource = trim($this->fk_code_type_resource);
}

// $this->oldcopy should have been set by the caller of update (here properties were already modified)
if (empty($this->oldcopy)) {
Expand All @@ -334,9 +381,12 @@ public function update($user = null, $notrigger = 0)
$sql .= " address=".(isset($this->address) ? "'".$this->db->escape($this->address)."'" : "null").",";
$sql .= " zip=".(isset($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null").",";
$sql .= " town=".(isset($this->town) ? "'".$this->db->escape($this->town)."'" : "null").",";
$sql .= " fk_country=".($this->country_id > 0 ? (int) $this->country_id : "null").",";
$sql .= " fk_state=".($this->state_id > 0 ? (int) $this->state_id : "null").",";
$sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
$sql .= " fk_country=".($this->country_id > 0 ? $this->country_id : "null").",";
$sql .= " fk_state=".($this->state_id > 0 ? $this->state_id : "null").",";
$sql .= " phone=".(isset($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null").",";
$sql .= " email=".(isset($this->email) ? "'".$this->db->escape($this->email)."'" : "null").",";
$sql .= " max_users=".(isset($this->max_users) ? (int) $this->max_users : "null").",";
$sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").",";
$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null');
$sql .= " WHERE rowid=".((int) $this->id);
Expand Down Expand Up @@ -553,9 +603,12 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = [])
$sql .= " t.address,";
$sql .= " t.zip,";
$sql .= " t.town,";
$sql .= " t.description,";
$sql .= " t.fk_country,";
$sql .= " t.fk_state,";
$sql .= " t.description,";
$sql .= " t.phone,";
$sql .= " t.email,";
$sql .= " t.max_users,";
$sql .= " t.fk_code_type_resource,";
$sql .= " t.tms,";
// Add fields from extrafields
Expand Down Expand Up @@ -600,9 +653,12 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = [])
$line->address = $obj->address;
$line->zip = $obj->zip;
$line->town = $obj->town;
$line->description = $obj->description;
$line->country_id = $obj->fk_country;
$line->state_id = $obj->fk_state;
$line->description = $obj->description;
$this->phone = $obj->phone;
$this->email = $obj->email;
$this->max_users = $obj->max_users;
$line->fk_code_type_resource = $obj->fk_code_type_resource;
$line->type_label = $obj->type_label;

Expand Down
Loading