From 9b6e5196ea32cdfac734b6298613a537122f44d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 6 Jun 2016 13:05:36 +0200 Subject: [PATCH] Debug module resource. Filter on agenda. --- htdocs/comm/action/index.php | 8 +++++-- htdocs/comm/action/listactions.php | 8 ++++++- htdocs/comm/action/pertype.php | 9 ++++++-- htdocs/comm/action/peruser.php | 9 ++++++-- htdocs/core/lib/agenda.lib.php | 21 ++++++++++++++++--- .../class/html.formresource.class.php | 5 +++-- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index d9990ef7525..addcb26fe17 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -78,7 +78,7 @@ if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no per } $action=GETPOST('action','alpha'); -//$year=GETPOST("year"); +$resourceid=GETPOST("resourceid","int"); $year=GETPOST("year","int")?GETPOST("year","int"):date("Y"); $month=GETPOST("month","int")?GETPOST("month","int"):date("m"); $week=GETPOST("week","int")?GETPOST("week","int"):date("W"); @@ -292,6 +292,7 @@ if ($status == 'todo') $title=$langs->trans("ToDoActions"); $param=''; if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode; +if ($resourceid > 0) $param.="&resourceid=".$resourceid; if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status; if ($filter) $param.="&filter=".$filter; if ($filtert) $param.="&filtert=".$filtert; @@ -349,7 +350,7 @@ $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,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup); +print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup,'', $resourceid); dol_fiche_end(); @@ -442,12 +443,15 @@ $sql.= ' a.fk_soc, a.fk_contact,'; $sql.= ' ca.code as type_code, ca.libelle as type_label'; $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"; +// We must filter on resource table +if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= ' WHERE a.fk_action = ca.id'; $sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; if ($actioncode) $sql.=" AND ca.code IN ('".implode("','", explode(',',$actioncode))."')"; +if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); 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 > 0) $sql.= ' AND a.fk_soc = '.$socid; diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 4cae6d5c4d0..e6ad597192a 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -36,6 +36,7 @@ $langs->load("agenda"); $langs->load("commercial"); $action=GETPOST('action','alpha'); +$resourceid=GETPOST("resourceid","int"); $year=GETPOST("year",'int'); $month=GETPOST("month",'int'); $day=GETPOST("day",'int'); @@ -156,6 +157,7 @@ $listofextcals=array(); $param=''; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($actioncode != '') $param.="&actioncode=".$actioncode; +if ($resourceid > 0) $param.="&resourceid=".$resourceid; if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status; if ($filter) $param.="&filter=".$filter; if ($filtert) $param.="&filtert=".$filtert; @@ -178,12 +180,15 @@ $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; $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"; +// We must filter on resource table +if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= " WHERE c.id = a.fk_action"; $sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; if ($actioncode) $sql.=" AND c.code IN ('".$db->escape($actioncode)."')"; +if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); 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 > 0) $sql.= " AND s.rowid = ".$socid; @@ -242,7 +247,7 @@ if ($resql) $head = calendars_prepare_head($param); dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); - print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,-1,$actioncode,$usergroup); + print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,-1,$actioncode,$usergroup,'',$resourceid); dol_fiche_end(); // Add link to show birthdays @@ -288,6 +293,7 @@ if ($resql) $nav=''; if ($optioncss != '') $nav.= ''; if ($actioncode) $nav.=''; + if ($resourceid) $nav.=''; if ($status || isset($_GET['status']) || isset($_POST['status'])) $nav.=''; if ($filter) $nav.=''; if ($filtert) $nav.=''; diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index 28a531c6b28..6138e79cafd 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -76,7 +76,7 @@ if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no per //$action=GETPOST('action','alpha'); $action='show_pertype'; -//$year=GETPOST("year"); +$resourceid=GETPOST("resourceid","int"); $year=GETPOST("year","int")?GETPOST("year","int"):date("Y"); $month=GETPOST("month","int")?GETPOST("month","int"):date("m"); $week=GETPOST("week","int")?GETPOST("week","int"):date("W"); @@ -202,6 +202,7 @@ if ($status == 'todo') $title=$langs->trans("ToDoActions"); $param=''; if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode; +if ($resourceid > 0) $param.="&resourceid=".$resourceid; if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status; if ($filter) $param.="&filter=".$filter; if ($filtert) $param.="&filtert=".$filtert; @@ -252,6 +253,7 @@ $nav.=''; $nav.=''; $nav.=''; $nav.=''; +$nav.=''; $nav.=''; $nav.=''; $nav.=''; @@ -279,7 +281,7 @@ $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, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup); +print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid); dol_fiche_end(); $showextcals=$listofextcals; @@ -356,12 +358,15 @@ $sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,'; $sql.= ' ca.code, ca.color'; $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"; +// We must filter on resource table +if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $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 ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); 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 > 0) $sql.= ' AND a.fk_soc = '.$socid; diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 033c67839f0..cd5f7d10fa7 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -76,7 +76,7 @@ if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no per //$action=GETPOST('action','alpha'); $action='show_peruser'; //We use 'show_week' mode -//$year=GETPOST("year"); +$resourceid=GETPOST("resourceid","int"); $year=GETPOST("year","int")?GETPOST("year","int"):date("Y"); $month=GETPOST("month","int")?GETPOST("month","int"):date("m"); $week=GETPOST("week","int")?GETPOST("week","int"):date("W"); @@ -202,6 +202,7 @@ if ($status == 'todo') $title=$langs->trans("ToDoActions"); $param=''; if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode; +if ($resourceid > 0) $param.="&resourceid=".$resourceid; if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status; if ($filter) $param.="&filter=".$filter; if ($filtert) $param.="&filtert=".$filtert; @@ -255,6 +256,7 @@ $nav.=''; $nav.=''; $nav.=''; $nav.=''; +$nav.=''; $nav.=''; $nav.=''; $nav.=''; @@ -287,7 +289,7 @@ $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, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup); +print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid); dol_fiche_end(); $showextcals=$listofextcals; @@ -364,12 +366,15 @@ $sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,'; $sql.= ' ca.code, ca.color'; $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"; +// We must filter on resource table +if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $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 ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); 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 > 0) $sql.= ' AND a.fk_soc = '.$socid; diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index ad40ba84938..cdc45de825e 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -41,12 +41,13 @@ * @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 type + * @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 string $excludetype A type to exclude ('systemauto', 'system', '') + * @param int $resourceid Preselected value of resource for filter on resource * @return void */ -function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid='', $excludetype='') +function print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid='', $excludetype='', $resourceid=0) { global $conf, $user, $langs, $db, $hookmanager; global $begin_h, $end_h, $begin_d, $end_d; @@ -80,6 +81,20 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print $form->select_dolgroups($usergroupid, 'usergroup', 1, '', ! $canedit); print ''; + if ($conf->resource->enabled) + { + include_once DOL_DOCUMENT_ROOT . '/resource/class/html.formresource.class.php'; + $formresource=new FormResource($db); + + // Resource + print ''; + print ''; + print $langs->trans("Resource"); + print '  '; + print $formresource->select_resource_list($resourceid, "resourceid", '', 1, 0, 0, null, '', 2); + print ''; + } + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions=new FormActions($db); diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 891ed33d1e5..b094aacd1ea 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -17,11 +17,12 @@ */ /** - * \file place/class/html.formresource.class.php + * \file resource/class/html.formresource.class.php * \ingroup core * \brief Class file to manage forms into resource module */ require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/resource/class/dolresource.class.php"); /** @@ -56,7 +57,7 @@ class FormResource /** * Output html form to select a resource * - * @param string $selected Preselected type + * @param int $selected Preselected resource id * @param string $htmlname Name of field in form * @param string $filter Optionnal filters criteras (example: 's.rowid <> x') * @param int $showempty Add an empty field