PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/comm/action/listactions.php

https://github.com/asterix14/dolibarr
PHP | 352 lines | 246 code | 48 blank | 58 comment | 83 complexity | 42ebf0ee0c517909c034e5c68f7c2efa MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/action/listactions.php
  22. * \ingroup agenda
  23. * \brief Page to list actions
  24. */
  25. require("../../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/agenda.lib.php");
  30. if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  31. $langs->load("companies");
  32. $langs->load("agenda");
  33. $langs->load("commercial");
  34. $action=GETPOST('action','alpha');
  35. $year=GETPOST("year",'int');
  36. $month=GETPOST("month",'int');
  37. $day=GETPOST("day",'int');
  38. $actioncode=GETPOST('actioncode');
  39. $pid=GETPOST("projectid",'int');
  40. $status=GETPOST("status",'alpha');
  41. $filter=GETPOST("filter");
  42. $filtera = GETPOST("userasked","int")?GETPOST("userasked","int"):GETPOST("filtera","int");
  43. $filtert = GETPOST("usertodo","int")?GETPOST("usertodo","int"):GETPOST("filtert","int");
  44. $filterd = GETPOST("userdone","int")?GETPOST("userdone","int"):GETPOST("filterd","int");
  45. $showbirthday = GETPOST("showbirthday","int");
  46. $sortfield = GETPOST("sortfield",'alpha');
  47. $sortorder = GETPOST("sortorder",'alpha');
  48. $page = GETPOST("page",'int');
  49. if ($page == -1) { $page = 0 ; }
  50. $limit = $conf->liste_limit;
  51. $offset = $limit * $page ;
  52. if (! $sortorder)
  53. {
  54. $sortorder="ASC";
  55. if ($status == 'todo') $sortorder="ASC";
  56. if ($status == 'done') $sortorder="DESC";
  57. }
  58. if (! $sortfield)
  59. {
  60. $sortfield="a.percent";
  61. if ($status == 'todo') $sortfield="a.datep";
  62. if ($status == 'done') $sortfield="a.datep2";
  63. }
  64. // Security check
  65. $socid = GETPOST("socid",'int');
  66. if ($user->societe_id) $socid=$user->societe_id;
  67. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  68. $canedit=1;
  69. if (! $user->rights->agenda->myactions->read) accessforbidden();
  70. if (! $user->rights->agenda->allactions->read) $canedit=0;
  71. if (! $user->rights->agenda->allactions->read || $_GET["filter"]=='mine') // If no permission to see all, we show only affected to me
  72. {
  73. $filtera=$user->id;
  74. $filtert=$user->id;
  75. $filterd=$user->id;
  76. }
  77. /*
  78. * Actions
  79. */
  80. if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday"))
  81. {
  82. $param='';
  83. foreach($_POST as $key => $val)
  84. {
  85. $param.='&'.$key.'='.urlencode($val);
  86. }
  87. //print $param;
  88. header("Location: ".DOL_URL_ROOT.'/comm/action/index.php?'.$param);
  89. exit;
  90. }
  91. /*
  92. * View
  93. */
  94. $now=dol_now();
  95. $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  96. llxHeader('',$langs->trans("Agenda"),$help_url);
  97. $form=new Form($db);
  98. $param='';
  99. if ($status) $param="&status=".$status;
  100. if ($filter) $param.="&filter=".$filter;
  101. if ($filtera) $param.="&filtera=".$filtera;
  102. if ($filtert) $param.="&filtert=".$filtert;
  103. if ($filterd) $param.="&filterd=".$filterd;
  104. if ($socid) $param.="&socid=".$socid;
  105. if ($showbirthday) $param.="&showbirthday=1";
  106. if ($pid) $param.="&projectid=".$pid;
  107. if ($_GET["type"]) $param.="&type=".$_REQUEST["type"];
  108. $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,";
  109. $sql.= " a.id, a.datep as dp, a.datep2 as dp2,";
  110. //$sql.= " a.datea as da, a.datea2 as da2,";
  111. $sql.= " a.fk_contact, a.note, a.label, a.percent as percent,";
  112. $sql.= " c.code as acode, c.libelle,";
  113. $sql.= " ua.login as loginauthor, ua.rowid as useridauthor,";
  114. $sql.= " ut.login as logintodo, ut.rowid as useridtodo,";
  115. $sql.= " ud.login as logindone, ud.rowid as useriddone,";
  116. $sql.= " sp.name, sp.firstname";
  117. $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c,";
  118. if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  119. $sql.= " ".MAIN_DB_PREFIX.'user as u,';
  120. $sql.= " ".MAIN_DB_PREFIX."actioncomm as a)";
  121. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")";
  122. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  123. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON a.fk_user_author = ua.rowid";
  124. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid";
  125. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ud ON a.fk_user_done = ud.rowid";
  126. $sql.= " WHERE c.id = a.fk_action";
  127. $sql.= ' AND a.fk_user_author = u.rowid';
  128. $sql.= ' AND a.entity = '.$conf->entity; // To limit to entity
  129. if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'";
  130. if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
  131. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  132. if ($socid) $sql.= " AND s.rowid = ".$socid;
  133. if ($_GET["type"]) $sql.= " AND c.id = ".$_GET["type"];
  134. if ($status == 'done') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
  135. if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
  136. if ($filtera > 0 || $filtert > 0 || $filterd > 0)
  137. {
  138. $sql.= " AND (";
  139. if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera;
  140. if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert;
  141. if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd;
  142. $sql.= ")";
  143. }
  144. $sql.= $db->order($sortfield,$sortorder);
  145. $sql.= $db->plimit($limit + 1, $offset);
  146. //print $sql;
  147. dol_syslog("comm/action/listactions.php sql=".$sql);
  148. $resql=$db->query($sql);
  149. if ($resql)
  150. {
  151. $actionstatic=new ActionComm($db);
  152. $societestatic=new Societe($db);
  153. $num = $db->num_rows($resql);
  154. $title=$langs->trans("DoneAndToDoActions");
  155. if ($status == 'done') $title=$langs->trans("DoneActions");
  156. if ($status == 'todo') $title=$langs->trans("ToDoActions");
  157. if ($socid)
  158. {
  159. $societe = new Societe($db);
  160. $societe->fetch($socid);
  161. $newtitle=$langs->trans($title).' '.$langs->trans("For").' '.$societe->nom;
  162. }
  163. else
  164. {
  165. $newtitle=$langs->trans($title);
  166. }
  167. $head = calendars_prepare_head('');
  168. dol_fiche_head($head, 'card', $langs->trans('Events'), 0, 'list');
  169. print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid);
  170. dol_fiche_end();
  171. // Add link to show birthdays
  172. $link='';
  173. /*
  174. $newparam=$param; // newparam is for birthday links
  175. $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
  176. if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
  177. $link='<a href="'.$_SERVER['PHP_SELF'];
  178. $link.='?'.$newparam;
  179. $link.='">';
  180. if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
  181. else $link.=$langs->trans("AgendaHideBirthdayEvents");
  182. $link.='</a>';
  183. */
  184. print_barre_liste($newtitle, $page, $_SERVER["PHP_SELF"], $param,$sortfield,$sortorder,$link,$num,0,'');
  185. //print '<br>';
  186. $i = 0;
  187. print '<table class="liste" width="100%">';
  188. print '<tr class="liste_titre">';
  189. print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"acode",$param,"","",$sortfield,$sortorder);
  190. //print_liste_field_titre($langs->trans("Title"),$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder);
  191. print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"a.datep",$param,'','align="center"',$sortfield,$sortorder);
  192. print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"a.datep2",$param,'','align="center"',$sortfield,$sortorder);
  193. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom",$param,"","",$sortfield,$sortorder);
  194. print_liste_field_titre($langs->trans("Contact"),$_SERVER["PHP_SELF"],"a.fk_contact",$param,"","",$sortfield,$sortorder);
  195. print_liste_field_titre($langs->trans("ActionUserAsk"),$_SERVER["PHP_SELF"],"ua.login",$param,"","",$sortfield,$sortorder);
  196. print_liste_field_titre($langs->trans("AffectedTo"),$_SERVER["PHP_SELF"],"ut.login",$param,"","",$sortfield,$sortorder);
  197. print_liste_field_titre($langs->trans("DoneBy"),$_SERVER["PHP_SELF"],"ud.login",$param,"","",$sortfield,$sortorder);
  198. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"a.percent",$param,"",'align="right"',$sortfield,$sortorder);
  199. print "</tr>\n";
  200. $contactstatic = new Contact($db);
  201. $now=dol_now();
  202. $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
  203. $var=true;
  204. while ($i < min($num,$limit))
  205. {
  206. $obj = $db->fetch_object($resql);
  207. $var=!$var;
  208. print "<tr $bc[$var]>";
  209. // Action (type)
  210. print '<td>';
  211. $actionstatic->id=$obj->id;
  212. $actionstatic->type_code=$obj->acode;
  213. $actionstatic->libelle=$obj->label;
  214. print $actionstatic->getNomUrl(1,28);
  215. print '</td>';
  216. // Titre
  217. //print '<td>';
  218. //print dol_trunc($obj->label,12);
  219. //print '</td>';
  220. print '<td align="center" nowrap="nowrap">';
  221. print dol_print_date($db->jdate($obj->dp),"day");
  222. $late=0;
  223. if ($obj->percent == 0 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) $late=1;
  224. if ($obj->percent == 0 && ! $obj->dp && $obj->dp2 && $db->jdate($obj->dp) < ($now - $delay_warning)) $late=1;
  225. if ($obj->percent > 0 && $obj->percent < 100 && $obj->dp2 && $db->jdate($obj->dp2) < ($now - $delay_warning)) $late=1;
  226. if ($obj->percent > 0 && $obj->percent < 100 && ! $obj->dp2 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) $late=1;
  227. if ($late) print img_warning($langs->trans("Late")).' ';
  228. print '</td>';
  229. print '<td align="center" nowrap="nowrap">';
  230. print dol_print_date($db->jdate($obj->dp2),"day");
  231. print '</td>';
  232. // Third party
  233. print '<td>';
  234. if ($obj->socid)
  235. {
  236. $societestatic->id=$obj->socid;
  237. $societestatic->client=$obj->client;
  238. $societestatic->nom=$obj->societe;
  239. print $societestatic->getNomUrl(1,'',10);
  240. }
  241. else print '&nbsp;';
  242. print '</td>';
  243. // Contact
  244. print '<td>';
  245. if ($obj->fk_contact > 0)
  246. {
  247. $contactstatic->name=$obj->name;
  248. $contactstatic->firstname=$obj->firstname;
  249. $contactstatic->id=$obj->fk_contact;
  250. print $contactstatic->getNomUrl(1,'',10);
  251. }
  252. else
  253. {
  254. print "&nbsp;";
  255. }
  256. print '</td>';
  257. // User author
  258. print '<td align="left">';
  259. if ($obj->useridauthor)
  260. {
  261. $userstatic=new User($db);
  262. $userstatic->id=$obj->useridauthor;
  263. $userstatic->login=$obj->loginauthor;
  264. print $userstatic->getLoginUrl(1);
  265. }
  266. else print '&nbsp;';
  267. print '</td>';
  268. // User to do
  269. print '<td align="left">';
  270. if ($obj->useridtodo)
  271. {
  272. $userstatic=new User($db);
  273. $userstatic->id=$obj->useridtodo;
  274. $userstatic->login=$obj->logintodo;
  275. print $userstatic->getLoginUrl(1);
  276. }
  277. else print '&nbsp;';
  278. print '</td>';
  279. // User did
  280. print '<td align="left">';
  281. if ($obj->useriddone)
  282. {
  283. $userstatic=new User($db);
  284. $userstatic->id=$obj->useriddone;
  285. $userstatic->login=$obj->logindone;
  286. print $userstatic->getLoginUrl(1);
  287. }
  288. else print '&nbsp;';
  289. print '</td>';
  290. // Status/Percent
  291. print '<td align="right" nowrap="nowrap">'.$actionstatic->LibStatut($obj->percent,6).'</td>';
  292. print "</tr>\n";
  293. $i++;
  294. }
  295. print "</table>";
  296. $db->free($resql);
  297. }
  298. else
  299. {
  300. dol_print_error($db);
  301. }
  302. $db->close();
  303. llxFooter();
  304. ?>