From 3d1907d79ae498ad59f794e19b420c7e87d8fe6b Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 09:34:15 +0100 Subject: [PATCH 1/7] Added resource phone, email & max_users --- htdocs/resource/class/dolresource.class.php | 58 ++++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 923c1fc24fe11..09fa31d71c9a4 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -58,10 +58,25 @@ class Dolresource extends CommonObject public $zip; /** - * @var string yown + * @var string town */ public $town; + /** + * @var string telephone number + */ + public $phone; + + /** + * @var string emil address + */ + public $email; + + /** + * @var int Maximum users + */ + public $max_users; + /** * @var string ID */ @@ -158,6 +173,9 @@ public function create(User $user, int $no_trigger = 0) $sql .= "zip,"; $sql .= "town,"; $sql .= "description,"; + $sql .= "phone,"; + $sql .= "email,"; + $sql .= "max_users,"; $sql .= "fk_country,"; $sql .= "fk_state,"; $sql .= "fk_code_type_resource,"; @@ -235,6 +253,9 @@ public function fetch($id, $ref = '') $sql .= " t.zip,"; $sql .= " t.town,"; $sql .= " t.description,"; + $sql .= " t.phone,"; + $sql .= " t.email,"; + $sql .= " t.max_users,"; $sql .= " t.fk_country,"; $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; @@ -262,11 +283,14 @@ public function fetch($id, $ref = '') $this->address = $obj->address; $this->zip = $obj->zip; $this->town = $obj->town; - $this->description = $obj->description; + $this->description = $obj->description; + $this->phone = $obj->phone; + $this->email = $obj->email; + $this->max_users = $obj->max_users; $this->country_id = $obj->fk_country; $this->state_id = $obj->fk_state; $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; @@ -310,18 +334,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 (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 (!is_numeric($this->country_id)) { $this->country_id = 0; } if (!is_numeric($this->state_id)) { $this->state_id = 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)) { @@ -335,8 +368,11 @@ public function update($user = null, $notrigger = 0) $sql .= " zip=".(isset($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null").","; $sql .= " town=".(isset($this->town) ? "'".$this->db->escape($this->town)."'" : "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_country=".($this->country_id > 0 ? (int) $this->country_id : "null").","; + $sql .= " fk_state=".($this->state_id > 0 ? (int) $this->state_id : "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); @@ -554,6 +590,9 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = []) $sql .= " t.zip,"; $sql .= " t.town,"; $sql .= " t.description,"; + $sql .= " t.phone,"; + $sql .= " t.email,"; + $sql .= " t.max_users,"; $sql .= " t.fk_country,"; $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; @@ -601,6 +640,9 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = []) $line->zip = $obj->zip; $line->town = $obj->town; $line->description = $obj->description; + $this->phone = $obj->phone; + $this->email = $obj->email; + $this->max_users = $obj->max_users; $line->country_id = $obj->fk_country; $line->state_id = $obj->fk_state; $line->fk_code_type_resource = $obj->fk_code_type_resource; From ea1e7e40cfced02e8f9fd13b749bc5377704de94 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 09:50:17 +0100 Subject: [PATCH 2/7] Cleaned code --- htdocs/resource/class/dolresource.class.php | 66 ++++++++++----------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 09fa31d71c9a4..232d544d1d58d 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -62,6 +62,21 @@ class Dolresource extends CommonObject */ public $town; + /** + * @var int ID country + */ + public $fk_country; + + /** + * @var int ID state + */ + public $fk_state; + + /** + * @var string description + */ + public $description; + /** * @var string telephone number */ @@ -84,21 +99,6 @@ class Dolresource extends CommonObject public $type_label; - /** - * @var string description - */ - public $description; - - /** - * @var int ID country - */ - public $fk_country; - - /** - * @var int ID state - */ - public $fk_state; - // Variable for a link of resource /** @@ -172,12 +172,12 @@ public function create(User $user, int $no_trigger = 0) $sql .= "address,"; $sql .= "zip,"; $sql .= "town,"; + $sql .= "fk_country,"; + $sql .= "fk_state,"; $sql .= "description,"; $sql .= "phone,"; $sql .= "email,"; $sql .= "max_users,"; - $sql .= "fk_country,"; - $sql .= "fk_state,"; $sql .= "fk_code_type_resource,"; $sql .= "note_public,"; $sql .= "note_private"; @@ -252,12 +252,12 @@ public function fetch($id, $ref = '') $sql .= " t.address,"; $sql .= " t.zip,"; $sql .= " t.town,"; + $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.description,"; $sql .= " t.phone,"; $sql .= " t.email,"; $sql .= " t.max_users,"; - $sql .= " t.fk_country,"; - $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.note_public,"; $sql .= " t.note_private,"; @@ -283,12 +283,12 @@ public function fetch($id, $ref = '') $this->address = $obj->address; $this->zip = $obj->zip; $this->town = $obj->town; + $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->country_id = $obj->fk_country; - $this->state_id = $obj->fk_state; $this->fk_code_type_resource = $obj->fk_code_type_resource; $this->note_public = $obj->note_public; $this->note_private = $obj->note_private; @@ -334,6 +334,12 @@ public function update($user = null, $notrigger = 0) if (isset($this->town)) { $this->town = trim($this->town); } + 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); } @@ -346,12 +352,6 @@ public function update($user = null, $notrigger = 0) if (!is_numeric($this->max_users)) { $this->max_users = 0; } - if (!is_numeric($this->country_id)) { - $this->country_id = 0; - } - if (!is_numeric($this->state_id)) { - $this->state_id = 0; - } if (isset($this->fk_code_type_resource)) { $this->fk_code_type_resource = trim($this->fk_code_type_resource); } @@ -367,12 +367,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 .= " 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_country=".($this->country_id > 0 ? (int) $this->country_id : "null").","; - $sql .= " fk_state=".($this->state_id > 0 ? (int) $this->state_id : "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); @@ -589,12 +589,12 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = []) $sql .= " t.address,"; $sql .= " t.zip,"; $sql .= " t.town,"; + $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.description,"; $sql .= " t.phone,"; $sql .= " t.email,"; $sql .= " t.max_users,"; - $sql .= " t.fk_country,"; - $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.tms,"; // Add fields from extrafields @@ -639,12 +639,12 @@ public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = []) $line->address = $obj->address; $line->zip = $obj->zip; $line->town = $obj->town; + $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->country_id = $obj->fk_country; - $line->state_id = $obj->fk_state; $line->fk_code_type_resource = $obj->fk_code_type_resource; $line->type_label = $obj->type_label; From 72e54583967beda0d3aff30da0adf5d838f2d42b Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 11:05:05 +0100 Subject: [PATCH 3/7] Added phone, email & max_users --- htdocs/resource/card.php | 68 +++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index d44427bc1dac3..754dfc1f2cdd0 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -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) { @@ -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); @@ -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'); @@ -294,6 +303,27 @@ $doleditor->Create(); print ''; + // Phone + print ''.$form->editfieldkey('Phone', 'phone', '', $object, 0).''; + print ''; + print img_picto('', 'object_phoning', 'class="pictofixedwidth"'); + print ''; + print ''; + + // Email + print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').''; + print ''; + print img_picto('', 'object_email', 'class="pictofixedwidth"'); + print ''; + print ''; + + // Max users + print ''.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0, 'string', '').''; + print ''; + print img_picto('', 'object_user', 'class="pictofixedwidth"'); + print ''; + print ''; + // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -353,6 +383,30 @@ print ''; print ''; + // Phone + print ''; + print ''.$langs->trans("Phone").''; + print ''; + print $object->phone; + print ''; + print ''; + + // Email + print ''; + print ''.$langs->trans("Email").''; + print ''; + print $object->email; + print ''; + print ''; + + // Max users + print ''; + print ''.$langs->trans("MaxUsers").''; + print ''; + print $object->max_users; + print ''; + print ''; + // Origin country code print ''; print ''.$langs->trans("CountryOrigin").''; From 3a63128324200d525d2ea298c3a7ee560c93ecfc Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 11:27:33 +0100 Subject: [PATCH 4/7] Cleaned code. Removed fields shown in header. --- htdocs/resource/card.php | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 754dfc1f2cdd0..8a3ebb4ae6699 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -299,7 +299,7 @@ print ''.$langs->trans("Description").''; print ''; 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 ''; @@ -307,14 +307,14 @@ print ''.$form->editfieldkey('Phone', 'phone', '', $object, 0).''; print ''; print img_picto('', 'object_phoning', 'class="pictofixedwidth"'); - print ''; + print ''; print ''; // Email print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').''; print ''; print img_picto('', 'object_email', 'class="pictofixedwidth"'); - print ''; + print ''; print ''; // Max users @@ -383,22 +383,6 @@ print ''; print ''; - // Phone - print ''; - print ''.$langs->trans("Phone").''; - print ''; - print $object->phone; - print ''; - print ''; - - // Email - print ''; - print ''.$langs->trans("Email").''; - print ''; - print $object->email; - print ''; - print ''; - // Max users print ''; print ''.$langs->trans("MaxUsers").''; @@ -407,14 +391,6 @@ print ''; print ''; - // Origin country code - print ''; - print ''.$langs->trans("CountryOrigin").''; - print ''; - print getCountry($object->country_id, 0, $db); - print ''; - - // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; From c97e375f1e85ee346cce87cb89e9c12c5fd42427 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 11:42:09 +0100 Subject: [PATCH 5/7] Cleaned code --- htdocs/resource/card.php | 16 ++++++++-------- htdocs/resource/class/dolresource.class.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 8a3ebb4ae6699..0c1e658104844 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -126,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 { @@ -195,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 { @@ -229,7 +229,7 @@ if ($action == 'create' || $action == 'edit') { if (!$user->hasRight('resource', 'write')) { - accessforbidden('', 0, 1); + accessforbidden('', 0); } // Create/Edit object @@ -242,7 +242,7 @@ // Ref print ''.$langs->trans("ResourceFormLabel_ref").''; - print ''; + print ''; // Address print ''.$form->editfieldkey('Address', 'address', '', $object, 0).''; @@ -266,7 +266,7 @@ // Origin country print ''.$langs->trans("CountryOrigin").''; - 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); } @@ -311,14 +311,14 @@ print ''; // Email - print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').''; + print ''.$form->editfieldkey('EMail', 'email', '', $object, 0).''; print ''; print img_picto('', 'object_email', 'class="pictofixedwidth"'); print ''; print ''; // Max users - print ''.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0, 'string', '').''; + print ''.$form->editfieldkey('MaxUsers', 'max_users', '', $object, 0).''; print ''; print img_picto('', 'object_user', 'class="pictofixedwidth"'); print ''; @@ -356,7 +356,7 @@ $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref'); print '
'; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 232d544d1d58d..e2de0f7addcc9 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -83,7 +83,7 @@ class Dolresource extends CommonObject public $phone; /** - * @var string emil address + * @var string email address */ public $email; From 1b5ea15549a4800e689ab9d3661530a2933109a0 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 12:00:06 +0100 Subject: [PATCH 6/7] Fixed resource create --- htdocs/resource/class/dolresource.class.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e2de0f7addcc9..da59c1ec275d4 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -158,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); From 3428f49a406141eca344cb7c6bc2fab8a5ee2642 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 15 Feb 2024 12:18:59 +0100 Subject: [PATCH 7/7] Add MaxUsers localization --- htdocs/langs/en_US/resource.lang | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/langs/en_US/resource.lang b/htdocs/langs/en_US/resource.lang index e8574dc680f83..252537f002291 100644 --- a/htdocs/langs/en_US/resource.lang +++ b/htdocs/langs/en_US/resource.lang @@ -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.)