time.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  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 3 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/projet/tasks/time.php
  22. * \ingroup project
  23. * \brief Page to add new time spent on a task
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. $langs->load('projects');
  32. $id=GETPOST('id','int');
  33. $projectid=GETPOST('projectid','int');
  34. $ref=GETPOST('ref','alpha');
  35. $action=GETPOST('action','alpha');
  36. $confirm=GETPOST('confirm','alpha');
  37. $withproject=GETPOST('withproject','int');
  38. $project_ref=GETPOST('project_ref','alpha');
  39. $search_dateday=GETPOST('search_dateday');
  40. $search_datemonth=GETPOST('search_datemonth');
  41. $search_dateyear=GETPOST('search_dateyear');
  42. $search_datehour='';
  43. $search_datewithhour='';
  44. $search_note=GETPOST('search_note','alpha');
  45. $search_duration=GETPOST('search_duration','int');
  46. $search_value=GETPOST('search_value','int');
  47. $search_task_ref=GETPOST('search_task_ref','alpha');
  48. $search_task_label=GETPOST('search_task_label','alpha');
  49. $search_user=GETPOST('search_user','int');
  50. // Security check
  51. $socid=0;
  52. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  53. if (!$user->rights->projet->lire) accessforbidden();
  54. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  55. $sortfield = GETPOST("sortfield",'alpha');
  56. $sortorder = GETPOST("sortorder",'alpha');
  57. $page = GETPOST("page",'int');
  58. if ($page == -1) { $page = 0; }
  59. $offset = $limit * $page;
  60. $pageprev = $page - 1;
  61. $pagenext = $page + 1;
  62. if (! $sortfield) $sortfield='t.task_date,t.task_datehour,t.rowid';
  63. if (! $sortorder) $sortorder='DESC';
  64. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  65. $hookmanager->initHooks(array('projecttaskcard','globalcard'));
  66. $object = new Task($db);
  67. $projectstatic = new Project($db);
  68. $extrafields_project = new ExtraFields($db);
  69. $extrafields_task = new ExtraFields($db);
  70. if ($projectid > 0 || ! empty($ref))
  71. {
  72. // fetch optionals attributes and labels
  73. $extralabels_projet=$extrafields_project->fetch_name_optionals_label($projectstatic->table_element);
  74. }
  75. $extralabels_task=$extrafields_task->fetch_name_optionals_label($object->table_element);
  76. /*
  77. * Actions
  78. */
  79. $parameters=array('socid'=>$socid, 'projectid'=>$projectid);
  80. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  81. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  83. // Purge search criteria
  84. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
  85. {
  86. $search_date='';
  87. $search_datehour='';
  88. $search_datewithhour='';
  89. $search_note='';
  90. $search_duration='';
  91. $search_value='';
  92. $search_date_creation='';
  93. $search_date_update='';
  94. $search_task_ref='';
  95. $search_task_label='';
  96. $search_user=0;
  97. $toselect='';
  98. $search_array_options=array();
  99. $action='';
  100. }
  101. if ($action == 'addtimespent' && $user->rights->projet->lire)
  102. {
  103. $error=0;
  104. $timespent_durationhour = GETPOST('timespent_durationhour','int');
  105. $timespent_durationmin = GETPOST('timespent_durationmin','int');
  106. if (empty($timespent_durationhour) && empty($timespent_durationmin))
  107. {
  108. setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")), null, 'errors');
  109. $error++;
  110. }
  111. if (empty($_POST["userid"]))
  112. {
  113. $langs->load("errors");
  114. setEventMessages($langs->trans('ErrorUserNotAssignedToTask'), null, 'errors');
  115. $error++;
  116. }
  117. if (! $error)
  118. {
  119. $object->fetch($id, $ref);
  120. $object->fetch_projet();
  121. if (empty($object->projet->statut))
  122. {
  123. setEventMessages($langs->trans("ProjectMustBeValidatedFirst"), null, 'errors');
  124. $error++;
  125. }
  126. else
  127. {
  128. $object->timespent_note = $_POST["timespent_note"];
  129. $object->progress = GETPOST('progress', 'int');
  130. $object->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds
  131. $object->timespent_duration+= $_POST["timespent_durationmin"]*60; // We store duration in seconds
  132. if (GETPOST("timehour") != '' && GETPOST("timehour") >= 0) // If hour was entered
  133. {
  134. $object->timespent_date = dol_mktime(GETPOST("timehour"),GETPOST("timemin"),0,GETPOST("timemonth"),GETPOST("timeday"),GETPOST("timeyear"));
  135. $object->timespent_withhour = 1;
  136. }
  137. else
  138. {
  139. $object->timespent_date = dol_mktime(12,0,0,GETPOST("timemonth"),GETPOST("timeday"),GETPOST("timeyear"));
  140. }
  141. $object->timespent_fk_user = $_POST["userid"];
  142. $result=$object->addTimeSpent($user);
  143. if ($result >= 0)
  144. {
  145. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  146. }
  147. else
  148. {
  149. setEventMessages($langs->trans($object->error), null, 'errors');
  150. $error++;
  151. }
  152. }
  153. }
  154. else
  155. {
  156. $action='';
  157. }
  158. }
  159. if ($action == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->lire)
  160. {
  161. $error=0;
  162. if (empty($_POST["new_durationhour"]) && empty($_POST["new_durationmin"]))
  163. {
  164. setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")), null, 'errors');
  165. $error++;
  166. }
  167. if (! $error)
  168. {
  169. $object->fetch($id, $ref);
  170. // TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
  171. $object->timespent_id = $_POST["lineid"];
  172. $object->timespent_note = $_POST["timespent_note_line"];
  173. $object->timespent_old_duration = $_POST["old_duration"];
  174. $object->timespent_duration = $_POST["new_durationhour"]*60*60; // We store duration in seconds
  175. $object->timespent_duration+= $_POST["new_durationmin"]*60; // We store duration in seconds
  176. if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
  177. {
  178. $object->timespent_date = dol_mktime(GETPOST("timelinehour"),GETPOST("timelinemin"),0,GETPOST("timelinemonth"),GETPOST("timelineday"),GETPOST("timelineyear"));
  179. $object->timespent_withhour = 1;
  180. }
  181. else
  182. {
  183. $object->timespent_date = dol_mktime(12,0,0,GETPOST("timelinemonth"),GETPOST("timelineday"),GETPOST("timelineyear"));
  184. }
  185. $object->timespent_fk_user = $_POST["userid_line"];
  186. $result=$object->updateTimeSpent($user);
  187. if ($result >= 0)
  188. {
  189. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  190. }
  191. else
  192. {
  193. setEventMessages($langs->trans($object->error), null, 'errors');
  194. $error++;
  195. }
  196. }
  197. else
  198. {
  199. $action='';
  200. }
  201. }
  202. if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->lire)
  203. {
  204. $object->fetchTimeSpent($_GET['lineid']);
  205. // TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
  206. $result = $object->delTimeSpent($user);
  207. if ($result < 0)
  208. {
  209. $langs->load("errors");
  210. setEventMessages($langs->trans($object->error), null, 'errors');
  211. $error++;
  212. $action='';
  213. }
  214. }
  215. // Retreive First Task ID of Project if withprojet is on to allow project prev next to work
  216. if (! empty($project_ref) && ! empty($withproject))
  217. {
  218. if ($projectstatic->fetch(0,$project_ref) > 0)
  219. {
  220. $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  221. if (count($tasksarray) > 0)
  222. {
  223. $id=$tasksarray[0]->id;
  224. }
  225. else
  226. {
  227. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject?'&withproject=1':'').(empty($mode)?'':'&mode='.$mode));
  228. exit;
  229. }
  230. }
  231. }
  232. // To show all time lines for project
  233. $projectidforalltimes=0;
  234. if (GETPOST('projectid'))
  235. {
  236. $projectidforalltimes=GETPOST('projectid','int');
  237. }
  238. /*
  239. * View
  240. */
  241. llxHeader("",$langs->trans("Task"));
  242. $form = new Form($db);
  243. $formother = new FormOther($db);
  244. $userstatic = new User($db);
  245. if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
  246. {
  247. /*
  248. * Fiche projet en mode visu
  249. */
  250. if ($projectidforalltimes)
  251. {
  252. $result=$projectstatic->fetch($projectidforalltimes);
  253. if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
  254. $res=$projectstatic->fetch_optionals($object->id,$extralabels_projet);
  255. }
  256. elseif ($object->fetch($id, $ref) >= 0)
  257. {
  258. $result=$projectstatic->fetch($object->fk_project);
  259. if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
  260. $res=$projectstatic->fetch_optionals($object->id,$extralabels_projet);
  261. $object->project = clone $projectstatic;
  262. }
  263. $userWrite = $projectstatic->restrictedProjectArea($user,'write');
  264. if ($projectstatic->id > 0)
  265. {
  266. if ($withproject)
  267. {
  268. // Tabs for project
  269. $tab='tasks';
  270. $head=project_prepare_head($projectstatic);
  271. dol_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public?'projectpub':'project'));
  272. $param=($mode=='mine'?'&mode=mine':'');
  273. // Project card
  274. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
  275. $morehtmlref='<div class="refidno">';
  276. // Title
  277. $morehtmlref.=$projectstatic->title;
  278. // Thirdparty
  279. if ($projectstatic->thirdparty->id > 0)
  280. {
  281. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $projectstatic->thirdparty->getNomUrl(1, 'project');
  282. }
  283. $morehtmlref.='</div>';
  284. // Define a complementary filter for search of next/prev ref.
  285. if (! $user->rights->projet->all->lire)
  286. {
  287. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,0);
  288. $projectstatic->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  289. }
  290. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  291. print '<div class="fichecenter">';
  292. print '<div class="fichehalfleft">';
  293. print '<div class="underbanner clearboth"></div>';
  294. print '<table class="border" width="100%">';
  295. // Visibility
  296. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  297. if ($projectstatic->public) print $langs->trans('SharedProject');
  298. else print $langs->trans('PrivateProject');
  299. print '</td></tr>';
  300. // Date start - end
  301. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  302. print dol_print_date($projectstatic->date_start,'day');
  303. $end=dol_print_date($projectstatic->date_end,'day');
  304. if ($end) print ' - '.$end;
  305. print '</td></tr>';
  306. // Budget
  307. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  308. if (strcmp($projectstatic->budget_amount, '')) print price($projectstatic->budget_amount,'',$langs,1,0,0,$conf->currency);
  309. print '</td></tr>';
  310. // Other attributes
  311. $cols = 2;
  312. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  313. print '</table>';
  314. print '</div>';
  315. print '<div class="fichehalfright">';
  316. print '<div class="ficheaddleft">';
  317. print '<div class="underbanner clearboth"></div>';
  318. print '<table class="border" width="100%">';
  319. // Description
  320. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  321. print nl2br($projectstatic->description);
  322. print '</td></tr>';
  323. // Categories
  324. if($conf->categorie->enabled) {
  325. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
  326. print $form->showCategories($projectstatic->id,'project',1);
  327. print "</td></tr>";
  328. }
  329. print '</table>';
  330. print '</div>';
  331. print '</div>';
  332. print '</div>';
  333. print '<div class="clearboth"></div>';
  334. dol_fiche_end();
  335. /*
  336. * Actions
  337. */
  338. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes))
  339. {
  340. print '<div class="tabsAction">';
  341. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  342. {
  343. if ($object->public || $userWrite > 0)
  344. {
  345. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans('AddTask').'</a>';
  346. }
  347. else
  348. {
  349. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  350. }
  351. }
  352. else
  353. {
  354. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  355. }
  356. print '</div>';
  357. }
  358. }
  359. }
  360. if (empty($projectidforalltimes))
  361. {
  362. $head=task_prepare_head($object);
  363. dol_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask');
  364. if ($action == 'deleteline')
  365. {
  366. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.'&lineid='.$_GET["lineid"].($withproject?'&withproject=1':''),$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1);
  367. }
  368. $param=($withproject?'&withproject=1':'');
  369. $linkback=$withproject?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>':'';
  370. if (! GETPOST('withproject') || empty($projectstatic->id))
  371. {
  372. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
  373. $object->next_prev_filter=" fk_projet in (".$projectsListId.")";
  374. }
  375. else $object->next_prev_filter=" fk_projet = ".$projectstatic->id;
  376. $morehtmlref='';
  377. // Project
  378. if (empty($withproject))
  379. {
  380. $morehtmlref.='<div class="refidno">';
  381. $morehtmlref.=$langs->trans("Project").': ';
  382. $morehtmlref.=$projectstatic->getNomUrl(1);
  383. $morehtmlref.='<br>';
  384. // Third party
  385. $morehtmlref.=$langs->trans("ThirdParty").': ';
  386. $morehtmlref.=$projectstatic->thirdparty->getNomUrl(1);
  387. $morehtmlref.='</div>';
  388. }
  389. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  390. print '<div class="fichecenter">';
  391. print '<div class="fichehalfleft">';
  392. print '<div class="underbanner clearboth"></div>';
  393. print '<table class="border" width="100%">';
  394. // Date start - Date end
  395. print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  396. $start = dol_print_date($object->date_start,'dayhour');
  397. print ($start?$start:'?');
  398. $end = dol_print_date($object->date_end,'dayhour');
  399. print ' - ';
  400. print ($end?$end:'?');
  401. if ($object->hasDelay()) print img_warning("Late");
  402. print '</td></tr>';
  403. // Planned workload
  404. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  405. print convertSecondToTime($object->planned_workload,'allhourmin');
  406. print '</td></tr>';
  407. print '</table>';
  408. print '</div>';
  409. print '<div class="fichehalfright"><div class="ficheaddleft">';
  410. print '<div class="underbanner clearboth"></div>';
  411. print '<table class="border" width="100%">';
  412. // Progress declared
  413. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td>';
  414. print $object->progress.' %';
  415. print '</td></tr>';
  416. // Progress calculated
  417. print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td>';
  418. if ($object->planned_workload)
  419. {
  420. $tmparray=$object->getSummaryOfTimeSpent();
  421. if ($tmparray['total_duration'] > 0) print round($tmparray['total_duration']/$object->planned_workload*100, 2).' %';
  422. else print '0 %';
  423. }
  424. else print '';
  425. print '</td></tr>';
  426. print '</table>';
  427. print '</div>';
  428. print '</div>';
  429. print '</div>';
  430. print '<div class="clearboth"></div>';
  431. dol_fiche_end();
  432. /*
  433. * Form to add time spent
  434. */
  435. if ($user->rights->projet->lire)
  436. {
  437. print '<br>';
  438. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  439. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  440. print '<input type="hidden" name="action" value="addtimespent">';
  441. print '<input type="hidden" name="id" value="'.$object->id.'">';
  442. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  443. print '<table class="noborder nohover" width="100%">';
  444. print '<tr class="liste_titre">';
  445. print '<td>'.$langs->trans("Date").'</td>';
  446. print '<td>'.$langs->trans("By").'</td>';
  447. print '<td>'.$langs->trans("Note").'</td>';
  448. print '<td>'.$langs->trans("NewTimeSpent").'</td>';
  449. print '<td>'.$langs->trans("ProgressDeclared").'</td>';
  450. print '<td></td>';
  451. print "</tr>\n";
  452. print '<tr class="oddeven">';
  453. // Date
  454. print '<td class="maxwidthonsmartphone">';
  455. //$newdate=dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
  456. $newdate='';
  457. print $form->select_date($newdate, 'time', ($conf->browser->layout == 'phone'?2:1), 1, 2, "timespent_date", 1, 0, 1);
  458. print '</td>';
  459. // Contributor
  460. print '<td class="maxwidthonsmartphone">';
  461. print img_object('','user','class="hideonsmartphone"');
  462. $contactsoftask=$object->getListContactId('internal');
  463. if (count($contactsoftask)>0)
  464. {
  465. $userid=$contactsoftask[0];
  466. print $form->select_dolusers((GETPOST('userid')?GETPOST('userid'):$userid), 'userid', 0, '', 0, '', $contactsoftask, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToTheTask"), 'maxwidth200');
  467. }
  468. else
  469. {
  470. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  471. }
  472. print '</td>';
  473. // Note
  474. print '<td>';
  475. print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="'.ROWS_2.'">'.($_POST['timespent_note']?$_POST['timespent_note']:'').'</textarea>';
  476. print '</td>';
  477. // Duration - Time spent
  478. print '<td>';
  479. print $form->select_duration('timespent_duration', ($_POST['timespent_duration']?$_POST['timespent_duration']:''), 0, 'text');
  480. print '</td>';
  481. // Progress declared
  482. print '<td class="nowrap">';
  483. print $formother->select_percent(GETPOST('progress')?GETPOST('progress'):$object->progress,'progress');
  484. print '</td>';
  485. print '<td align="center">';
  486. print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
  487. print '</td></tr>';
  488. print '</table></form>';
  489. print '<br>';
  490. }
  491. }
  492. if ($projectstatic->id > 0)
  493. {
  494. if ($action == 'deleteline')
  495. {
  496. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.'&lineid='.$_GET["lineid"].($withproject?'&withproject=1':''),$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1);
  497. }
  498. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  499. $hookmanager->initHooks(array('tasktimelist'));
  500. $extrafields = new ExtraFields($db);
  501. // Definition of fields for list
  502. $arrayfields=array();
  503. $arrayfields['t.task_date']=array('label'=>$langs->trans("Date"), 'checked'=>1);
  504. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
  505. {
  506. $arrayfields['t.task_ref']=array('label'=>$langs->trans("RefTask"), 'checked'=>1);
  507. $arrayfields['t.task_label']=array('label'=>$langs->trans("LabelTask"), 'checked'=>1);
  508. }
  509. $arrayfields['author']=array('label'=>$langs->trans("By"), 'checked'=>1);
  510. $arrayfields['t.note']=array('label'=>$langs->trans("Note"), 'checked'=>1);
  511. $arrayfields['t.task_duration']=array('label'=>$langs->trans("Duration"), 'checked'=>1);
  512. $arrayfields['value']=array('label'=>$langs->trans("Value"), 'checked'=>1, 'enabled'=>$conf->salaries->enabled);
  513. // Extra fields
  514. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  515. {
  516. foreach($extrafields->attribute_label as $key => $val)
  517. {
  518. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  519. }
  520. }
  521. /*
  522. * List of time spent
  523. */
  524. $tasks = array();
  525. $sql = "SELECT t.rowid, t.fk_task, t.task_date, t.task_datehour, t.task_date_withhour, t.task_duration, t.fk_user, t.note, t.thm,";
  526. $sql .= " pt.ref, pt.label,";
  527. $sql .= " u.lastname, u.firstname, u.login, u.photo";
  528. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  529. $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  530. if (empty($projectidforalltimes)) $sql .= " AND t.fk_task =".$object->id;
  531. else $sql.= " AND pt.fk_projet IN (".$projectidforalltimes.")";
  532. if ($search_ref) $sql .= natural_search('c.ref', $search_ref);
  533. if ($search_note) $sql .= natural_search('t.note', $search_note);
  534. if ($search_task_ref) $sql .= natural_search('pt.ref', $search_task_ref);
  535. if ($search_task_label) $sql .= natural_search('pt.label', $search_task_label);
  536. if ($search_user > 0) $sql .= natural_search('t.fk_user', $search_user);
  537. $sql .= $db->order($sortfield, $sortorder);
  538. $var=true;
  539. $resql = $db->query($sql);
  540. if ($resql)
  541. {
  542. $num = $db->num_rows($resql);
  543. $totalnboflines=$num;
  544. if (! empty($projectidforalltimes))
  545. {
  546. $title=$langs->trans("ListTaskTimeUserProject");
  547. $linktotasks='<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("GoToListOfTasks").'</a>';
  548. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1);
  549. print load_fiche_titre($title,$linktotasks,'title_generic.png');
  550. }
  551. $i = 0;
  552. while ($i < $num)
  553. {
  554. $row = $db->fetch_object($resql);
  555. $tasks[$i] = $row;
  556. $i++;
  557. }
  558. $db->free($resql);
  559. }
  560. else
  561. {
  562. dol_print_error($db);
  563. }
  564. $arrayofselected=is_array($toselect)?$toselect:array();
  565. $params='';
  566. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  567. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  568. if ($search_note != '') $params.= '&amp;search_note='.urlencode($search_note);
  569. if ($search_duration != '') $params.= '&amp;search_field2='.urlencode($search_duration);
  570. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  571. // Add $param from extra fields
  572. /*foreach ($search_array_options as $key => $val)
  573. {
  574. $crit=$val;
  575. $tmpkey=preg_replace('/search_options_/','',$key);
  576. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  577. }*/
  578. if ($id) $params.='&amp;id='.$id;
  579. if ($projectid) $params.='&amp;projectid='.$projectid;
  580. if ($withproject) $params.='&amp;withproject='.$withproject;
  581. $arrayofmassactions = array(
  582. //'presend'=>$langs->trans("SendByMail"),
  583. //'builddoc'=>$langs->trans("PDFMerge"),
  584. );
  585. //if ($user->rights->projet->creer) $arrayofmassactions['delete']=$langs->trans("Delete");
  586. if ($massaction == 'presend') $arrayofmassactions=array();
  587. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  588. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
  589. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  590. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  591. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  592. if ($action == 'editline') print '<input type="hidden" name="action" value="updateline">';
  593. else print '<input type="hidden" name="action" value="list">';
  594. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  595. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  596. print '<input type="hidden" name="page" value="'.$page.'">';
  597. print '<input type="hidden" name="id" value="'.$id.'">';
  598. print '<input type="hidden" name="projectid" value="'.$projectidforalltimes.'">';
  599. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  600. $moreforfilter = '';
  601. $parameters=array();
  602. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  603. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  604. else $moreforfilter = $hookmanager->resPrint;
  605. if (! empty($moreforfilter))
  606. {
  607. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  608. print $moreforfilter;
  609. print '</div>';
  610. }
  611. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  612. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  613. print '<div class="div-table-responsive">';
  614. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  615. // Fields title search
  616. print '<tr class="liste_titre_filter">';
  617. // Date
  618. if (! empty($arrayfields['t.task_date']['checked'])) print '<td class="liste_titre"></td>';
  619. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
  620. {
  621. if (! empty($arrayfields['t.task_ref']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
  622. if (! empty($arrayfields['t.task_label']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
  623. }
  624. // Author
  625. if (! empty($arrayfields['author']['checked'])) print '<td class="liste_titre">'.$form->select_dolusers($search_user > 0 ? $search_user : -1, 'search_user', 1).'</td>';
  626. // Note
  627. if (! empty($arrayfields['t.note']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_note" value="'.dol_escape_htmltag($search_note).'"></td>';
  628. // Duration
  629. if (! empty($arrayfields['t.task_duration']['checked'])) print '<td class="liste_titre right"></td>';
  630. // Value in currency
  631. if (! empty($arrayfields['value']['checked'])) print '<td class="liste_titre"></td>';
  632. // Extra fields
  633. /*
  634. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  635. {
  636. foreach($extrafields->attribute_label as $key => $val)
  637. {
  638. if (! empty($arrayfields["ef.".$key]['checked']))
  639. {
  640. $align=$extrafields->getAlignFlag($key);
  641. $typeofextrafield=$extrafields->attribute_type[$key];
  642. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  643. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  644. {
  645. $crit=$val;
  646. $tmpkey=preg_replace('/search_options_/','',$key);
  647. $searchclass='';
  648. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  649. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  650. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  651. }
  652. print '</td>';
  653. }
  654. }
  655. }*/
  656. // Fields from hook
  657. $parameters=array('arrayfields'=>$arrayfields);
  658. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  659. print $hookmanager->resPrint;
  660. // Action column
  661. print '<td class="liste_titre center">';
  662. $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
  663. print $searchpicto;
  664. print '</td>';
  665. print '</tr>'."\n";
  666. print '<tr class="liste_titre">';
  667. if (! empty($arrayfields['t.task_date']['checked'])) print_liste_field_titre($arrayfields['t.task_date']['label'],$_SERVER['PHP_SELF'],'t.task_date,t.task_datehour,t.rowid','',$params,'',$sortfield,$sortorder);
  668. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
  669. {
  670. if (! empty($arrayfields['t.task_ref']['checked'])) print_liste_field_titre($arrayfields['t.task_ref']['label'],$_SERVER['PHP_SELF'],'pt.ref','',$params,'',$sortfield,$sortorder);
  671. if (! empty($arrayfields['t.task_label']['checked'])) print_liste_field_titre($arrayfields['t.task_label']['label'],$_SERVER['PHP_SELF'],'pt.label','',$params,'',$sortfield,$sortorder);
  672. }
  673. if (! empty($arrayfields['author']['checked'])) print_liste_field_titre($arrayfields['author']['label'],$_SERVER['PHP_SELF'],'','',$params,'',$sortfield,$sortorder);
  674. if (! empty($arrayfields['t.note']['checked'])) print_liste_field_titre($arrayfields['t.note']['label'],$_SERVER['PHP_SELF'],'t.note','',$params,'',$sortfield,$sortorder);
  675. if (! empty($arrayfields['t.task_duration']['checked'])) print_liste_field_titre($arrayfields['t.task_duration']['label'],$_SERVER['PHP_SELF'],'t.task_duration','',$params,'align="right"',$sortfield,$sortorder);
  676. if (! empty($arrayfields['value']['checked'])) print_liste_field_titre($arrayfields['value']['label'],$_SERVER['PHP_SELF'],'','',$params,'align="right"',$sortfield,$sortorder);
  677. // Extra fields
  678. /*
  679. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  680. {
  681. foreach($extrafields->attribute_label as $key => $val)
  682. {
  683. if (! empty($arrayfields["ef.".$key]['checked']))
  684. {
  685. $align=$extrafields->getAlignFlag($key);
  686. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  687. }
  688. }
  689. }*/
  690. // Hook fields
  691. $parameters=array('arrayfields'=>$arrayfields);
  692. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  693. print $hookmanager->resPrint;
  694. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch ');
  695. print "</tr>\n";
  696. $tasktmp = new Task($db);
  697. $i = 0;
  698. $childids = $user->getAllChildIds();
  699. $total = 0;
  700. $totalvalue = 0;
  701. $totalarray=array();
  702. foreach ($tasks as $task_time)
  703. {
  704. print '<tr class="oddeven">';
  705. $date1=$db->jdate($task_time->task_date);
  706. $date2=$db->jdate($task_time->task_datehour);
  707. // Date
  708. if (! empty($arrayfields['t.task_date']['checked']))
  709. {
  710. print '<td class="nowrap">';
  711. if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
  712. {
  713. print $form->select_date(($date2?$date2:$date1),'timeline',1,1,2,"timespent_date",1,0,1);
  714. }
  715. else
  716. {
  717. print dol_print_date(($date2?$date2:$date1),($task_time->task_date_withhour?'dayhour':'day'));
  718. }
  719. print '</td>';
  720. if (! $i) $totalarray['nbfield']++;
  721. }
  722. // Task ref
  723. if (! empty($arrayfields['t.task_ref']['checked']))
  724. {
  725. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
  726. {
  727. print '<td class="nowrap">';
  728. $tasktmp->id = $task_time->fk_task;
  729. $tasktmp->ref = $task_time->ref;
  730. $tasktmp->label = $task_time->label;
  731. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  732. print '</td>';
  733. if (! $i) $totalarray['nbfield']++;
  734. }
  735. }
  736. // Task label
  737. if (! empty($arrayfields['t.task_label']['checked']))
  738. {
  739. if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
  740. {
  741. print '<td class="nowrap">';
  742. print $task_time->label;
  743. print '</td>';
  744. if (! $i) $totalarray['nbfield']++;
  745. }
  746. }
  747. // User
  748. if (! empty($arrayfields['author']['checked']))
  749. {
  750. print '<td>';
  751. if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
  752. {
  753. if (empty($object->id)) $object->fetch($id);
  754. $contactsoftask=$object->getListContactId('internal');
  755. if (!in_array($task_time->fk_user,$contactsoftask)) {
  756. $contactsoftask[]=$task_time->fk_user;
  757. }
  758. if (count($contactsoftask)>0) {
  759. print img_object('','user','class="hideonsmartphone"');
  760. print $form->select_dolusers($task_time->fk_user,'userid_line',0,'',0,'',$contactsoftask);
  761. }else {
  762. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  763. }
  764. }
  765. else
  766. {
  767. $userstatic->id = $task_time->fk_user;
  768. $userstatic->lastname = $task_time->lastname;
  769. $userstatic->firstname = $task_time->firstname;
  770. $userstatic->photo = $task_time->photo;
  771. print $userstatic->getNomUrl(-1);
  772. }
  773. print '</td>';
  774. if (! $i) $totalarray['nbfield']++;
  775. }
  776. // Note
  777. if (! empty($arrayfields['t.note']['checked']))
  778. {
  779. print '<td align="left">';
  780. if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
  781. {
  782. print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  783. }
  784. else
  785. {
  786. print dol_nl2br($task_time->note);
  787. }
  788. print '</td>';
  789. if (! $i) $totalarray['nbfield']++;
  790. }
  791. // Time spent
  792. if (! empty($arrayfields['t.task_duration']['checked']))
  793. {
  794. print '<td align="right">';
  795. if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
  796. {
  797. print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
  798. print $form->select_duration('new_duration',$task_time->task_duration,0,'text');
  799. }
  800. else
  801. {
  802. print convertSecondToTime($task_time->task_duration,'allhourmin');
  803. }
  804. print '</td>';
  805. if (! $i) $totalarray['nbfield']++;
  806. if (! $i) $totalarray['totaldurationfield']=$totalarray['nbfield'];
  807. $totalarray['totalduration'] += $task_time->task_duration;
  808. }
  809. // Value spent
  810. if (! empty($arrayfields['value']['checked']))
  811. {
  812. print '<td align="right">';
  813. $value = price2num($task_time->thm * $task_time->task_duration / 3600);
  814. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  815. print '</td>';
  816. if (! $i) $totalarray['nbfield']++;
  817. if (! $i) $totalarray['totalvaluefield']=$totalarray['nbfield'];
  818. $totalarray['totalvalue'] += $value;
  819. }
  820. // Fields from hook
  821. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  822. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  823. print $hookmanager->resPrint;
  824. // Action column
  825. print '<td class="center"">';
  826. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
  827. {
  828. print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
  829. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  830. print '<br>';
  831. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
  832. }
  833. else if ($user->rights->projet->lire) // Read project and enter time consumed on assigned tasks
  834. {
  835. if ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
  836. {
  837. print '&nbsp;';
  838. print '<a href="'.$_SERVER["PHP_SELF"].'?'.($projectidforalltimes?'projectid='.$projectidforalltimes.'&amp;':'').'id='.$task_time->fk_task.'&amp;action=editline&amp;lineid='.$task_time->rowid.($withproject?'&amp;withproject=1':'').'">';
  839. print img_edit();
  840. print '</a>';
  841. print '&nbsp;';
  842. print '<a href="'.$_SERVER["PHP_SELF"].'?'.($projectidforalltimes?'projectid='.$projectidforalltimes.'&amp;':'').'id='.$task_time->fk_task.'&amp;action=deleteline&amp;lineid='.$task_time->rowid.($withproject?'&amp;withproject=1':'').'">';
  843. print img_delete();
  844. print '</a>';
  845. }
  846. }
  847. print '</td>';
  848. if (! $i) $totalarray['nbfield']++;
  849. print "</tr>\n";
  850. $i++;
  851. }
  852. // Show total line
  853. if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield']))
  854. {
  855. print '<tr class="liste_total">';
  856. $i=0;
  857. while ($i < $totalarray['nbfield'])
  858. {
  859. $i++;
  860. if ($i == 1)
  861. {
  862. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  863. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  864. }
  865. elseif ($totalarray['totaldurationfield'] == $i) print '<td align="right">'.convertSecondToTime($totalarray['totalduration'],'allhourmin').'</td>';
  866. elseif ($totalarray['totalvaluefield'] == $i) print '<td align="right">'.price($totalarray['totalvalue']).'</td>';
  867. else print '<td></td>';
  868. }
  869. print '</tr>';
  870. }
  871. print '</tr>';
  872. print "</table>";
  873. print '</div>';
  874. print "</form>";
  875. }
  876. }
  877. llxFooter();
  878. $db->close();