From 57ef86fdde55a300db3ee59089df6ee36664d25b Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 15:52:20 +0200 Subject: [PATCH 001/145] NEW added address, zip & town to resource object --- htdocs/resource/class/dolresource.class.php | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e60f6a7a352..e5b3ae43b88 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -44,6 +44,12 @@ class Dolresource extends CommonObject */ public $picto = 'resource'; + /** + * @var string address variables + */ + public $address; + public $zip; + public $town; /** * @var int ID @@ -122,6 +128,15 @@ class Dolresource extends CommonObject if (isset($this->ref)) { $this->ref = trim($this->ref); } + if (isset($this->address)) { + $this->address = trim($this->address); + } + if (isset($this->zip)) { + $this->zip = trim($this->zip); + } + if (isset($this->town)) { + $this->town = trim($this->town); + } if (isset($this->description)) { $this->description = trim($this->description); } @@ -143,6 +158,9 @@ class Dolresource extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; $sql .= "entity,"; $sql .= "ref,"; + $sql .= "address,"; + $sql .= "zip,"; + $sql .= "town,"; $sql .= "description,"; $sql .= "fk_country,"; $sql .= "fk_code_type_resource,"; @@ -219,6 +237,9 @@ class Dolresource extends CommonObject $sql .= " t.rowid,"; $sql .= " t.entity,"; $sql .= " t.ref,"; + $sql .= " t.address,"; + $sql .= " t.zip,"; + $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; $sql .= " t.fk_code_type_resource,"; @@ -243,6 +264,9 @@ class Dolresource extends CommonObject $this->id = $obj->rowid; $this->entity = $obj->entity; $this->ref = $obj->ref; + $this->address = $obj->address; + $this->zip = $obj->zip; + $this->town = $obj->zip; $this->description = $obj->description; $this->country_id = $obj->fk_country; $this->fk_code_type_resource = $obj->fk_code_type_resource; @@ -281,6 +305,15 @@ class Dolresource extends CommonObject if (isset($this->ref)) { $this->ref = trim($this->ref); } + if (isset($this->address)) { + $this->address = trim($this->address); + } + if (isset($this->zip)) { + $this->zip = trim($this->zip); + } + 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); } @@ -299,6 +332,9 @@ class Dolresource extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; + $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 .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " fk_country=".($this->country_id > 0 ? $this->country_id : "null").","; $sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").","; @@ -517,6 +553,9 @@ class Dolresource extends CommonObject $sql .= " t.rowid,"; $sql .= " t.entity,"; $sql .= " t.ref,"; + $sql .= " t.address,"; + $sql .= " t.zip,"; + $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; $sql .= " t.fk_code_type_resource,"; @@ -560,6 +599,9 @@ class Dolresource extends CommonObject $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->ref = $obj->ref; + $line->address = $obj->address; + $line->zip = $obj->zip; + $line->town = $obj->town; $line->description = $obj->description; $line->country_id = $obj->fk_country; $line->fk_code_type_resource = $obj->fk_code_type_resource; From 19484ac5d5700b6cfb39affd81f7f18c864b2920 Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 17:03:24 +0200 Subject: [PATCH 002/145] Added getBannerAddress method. Fixed fetching town. --- htdocs/resource/class/dolresource.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index e5b3ae43b88..4c6f99e6b26 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -266,7 +266,7 @@ class Dolresource extends CommonObject $this->ref = $obj->ref; $this->address = $obj->address; $this->zip = $obj->zip; - $this->town = $obj->zip; + $this->town = $obj->town; $this->description = $obj->description; $this->country_id = $obj->fk_country; $this->fk_code_type_resource = $obj->fk_code_type_resource; @@ -969,4 +969,12 @@ class Dolresource extends CommonObject return -1; } } + + /** + * @return string + */ + public function getBannerAddress() + { + return $this->getFullAddress(1,', '); + } } From 5871f1902746f2a09a56533498ca8b266ad6ef5c Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 25 Oct 2023 17:03:52 +0200 Subject: [PATCH 003/145] Cleaned code --- htdocs/resource/card.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 3ee118d06c7..b0830755414 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -276,12 +276,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - $morehtmlref .= '
'; - - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); print '
'; From 40d22cf012cd5c1f6a6f55897a5b4ac2a8485ef6 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:09:26 +0200 Subject: [PATCH 004/145] Added address, zip & town form fields. Moved country field. --- htdocs/resource/card.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index b0830755414..301a02f8576 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -222,6 +222,34 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { print ''.$langs->trans("ResourceFormLabel_ref").''; print ''; + // Address + print ''.$form->editfieldkey('Address', 'address', '', $object, 0).''; + print ''; + print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent'); + print ''; + + // Zip / Town + print ''.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'browser->layout == 'phone' ? ' colspan="3"': '').'>'; + print $formresource->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100'); + print ''; + if ($conf->browser->layout == 'phone') { + print ''; + } + print ''.$form->editfieldkey('Town', 'town', '', $object, 0).'browser->layout == 'phone' ? ' colspan="3"': '').'>'; + print $formresource->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); + print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent'); + print ''; + + // Origin country + print ''.$langs->trans("CountryOrigin").''; + print $form->select_country($object->country_id, 'country_id'); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } + print ''; + // Type print ''.$langs->trans("ResourceType").''; print ''; @@ -236,14 +264,6 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { $doleditor->Create(); print ''; - // Origin country - print ''.$langs->trans("CountryOrigin").''; - print $form->select_country($object->country_id, 'country_id'); - if ($user->admin) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - } - print ''; - // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook From f685eb66f67ef1c150df1dd3e6442b666b632809 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:09:57 +0200 Subject: [PATCH 005/145] Added select_ziptown method --- .../class/html.formresource.class.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 527fa93a483..ef7101a12a5 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -239,4 +239,38 @@ class FormResource print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return a select list with zip codes and their town + * + * @param string $selected Preselected value + * @param string $htmlname HTML select name + * @param array $fields Array with key of fields to refresh after selection + * @param int $fieldsize Field size + * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs) + * @param string $moreattrib Add more attribute on HTML input field + * @param string $morecss More css + * @return string + */ + public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = array(), $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '') + { + // phpcs:enable + global $conf; + + $out = ''; + + $size = ''; + if (!empty($fieldsize)) { + $size = 'size="' . $fieldsize . '"'; + } + + if ($conf->use_javascript_ajax && empty($disableautocomplete)) { + $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT . '/core/ajax/ziptown.php') . "\n"; + $moreattrib .= ' autocomplete="off"'; + } + $out .= '' . "\n"; + + return $out; + } } From 905471fbdd7eecb1efe766eb0e181ff68bf78cba Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 09:30:10 +0200 Subject: [PATCH 006/145] Added address, zip & town to add, update & get logic. --- htdocs/resource/card.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 301a02f8576..326ad5a40ed 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -39,9 +39,12 @@ $id = GETPOST('id', 'int'); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); $ref = GETPOST('ref', 'alpha'); +$address = GETPOST('address', 'alpha'); +$zip = GETPOST('zipcode', 'alpha'); +$town = GETPOST('town', 'alpha'); $description = GETPOST('description', 'restricthtml'); $confirm = GETPOST('confirm', 'aZ09'); -$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); +$fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $country_id = GETPOST('country_id', 'int'); // Protection if external user @@ -98,6 +101,9 @@ if (empty($reshook)) { $action = 'create'; } else { $object->ref = $ref; + $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; @@ -138,6 +144,9 @@ if (empty($reshook)) { $res = $object->fetch($id); if ($res > 0) { $object->ref = $ref; + $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; From 96d9b1c7925514b446f3986e1d57cd56c8c1e845 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 11:44:42 +0200 Subject: [PATCH 007/145] Added address state --- htdocs/resource/card.php | 20 ++++++++++++++++++++ htdocs/resource/class/dolresource.class.php | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 326ad5a40ed..cc84eb6275e 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -46,6 +46,7 @@ $description = GETPOST('description', 'restricthtml'); $confirm = GETPOST('confirm', 'aZ09'); $fk_code_type_resource = GETPOST('fk_code_type_resource', 'alpha'); $country_id = GETPOST('country_id', 'int'); +$state_id = GETPOST('state_id', 'int'); // Protection if external user if ($user->socid > 0) { @@ -107,6 +108,7 @@ if (empty($reshook)) { $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; + $object->state_id = $state_id; // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); @@ -150,6 +152,7 @@ if (empty($reshook)) { $object->description = $description; $object->fk_code_type_resource = $fk_code_type_resource; $object->country_id = $country_id; + $object->state_id = $state_id; // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); @@ -259,6 +262,23 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { } print ''; + // State + if (empty($conf->global->SOCIETE_DISABLE_STATE)) { + if ((getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 || getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 2)) { + print ''.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).''; + } else { + print ''.$form->editfieldkey('State', 'state_id', '', $object, 0).''; + } + + if ($object->country_id) { + print img_picto('', 'state', 'class="pictofixedwidth"'); + print $formresource->select_state($object->state_id, $object->country_code); + } else { + print $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + } + print ''; + } + // Type print ''.$langs->trans("ResourceType").''; print ''; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 4c6f99e6b26..0d80b2e08e8 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -63,8 +63,11 @@ class Dolresource extends CommonObject */ public $description; + /** + * @var int ID + */ public $fk_country; - + public $fk_state; // Variable for a link of resource @@ -143,6 +146,9 @@ class Dolresource extends CommonObject 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); } @@ -163,6 +169,7 @@ class Dolresource extends CommonObject $sql .= "town,"; $sql .= "description,"; $sql .= "fk_country,"; + $sql .= "fk_state,"; $sql .= "fk_code_type_resource,"; $sql .= "note_public,"; $sql .= "note_private"; @@ -171,6 +178,7 @@ class Dolresource extends CommonObject $sql .= " ".(!isset($this->ref) ? 'NULL' : "'".$this->db->escape($this->ref)."'").","; $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").","; $sql .= " ".($this->country_id > 0 ? $this->country_id : 'null').","; + $sql .= " ".($this->state_id > 0 ? $this->state_id : 'null').","; $sql .= " ".(!isset($this->fk_code_type_resource) ? 'NULL' : "'".$this->db->escape($this->fk_code_type_resource)."'").","; $sql .= " ".(!isset($this->note_public) ? 'NULL' : "'".$this->db->escape($this->note_public)."'").","; $sql .= " ".(!isset($this->note_private) ? 'NULL' : "'".$this->db->escape($this->note_private)."'"); @@ -242,6 +250,7 @@ class Dolresource extends CommonObject $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.note_public,"; $sql .= " t.note_private,"; @@ -269,6 +278,7 @@ class Dolresource extends CommonObject $this->town = $obj->town; $this->description = $obj->description; $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; @@ -323,6 +333,9 @@ class Dolresource extends CommonObject if (!is_numeric($this->country_id)) { $this->country_id = 0; } + if (!is_numeric($this->state_id)) { + $this->state_id = 0; + } // $this->oldcopy should have been set by the caller of update (here properties were already modified) if (empty($this->oldcopy)) { @@ -337,6 +350,7 @@ class Dolresource extends CommonObject $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 .= " 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); @@ -558,6 +572,7 @@ class Dolresource extends CommonObject $sql .= " t.town,"; $sql .= " t.description,"; $sql .= " t.fk_country,"; + $sql .= " t.fk_state,"; $sql .= " t.fk_code_type_resource,"; $sql .= " t.tms,"; // Add fields from extrafields @@ -604,6 +619,7 @@ class Dolresource extends CommonObject $line->town = $obj->town; $line->description = $obj->description; $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 bef4a371d07bdcef3ea00dbbc466fb3e84b5770b Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 26 Oct 2023 11:44:58 +0200 Subject: [PATCH 008/145] Added select_state method --- .../class/html.formresource.class.php | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index ef7101a12a5..2c391cf733e 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -273,4 +273,116 @@ class FormResource return $out; } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns the drop-down list of departments/provinces/cantons for all countries or for a given country. + * In the case of an all-country list, the display breaks on the country. + * The key of the list is the code (there can be several entries for a given code but in this case, the country field differs). + * Thus the links with the departments are done on a department independently of its name. + * + * @param int $selected Code state preselected (mus be state id) + * @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show + * @param string $htmlname Id of department. If '', we want only the string with