list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2006-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/tasks/list.php
  21. * \ingroup project
  22. * \brief List all task of a project
  23. */
  24. require ("../../main.inc.php");
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. $langs->load('projects');
  31. $langs->load('users');
  32. $langs->load('companies');
  33. $id=GETPOST('id','int');
  34. $search_all=GETPOST('search_all');
  35. $search_project=GETPOST('search_project');
  36. if (! isset($_GET['search_projectstatus']) && ! isset($_POST['search_projectstatus'])) $search_projectstatus=1;
  37. else $search_projectstatus=GETPOST('search_projectstatus');
  38. $search_project_ref=GETPOST('search_project_ref');
  39. $search_project_title=GETPOST('search_project_title');
  40. $search_task_ref=GETPOST('search_task_ref');
  41. $search_task_label=GETPOST('search_task_label');
  42. $search_task_description=GETPOST('search_task_description');
  43. $search_project_user=GETPOST('search_project_user');
  44. $search_task_user=GETPOST('search_task_user');
  45. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  46. if ($mine) { $search_task_user = $user->id; $mine = 0; }
  47. $sday = GETPOST('sday','int');
  48. $smonth = GETPOST('smonth','int');
  49. $syear = GETPOST('syear','int');
  50. $day = GETPOST('day','int');
  51. $month = GETPOST('month','int');
  52. $year = GETPOST('year','int');
  53. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  54. $contextpage='tasklist';
  55. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  56. $hookmanager->initHooks(array($contextpage));
  57. $extrafields = new ExtraFields($db);
  58. // fetch optionals attributes and labels
  59. $extralabels = $extrafields->fetch_name_optionals_label('project');
  60. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  61. // Security check
  62. $socid=0;
  63. if ($user->societe_id > 0) $socid = $user->societe_id;
  64. if (!$user->rights->projet->lire) accessforbidden();
  65. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  66. $sortfield = GETPOST("sortfield",'alpha');
  67. $sortorder = GETPOST("sortorder",'alpha');
  68. $page = GETPOST("page",'int');
  69. if ($page == -1) { $page = 0; }
  70. $offset = $limit * $page;
  71. $pageprev = $page - 1;
  72. $pagenext = $page + 1;
  73. if (! $sortfield) $sortfield='p.ref';
  74. if (! $sortorder) $sortorder='DESC';
  75. // List of fields to search into when doing a "search in all"
  76. $fieldstosearchall = array(
  77. 't.ref'=>"Ref",
  78. 't.label'=>"Label",
  79. 't.description'=>"Description",
  80. 't.note_public'=>"NotePublic",
  81. );
  82. if (empty($user->socid)) $fieldstosearchall['t.note_private']="NotePrivate";
  83. $arrayfields=array(
  84. 'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>1),
  85. 'p.title'=>array('label'=>$langs->trans("ProjectLabel"), 'checked'=>0),
  86. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>0),
  87. 'p.fk_statut'=>array('label'=>$langs->trans("ProjectStatus"), 'checked'=>1),
  88. 't.ref'=>array('label'=>$langs->trans("RefTask"), 'checked'=>1, 'position'=>80),
  89. 't.label'=>array('label'=>$langs->trans("LabelTask"), 'checked'=>1, 'position'=>80),
  90. 't.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>100),
  91. 't.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>101),
  92. 't.planned_workload'=>array('label'=>$langs->trans("PlannedWorkload"), 'checked'=>1, 'position'=>102),
  93. 't.duration_effective'=>array('label'=>$langs->trans("TimeSpent"), 'checked'=>1, 'position'=>103),
  94. 't.progress_calculated'=>array('label'=>$langs->trans("ProgressCalculated"), 'checked'=>1, 'position'=>104),
  95. 't.progress'=>array('label'=>$langs->trans("ProgressDeclared"), 'checked'=>1, 'position'=>105),
  96. 't.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  97. 't.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  98. //'t.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  99. );
  100. // Extra fields
  101. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  102. {
  103. foreach($extrafields->attribute_label as $key => $val)
  104. {
  105. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  106. }
  107. }
  108. /*
  109. * Actions
  110. */
  111. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  112. // Purge criteria
  113. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  114. {
  115. $search_all="";
  116. $search_project="";
  117. $search_projectstatus=-1;
  118. $search_project_ref="";
  119. $search_project_title="";
  120. $search_task_ref="";
  121. $search_task_label="";
  122. $search_task_description="";
  123. $search_task_user=-1;
  124. $search_project_user=-1;
  125. $sday='';
  126. $smonth='';
  127. $syear='';
  128. $day='';
  129. $month='';
  130. $year='';
  131. }
  132. if (empty($search_projectstatus) && $search_projectstatus == '') $search_projectstatus=1;
  133. /*
  134. * View
  135. */
  136. $form=new Form($db);
  137. $formother=new FormOther($db);
  138. $socstatic=new Societe($db);
  139. $projectstatic = new Project($db);
  140. $taskstatic = new Task($db);
  141. $puser=new User($db);
  142. $tuser=new User($db);
  143. if ($search_project_user > 0) $puser->fetch($search_project_user);
  144. if ($search_task_user > 0) $tuser->fetch($search_task_user);
  145. $title=$langs->trans("Activities");
  146. if ($search_task_user == $user->id) $title=$langs->trans("MyActivities");
  147. llxHeader("",$title,"Projet");
  148. if ($id)
  149. {
  150. $projectstatic->fetch($id);
  151. $projectstatic->societe->fetch($projectstatic->societe->id);
  152. }
  153. // Get list of project id allowed to user (in a string list separated by coma)
  154. if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
  155. //var_dump($projectsListId);
  156. // Get id of types of contacts for projects (This list never contains a lot of elements)
  157. $listofprojectcontacttype=array();
  158. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  159. $sql.= " WHERE ctc.element = '" . $projectstatic->element . "'";
  160. $sql.= " AND ctc.source = 'internal'";
  161. $resql = $db->query($sql);
  162. if ($resql)
  163. {
  164. while($obj = $db->fetch_object($resql))
  165. {
  166. $listofprojectcontacttype[$obj->rowid]=$obj->code;
  167. }
  168. }
  169. else dol_print_error($db);
  170. if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0'; // To avoid sql syntax error if not found
  171. // Get id of types of contacts for tasks (This list never contains a lot of elements)
  172. $listoftaskcontacttype=array();
  173. $sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
  174. $sql.= " WHERE ctc.element = '" . $taskstatic->element . "'";
  175. $sql.= " AND ctc.source = 'internal'";
  176. $resql = $db->query($sql);
  177. if ($resql)
  178. {
  179. while($obj = $db->fetch_object($resql))
  180. {
  181. $listoftaskcontacttype[$obj->rowid]=$obj->code;
  182. }
  183. }
  184. else dol_print_error($db);
  185. if (count($listoftaskcontacttype) == 0) $listoftaskcontacttype[0]='0'; // To avoid sql syntax error if not found
  186. $distinct='DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is only once.
  187. $sql = "SELECT ".$distinct." p.rowid as projectid, p.ref as projectref, p.title as projecttitle, p.fk_statut as projectstatus, p.fk_opp_status, p.public, p.fk_user_creat as projectusercreate";
  188. $sql.= ", s.nom as name, s.rowid as socid";
  189. $sql.= ", t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_update";
  190. $sql.= ", t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut";
  191. // Add fields for extrafields
  192. foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key;
  193. // Add fields from hooks
  194. $parameters=array();
  195. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  196. $sql.=$hookmanager->resPrint;
  197. $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
  198. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid,";
  199. $sql.= " ".MAIN_DB_PREFIX."projet_task as t";
  200. if ($search_project_user > 0)
  201. {
  202. $sql.=", ".MAIN_DB_PREFIX."element_contact as ecp";
  203. }
  204. if ($search_task_user > 0)
  205. {
  206. $sql.=", ".MAIN_DB_PREFIX."element_contact as ect";
  207. }
  208. $sql.= " WHERE t.fk_projet = p.rowid";
  209. $sql.= " AND p.entity IN (".getEntity('project').')';
  210. if (! $user->rights->projet->all->lire) $sql.=" p.rowid IN (".join(',',$projectsListId).")"; // public and assigned to projects, or restricted to company for external users
  211. // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
  212. if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
  213. if ($search_project_ref) $sql .= natural_search('p.ref', $search_project_ref);
  214. if ($search_project_title) $sql .= natural_search('p.title', $search_project_title);
  215. if ($search_task_ref) $sql .= natural_search('t.ref', $search_task_ref);
  216. if ($search_task_label) $sql .= natural_search('t.label', $search_task_label);
  217. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  218. if ($smonth > 0)
  219. {
  220. if ($syear > 0 && empty($sday))
  221. $sql.= " AND t.dateo BETWEEN '".$db->idate(dol_get_first_day($syear,$smonth,false))."' AND '".$db->idate(dol_get_last_day($syear,$smonth,false))."'";
  222. else if ($syear > 0 && ! empty($sday))
  223. $sql.= " AND t.dateo BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
  224. else
  225. $sql.= " AND date_format(t.dateo, '%m') = '".$smonth."'";
  226. }
  227. else if ($syear > 0)
  228. {
  229. $sql.= " AND t.dateo BETWEEN '".$db->idate(dol_get_first_day($syear,1,false))."' AND '".$db->idate(dol_get_last_day($syear,12,false))."'";
  230. }
  231. if ($month > 0)
  232. {
  233. if ($year > 0 && empty($day))
  234. $sql.= " AND t.datee BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  235. else if ($year > 0 && ! empty($day))
  236. $sql.= " AND t.datee BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  237. else
  238. $sql.= " AND date_format(t.datee, '%m') = '".$month."'";
  239. }
  240. else if ($year > 0)
  241. {
  242. $sql.= " AND t.datee BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  243. }
  244. if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  245. if ($search_projectstatus >= 0) $sql .= " AND p.fk_statut = ".$db->escape($search_projectstatus);
  246. if ($search_public!='') $sql .= " AND p.public = ".$db->escape($search_public);
  247. if ($search_project_user > 0) $sql.= " AND ecp.fk_c_type_contact IN (".join(',',array_keys($listofprojectcontacttype)).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".$search_project_user;
  248. if ($search_task_user > 0) $sql.= " AND ect.fk_c_type_contact IN (".join(',',array_keys($listoftaskcontacttype)).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".$search_task_user;
  249. // Add where from hooks
  250. $parameters=array();
  251. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  252. $sql.=$hookmanager->resPrint;
  253. $sql.= $db->order($sortfield,$sortorder);
  254. $nbtotalofrecords = 0;
  255. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  256. {
  257. $result = $db->query($sql);
  258. $nbtotalofrecords = $db->num_rows($result);
  259. }
  260. $sql.= $db->plimit($limit + 1,$offset);
  261. dol_syslog("list allowed project", LOG_DEBUG);
  262. //print $sql;
  263. $resql = $db->query($sql);
  264. if ($resql)
  265. {
  266. $var=true;
  267. $num = $db->num_rows($resql);
  268. $param='';
  269. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  270. if ($sday) $param.='&sday='.$day;
  271. if ($smonth) $param.='&smonth='.$smonth;
  272. if ($syear) $param.='&syear=' .$syear;
  273. if ($day) $param.='&day='.$day;
  274. if ($month) $param.='&month='.$month;
  275. if ($year) $param.='&year=' .$year;
  276. if ($socid) $param.='&socid='.$socid;
  277. if ($search_all != '') $param.='&search_all='.$search_all;
  278. if ($search_project_ref != '') $param.='&search_project_ref='.$search_project_ref;
  279. if ($search_project_title != '') $param.='&search_project_title='.$search_project_title;
  280. if ($search_ref != '') $param.='&search_ref='.$search_ref;
  281. if ($search_label != '') $param.='&search_label='.$search_label;
  282. if ($search_societe != '') $param.='&search_societe='.$search_societe;
  283. if ($search_projectstatus != '') $param.='&search_projectstatus='.$search_projectstatus;
  284. if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all','none'))) $param.='&search_opp_status='.urlencode($search_opp_status);
  285. if ($search_public != '') $param.='&search_public='.$search_public;
  286. if ($search_project_user > 0) $param.='&search_project_user='.$search_project_user;
  287. if ($search_task_user > 0) $param.='&search_task_user='.$search_task_user;
  288. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  289. // Add $param from extra fields
  290. foreach ($search_array_options as $key => $val)
  291. {
  292. $crit=$val;
  293. $tmpkey=preg_replace('/search_options_/','',$key);
  294. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  295. }
  296. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  297. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  298. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  299. print '<input type="hidden" name="action" value="list">';
  300. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  301. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  302. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  303. print '<input type="hidden" name="type" value="'.$type.'">';
  304. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'title_project', 0, '', '', $limit);
  305. // Show description of content
  306. if ($search_task_user == $user->id) print $langs->trans("MyTasksDesc").'<br><br>';
  307. else
  308. {
  309. if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
  310. else print $langs->trans("ProjectsPublicDesc").'<br><br>';
  311. }
  312. if ($search_all)
  313. {
  314. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  315. print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
  316. }
  317. // If the user can view users
  318. $moreforfilter.='<div class="divsearchfield">';
  319. $moreforfilter.=$langs->trans('ProjectsWithThisUserAsContact'). ' ';
  320. $includeonly='';
  321. if (empty($user->rights->user->user->lire)) $includeonly=array($user->id);
  322. $moreforfilter.=$form->select_dolusers($search_project_user, 'search_project_user', 1, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300');
  323. $moreforfilter.='</div>';
  324. // If the user can view users
  325. $moreforfilter.='<div class="divsearchfield">';
  326. $moreforfilter.=$langs->trans('TasksWithThisUserAsContact'). ': ';
  327. $includeonly='';
  328. if (empty($user->rights->user->user->lire)) $includeonly=array($user->id);
  329. $moreforfilter.=$form->select_dolusers($search_task_user, 'search_task_user', 1, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300');
  330. $moreforfilter.='</div>';
  331. if (! empty($moreforfilter))
  332. {
  333. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  334. print $moreforfilter;
  335. $parameters=array();
  336. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  337. print $hookmanager->resPrint;
  338. print '</div>';
  339. }
  340. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  341. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  342. print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'" id="tablelines3">';
  343. print '<tr class="liste_titre">';
  344. if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder);
  345. if (! empty($arrayfields['p.title']['checked'])) print_liste_field_titre($arrayfields['p.title']['label'],$_SERVER["PHP_SELF"],"p.title","",$param,"",$sortfield,$sortorder);
  346. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  347. if (! empty($arrayfields['p.fk_statut']['checked'])) print_liste_field_titre($arrayfields['p.fk_statut']['label'],$_SERVER["PHP_SELF"],"p.fk_statut","",$param,"",$sortfield,$sortorder);
  348. if (! empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'],$_SERVER["PHP_SELF"],"t.ref","",$param,"",$sortfield,$sortorder);
  349. if (! empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'],$_SERVER["PHP_SELF"],"t.label","",$param,"",$sortfield,$sortorder);
  350. if (! empty($arrayfields['t.dateo']['checked'])) print_liste_field_titre($arrayfields['t.dateo']['label'],$_SERVER["PHP_SELF"],"t.dateo","",$param,'align="center"',$sortfield,$sortorder);
  351. if (! empty($arrayfields['t.datee']['checked'])) print_liste_field_titre($arrayfields['t.datee']['label'],$_SERVER["PHP_SELF"],"t.datee","",$param,'align="center"',$sortfield,$sortorder);
  352. if (! empty($arrayfields['t.planned_workload']['checked'])) print_liste_field_titre($arrayfields['t.planned_workload']['label'],$_SERVER["PHP_SELF"],"t.planned_workload","",$param,'align="center"',$sortfield,$sortorder);
  353. if (! empty($arrayfields['t.duration_effective']['checked'])) print_liste_field_titre($arrayfields['t.duration_effective']['label'],$_SERVER["PHP_SELF"],"t.duration_effective","",$param,'align="center"',$sortfield,$sortorder);
  354. if (! empty($arrayfields['t.progress_calculated']['checked'])) print_liste_field_titre($arrayfields['t.progress_calculated']['label'],$_SERVER["PHP_SELF"],"","",$param,'align="center"');
  355. if (! empty($arrayfields['t.progress']['checked'])) print_liste_field_titre($arrayfields['t.progress']['label'],$_SERVER["PHP_SELF"],"t.progress","",$param,'align="center"',$sortfield,$sortorder);
  356. // Extra fields
  357. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  358. {
  359. foreach($extrafields->attribute_label as $key => $val)
  360. {
  361. if (! empty($arrayfields["ef.".$key]['checked']))
  362. {
  363. $align=$extrafields->getAlignFlag($key);
  364. print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  365. }
  366. }
  367. }
  368. // Hook fields
  369. $parameters=array('arrayfields'=>$arrayfields);
  370. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  371. print $hookmanager->resPrint;
  372. if (! empty($arrayfields['t.datec']['checked'])) print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  373. if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  374. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
  375. print "</tr>\n";
  376. print '<tr class="liste_titre">';
  377. if (! empty($arrayfields['p.ref']['checked']))
  378. {
  379. print '<td class="liste_titre">';
  380. print '<input type="text" class="flat" name="search_project_ref" value="'.$search_project_ref.'" size="4">';
  381. print '</td>';
  382. }
  383. if (! empty($arrayfields['p.title']['checked']))
  384. {
  385. print '<td class="liste_titre">';
  386. print '<input type="text" class="flat" name="search_project_title" value="'.$search_project_title.'" size="6">';
  387. print '</td>';
  388. }
  389. if (! empty($arrayfields['s.nom']['checked']))
  390. {
  391. print '<td class="liste_titre">';
  392. print '<input type="text" class="flat" name="search_societe" value="'.dol_escape_htmltag($search_societe).'" size="4">';
  393. print '</td>';
  394. }
  395. if (! empty($arrayfields['p.fk_statut']['checked']))
  396. {
  397. print '<td class="liste_titre">';
  398. $listofstatus=array(-1=>'&nbsp;');
  399. foreach($projectstatic->statuts_short as $key => $val) $listofstatus[$key]=$langs->trans($val);
  400. print Form::selectarray('search_projectstatus', $listofstatus, $search_projectstatus);
  401. print '</td>';
  402. }
  403. if (! empty($arrayfields['t.ref']['checked']))
  404. {
  405. print '<td class="liste_titre">';
  406. print '<input type="text" class="flat" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'" size="4">';
  407. print '</td>';
  408. }
  409. if (! empty($arrayfields['t.label']['checked']))
  410. {
  411. print '<td class="liste_titre">';
  412. print '<input type="text" class="flat" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'" size="8">';
  413. print '</td>';
  414. }
  415. // Start date
  416. if (! empty($arrayfields['t.dateo']['checked']))
  417. {
  418. print '<td class="liste_titre center">';
  419. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="sday" value="'.$sday.'">';
  420. print '<input class="flat" type="text" size="1" maxlength="2" name="smonth" value="'.$smonth.'">';
  421. $formother->select_year($syear?$syear:-1,'syear',1, 20, 5);
  422. print '</td>';
  423. }
  424. // End date
  425. if (! empty($arrayfields['t.datee']['checked']))
  426. {
  427. print '<td class="liste_titre center">';
  428. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  429. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  430. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  431. print '</td>';
  432. }
  433. if (! empty($arrayfields['t.planned_workload']['checked'])) print '<td></td>';
  434. if (! empty($arrayfields['t.duration_effective']['checked'])) print '<td></td>';
  435. if (! empty($arrayfields['t.progress_calculated']['checked'])) print '<td></td>';
  436. if (! empty($arrayfields['t.progress']['checked'])) print '<td></td>';
  437. // Extra fields
  438. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  439. {
  440. foreach($extrafields->attribute_label as $key => $val)
  441. {
  442. if (! empty($arrayfields["ef.".$key]['checked'])) print '<td class="liste_titre"></td>';
  443. }
  444. }
  445. // Fields from hook
  446. $parameters=array('arrayfields'=>$arrayfields);
  447. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  448. print $hookmanager->resPrint;
  449. if (! empty($arrayfields['t.datec']['checked']))
  450. {
  451. // Date creation
  452. print '<td class="liste_titre">';
  453. print '</td>';
  454. }
  455. if (! empty($arrayfields['t.tms']['checked']))
  456. {
  457. // Date modification
  458. print '<td class="liste_titre">';
  459. print '</td>';
  460. }
  461. // Action column
  462. print '<td class="liste_titre" align="right">';
  463. $searchpitco=$form->showFilterAndCheckAddButtons(0);
  464. print $searchpitco;
  465. print '</td>';
  466. print '</tr>';
  467. $i = 0;
  468. while ($i < min($num,$limit))
  469. {
  470. $obj = $db->fetch_object($resql);
  471. $projectstatic->id = $obj->projectid;
  472. $projectstatic->ref = $obj->projectref;
  473. $projectstatic->title = $obj->projecttitle;
  474. $projectstatic->public = $obj->public;
  475. $projectstatic->statut = $obj->projectstatus;
  476. $taskstatic->id = $obj->id;
  477. $taskstatic->ref = $obj->ref;
  478. $taskstatic->label = $obj->label;
  479. $taskstatic->fk_statut = $obj->fk_statut;
  480. $taskstatic->progress = $obj->progress;
  481. $userAccess = $projectstatic->restrictedProjectArea($user); // why this ?
  482. if ($userAccess >= 0)
  483. {
  484. $var=!$var;
  485. print "<tr ".$bc[$var].">";
  486. // Project url
  487. if (! empty($arrayfields['p.ref']['checked']))
  488. {
  489. print '<td class="nowrap">';
  490. print $projectstatic->getNomUrl(1, 'task');
  491. print '</td>';
  492. }
  493. // Title
  494. if (! empty($arrayfields['p.title']['checked']))
  495. {
  496. print '<td>';
  497. print dol_trunc($obj->projecttitle,80);
  498. print '</td>';
  499. }
  500. // Company
  501. if (! empty($arrayfields['s.nom']['checked']))
  502. {
  503. print '<td>';
  504. if ($obj->socid)
  505. {
  506. $socstatic->id=$obj->socid;
  507. $socstatic->name=$obj->name;
  508. print $socstatic->getNomUrl(1);
  509. }
  510. else
  511. {
  512. print '&nbsp;';
  513. }
  514. print '</td>';
  515. }
  516. // Status
  517. if (! empty($arrayfields['p.fk_statut']['checked']))
  518. {
  519. print '<td>';
  520. print $projectstatic->getLibStatut(1);
  521. print '</td>';
  522. }
  523. // Ref
  524. if (! empty($arrayfields['t.ref']['checked']))
  525. {
  526. print '<td>';
  527. print $taskstatic->getNomUrl(1,'withproject');
  528. print '</td>';
  529. }
  530. // Label
  531. if (! empty($arrayfields['t.label']['checked']))
  532. {
  533. print '<td>';
  534. print $taskstatic->label;
  535. print '</td>';
  536. }
  537. // Date start
  538. if (! empty($arrayfields['t.dateo']['checked']))
  539. {
  540. print '<td class="center">';
  541. print dol_print_date($db->jdate($obj->date_start),'day');
  542. print '</td>';
  543. }
  544. // Date end
  545. if (! empty($arrayfields['t.datee']['checked']))
  546. {
  547. print '<td class="center">';
  548. print dol_print_date($db->jdate($obj->date_end),'day');
  549. print '</td>';
  550. }
  551. $plannedworkloadoutputformat='allhourmin';
  552. $timespentoutputformat='allhourmin';
  553. if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  554. if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
  555. // Planned workload
  556. if (! empty($arrayfields['t.planned_workload']['checked']))
  557. {
  558. print '<td class="center">';
  559. $fullhour=convertSecondToTime($obj->planned_workload,$plannedworkloadoutputformat);
  560. $workingdelay=convertSecondToTime($obj->planned_workload,'all',86400,7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
  561. if ($obj->planned_workload != '')
  562. {
  563. print $fullhour;
  564. // TODO Add delay taking account of working hours per day and working day per week
  565. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  566. }
  567. //else print '--:--';
  568. print '</td>';
  569. }
  570. // Time spent
  571. if (! empty($arrayfields['t.duration_effective']['checked']))
  572. {
  573. $showlineingray=0;$showproject=1;
  574. print '<td class="center">';
  575. if ($showlineingray) print '<i>';
  576. else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
  577. if ($obj->duration_effective) print convertSecondToTime($obj->duration_effective,$timespentoutputformat);
  578. else print '--:--';
  579. if ($showlineingray) print '</i>';
  580. else print '</a>';
  581. print '</td>';
  582. }
  583. // Calculated progress
  584. if (! empty($arrayfields['t.progress_calculated']['checked']))
  585. {
  586. print '<td class="center">';
  587. if ($obj->planned_workload || $obj->duration_effective)
  588. {
  589. if ($obj->planned_workload) print round(100 * $obj->duration_effective / $obj->planned_workload,2).' %';
  590. else print $langs->trans('WorkloadNotDefined');
  591. }
  592. print '</td>';
  593. }
  594. // Declared progress
  595. if (! empty($arrayfields['t.progress']['checked']))
  596. {
  597. print '<td class="center">';
  598. if ($obj->progress != '')
  599. {
  600. print $obj->progress.' %';
  601. }
  602. print '</td>';
  603. }
  604. // Extra fields
  605. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  606. {
  607. foreach($extrafields->attribute_label as $key => $val)
  608. {
  609. if (! empty($arrayfields["ef.".$key]['checked']))
  610. {
  611. print '<td';
  612. $align=$extrafields->getAlignFlag($key);
  613. if ($align) print ' align="'.$align.'"';
  614. print '>';
  615. $tmpkey='options_'.$key;
  616. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  617. print '</td>';
  618. }
  619. }
  620. }
  621. // Fields from hook
  622. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  623. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  624. print $hookmanager->resPrint;
  625. // Date creation
  626. if (! empty($arrayfields['t.datec']['checked']))
  627. {
  628. print '<td align="center">';
  629. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  630. print '</td>';
  631. }
  632. // Date modification
  633. if (! empty($arrayfields['t.tms']['checked']))
  634. {
  635. print '<td align="center">';
  636. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  637. print '</td>';
  638. }
  639. // Status
  640. /*if (! empty($arrayfields['p.fk_statut']['checked']))
  641. {
  642. $projectstatic->statut = $obj->fk_statut;
  643. print '<td align="right">'.$projectstatic->getLibStatut(5).'</td>';
  644. }*/
  645. // Action column
  646. print '<td></td>';
  647. print "</tr>\n";
  648. //print projectLinesa();
  649. }
  650. $i++;
  651. }
  652. $db->free($resql);
  653. $parameters=array('sql' => $sql);
  654. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  655. print $hookmanager->resPrint;
  656. print "</table>";
  657. print '</form>';
  658. }
  659. else
  660. {
  661. dol_print_error($db);
  662. }
  663. llxFooter();
  664. $db->close();