From 1f4bd8476b057f687efec464ebeb18a13ebe7a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 15:42:15 +0100 Subject: [PATCH 01/17] doxygen --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index fe7866f3a50..9ea5808c374 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3952,7 +3952,7 @@ function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin = '1', $morecss * However, one must try to call it only within php pages, classes must return their error through their property "error". * * @param DoliDB $db Database handler - * @param string|[string] $error String or array of errors strings to show + * @param string|string[] $error String or array of errors strings to show * @param array $errors Array of errors * @return void * @see dol_htmloutput_errors() @@ -6691,7 +6691,7 @@ function dolGetFirstLastname($firstname, $lastname, $nameorder = -1) * Note: Calling dol_htmloutput_events is done into pages by standard llxFooter() function. * Note: Prefer to use setEventMessages instead. * - * @param string|[string] $mesgs Message string or array + * @param string|string[] $mesgs Message string or array * @param string $style Which style to use ('mesgs' by default, 'warnings', 'errors') * @return void * @see dol_htmloutput_events() From 3efcb0dfeb2286532fa8c5e321fa0d05eb16ebf8 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Sun, 25 Oct 2020 16:19:16 +0100 Subject: [PATCH 02/17] Display application Title if filled on login page --- htdocs/core/tpl/login.tpl.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 6ae102d47fb..3f4507ebfe3 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -52,7 +52,13 @@ $arrayofjs = array( '/includes/jstz/jstz.min.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION)), '/core/js/dst.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION)) ); -$titleofloginpage = $langs->trans('Login').' @ '.$titletruedolibarrversion; // $titletruedolibarrversion is defined by dol_loginfunction in security2.lib.php. We must keep the @, some tools use it to know it is login page and find true dolibarr version. + +// we display application title instead Login term +if (!empty($conf->global->MAIN_APPLICATION_TITLE)) + $titleofloginpage = $conf->global->MAIN_APPLICATION_TITLE; +else + $titleofloginpage = $langs->trans('Login'); +$titleofloginpage.= ' @ '.$titletruedolibarrversion; // $titletruedolibarrversion is defined by dol_loginfunction in security2.lib.php. We must keep the @, some tools use it to know it is login page and find true dolibarr version. $disablenofollow = 1; if (!preg_match('/'.constant('DOL_APPLICATION_TITLE').'/', $title)) $disablenofollow = 0; From 949be12e19cade59ab345f9729974d7b9ff98381 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 25 Oct 2020 17:26:15 +0100 Subject: [PATCH 03/17] fix migration livraison to delivery --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 7 +++++-- htdocs/install/mysql/tables/llx_deliverydet.key.sql | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index a73ca40d86f..9957e23e012 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -456,9 +456,12 @@ ALTER TABLE llx_delivery ADD CONSTRAINT fk_delivery_fk_soc FOREIGN KEY (fk_soc ALTER TABLE llx_delivery ADD CONSTRAINT fk_delivery_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); ALTER TABLE llx_delivery ADD CONSTRAINT fk_delivery_fk_user_valid FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid); -ALTER TABLE llx_deliverydet CHANGE COLUMN fk_livraison fk_delivery integer; +ALTER TABLE llx_deliverydet DROP CONSTRAINT fk_livraisondet_fk_livraison; +ALTER TABLE llx_deliverydet DROP INDEX idx_livraisondet_fk_expedition; +ALTER TABLE llx_deliverydet CHANGE COLUMN fk_livraison fk_delivery integer; +ALTER TABLE llx_deliverydet ADD INDEX idx_deliverydet_fk_delivery (fk_delivery); +ALTER TABLE llx_deliverydet ADD CONSTRAINT fk_deliverydet_fk_delivery FOREIGN KEY (fk_delivery) REFERENCES llx_delivery (rowid); --- update llx_extrafields UPDATE llx_extrafields SET elementtype = 'delivery' WHERE elementtype = 'livraison'; UPDATE llx_extrafields SET elementtype = 'deliverydet' WHERE elementtype = 'livraisondet'; diff --git a/htdocs/install/mysql/tables/llx_deliverydet.key.sql b/htdocs/install/mysql/tables/llx_deliverydet.key.sql index 67ad3c37615..ce302383f4b 100644 --- a/htdocs/install/mysql/tables/llx_deliverydet.key.sql +++ b/htdocs/install/mysql/tables/llx_deliverydet.key.sql @@ -18,5 +18,5 @@ -- =================================================================== -ALTER TABLE llx_deliverydet ADD INDEX idx_deliverydet_fk_expedition (fk_delivery); +ALTER TABLE llx_deliverydet ADD INDEX idx_deliverydet_fk_delivery (fk_delivery); ALTER TABLE llx_deliverydet ADD CONSTRAINT fk_deliverydet_fk_delivery FOREIGN KEY (fk_delivery) REFERENCES llx_delivery (rowid); From f2d21d68d68173de15bc4dbc5a8a126901865551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 18:23:00 +0100 Subject: [PATCH 04/17] selectTypeContact return void --- htdocs/core/tpl/contacts.tpl.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php index 1cb8b813001..012c39c126d 100644 --- a/htdocs/core/tpl/contacts.tpl.php +++ b/htdocs/core/tpl/contacts.tpl.php @@ -108,7 +108,7 @@ if ($permission) element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) $tmpobject = $objectsrc; - echo $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal'); + $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal'); ?>
 
">
@@ -117,8 +117,7 @@ if ($permission)
address = 'Twist road'; @@ -239,7 +247,8 @@ class Don extends CommonObject $this->note_private = 'Private note'; $this->note_public = 'Public note'; $this->email = 'email@email.com'; - $this->note = ''; + $this->phone = '0123456789'; + $this->phone_mobile = '0606060606'; $this->statut = 1; } @@ -392,17 +401,17 @@ class Don extends CommonObject $sql .= ", '".$this->db->escape($this->address)."'"; $sql .= ", '".$this->db->escape($this->zip)."'"; $sql .= ", '".$this->db->escape($this->town)."'"; - $sql .= ", ".($this->country_id > 0 ? $this->country_id : '0'); - $sql .= ", ".((int) $this->public); - $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : "null"); + $sql .= ", ".(int) $this->country_id; + $sql .= ", ".(int) $this->public; + $sql .= ", ".($this->fk_project > 0 ? (int) $this->fk_project : "null"); $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); $sql .= ", ".$user->id; $sql .= ", null"; $sql .= ", '".$this->db->idate($this->date)."'"; - $sql .= ", '".$this->db->escape($this->email)."'"; - $sql .= ", '".$this->db->escape($this->phone)."'"; - $sql .= ", '".$this->db->escape($this->phone_mobile)."'"; + $sql .= ", '".$this->db->escape(trim($this->email))."'"; + $sql .= ", '".$this->db->escape(trim($this->phone))."'"; + $sql .= ", '".$this->db->escape(trim($this->phone_mobile))."'"; $sql .= ")"; $resql = $this->db->query($sql); @@ -426,13 +435,9 @@ class Don extends CommonObject // Update extrafield if (!$error) { - if (!$error) - { - $result = $this->insertExtraFields(); - if ($result < 0) - { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } } @@ -490,9 +495,9 @@ class Don extends CommonObject $sql .= ",note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); $sql .= ",datedon='".$this->db->idate($this->date)."'"; $sql .= ",date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null"); - $sql .= ",email='".$this->db->escape($this->email)."'"; - $sql .= ",phone='".$this->db->escape($this->phone)."'"; - $sql .= ",phone_mobile='".$this->db->escape($this->phone_mobile)."'"; + $sql .= ",email='".$this->db->escape(trim($this->email))."'"; + $sql .= ",phone='".$this->db->escape(trim($this->phone))."'"; + $sql .= ",phone_mobile='".$this->db->escape(trim($this->phone_mobile))."'"; $sql .= ",fk_statut=".$this->statut; $sql .= " WHERE rowid = ".$this->id; @@ -511,13 +516,10 @@ class Don extends CommonObject // Update extrafield if (!$error) { - if (!$error) + $result = $this->insertExtraFields(); + if ($result < 0) { - $result = $this->insertExtraFields(); - if ($result < 0) - { - $error++; - } + $error++; } } @@ -555,18 +557,14 @@ class Don extends CommonObject $this->db->begin(); - if (!$error) - { - if (!$notrigger) - { - // Call trigger - $result = $this->call_trigger('DON_DELETE', $user); + if (!$error && !$notrigger) { + // Call trigger + $result = $this->call_trigger('DON_DELETE', $user); - if ($result < 0) { - $error++; - } - // End call triggers + if ($result < 0) { + $error++; } + // End call triggers } // Delete donation From 772661c6ba3203ff3795222d5124060f7e509569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 19:44:01 +0100 Subject: [PATCH 06/17] clean code --- htdocs/categories/class/categorie.class.php | 359 +++++++------------- htdocs/categories/edit.php | 35 +- 2 files changed, 138 insertions(+), 256 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index d3752ef43d8..0a7654917a5 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -208,6 +208,11 @@ class Categorie extends CommonObject */ public $color; + /** + * @var int Visible + */ + public $visible; + /** * @var int Id of thirdparty when CATEGORY_ASSIGNED_TO_A_CUSTOMER is set */ @@ -312,11 +317,9 @@ class Categorie extends CommonObject $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext"; $sql .= ", date_creation, tms, fk_user_creat, fk_user_modif"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; - if ($id > 0) - { + if ($id > 0) { $sql .= " WHERE rowid = ".$id; - } elseif (!empty($ref_ext)) - { + } elseif (!empty($ref_ext)) { $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'"; } else { $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; @@ -325,27 +328,25 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql) > 0) - { + if ($resql) { + if ($this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); $this->id = $res['rowid']; //$this->ref = $res['rowid']; - $this->fk_parent = $res['fk_parent']; + $this->fk_parent = (int) $res['fk_parent']; $this->label = $res['label']; $this->description = $res['description']; $this->color = $res['color']; - $this->socid = $res['fk_soc']; - $this->visible = $res['visible']; - $this->type = $res['type']; + $this->socid = (int) $res['fk_soc']; + $this->visible = (int) $res['visible']; + $this->type = (int) $res['type']; $this->ref_ext = $res['ref_ext']; - $this->entity = $res['entity']; + $this->entity = (int) $res['entity']; $this->date_creation = $this->db->jdate($res['date_creation']); $this->date_modification = $this->db->jdate($res['tms']); - $this->user_creation = $res['fk_user_creat']; - $this->user_modification = $res['fk_user_modif']; + $this->user_creation = (int) $res['fk_user_creat']; + $this->user_modification = (int) $res['fk_user_modif']; // Retrieve all extrafield // fetch optionals attributes and labels @@ -397,8 +398,7 @@ class Categorie extends CommonObject if (empty($this->visible)) $this->visible = 0; $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0); - if ($this->already_exists()) - { + if ($this->already_exists()) { $this->error = $langs->trans("ImpossibleAddCat", $this->label); $this->error .= " : ".$langs->trans("CategoryExistsAtSameLevel"); dol_syslog($this->error, LOG_WARNING); @@ -412,8 +412,7 @@ class Categorie extends CommonObject $sql .= " label,"; $sql .= " description,"; $sql .= " color,"; - if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) - { + if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) { $sql .= "fk_soc,"; } $sql .= " visible,"; @@ -424,54 +423,47 @@ class Categorie extends CommonObject $sql .= " date_creation,"; $sql .= " fk_user_creat"; $sql .= ") VALUES ("; - $sql .= $this->db->escape($this->fk_parent).","; + $sql .= (int) $this->fk_parent.","; $sql .= "'".$this->db->escape($this->label)."',"; $sql .= "'".$this->db->escape($this->description)."',"; $sql .= "'".$this->db->escape($this->color)."',"; - if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) - { + if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) { $sql .= ($this->socid != -1 ? $this->socid : 'null').","; } $sql .= "'".$this->db->escape($this->visible)."',"; $sql .= $this->db->escape($type).","; $sql .= (!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : 'null').","; $sql .= (!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : 'null').","; - $sql .= $this->db->escape($conf->entity).","; + $sql .= (int) $conf->entity.","; $sql .= "'".$this->db->idate($now)."', "; $sql .= (int) $user->id; $sql .= ")"; $res = $this->db->query($sql); - if ($res) - { + if ($res) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX."categorie"); - if ($id > 0) - { + if ($id > 0) { $this->id = $id; $action = 'create'; // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('CATEGORY_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return $id; } else { @@ -510,8 +502,7 @@ class Categorie extends CommonObject $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0); $this->visible = ($this->visible != "" ? intval($this->visible) : 0); - if ($this->already_exists()) - { + if ($this->already_exists()) { $this->error = $langs->trans("ImpossibleUpdateCat"); $this->error .= " : ".$langs->trans("CategoryExistsAtSameLevel"); return -1; @@ -524,8 +515,7 @@ class Categorie extends CommonObject $sql .= " description = '".$this->db->escape($this->description)."',"; $sql .= " ref_ext = '".$this->db->escape($this->ref_ext)."',"; $sql .= " color = '".$this->db->escape($this->color)."'"; - if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) - { + if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) { $sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null'); } $sql .= ", visible = '".$this->db->escape($this->visible)."'"; @@ -534,22 +524,18 @@ class Categorie extends CommonObject $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $action = 'update'; // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('CATEGORY_MODIFY', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } @@ -586,8 +572,7 @@ class Categorie extends CommonObject $this->db->begin(); - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('CATEGORY_DELETE', $user); if ($result < 0) $error++; @@ -595,14 +580,12 @@ class Categorie extends CommonObject } /* FIX #1317 : Check for child category and move up 1 level*/ - if (!$error) - { + if (!$error) { $sql = "UPDATE ".MAIN_DB_PREFIX."categorie"; $sql .= " SET fk_parent = ".$this->fk_parent; $sql .= " WHERE fk_parent = ".$this->id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->error = $this->db->lasterror(); $error++; } @@ -630,18 +613,15 @@ class Categorie extends CommonObject } // Removed extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete erreur ".$this->error, LOG_ERR); } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -676,29 +656,23 @@ class Categorie extends CommonObject $sql .= " VALUES (".$this->id.", ".$obj->id.")"; dol_syslog(get_class($this).'::add_type', LOG_DEBUG); - if ($this->db->query($sql)) - { - if (!empty($conf->global->CATEGORIE_RECURSIV_ADD)) - { + if ($this->db->query($sql)) { + if (!empty($conf->global->CATEGORIE_RECURSIV_ADD)) { $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'categorie'; $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::add_type", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql) > 0) - { + if ($resql) { + if ($this->db->num_rows($resql) > 0) { $objparent = $this->db->fetch_object($resql); - if (!empty($objparent->fk_parent)) - { + if (!empty($objparent->fk_parent)) { $cat = new Categorie($this->db); $cat->id = $objparent->fk_parent; if (!$cat->containsObject($type, $obj->id)) { $result = $cat->add_type($obj, $type); - if ($result < 0) - { + if ($result < 0) { $this->error = $cat->error; $error++; } @@ -710,8 +684,7 @@ class Categorie extends CommonObject $this->error = $this->db->lasterror(); } - if ($error) - { + if ($error) { $this->db->rollback(); return -1; } @@ -725,8 +698,7 @@ class Categorie extends CommonObject if ($result < 0) { $error++; } // End call triggers - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -735,8 +707,7 @@ class Categorie extends CommonObject } } else { $this->db->rollback(); - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $this->db->lasterrno(); return -3; } else { @@ -778,16 +749,14 @@ class Categorie extends CommonObject $sql .= " AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".$obj->id; dol_syslog(get_class($this).'::del_type', LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { // Call trigger $this->context = array('unlinkoff'=>$obj); // Save object we want to link category to into category instance to provide information to trigger $result = $this->call_trigger('CATEGORY_UNLINK', $user); if ($result < 0) { $error++; } // End call triggers - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -829,8 +798,7 @@ class Categorie extends CommonObject $sql .= " AND c.fk_categorie = ".$this->id; $sql .= " AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = o.rowid"; // Protection for external users - if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) - { + if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) { $sql .= " AND o.rowid = ".$user->socid; } if ($limit > 0 || $offset > 0) $sql .= $this->db->plimit($limit + 1, $offset); @@ -838,10 +806,8 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - while ($rec = $this->db->fetch_array($resql)) - { + if ($resql) { + while ($rec = $this->db->fetch_array($resql)) { if ($onlyids) { $objs[] = $rec['fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])]; } else { @@ -927,20 +893,17 @@ class Categorie extends CommonObject $offset = 0; $nbtotalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) - { + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $this->db->query($sql); $nbtotalofrecords = $this->db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } } if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -949,17 +912,14 @@ class Categorie extends CommonObject } $result = $this->db->query($sql); - if ($result) - { + if ($result) { $i = 0; $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $category_static = new Categorie($this->db); - if ($category_static->fetch($obj->rowid)) - { + if ($category_static->fetch($obj->rowid)) { $categories[$i]['id'] = $category_static->id; $categories[$i]['fk_parent'] = $category_static->fk_parent; $categories[$i]['label'] = $category_static->label; @@ -1004,11 +964,9 @@ class Categorie extends CommonObject $sql .= " AND entity IN (".getEntity('category').")"; $res = $this->db->query($sql); - if ($res) - { + if ($res) { $cats = array(); - while ($rec = $this->db->fetch_array($res)) - { + while ($rec = $this->db->fetch_array($res)) { $cat = new Categorie($this->db); $cat->fetch($rec['rowid']); $cats[] = $cat; @@ -1039,10 +997,8 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::load_motherof", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->motherof[$obj->id_son] = $obj->id_parent; } return 1; @@ -1083,19 +1039,15 @@ class Categorie extends CommonObject return -1; } - if (is_string($markafterid)) - { + if (is_string($markafterid)) { $markafterid = explode(',', $markafterid); - } elseif (is_numeric($markafterid)) - { - if ($markafterid > 0) - { + } elseif (is_numeric($markafterid)) { + if ($markafterid > 0) { $markafterid = array($markafterid); } else { $markafterid = array(); } - } elseif (!is_array($markafterid)) - { + } elseif (!is_array($markafterid)) { $markafterid = array(); } @@ -1115,11 +1067,9 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::get_full_arbo get category list", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $this->cats[$obj->rowid]['rowid'] = $obj->rowid; $this->cats[$obj->rowid]['id'] = $obj->rowid; $this->cats[$obj->rowid]['fk_parent'] = $obj->fk_parent; @@ -1137,15 +1087,13 @@ class Categorie extends CommonObject // We add the fullpath property to each elements of first level (no parent exists) dol_syslog(get_class($this)."::get_full_arbo call to build_path_from_id_categ", LOG_DEBUG); - foreach ($this->cats as $key => $val) - { + foreach ($this->cats as $key => $val) { //print 'key='.$key.'
'."\n"; $this->build_path_from_id_categ($key, 0); // Process a branch from the root category key (this category has no parent) } // Include or exclude leaf including $markafterid from tree - if (count($markafterid) > 0) - { + if (count($markafterid) > 0) { $keyfiltercatid = '('.implode('|', $markafterid).')'; //print "Look to discard category ".$markafterid."\n"; @@ -1153,13 +1101,11 @@ class Categorie extends CommonObject $keyfilter2 = '_'.$keyfiltercatid.'$'; $keyfilter3 = '^'.$keyfiltercatid.'_'; $keyfilter4 = '_'.$keyfiltercatid.'_'; - foreach ($this->cats as $key => $val) - { + foreach ($this->cats as $key => $val) { $test = (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath']) || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath'])); - if (($test && !$include) || (!$test && $include)) - { + if (($test && !$include) || (!$test && $include)) { unset($this->cats[$key]); } } @@ -1189,8 +1135,7 @@ class Categorie extends CommonObject // phpcs:enable dol_syslog(get_class($this)."::build_path_from_id_categ id_categ=".$id_categ." protection=".$protection, LOG_DEBUG); - if (!empty($this->cats[$id_categ]['fullpath'])) - { + if (!empty($this->cats[$id_categ]['fullpath'])) { // Already defined dol_syslog(get_class($this)."::build_path_from_id_categ fullpath and fulllabel already defined", LOG_WARNING); return; @@ -1204,8 +1149,7 @@ class Categorie extends CommonObject $this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label']; $i = 0; $cursor_categ = $id_categ; //print 'Work for id_categ='.$id_categ.'
'."\n"; - while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) - { + while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) { //print '  cursor_categ='.$cursor_categ.' i='.$i.' '.$this->motherof[$cursor_categ].'
'."\n"; $this->cats[$id_categ]['fullpath'] = '_'.$this->motherof[$cursor_categ].$this->cats[$id_categ]['fullpath']; $this->cats[$id_categ]['fulllabel'] = $this->cats[$this->motherof[$cursor_categ]]['label'].' >> '.$this->cats[$id_categ]['fulllabel']; @@ -1231,8 +1175,7 @@ class Categorie extends CommonObject { // phpcs:enable // Display $this->cats - foreach ($this->cats as $key => $val) - { + foreach ($this->cats as $key => $val) { print 'id: '.$this->cats[$key]['id']; print ' label: '.$this->cats[$key]['label']; print ' mother: '.$this->cats[$key]['fk_parent']; @@ -1265,11 +1208,9 @@ class Categorie extends CommonObject $sql .= " AND fk_parent = 0"; $res = $this->db->query($sql); - if ($res) - { + if ($res) { $cats = array(); - while ($rec = $this->db->fetch_array($res)) - { + while ($rec = $this->db->fetch_array($res)) { $cat = new Categorie($this->db); $cat->fetch($rec['rowid']); $cats[$rec['rowid']] = $cat; @@ -1319,18 +1260,15 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::already_exists", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql) > 0) // Checking for empty resql - { + if ($resql) { + if ($this->db->num_rows($resql) > 0) { // Checking for empty resql $obj = $this->db->fetch_array($resql); /* If object called create, obj cannot have is id. * If object called update, he mustn't have the same label as an other category for this mother. * So if the result have the same id, update is not for label, and if result have an other one, * update may be for label. */ - if ($obj[0] > 0 && $obj[0] != $this->id) - { + if ($obj[0] > 0 && $obj[0] != $this->id) { dol_syslog(get_class($this)."::already_exists category with name=".$this->label." and parent ".$this->fk_parent." exists: rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); return 1; } @@ -1361,24 +1299,19 @@ class Categorie extends CommonObject $ways = array(); $allways = $this->get_all_ways(); // Load array of categories - foreach ($allways as $way) - { + foreach ($allways as $way) { $w = array(); $i = 0; $forced_color = ''; - foreach ($way as $cat) - { + foreach ($way as $cat) { $i++; - if (empty($nocolor)) - { + if (empty($nocolor)) { $forced_color = 'toreplace'; - if ($i == count($way)) - { + if ($i == count($way)) { // Check contrast with background and correct text color $forced_color = 'categtextwhite'; - if ($cat->color) - { + if ($cat->color) { if (colorIsLight($cat->color)) $forced_color = 'categtextblack'; } } @@ -1421,12 +1354,9 @@ class Categorie extends CommonObject $res = $this->db->query($sql); - if ($res) - { - while ($rec = $this->db->fetch_array($res)) - { - if ($rec['fk_parent'] > 0) - { + if ($res) { + while ($rec = $this->db->fetch_array($res)) { + if ($rec['fk_parent'] > 0) { $cat = new Categorie($this->db); $cat->fetch($rec['fk_parent']); $parents[] = $cat; @@ -1452,13 +1382,10 @@ class Categorie extends CommonObject $ways = array(); $parents = $this->get_meres(); - if (!empty($parents)) - { - foreach ($parents as $parent) - { + if (!empty($parents)) { + foreach ($parents as $parent) { $allways = $parent->get_all_ways(); - foreach ($allways as $way) - { + foreach ($allways as $way) { $w = $way; $w[] = $this; $ways[] = $w; @@ -1488,8 +1415,7 @@ class Categorie extends CommonObject if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; - if ($type === Categorie::TYPE_BANK_LINE) // TODO Remove this with standard category code - { + if ($type === Categorie::TYPE_BANK_LINE) { // TODO Remove this with standard category code // Load bank groups $sql = "SELECT c.label, c.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c"; @@ -1497,10 +1423,8 @@ class Categorie extends CommonObject $sql .= " ORDER BY c.label"; $res = $this->db->query($sql); - if ($res) - { - while ($obj = $this->db->fetch_object($res)) - { + if ($res) { + while ($obj = $this->db->fetch_object($res)) { if ($mode == 'id') { $cats[] = $obj->rowid; } elseif ($mode == 'label') { @@ -1523,10 +1447,8 @@ class Categorie extends CommonObject $sql .= " AND c.entity IN (".getEntity('category').")"; $res = $this->db->query($sql); - if ($res) - { - while ($obj = $this->db->fetch_object($res)) - { + if ($res) { + while ($obj = $this->db->fetch_object($res)) { if ($mode == 'id') { $cats[] = $obj->rowid; } elseif ($mode == 'label') { @@ -1579,24 +1501,20 @@ class Categorie extends CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; $sql .= " WHERE type = ".$this->MAP_ID[$type]; $sql .= " AND entity IN (".getEntity('category').")"; - if ($nom) - { + if ($nom) { if (!$exact) $nom = '%'.str_replace('*', '%', $nom).'%'; if (!$case) $sql .= " AND label LIKE '".$this->db->escape($nom)."'"; else $sql .= " AND label LIKE BINARY '".$this->db->escape($nom)."'"; } - if ($id) - { + if ($id) { $sql .= " AND rowid = '".$id."'"; } $res = $this->db->query($sql); - if ($res) - { - while ($rec = $this->db->fetch_array($res)) - { + if ($res) { + while ($rec = $this->db->fetch_array($res)) { $cat = new Categorie($this->db); $cat->fetch($rec['rowid']); $cats[] = $cat; @@ -1628,8 +1546,7 @@ class Categorie extends CommonObject // Check contrast with background and correct text color $forced_color = 'categtextwhite'; - if ($this->color) - { + if ($this->color) { if (colorIsLight($this->color)) $forced_color = 'categtextblack'; } @@ -1662,14 +1579,12 @@ class Categorie extends CommonObject $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, 'category').$this->id."/"; $dir .= "photos/"; - if (!file_exists($dir)) - { + if (!file_exists($dir)) { dol_mkdir($dir); } if (file_exists($dir)) { - if (is_array($file['name']) && count($file['name']) > 0) - { + if (is_array($file['name']) && count($file['name']) > 0) { $nbfile = count($file['name']); for ($i = 0; $i <= $nbfile; $i++) { $originImage = $dir.$file['name'][$i]; @@ -1714,22 +1629,17 @@ class Categorie extends CommonObject $dirthumb = $dir.'thumbs/'; - if (file_exists($dir)) - { + if (file_exists($dir)) { $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (dol_is_file($dir.$file) && preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) - { + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (dol_is_file($dir.$file) && preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) { $nbphoto++; $photo = $file; // On determine nom du fichier vignette $photo_vignette = ''; - if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) - { + if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) { $photo_vignette = preg_replace('/'.$regs[0].'/i', '', $photo).'_small'.$regs[0]; } @@ -1773,11 +1683,9 @@ class Categorie extends CommonObject dol_delete_file($file, 1); // Si elle existe, on efface la vignette - if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) - { + if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) { $photo_vignette = preg_replace('/'.$regs[0].'/i', '', $filename).'_small'.$regs[0]; - if (file_exists($dirthumb.$photo_vignette)) - { + if (file_exists($dirthumb.$photo_vignette)) { dol_delete_file($dirthumb.$photo_vignette, 1); } } @@ -1812,8 +1720,7 @@ class Categorie extends CommonObject $langs_available = $langs->get_available_languages(); $current_lang = $langs->getDefaultLang(); - foreach ($langs_available as $key => $value) - { + foreach ($langs_available as $key => $value) { $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie_lang"; $sql .= " WHERE fk_category=".$this->id; @@ -1821,10 +1728,8 @@ class Categorie extends CommonObject $result = $this->db->query($sql); - if ($key == $current_lang) - { - if ($this->db->num_rows($result)) // si aucune ligne dans la base - { + if ($key == $current_lang) { + if ($this->db->num_rows($result)) { // si aucune ligne dans la base $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang"; $sql2 .= " SET label='".$this->db->escape($this->label)."',"; $sql2 .= " description='".$this->db->escape($this->description)."'"; @@ -1835,15 +1740,12 @@ class Categorie extends CommonObject $sql2 .= "','".$this->db->escape($this->multilangs["$key"]["description"])."')"; } dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG); - if (!$this->db->query($sql2)) - { + if (!$this->db->query($sql2)) { $this->error = $this->db->lasterror(); return -1; } - } elseif (isset($this->multilangs["$key"])) - { - if ($this->db->num_rows($result)) // si aucune ligne dans la base - { + } elseif (isset($this->multilangs["$key"])) { + if ($this->db->num_rows($result)) { // si aucune ligne dans la base $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang"; $sql2 .= " SET label='".$this->db->escape($this->multilangs["$key"]["label"])."',"; $sql2 .= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'"; @@ -1857,8 +1759,7 @@ class Categorie extends CommonObject // on ne sauvegarde pas des champs vides if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"] || $this->multilangs["$key"]["note"]) dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG); - if (!$this->db->query($sql2)) - { + if (!$this->db->query($sql2)) { $this->error = $this->db->lasterror(); return -1; } @@ -1892,13 +1793,10 @@ class Categorie extends CommonObject $sql .= " WHERE fk_category=".$this->id; $result = $this->db->query($sql); - if ($result) - { - while ($obj = $this->db->fetch_object($result)) - { + if ($result) { + while ($obj = $this->db->fetch_object($result)) { //print 'lang='.$obj->lang.' current='.$current_lang.'
'; - if ($obj->lang == $current_lang) // si on a les traduct. dans la langue courante on les charge en infos principales. - { + if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales. $this->label = $obj->label; $this->description = $obj->description; } @@ -1988,26 +1886,21 @@ class Categorie extends CommonObject { if ($type == 'bank_account') $type = 'account'; - if (empty($searchList) && !is_array($searchList)) - { + if (empty($searchList) && !is_array($searchList)) { return ""; } - foreach ($searchList as $searchCategory) - { - if (intval($searchCategory) == -2) - { + foreach ($searchList as $searchCategory) { + if (intval($searchCategory) == -2) { $searchCategorySqlList[] = " cp.fk_categorie IS NULL"; - } elseif (intval($searchCategory) > 0) - { + } elseif (intval($searchCategory) > 0) { $searchCategorySqlList[] = " ".$rowIdName ." IN (SELECT fk_".$type." FROM ".MAIN_DB_PREFIX."categorie_".$type ." WHERE fk_categorie = ".$searchCategory.")"; } } - if (!empty($searchCategorySqlList)) - { + if (!empty($searchCategorySqlList)) { return " AND (".implode(' AND ', $searchCategorySqlList).")"; } else { return ""; diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 8c05c313987..9f7aebf7fec 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -34,7 +34,7 @@ $langs->load("categories"); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alphanohtml'); -$type = GETPOST('type', 'alphanohtml'); +$type = (int) GETPOST('type', 'int'); $action = (GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'edit'); $confirm = GETPOST('confirm'); $cancel = GETPOST('cancel', 'alpha'); @@ -43,11 +43,10 @@ $socid = GETPOST('socid', 'int'); $label = GETPOST('label', 'alphanohtml'); $description = GETPOST('description', 'restricthtml'); $color = preg_replace('/[^0-9a-f#]/i', '', GETPOST('color', 'alphanohtml')); -$visible = GETPOST('visible'); -$parent = GETPOST('parent'); +$visible = (int) GETPOST('visible', 'int'); +$parent = (int) GETPOST('parent', 'int'); -if ($id == "") -{ +if ($id == "") { dol_print_error('', 'Missing parameter id'); exit(); } @@ -56,8 +55,7 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); -if ($id > 0) -{ +if ($id > 0) { $result = $object->fetch($id); } @@ -72,40 +70,32 @@ $hookmanager->initHooks(array('categorycard')); * Actions */ -if ($cancel) -{ +if ($cancel) { header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type); exit; } // Action mise a jour d'une categorie -if ($action == 'update' && $user->rights->categorie->creer) -{ +if ($action == 'update' && $user->rights->categorie->creer) { $object->oldcopy = dol_clone($object); $object->label = $label; $object->description = dol_htmlcleanlastbr($description); $object->color = $color; $object->socid = ($socid ? $socid : 'null'); $object->visible = $visible; - - if ($parent != "-1") - $object->fk_parent = $parent; - else $object->fk_parent = ""; + $object->fk_parent = $parent != -1 ? $parent : 0; - if (empty($object->label)) - { + if (empty($object->label)) { $error++; $action = 'edit'; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } - if (!$error && empty($object->error)) - { + if (!$error && empty($object->error)) { $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; - if (!$error && $object->update($user) > 0) - { + if (!$error && $object->update($user) > 0) { header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$object->id.'&type='.$type); exit; } else { @@ -173,8 +163,7 @@ print ''; $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (empty($reshook)) -{ +if (empty($reshook)) { print $object->showOptionals($extrafields, 'edit', $parameters); } From a031adf99e670ad498e47d80627d13cb318aa3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 20:07:22 +0100 Subject: [PATCH 07/17] clean code --- htdocs/categories/class/categorie.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 0a7654917a5..302366f6669 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -323,7 +323,7 @@ class Categorie extends CommonObject $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'"; } else { $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; - if (!is_null($type)) $sql .= " AND type = ".$this->db->escape($type); + if (!is_null($type)) $sql .= " AND type = ".(int) $type; } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -518,8 +518,8 @@ class Categorie extends CommonObject if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) { $sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null'); } - $sql .= ", visible = '".$this->db->escape($this->visible)."'"; - $sql .= ", fk_parent = ".$this->fk_parent; + $sql .= ", visible = ".(int) $this->visible; + $sql .= ", fk_parent = ".(int) $this->fk_parent; $sql .= ", fk_user_modif = ".(int) $user->id; $sql .= " WHERE rowid = ".$this->id; @@ -1203,7 +1203,7 @@ class Categorie extends CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; $sql .= " WHERE entity IN (".getEntity('category').")"; if (!is_null($type)) - $sql .= " AND type = ".$type; + $sql .= " AND type = ".(int) $type; if ($parent) $sql .= " AND fk_parent = 0"; From 10ff359889d3c7d354bfa61bc9c41f9548392b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 22:39:12 +0100 Subject: [PATCH 08/17] set unknow variables --- htdocs/ticket/class/ticket.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 391bd4dce2d..5ef0bb4148a 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -1515,6 +1515,8 @@ class Ticket extends CommonObject $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $sendtocc = ''; + $deliveryreceipt = 0; $mailfile = new CMailFile($subject, $info_sendto['email'], $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, 0); if ($mailfile->error || $mailfile->errors) { setEventMessages($mailfile->error, $mailfile->errors, 'errors'); From f2c0e3765d4bef91136e66dc678faeff0c6a1afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 23:29:51 +0100 Subject: [PATCH 09/17] Update card.php --- htdocs/fourn/facture/card.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index c304a4edce7..3c60501342b 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2304,20 +2304,17 @@ if ($action == 'create') if ($action == 'valid') { // We check if number is temporary number - if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) // empty should not happened, but when it occurs, the test save life - { + if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) { + // empty should not happened, but when it occurs, the test save life $numref = $object->getNextNumRef($societe); } else { $numref = $object->ref; } - if ($numref < 0) - { + if ($numref < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = ''; - } - else - { + } else { $text = $langs->trans('ConfirmValidateBill', $numref); /*if (! empty($conf->notification->enabled)) { From ab0d5514c708019a01323b29174a552a620111a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 25 Oct 2020 23:55:08 +0100 Subject: [PATCH 10/17] doxygen --- htdocs/delivery/class/delivery.class.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index bd6ef948c6c..b6614892c38 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -67,8 +67,19 @@ class Delivery extends CommonObject */ public $picto = 'sending'; - public $draft; - public $socid; + /** + * @var int draft status + */ + public $draft; + + /** + * @var int thirdparty id + */ + public $socid; + + /** + * @var string ref custome + */ public $ref_customer; /** @@ -86,7 +97,9 @@ class Delivery extends CommonObject */ public $date_valid; - + /** + * @var string model pdf + */ public $model_pdf; From 44152c934324bbba791eff174bdb61ecaf4a0fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 00:00:37 +0100 Subject: [PATCH 11/17] undefined variable --- htdocs/datapolicy/class/datapolicy.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/datapolicy/class/datapolicy.class.php b/htdocs/datapolicy/class/datapolicy.class.php index ff9abcf5dce..411e5a46b34 100644 --- a/htdocs/datapolicy/class/datapolicy.class.php +++ b/htdocs/datapolicy/class/datapolicy.class.php @@ -167,6 +167,7 @@ class DataPolicy } else { $l = $langs->defaultlang; } + // TODO Use a dolibarr email template $s = "DATAPOLICIESSUBJECT_".$l; $ma = "DATAPOLICIESCONTENT_".$l; $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l; @@ -242,6 +243,7 @@ class DataPolicy } else { $l = $langs->defaultlang; } + // TODO Use a dolibarr email template $s = "DATAPOLICIESSUBJECT_".$l; $ma = "DATAPOLICIESCONTENT_".$l; $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l; @@ -310,9 +312,6 @@ class DataPolicy $sendto = $adherent->email; - // TODO Use a dolibarr email template - $s = 'TXTLINKDATAPOLICIESSUBJECT_'.$l; - $ma = 'TXTLINKDATAPOLICIESMESSAGE_'.$l; $code = md5($adherent->email); if (!empty($adherent->default_lang)) { @@ -320,6 +319,9 @@ class DataPolicy } else { $l = $langs->defaultlang; } + // TODO Use a dolibarr email template + $s = 'TXTLINKDATAPOLICIESSUBJECT_'.$l; + $ma = 'TXTLINKDATAPOLICIESMESSAGE_'.$l; $la = 'TXTLINKDATAPOLICIESACCEPT_'.$l; $lr = 'TXTLINKDATAPOLICIESREFUSE_'.$l; From c2b6ff969a630d5e21e51bda9ed9715c5a61c981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 00:05:43 +0100 Subject: [PATCH 12/17] Update datapolicy.class.php --- htdocs/datapolicy/class/datapolicy.class.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/datapolicy/class/datapolicy.class.php b/htdocs/datapolicy/class/datapolicy.class.php index 411e5a46b34..24490b9fb19 100644 --- a/htdocs/datapolicy/class/datapolicy.class.php +++ b/htdocs/datapolicy/class/datapolicy.class.php @@ -152,7 +152,7 @@ class DataPolicy * @param mixed $contact Contact * @return void */ - public function sendMailDataPolicyContact($contact) + public static function sendMailDataPolicyContact($contact) { global $langs, $conf, $db, $user; @@ -227,7 +227,7 @@ class DataPolicy * @param Societe $societe Object societe * @return void */ - public function sendMailDataPolicyCompany($societe) + public static function sendMailDataPolicyCompany($societe) { global $langs, $conf, $db, $user; @@ -266,10 +266,8 @@ class DataPolicy $actiontypecode = 'AC_EMAIL'; $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; - if ($message) - { - if ($sendtocc) - { + if ($message) { + if ($sendtocc) { $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc); } $actionmsg .= dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject); @@ -302,7 +300,7 @@ class DataPolicy * @param Adherent $adherent Member * @return void */ - public function sendMailDataPolicyAdherent($adherent) + public static function sendMailDataPolicyAdherent($adherent) { global $langs, $conf, $db, $user; From 457f8b9766535c709a07f1f2847161aa0dc832d8 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 26 Oct 2020 10:49:07 +0100 Subject: [PATCH 13/17] fix bad link index thirdparty --- htdocs/societe/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index 24538c78d66..ddd865521d7 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -293,15 +293,15 @@ if ($result) $s = ''; if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) { - $s .= ''.dol_substr($langs->trans("Prospect"), 0, 1).''; + $s .= ''.dol_substr($langs->trans("Prospect"), 0, 1).''; } if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) { - $s .= ''.dol_substr($langs->trans("Customer"), 0, 1).''; + $s .= ''.dol_substr($langs->trans("Customer"), 0, 1).''; } if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $obj->fournisseur) { - $s .= ''.dol_substr($langs->trans("Supplier"), 0, 1).''; + $s .= ''.dol_substr($langs->trans("Supplier"), 0, 1).''; } print $s; print ''; From e7e8a91b1388c180cb1ecf85a16d34824a4182ec Mon Sep 17 00:00:00 2001 From: CHABANE HADJER <50581285+hchabane21@users.noreply.github.com> Date: Mon, 26 Oct 2020 16:38:11 +0100 Subject: [PATCH 14/17] Adding Payzen payment module hooks. --- htdocs/public/payment/newpayment.php | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index c188dd1db7a..1986416e4de 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -50,6 +50,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; +// Hook added by Payzen. +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager = new HookManager($db); +$hookmanager->initHooks(array('newpayment')); // Load translation files $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data @@ -202,6 +206,12 @@ if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->strip // Initialize $validpaymentmethod $validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod); +// This hook is used to push to $validpaymentmethod the Payzen payment method as valid. +$parameters = [ + 'paymentmethod' => $paymentmethod, + 'validpaymentmethod' => &$validpaymentmethod +]; +$reshook = $hookmanager->executeHooks('doValidatePayment', $parameters, $object, $action); // Check security token $valid = true; @@ -1641,6 +1651,12 @@ if ($action != 'dopayment') { if ($found && !$error) // We are in a management option and no error { + // Check status of the object (Invoice) to verify if it is paid in Payzen. + $parameters = [ + 'source' => $source, + 'object' => $object + ]; + $reshook = $hookmanager->executeHooks('doCheckStatus', $parameters, $object, $action); if ($source == 'order' && $object->billed) { print '

'.$langs->trans("OrderBilled").''; @@ -1661,6 +1677,11 @@ if ($action != 'dopayment') // Buttons for all payments registration methods + // This hook is used to add Payzen Button to newpayment.php. + $parameters = [ + 'paymentmethod' => $paymentmethod + ]; + $reshook = $hookmanager->executeHooks('doAddButton', $parameters, $object, $action); if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) { print '
'; @@ -2249,6 +2270,14 @@ if (preg_match('/^dopayment/', $action)) // If we choosed/click on the payment print ''; } } + // This hook is used to show the embedded form to make payments with Payzen. + $parameters = [ + 'paymentmethod' => $paymentmethod, + 'amount' => price2num(GETPOST("newamount"), 'MT'), + 'tag' => GETPOST("tag", 'alpha'), + 'dopayment' => GETPOST('dopayment', 'alpha') + ]; + $reshook = $hookmanager->executeHooks('doPayment', $parameters, $object, $action); } From b2f08e576235a7afa639585bfabd3e1d2c32c1f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 Oct 2020 19:23:23 +0100 Subject: [PATCH 15/17] Update categorie.class.php --- htdocs/categories/class/categorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 302366f6669..8d9b96976cd 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -323,7 +323,7 @@ class Categorie extends CommonObject $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'"; } else { $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; - if (!is_null($type)) $sql .= " AND type = ".(int) $type; + if (!is_null($type)) $sql .= " AND type = ".((int) $type); } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); From 5e19483c99bed54895c2fee9a6ef279ac3a20dbc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 Oct 2020 19:26:55 +0100 Subject: [PATCH 16/17] Update don.class.php --- htdocs/don/class/don.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index eedd82fc7e0..a6fa9fa987d 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -401,7 +401,7 @@ class Don extends CommonObject $sql .= ", '".$this->db->escape($this->address)."'"; $sql .= ", '".$this->db->escape($this->zip)."'"; $sql .= ", '".$this->db->escape($this->town)."'"; - $sql .= ", ".(int) $this->country_id; + $sql .= ", ".(int) ($this->country_id > 0 ? $this->country_id : 0); $sql .= ", ".(int) $this->public; $sql .= ", ".($this->fk_project > 0 ? (int) $this->fk_project : "null"); $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); From 680f4f9feeaa9a3469364043b19067c5922c9985 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 Oct 2020 19:32:21 +0100 Subject: [PATCH 17/17] Update login.tpl.php --- htdocs/core/tpl/login.tpl.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 3f4507ebfe3..07229bcfed8 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -53,11 +53,12 @@ $arrayofjs = array( '/core/js/dst.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION)) ); -// we display application title instead Login term -if (!empty($conf->global->MAIN_APPLICATION_TITLE)) +// We display application title instead Login term +if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { $titleofloginpage = $conf->global->MAIN_APPLICATION_TITLE; -else +} else { $titleofloginpage = $langs->trans('Login'); +} $titleofloginpage.= ' @ '.$titletruedolibarrversion; // $titletruedolibarrversion is defined by dol_loginfunction in security2.lib.php. We must keep the @, some tools use it to know it is login page and find true dolibarr version. $disablenofollow = 1;