From 4eeee464bad25a13c4290c60eb748b1f2826ad4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Aug 2024 01:59:00 +0200 Subject: [PATCH 1/3] Code comment --- htdocs/core/modules/modAgenda.class.php | 25 +++++++++++++++++++++ htdocs/core/modules/modExpedition.class.php | 2 -- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index 3fe523af548..6f05062276d 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -101,6 +101,7 @@ class modAgenda extends DolibarrModules } else { dol_print_error($this->db->lasterror()); } + //$this->const[] = array("MAIN_AGENDA_XCAL_EXPORTKEY", "chaine", "123456", "Securekey for the public link"); // New pages on tabs // ----------------- @@ -585,4 +586,28 @@ class modAgenda extends DolibarrModules $keyforaliasextra = 'extra'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; } + + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + public function init($options = '') + { + global $conf; + + // Permissions + $this->remove($options); + + $sql = array( + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type='member' AND entity = ".((int) $conf->entity), + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','member',".((int) $conf->entity).")" + ); + + return $this->_init($sql, $options); + } } diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 36633e11f5d..0448e1a8f11 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -357,8 +357,6 @@ class modExpedition extends DolibarrModules } } - $sql = array(); - $sql = array( "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'shipping' AND entity = ".((int) $conf->entity), "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'shipping', ".((int) $conf->entity).")", From 5c36a834d126f17cde1b1f19d13fe09b65dedcba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Aug 2024 04:12:09 +0200 Subject: [PATCH 2/3] Debug v20 - Fix sql distinct --- htdocs/core/lib/company.lib.php | 31 ++++++++++++++++++------------ htdocs/langs/en_US/commercial.lang | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/user/agenda.php | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index b0b89cc5605..14fa5b0cb17 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1801,12 +1801,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agendadao')); - // Recherche histo sur actioncomm - if (is_object($objcon) && $objcon->id > 0) { - $sql = "SELECT DISTINCT a.id, a.label as label,"; - } else { - $sql = "SELECT a.id, a.label as label,"; - } + $sql = "SELECT a.id, a.label as label,"; $sql .= " a.datep as dp,"; $sql .= " a.datep2 as dp2,"; $sql .= " a.percent as percent, 'action' as type,"; @@ -1848,18 +1843,20 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr } $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; + // Link to the owner of action $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; + // Link to action types $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id"; - if (is_object($filterobj) && get_class($filterobj) !== 'User') { - $force_filter_contact = false; - } else { + // Set $force_filter_contact: + // - true for a filter on a user or a contact, so a link on table llx_actioncomm_resources or llx_actioncomm.fk_user_action + // - false for a link on table llx_element_resources + $force_filter_contact = false; + if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') { $force_filter_contact = true; } if (is_object($objcon) && $objcon->id > 0) { $force_filter_contact = true; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm"; - $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id); } // Fields from hook @@ -1896,6 +1893,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr } $sql .= " WHERE a.entity IN (".getEntity('agenda').")"; + if ($force_filter_contact === false) { if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) { $sql .= " AND a.fk_soc = ".((int) $filterobj->id); @@ -1955,7 +1953,16 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr return 'Bad value for $filterobj'; } } else { - $sql .= " AND u.rowid = ". ((int) $filterobj->id); + if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') { + $sql .= " AND (u.rowid = ". ((int) $filterobj->id).' OR '; + $sql .= " EXISTS (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE a.id = r.fk_actioncomm"; + $sql .= " AND r.element_type = '".$db->escape($filterobj->table_element)."' AND r.fk_element = ".((int) $filterobj->id).')'; + $sql .= ")"; + } + if (is_object($objcon) && $objcon->id > 0) { + $sql .= " AND EXISTS (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE a.id = r.fk_actioncomm"; + $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id).')'; + } } if (!empty($tms_start) && !empty($tms_end)) { diff --git a/htdocs/langs/en_US/commercial.lang b/htdocs/langs/en_US/commercial.lang index 2ac4a52aff9..43f5c1ece32 100644 --- a/htdocs/langs/en_US/commercial.lang +++ b/htdocs/langs/en_US/commercial.lang @@ -14,6 +14,7 @@ ConfirmDeleteAction=Are you sure you want to delete this event? CardAction=Event card ActionOnCompany=Related company ActionOnContact=Related contact +ActionOnUser=Related user TaskRDVWith=Meeting with %s ShowTask=Show task ShowAction=Show event diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 81a316b7f68..a8c380e5c07 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -503,6 +503,7 @@ ContactsAddressesForCompany=Contacts/addresses for this third party AddressesForCompany=Addresses for this third party ActionsOnCompany=Events for this third party ActionsOnContact=Events for this contact/address +ActionsOnUser=Events for this user ActionsOnContract=Events for this contract ActionsOnMember=Events about this member ActionsOnProduct=Events about this product diff --git a/htdocs/user/agenda.php b/htdocs/user/agenda.php index 5b8cf4ffe56..0e0894ad4ca 100644 --- a/htdocs/user/agenda.php +++ b/htdocs/user/agenda.php @@ -197,7 +197,7 @@ if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $cachekey = 'count_events_user_'.$object->id; $nbEvent = dol_getcache($cachekey); - $titlelist = $langs->trans("ActionsOnCompany").(is_numeric($nbEvent) ? '('.$nbEvent.')' : ''); + $titlelist = $langs->trans("ActionsOnUser").(is_numeric($nbEvent) ? '('.$nbEvent.')' : ''); if (!empty($conf->dol_optimize_smallscreen)) { $titlelist = $langs->trans("Actions").(is_numeric($nbEvent) ? '('.$nbEvent.')' : ''); } From fe21cc36056f5e1b6aa3c6e2fbf08697a4622dd9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Aug 2024 04:37:19 +0200 Subject: [PATCH 3/3] Debug v20 --- htdocs/adherents/card.php | 4 ++-- htdocs/adherents/subscription/card.php | 2 +- htdocs/comm/action/class/actioncomm.class.php | 13 +++++++++---- htdocs/core/class/html.formactions.class.php | 2 +- htdocs/supplier_proposal/card.php | 4 ++-- htdocs/user/card.php | 4 +++- htdocs/user/group/card.php | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 4a64b30cd2a..34a49fc3d3b 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -2083,7 +2083,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print '
'; - $MAX = 10; + $MAXEVENT = 10; $morehtmlcenter = ''; $messagingUrl = DOL_URL_ROOT.'/adherents/messaging.php?rowid='.$object->id; @@ -2093,7 +2093,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAX, '', $morehtmlcenter); + $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter); print '
'; } diff --git a/htdocs/adherents/subscription/card.php b/htdocs/adherents/subscription/card.php index ad1f0633c96..5bcaf2246d5 100644 --- a/htdocs/adherents/subscription/card.php +++ b/htdocs/adherents/subscription/card.php @@ -406,7 +406,7 @@ if ($rowid && $action != 'edit') { /* include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, $object->element, $socid, 1); + $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT); */ print ''; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 71e0e221ffe..207743d770a 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1299,7 +1299,7 @@ class ActionComm extends CommonObject /** * Load all objects with filters. - * @TODO WARNING: This make a fetch on all records instead of making one request with a join. + * @TODO WARNING: This make a fetch on all records instead of making one request with a join, like done into show_actions_done. * * @param int $socid Filter by thirdparty * @param int $fk_element Id of element action is linked to @@ -1341,9 +1341,14 @@ class ActionComm extends CommonObject if ($elementtype == 'project') { $sql .= ' AND a.fk_project = '.((int) $fk_element); } elseif ($elementtype == 'contact') { - $sql .= ' AND a.id IN'; - $sql .= " (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX."actioncomm_resources WHERE"; - $sql .= " element_type = 'socpeople' AND fk_element = ".((int) $fk_element).')'; + $sql .= ' AND EXISTS'; + $sql .= " (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE"; + $sql .= " r.element_type = 'socpeople' AND r.fk_element = ".((int) $fk_element).' AND r.fk_actioncomm = a.id)'; + } elseif ($elementtype == 'user') { + $sql .= " AND (a.fk_user_action = ".((int) $fk_element)." OR EXISTS"; + $sql .= " (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE"; + $sql .= " r.element_type = 'user' AND r.fk_element = ".((int) $fk_element).' AND r.fk_actioncomm = a.id)'; + $sql .= ")"; } else { $sql .= " AND a.fk_element = ".((int) $fk_element)." AND a.elementtype = '".$this->db->escape($elementtype)."'"; } diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 337f211f182..b15a7545d37 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -214,7 +214,7 @@ class FormActions $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser')); $url .= '&origin='.urlencode($typeelement).'&originid='.((int) $object->id).((!empty($object->socid) && $object->socid > 0) ? '&socid='.((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid='.((int) $socid) : '')); $url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : ''); - $url .= ($assignedtouser > 0 ? '&assignedtouser='.$assignedtouser : ''); + $url .= ($assignedtouser > 0 ? '&assignedtouser='.((int) $assignedtouser) : ''); $url .= '&backtopage='.urlencode($urlbacktopage); $morehtmlright .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url); } diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 77b1acef553..25f877de50b 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -2077,14 +2077,14 @@ if ($action == 'create') { // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - + $MAXEVENT = 10; print '
'; // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1); + $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1, '', $MAXEVENT); print '
'; } diff --git a/htdocs/user/card.php b/htdocs/user/card.php index fbec74cf25a..4bf758cf123 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2974,12 +2974,14 @@ if ($action == 'create' || $action == 'adduserldap') { $linktoelem = $form->showLinkToObjectBlock($object, null, null); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + $MAXEVENT = 10; + print '
'; // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'user', $socid, 1, 'listactions', 0, '', '', $object->id); + $somethingshown = $formactions->showactions($object, 'user', $socid, 1, 'listactions', $MAXEVENT, '', '', $object->id); print '
'; } diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index 098648b6ba5..6a1030ab8c6 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -508,7 +508,7 @@ if ($action == 'create') { // List of actions on element /*include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'usergroup', $socid, 1);*/ + $somethingshown = $formactions->showactions($object, 'usergroup', $socid, 1, '', $MAXEVENT);*/ print ''; }