From 6916d251b57ee09325a61e70f9a0d4ac5dc1feec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 28 Jun 2014 20:49:10 +0200 Subject: [PATCH] New: Can filter events on a group of users. --- ChangeLog | 1 + htdocs/comm/action/index.php | 57 ++++++++++++++++++++++++--- htdocs/comm/action/listactions.php | 19 +++++---- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/agenda.lib.php | 47 +++------------------- htdocs/langs/en_US/agenda.lang | 3 +- 6 files changed, 72 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index d018c4ec8ea..8e94283923e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ English Dolibarr ChangeLog For users: New: [ task #867 ] Remove ESAEB external module code from core. New: Can create proposal from an intervention. +New: Can filter events on a group of users. For translators: - Update language files. diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index d5434ac86bf..da5b7f95137 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -42,6 +42,7 @@ $filter=GETPOST("filter",'',3); $filtera = GETPOST("userasked","int",3)?GETPOST("userasked","int",3):GETPOST("filtera","int",3); $filtert = GETPOST("usertodo","int",3)?GETPOST("usertodo","int",3):GETPOST("filtert","int",3); $filterd = GETPOST("userdone","int",3)?GETPOST("userdone","int",3):GETPOST("filterd","int",3); +$usergroup = GETPOST("usergroup","int",3); $showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1; @@ -296,9 +297,51 @@ $paramnoaction=preg_replace('/action=[a-z_]+/','',$param); $head = calendars_prepare_head($paramnoaction); dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); -print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$listofextcals,$actioncode,1); +print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$listofextcals,$actioncode,$usergroup); dol_fiche_end(); +$showextcals=$listofextcals; +// Legend +if ($conf->use_javascript_ajax) +{ + $s=''; + //print ''; + + //print $langs->trans("Calendars").': '; + //print ''; + $s.='' . "\n"; + if (! empty($conf->use_javascript_ajax)) + { + $s.='
' . $langs->trans("LocalAgenda").'  
'; + if (is_array($showextcals) && count($showextcals) > 0) + { + foreach ($showextcals as $val) + { + $htmlname = dol_string_nospecial($val['name']); + $s.='' . "\n"; + $s.='
' . $val ['name'] . '  
'; + } + } + } + $s.='
'.$langs->trans("AgendaShowBirthdayEvents").'  
'; + + //print ''; +} + + $link=''; // Add link to show birthdays if (empty($conf->use_javascript_ajax)) @@ -314,7 +357,7 @@ if (empty($conf->use_javascript_ajax)) $link.=''; } -print_fiche_titre($title,$link.'     '.$nav, ''); +print_fiche_titre($s,$link.'     '.$nav, ''); // Get event in an array @@ -330,15 +373,16 @@ $sql.= ' a.fk_user_author,a.fk_user_action,a.fk_user_done,'; $sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,'; $sql.= ' a.fk_soc, a.fk_contact,'; $sql.= ' ca.code'; -$sql.= ' FROM ('.MAIN_DB_PREFIX.'c_actioncomm as ca,'; -$sql.= " ".MAIN_DB_PREFIX."actioncomm as a)"; +$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; +if ($usergroup) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu"; $sql.= ' WHERE a.fk_action = ca.id'; $sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; if ($actioncode) $sql.=" AND ca.code='".$db->escape($actioncode)."'"; if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid); if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; -if ($user->societe_id) $sql.= ' AND a.fk_soc = '.$user->societe_id; // To limit to external user company +if ($socid) $sql.= ' AND a.fk_soc = '.$socid; +if ($usergroup) $sql.= " AND ugu.fk_user = a.fk_user_action"; if ($action == 'show_day') { $sql.= " AND ("; @@ -372,12 +416,13 @@ if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable if ($status == '50') { $sql.= " AND (a.percent >= 0 AND a.percent < 100)"; } // Running if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; } if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; } -if ($filtera > 0 || $filtert > 0 || $filterd > 0) +if ($filtera > 0 || $filtert > 0 || $filterd > 0 || $usergroup) { $sql.= " AND ("; if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera; if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert; if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd; + if ($usergroup) $sql.= ($filtera>0||$filtert>0||$filterd>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup; $sql.= ")"; } // Sort on date diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 494a5339f96..d98c84e7bae 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -146,6 +146,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c,"; $sql.= " ".MAIN_DB_PREFIX.'user as u,'; $sql.= " ".MAIN_DB_PREFIX."actioncomm as a"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; +if ($usergroup) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON a.fk_user_author = ua.rowid"; @@ -153,24 +154,26 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ud ON a.fk_user_done = ud.rowid"; $sql.= " WHERE c.id = a.fk_action"; $sql.= ' AND a.fk_user_author = u.rowid'; -$sql.= ' AND a.entity IN ('.getEntity().')'; // To limit to entity +$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; // To limit to entity if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'"; if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid); if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; if ($socid) $sql.= " AND s.rowid = ".$socid; +if ($usergroup) $sql.= " AND ugu.fk_user = a.fk_user_action"; if ($type) $sql.= " AND c.id = ".$type; if ($status == '0') { $sql.= " AND a.percent = 0"; } if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable if ($status == '50') { $sql.= " AND (a.percent >= 0 AND a.percent < 100)"; } // Running if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; } if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; } -if ($filtera > 0 || $filtert > 0 || $filterd > 0) +if ($filtera > 0 || $filtert > 0 || $filterd > 0 || $usergroup) { - $sql.= " AND ("; - if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera; - if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert; - if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd; - $sql.= ")"; + $sql.= " AND ("; + if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera; + if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert; + if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd; + if ($usergroup) $sql.= ($filtera>0||$filtert>0||$filterd>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup; + $sql.= ")"; } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); @@ -210,7 +213,7 @@ if ($resql) $head = calendars_prepare_head(''); dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); - print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,-1,'',0); + print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,-1,''); dol_fiche_end(); // Add link to show birthdays diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e08a076624e..0adb10c1d22 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4239,7 +4239,7 @@ class Form $i = 0; if ($num) { - $out.= ''; if ($show_empty) $out.= ''."\n"; while ($i < $num) diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 8eddf330c0f..9e41b0e5c1d 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -41,17 +41,16 @@ * @param int $socid Third party id * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend * @param string $actioncode Preselected value of actioncode for filter on type - * @param int $showbirthday Show check to toggle birthday events + * @param int $usergroupid Id of group to filter on users * @return void */ -function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $showextcals=array(), $actioncode='', $showbirthday=0) +function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $showextcals=array(), $actioncode='', $usergroupid='') { global $conf, $user, $langs, $db; // Filters print '
'; print ''; - print ''; print ''; print ''; print ''; @@ -80,6 +79,10 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh //print '  '; print $form->select_dolusers($filtert, 'usertodo', 1, '', ! $canedit); print ajax_combobox('usertodo'); + print '   '.$langs->trans("or") . ' '; + print $langs->trans("ActionsForUsersGroup").'   '; + print $form->select_dolgroups($usergroupid, 'usergroup', 1, '', ! $canedit); + print ajax_combobox('usergroup'); print ''; /*print ''; @@ -146,44 +149,6 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print ''; print ''; - // Legend - if ($conf->use_javascript_ajax) - { - print ''; - - //print $langs->trans("Calendars").': '; - //print ''; - print '' . "\n"; - if (! empty($conf->use_javascript_ajax)) - { - if (is_array($showextcals) && count($showextcals) > 0) - { - print '
' . $langs->trans("LocalAgenda").'  
'; - foreach ($showextcals as $val) - { - $htmlname = dol_string_nospecial($val['name']); - print '' . "\n"; - print '
' . $val ['name'] . '  
'; - } - } - } - if ($showbirthday) print '
'.$langs->trans("AgendaShowBirthdayEvents").'  
'; - - print ''; - } print ''; print ''; diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index f399a81d91d..6f17fd17e2e 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -25,7 +25,8 @@ ListOfEvents= List of Dolibarr events ActionsAskedBy=Events reported by ActionsToDoBy=Events assigned to ActionsDoneBy=Events done by -ActionsAskedBy=Events for user +ActionsForUser=Events for user +ActionsForUsersGroup=Events for all users of group AllMyActions= All my events/tasks AllActions= All events/tasks ViewList=List view