From 50b27239a7dcb80b882d7998701931280a404fcd Mon Sep 17 00:00:00 2001 From: ATM john Date: Tue, 15 Dec 2020 11:34:04 +0100 Subject: [PATCH 01/11] Fix missing hook for project overview control --- htdocs/projet/class/project.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index a0b6e38423b..335b06a0456 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -576,6 +576,9 @@ class Project extends CommonObject public function get_element_list($type, $tablename, $datefieldname = '', $dates = '', $datee = '', $projectkey = 'fk_projet') { // phpcs:enable + + global $hookmanager; + $elements = array(); if ($this->id <= 0) return $elements; @@ -630,6 +633,21 @@ class Project extends CommonObject if (empty($datefieldname)) return 'Error this object has no date field defined'; $sql .= " AND (".$datefieldname." <= '".$this->db->idate($datee)."' OR ".$datefieldname." IS NULL)"; } + + $hookmanager->initHooks(array('projectdao')); + $parameters = array( + 'sql'=>$sql, + 'type' => $type, + 'tablename' => $tablename, + 'datefieldname' => $datefieldname, + 'dates' => $dates, + 'datee' => $datee, + 'fk_projet' => $projectkey + ); + $reshook = $hookmanager->executeHooks('getElementList', $parameters, $object, $action); + if ($reshook > 0) $sql = $hookmanager->resPrint; + else $sql .= $hookmanager->resPrint; + if (!$sql) return -1; //print $sql; From 1f29d4f5e8c47144db678abd0bf835e513f3964a Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 16 Dec 2020 16:25:30 +0100 Subject: [PATCH 02/11] Add missing hooks --- htdocs/projet/element.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index c513123c9bf..975b8fcdbed 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -652,9 +652,29 @@ print ''.$langs->trans("AmountTTC").''; print ''; $total_revenue_ht = 0; +$balance_ht = 0; +$balance_ttc = 0; foreach ($listofreferent as $key => $value) { + $parameters = array( + 'total_revenue_ht' =>& $total_revenue_ht, + 'balance_ht' =>& $balance_ht, + 'balance_ttc' =>& $balance_ttc, + 'key' => $key, + 'value' =>& $value, + 'dates' => $dates, + 'datee' => $datee + ); + $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + elseif ($reshook > 0){ + print $hookmanager->resPrint; + continue; + } + $name = $langs->trans($value['name']); $title = $value['title']; $classname = $value['class']; @@ -849,6 +869,22 @@ print '
'; // Detail foreach ($listofreferent as $key => $value) { + + $parameters = array( + 'key' => $key, + 'value' =>& $value, + 'dates' => $dates, + 'datee' => $datee + ); + $reshook = $hookmanager->executeHooks('printOverviewDetail', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + elseif ($reshook > 0){ + print $hookmanager->resPrint; + continue; + } + $title = $value['title']; $classname = $value['class']; $tablename = $value['table']; From e61b71bc93801a8771d4c0eead1f37838c201fa1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 16 Dec 2020 15:40:38 +0000 Subject: [PATCH 03/11] Fixing style errors. --- htdocs/projet/element.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 975b8fcdbed..b334688558b 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -869,7 +869,6 @@ print '
'; // Detail foreach ($listofreferent as $key => $value) { - $parameters = array( 'key' => $key, 'value' =>& $value, From 2cc51c1aef20b25eee544ef17ceb3bc27ff00df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 16 Dec 2020 20:13:11 +0100 Subject: [PATCH 04/11] bookmark class doxygen --- htdocs/bookmarks/class/bookmark.class.php | 75 ++++++++++++++--------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/htdocs/bookmarks/class/bookmark.class.php b/htdocs/bookmarks/class/bookmark.class.php index f7098f1d780..f5bbefae3d3 100644 --- a/htdocs/bookmarks/class/bookmark.class.php +++ b/htdocs/bookmarks/class/bookmark.class.php @@ -83,8 +83,14 @@ class Bookmark extends CommonObject */ public $title; + /** + * @var int position of bookmark + */ public $position; + /** + * @var string favicon + */ public $favicon; @@ -116,8 +122,7 @@ class Bookmark extends CommonObject dol_syslog("Bookmark::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -151,7 +156,9 @@ class Bookmark extends CommonObject // Clean parameters $this->url = trim($this->url); $this->title = trim($this->title); - if (empty($this->position)) $this->position = 0; + if (empty($this->position)) { + $this->position = 0; + } $now = dol_now(); @@ -164,17 +171,15 @@ class Bookmark extends CommonObject $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").","; $sql .= " '".$this->db->idate($now)."',"; $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',"; - $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', '".$this->db->escape($this->position)."'"; - $sql .= ", ".$this->db->escape($conf->entity); + $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position; + $sql .= ", ".(int) $conf->entity; $sql .= ")"; dol_syslog("Bookmark::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark"); - if ($id > 0) - { + if ($id > 0) { $this->id = $id; $this->db->commit(); return $id; @@ -202,7 +207,9 @@ class Bookmark extends CommonObject // Clean parameters $this->url = trim($this->url); $this->title = trim($this->title); - if (empty($this->position)) $this->position = 0; + if (empty($this->position)) { + $this->position = 0; + } $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0"); @@ -211,12 +218,11 @@ class Bookmark extends CommonObject $sql .= " ,target = '".$this->db->escape($this->target)."'"; $sql .= " ,title = '".$this->db->escape($this->title)."'"; $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'"; - $sql .= " ,position = '".$this->db->escape($this->position)."'"; + $sql .= " ,position = ".(int) $this->position; $sql .= " WHERE rowid = ".$this->id; dol_syslog("Bookmark::update", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { return 1; } else { $this->error = $this->db->lasterror(); @@ -237,8 +243,7 @@ class Bookmark extends CommonObject dol_syslog("Bookmark::remove", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { return 1; } else { $this->error = $this->db->lasterror(); @@ -288,7 +293,9 @@ class Bookmark extends CommonObject { global $conf, $langs, $hookmanager; - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } $result = ''; @@ -298,33 +305,40 @@ class Bookmark extends CommonObject $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id; - if ($option != 'nolink') - { + if ($option != 'nolink') { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowBookmark"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } else { + $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + } $linkstart = ''; $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->ref; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->ref; + } $result .= $linkend; //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); @@ -332,8 +346,11 @@ class Bookmark extends CommonObject $hookmanager->initHooks(array('mybookmarkdao')); $parameters = array('id'=>$this->id, 'getnomurl'=>$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) $result = $hookmanager->resPrint; - else $result .= $hookmanager->resPrint; + if ($reshook > 0) { + $result = $hookmanager->resPrint; + } else { + $result .= $hookmanager->resPrint; + } return $result; } From 3b19151c18639d5cb426f9e2552a5d6298a97e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 16 Dec 2020 20:15:48 +0100 Subject: [PATCH 05/11] bookmark --- htdocs/bookmarks/admin/bookmark.php | 15 ++-- htdocs/bookmarks/bookmarks.lib.php | 132 ++++++++++++++-------------- 2 files changed, 73 insertions(+), 74 deletions(-) diff --git a/htdocs/bookmarks/admin/bookmark.php b/htdocs/bookmarks/admin/bookmark.php index 9aa1989fa2e..c049d4af16f 100644 --- a/htdocs/bookmarks/admin/bookmark.php +++ b/htdocs/bookmarks/admin/bookmark.php @@ -28,20 +28,21 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; // Load translation files required by the page $langs->load("admin"); -if (!$user->admin) -accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} $action = GETPOST('action', 'aZ09'); -if ($action == 'setvalue') -{ +if ($action == 'setvalue') { $showmenu = GETPOST('BOOKMARKS_SHOW_IN_MENU', 'alpha'); $res = dolibarr_set_const($db, "BOOKMARKS_SHOW_IN_MENU", $showmenu, 'chaine', 0, '', $conf->entity); - if (!$res > 0) $error++; + if (!$res > 0) { + $error++; + } - if (!$error) - { + if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 63a95fed4c0..ffd1673ac63 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -38,20 +38,23 @@ function printDropdownBookmarksList() $url = $_SERVER["PHP_SELF"]; - if (!empty($_SERVER["QUERY_STRING"])) - { + if (!empty($_SERVER["QUERY_STRING"])) { $url .= (dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : ''); } else { global $sortfield, $sortorder; $tmpurl = ''; // No urlencode, all param $url will be urlencoded later - if ($sortfield) $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield; - if ($sortorder) $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder; - if (is_array($_POST)) - { - foreach ($_POST as $key => $val) - { - if (preg_match('/^search_/', $key) && $val != '') $tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val; + if ($sortfield) { + $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield; + } + if ($sortorder) { + $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder; + } + if (is_array($_POST)) { + foreach ($_POST as $key => $val) { + if (preg_match('/^search_/', $key) && $val != '') { + $tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val; + } } } $url .= ($tmpurl ? '?'.$tmpurl : ''); @@ -68,8 +71,7 @@ function printDropdownBookmarksList() // Url to go on create new bookmark page $newbtn = ''; - if (!empty($user->rights->bookmark->creer)) - { + if (!empty($user->rights->bookmark->creer)) { //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url); $newbtn .= ''; @@ -81,13 +83,11 @@ function printDropdownBookmarksList() $sql .= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)"; $sql .= " AND entity IN (".getEntity('bookmarks').")"; $sql .= " ORDER BY position"; - if ($resql = $db->query($sql)) - { + if ($resql = $db->query($sql)) { if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $bookmarkList = '