From 7db64c5bcc08d3bc3149df0db021386da6ba110d Mon Sep 17 00:00:00 2001 From: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:29:24 +0100 Subject: [PATCH] NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 --- htdocs/comm/action/index.php | 17 +++++++++-- htdocs/comm/action/list.php | 16 ++++++++++- htdocs/comm/action/peruser.php | 14 ++++++++- htdocs/core/lib/agenda.lib.php | 52 +++++++++++++++++++++------------- 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index ad681813b42..cbf37aae56d 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -58,6 +58,7 @@ $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3); $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3); $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1; +$search_categ_cus = GETPOST("search_categ_cus", "int", 3) ? GETPOST("search_categ_cus", "int", 3) : 0; // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user. if (empty($filtert) && !getDolGlobalString('AGENDA_ALL_CALENDARS')) { @@ -419,6 +420,9 @@ $param .= "&maxprint=".urlencode($maxprint); if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') { $param .= '&mode='.urlencode($mode); } +if ($search_categ_cus != 0) { + $param .= '&search_categ_cus='.urlencode($search_categ_cus); +} // Show navigation bar $nav = ''; @@ -843,11 +847,20 @@ if ($filtert > 0 || $usergroup > 0) { } $sql .= ")"; } + +// Search in categories, -1 is all and -2 is no categories +if ($search_categ_cus != -1) { + if ($search_categ_cus == -2) { + $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)"; + } elseif ($search_categ_cus > 0) { + $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize($search_categ_cus)."))"; + } +} + // Sort on date $sql .= ' ORDER BY datep'; //print $sql; - dol_syslog("comm/action/index.php", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { @@ -1495,7 +1508,7 @@ if (empty($mode) || $mode == 'show_month') { // View by month $newparam .= '&viewcal=1'; print '
'; - print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid); + print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus); print '
'; print '
'; diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index 301216c6567..55cb92d71f3 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -96,6 +96,7 @@ $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3); $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3); $showbirthday = empty($conf->use_javascript_ajax) ? (GETPOST("search_showbirthday", "int") ? GETPOST("search_showbirthday", "int") : GETPOST("showbirthday", "int")) : 1; +$search_categ_cus = GETPOST("search_categ_cus", "int", 3) ? GETPOST("search_categ_cus", "int", 3) : 0; // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $object = new ActionComm($db); @@ -388,6 +389,10 @@ if (GETPOST('dateend_dtendyear', 'int')) { if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } +if ($search_categ_cus != 0) { + $param .= '&search_categ_cus='.urlencode($search_categ_cus); +} + // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -569,6 +574,15 @@ if ($dateend_dtend > 0) { $sql .= " AND a.datep2 <= '".$db->idate($dateend_dtend)."'"; } +// Search in categories, -1 is all and -2 is no categories +if ($search_categ_cus != -1) { + if ($search_categ_cus == -2) { + $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)"; + } elseif ($search_categ_cus > 0) { + $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize($search_categ_cus)."))"; + } +} + // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -737,7 +751,7 @@ if ($massactionbutton) { $i = 0; print '
'; -print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid); +print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus); print '
'; print '
'; diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 1e480c79a14..90f2735998b 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -107,6 +107,7 @@ $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GET $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha'); $maxprint = ((GETPOST("maxprint", 'int') != '') ? GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$search_categ_cus = GETPOST("search_categ_cus", "int", 3) ? GETPOST("search_categ_cus", "int", 3) : 0; // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) if (GETPOST('search_actioncode', 'array:aZ09')) { $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3); @@ -322,6 +323,9 @@ if ($begin_d != '') { if ($end_d != '') { $param .= '&end_d='.urlencode($end_d); } +if ($search_categ_cus != 0) { + $param .= '&search_categ_cus='.urlencode($search_categ_cus); +} $param .= "&maxprint=".urlencode($maxprint); $paramnoactionodate = $param; @@ -513,7 +517,7 @@ $s = $newtitle; print $s; print '
'; -print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid); +print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus); print '
'; @@ -650,6 +654,14 @@ if ($status == 'done' || $status == '100') { if ($status == 'todo') { $sql .= " AND (a.percent >= 0 AND a.percent < 100)"; } +// Search in categories, -1 is all and -2 is no categories +if ($search_categ_cus != -1) { + if ($search_categ_cus == -2) { + $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)"; + } elseif ($search_categ_cus > 0) { + $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize($search_categ_cus)."))"; + } +} // Sort on date $sql .= $db->order("fk_user_action, datep"); //print $sql; diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 1ed670a12bb..ff07283664d 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -28,24 +28,25 @@ /** * Show filter form in agenda view * - * @param Form $form Form object - * @param int $canedit Can edit filter fields - * @param int $status Status - * @param int $year Year - * @param int $month Month - * @param int $day Day - * @param int $showbirthday Show birthday - * @param string $filtera Filter on create by user - * @param string $filtert Filter on assigned to user - * @param string $filtered Filter of done by user - * @param int $pid Product id - * @param int $socid Third party id - * @param string $action Action string - * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend - * @param string|array $actioncode Preselected value(s) of actioncode for filter on event type - * @param int $usergroupid Id of group to filter on users - * @param string $excludetype A type to exclude ('systemauto', 'system', '') - * @param int $resourceid Preselected value of resource for filter on resource + * @param Form $form Form object + * @param int $canedit Can edit filter fields + * @param int $status Status + * @param int $year Year + * @param int $month Month + * @param int $day Day + * @param int $showbirthday Show birthday + * @param string $filtera Filter on create by user + * @param string $filtert Filter on assigned to user + * @param string $filtered Filter of done by user + * @param int $pid Product id + * @param int $socid Third party id + * @param string $action Action string + * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend + * @param string|array $actioncode Preselected value(s) of actioncode for filter on event type + * @param int $usergroupid Id of group to filter on users + * @param string $excludetype A type to exclude ('systemauto', 'system', '') + * @param int $resourceid Preselected value of resource for filter on resource + * @param array $search_categ_cus Tag id * @return void */ function print_actions_filter( @@ -66,7 +67,8 @@ function print_actions_filter( $actioncode = '', $usergroupid = 0, $excludetype = '', - $resourceid = 0 + $resourceid = 0, + $search_categ_cus = 0 ) { global $user, $langs, $db, $hookmanager; global $massaction; @@ -139,6 +141,18 @@ function print_actions_filter( print '
'; } + if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; + $formother = new FormOther($db); + $langs->load('categories'); + + print '
'; + print img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); + print $formother->select_categories('actioncomm', $search_categ_cus, 'search_categ_cus', 1, $langs->trans('ActionCommCategoriesArea')); + print '
'; + } + if ($canedit && !preg_match('/list/', $_SERVER["PHP_SELF"])) { // Status print '
';