From 839892ba9fe88adc74a2ef49cd486fbdeb50cf5b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Jan 2010 09:44:52 +0000 Subject: [PATCH] Mutualize some code and fix filters on projects --- htdocs/comm/action/index.php | 99 +++++------------------------- htdocs/comm/action/listactions.php | 68 ++++++++++++-------- htdocs/lib/agenda.lib.php | 92 ++++++++++++++++++++++++++- 3 files changed, 151 insertions(+), 108 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 791deef2f88..7dc2232d915 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -30,6 +30,7 @@ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/agenda.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $filtera = isset($_REQUEST["userasked"])?$_REQUEST["userasked"]:(isset($_REQUEST["filtera"])?$_REQUEST["filtera"]:''); @@ -37,17 +38,15 @@ $filtert = isset($_REQUEST["usertodo"])?$_REQUEST["usertodo"]:(isset($_REQUEST[" $filterd = isset($_REQUEST["userdone"])?$_REQUEST["userdone"]:(isset($_REQUEST["filterd"])?$_REQUEST["filterd"]:''); $showbirthday = isset($_REQUEST["showbirthday"])?$_REQUEST["showbirthday"]:0; -$page = $_GET["page"]; -$sortfield=$_GET["sortfield"]; -$sortorder=$_GET["sortorder"]; +$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; +$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; +$page = isset($_GET["page"])?$_GET["page"]:$_POST["page"]; if ($page == -1) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="a.datec"; -$status=isset($_GET["status"])?$_GET["status"]:$_POST["status"]; - // Security check $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; @@ -63,9 +62,12 @@ if (! $user->rights->agenda->allactions->read || $_GET["filter"]=='mine') $filterd=$user->id; } +$action=isset($_REQUEST['action'])?$_REQUEST['action']:''; $year=isset($_REQUEST["year"])?$_REQUEST["year"]:date("Y"); $month=isset($_REQUEST["month"])?$_REQUEST["month"]:date("m"); $day=isset($_REQUEST["day"])?$_REQUEST["day"]:0; +$pid=isset($_REQUEST["projectid"])?$_REQUEST["projectid"]:0; +$status=isset($_GET["status"])?$_GET["status"]:$_POST["status"]; $langs->load("other"); @@ -145,9 +147,9 @@ if ($filter) $param.="&filter=".$filter; if ($filtera) $param.="&filtera=".$filtera; if ($filtert) $param.="&filtert=".$filtert; if ($filterd) $param.="&filterd=".$filterd; -if ($time) $param.="&time=".$_REQUEST["time"]; -if ($socid) $param.="&socid=".$_REQUEST["socid"]; +if ($socid) $param.="&socid=".$socid; if ($showbirthday) $param.="&showbirthday=1"; +if ($pid) $param.="&projectid=".$pid; if (! empty($_REQUEST["type"])) $param.="&type=".$_REQUEST["type"]; // Show navigation bar @@ -162,74 +164,7 @@ $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:''); print_fiche_titre($title,$nav); -// Filters -if ($canedit || $conf->projet->enabled) -{ - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($canedit || $conf->projet->enabled) - { - print ''; - - // Buttons - print ''; - print ''; - } - print '
'; - - print ''; - - if ($canedit) - { - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - } - - if ($conf->projet->enabled) - { - print ''; - print ''; - } - - print '
'; - print $langs->trans("ActionsAskedBy"); - print '  '; - print $form->select_users($filtera,'userasked',1,'',!$canedit); - print '
'; - print $langs->trans("ActionsToDoBy"); - print '  '; - print $form->select_users($filtert,'usertodo',1,'',!$canedit); - print '
'; - print $langs->trans("ActionsDoneBy"); - print '  '; - print $form->select_users($filterd,'userdone',1,'',!$canedit); - print '
'; - print $langs->trans("Project").'   '; - print ''; - select_projects($socid,$_REQUEST["projectid"],'projectid'); - print '
'; - print '
'; - print img_picto($langs->trans("ViewList"),'object_list').' '; - print '
'; - print '
'; - print img_picto($langs->trans("ViewCal"),'object_calendar').' '; - print '
'; - print '

'; -} +print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid); // Get event in an array @@ -247,9 +182,9 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; $sql.= ', '.MAIN_DB_PREFIX.'c_actioncomm as ca'; $sql.= ', '.MAIN_DB_PREFIX.'user as u'; $sql.= ' WHERE a.fk_action = ca.id'; -$sql.= ' AND a.fk_user_author = u.rowid'; -$sql.= ' AND u.entity in (0,'.$conf->entity.')'; -if ($_REQUEST["projectid"]) $sql.=" AND a.fk_project=".addslashes($_REQUEST["projectid"]); +$sql.= ' AND a.fk_user_author = u.rowid'; // To limit to entity +$sql.= ' AND u.entity in (0,'.$conf->entity.')'; // To limit to entity +if ($pid) $sql.=" AND a.fk_project=".addslashes($pid); if ($_GET["action"] == 'show_day') { $sql.= ' AND ('; @@ -281,17 +216,17 @@ if ($filtera > 0 || $filtert > 0 || $filterd > 0) { $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 ($filtert > 0) $sql.= ($filtera>0?" AND ":"")." a.fk_user_action = ".$filtert; + if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" AND ":"")." a.fk_user_done = ".$filterd; $sql.= ")"; } if ($status == 'done') { $sql.= " AND a.percent = 100"; } if ($status == 'todo') { $sql.= " AND a.percent < 100"; } // Sort on date $sql.= ' ORDER BY datep'; -dol_syslog("comm/action/index.php sql=".$sql, LOG_DEBUG); - //print $sql; + +dol_syslog("comm/action/index.php sql=".$sql, LOG_DEBUG); $resql=$db->query($sql); if ($resql) { diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index c1f683f7478..59d0511d155 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Eric Seigne - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -20,29 +20,44 @@ */ /** - \file htdocs/comm/action/listactions.php - \ingroup agenda - \brief Page liste des actions commerciales - \version $Id$ -*/ + * \file htdocs/comm/action/listactions.php + * \ingroup agenda + * \brief Page liste des actions commerciales + * \version $Id$ + */ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/actioncomm.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/agenda.lib.php"); +if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $langs->load("companies"); $langs->load("agenda"); +$action=isset($_REQUEST['action'])?$_REQUEST['action']:''; +$year=isset($_REQUEST["year"])?$_REQUEST["year"]:''; +$month=isset($_REQUEST["month"])?$_REQUEST["month"]:''; +$day=isset($_REQUEST["day"])?$_REQUEST["day"]:0; +$pid=isset($_REQUEST["projectid"])?$_REQUEST["projectid"]:0; +$status=isset($_GET["status"])?$_GET["status"]:$_POST["status"]; + $filtera = isset($_REQUEST["userasked"])?$_REQUEST["userasked"]:(isset($_REQUEST["filtera"])?$_REQUEST["filtera"]:''); $filtert = isset($_REQUEST["usertodo"])?$_REQUEST["usertodo"]:(isset($_REQUEST["filtert"])?$_REQUEST["filtert"]:''); $filterd = isset($_REQUEST["userdone"])?$_REQUEST["userdone"]:(isset($_REQUEST["filterd"])?$_REQUEST["filterd"]:''); $socid = isset($_GET["socid"])?$_GET["socid"]:$_POST["socid"]; + $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $page = isset($_GET["page"])?$_GET["page"]:$_POST["page"]; +if ($page == -1) { $page = 0 ; } +$limit = $conf->liste_limit; +$offset = $limit * $page ; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="a.datec"; -$status=isset($_GET["status"])?$_GET["status"]:$_POST["status"]; // Security check $socid = isset($_GET["socid"])?$_GET["socid"]:''; @@ -102,6 +117,16 @@ llxHeader('',$langs->trans("Agenda"),$help_url); $form=new Form($db); +$param=''; +if ($status) $param="&status=".$status; +if ($filter) $param.="&filter=".$filter; +if ($filtera) $param.="&filtera=".$filtera; +if ($filtert) $param.="&filtert=".$filtert; +if ($filterd) $param.="&filterd=".$filterd; +if ($socid) $param.="&socid=".$socid; +if ($pid) $param.="&projectid=".$pid; +if ($_GET["type"]) $param.="&type=".$_REQUEST["type"]; + $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; $sql.= " a.id, a.datep as dp, a.datep2 as dp2,"; //$sql.= " a.datea as da, a.datea2 as da2,"; @@ -111,28 +136,30 @@ $sql.= " ua.login as loginauthor, ua.rowid as useridauthor,"; $sql.= " ut.login as logintodo, ut.rowid as useridtodo,"; $sql.= " ud.login as logindone, ud.rowid as useriddone,"; $sql.= " sp.name, sp.firstname"; -$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c,"; +$sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c,"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; -$sql.= " ".MAIN_DB_PREFIX."actioncomm as a"; +$sql.= " ".MAIN_DB_PREFIX."actioncomm as a,"; +$sql.= " ".MAIN_DB_PREFIX.'user as u)'; $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"; $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 s.entity = ".$conf->entity; +$sql.= ' AND a.fk_user_author = u.rowid'; // To limit to entity +$sql.= ' AND u.entity in (0,'.$conf->entity.')'; // To limit to entity +if ($pid) $sql.=" AND a.fk_project=".addslashes($pid); if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($_GET["type"]) $sql.= " AND c.id = ".$_GET["type"]; -if ($_REQUEST["time"] == "today") $sql.= " AND date_format(a.datep, '%d%m%Y') = ".strftime("%d%m%Y",time()); if ($status == 'done') { $sql.= " AND a.percent = 100"; } if ($status == 'todo') { $sql.= " AND a.percent < 100"; } if ($filtera > 0 || $filtert > 0 || $filterd > 0) { $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 ($filtert > 0) $sql.= ($filtera>0?" AND ":"")." a.fk_user_action = ".$filtert; + if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" AND ":"")." a.fk_user_done = ".$filterd; $sql.= ")"; } $sql.= " ORDER BY ".$sortfield." ".$sortorder; @@ -152,16 +179,6 @@ if ($resql) if ($status == 'done') $title=$langs->trans("DoneActions"); if ($status == 'todo') $title=$langs->trans("ToDoActions"); - $param=''; - if ($status) $param="&status=".$status; - if ($filter) $param.="&filter=".$filter; - if ($filtera) $param.="&filtera=".$filtera; - if ($filtert) $param.="&filtert=".$filtert; - if ($filterd) $param.="&filterd=".$filterd; - if ($time) $param.="&time=".$_REQUEST["time"]; - if ($socid) $param.="&socid=".$_REQUEST["socid"]; - if ($_GET["type"]) $param.="&type=".$_REQUEST["type"]; - if ($socid) { $societe = new Societe($db); @@ -176,12 +193,13 @@ if ($resql) //print '
'; + print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid); +/* if ($canedit) { print '
'; print ''; print ''; - print ''; print ''; print ''; print '
'; @@ -217,7 +235,7 @@ if ($resql) print '
'; print '

'; } - +*/ $i = 0; print ""; diff --git a/htdocs/lib/agenda.lib.php b/htdocs/lib/agenda.lib.php index 5b85d1cf4c0..4f77a1f7019 100644 --- a/htdocs/lib/agenda.lib.php +++ b/htdocs/lib/agenda.lib.php @@ -20,11 +20,101 @@ /** * \file htdocs/lib/agenda.lib.php - * \brief Ensemble de fonctions de base de dolibarr sous forme d'include + * \brief Set of function for the agenda module * \version $Id$ */ +/** + * Show filter form in agenda view + * + * @param unknown_type $canedit + * @param unknown_type $status + * @param unknown_type $year + * @param unknown_type $month + * @param unknown_type $day + * @param unknown_type $showborthday + * @param unknown_type $action + * @param unknown_type $filtera + * @param unknown_type $filtert + * @param unknown_type $filterd + * @param unknown_type $pid + * @param unknown_type $socid + */ +function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid) +{ + global $conf,$langs; + + // Filters + if ($canedit || $conf->projet->enabled) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + if ($canedit || $conf->projet->enabled) + { + print ''; + + // Buttons + print ''; + print ''; + } + print '
'; + + print ''; + + if ($canedit) + { + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + } + + if ($conf->projet->enabled) + { + print ''; + print ''; + } + + print '
'; + print $langs->trans("ActionsAskedBy"); + print '  '; + print $form->select_users($filtera,'userasked',1,'',!$canedit); + print '
'; + print $langs->trans("ActionsToDoBy"); + print '  '; + print $form->select_users($filtert,'usertodo',1,'',!$canedit); + print '
'; + print $langs->trans("ActionsDoneBy"); + print '  '; + print $form->select_users($filterd,'userdone',1,'',!$canedit); + print '
'; + print $langs->trans("Project").'   '; + print ''; + select_projects($socid,$pid,'projectid'); + print '
'; + print '
'; + print img_picto($langs->trans("ViewList"),'object_list').' '; + print '
'; + print '
'; + print img_picto($langs->trans("ViewCal"),'object_calendar').' '; + print '
'; + print '
'; + } +} + + /** * \brief Show actions to do array * \param max Max nb of records