task.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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@inodbox.com>
  5. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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 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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/projet/tasks/task.php
  22. * \ingroup project
  23. * \brief Page of a project 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/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
  34. // Load translation files required by the page
  35. $langs->loadlangs(array('projects', 'companies'));
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST("ref", 'alpha', 1); // task ref
  40. $taskref = GETPOST("taskref", 'alpha'); // task ref
  41. $withproject = GETPOST('withproject', 'int');
  42. $project_ref = GETPOST('project_ref', 'alpha');
  43. $planned_workload = ((GETPOST('planned_workloadhour', 'int') != '' || GETPOST('planned_workloadmin', 'int') != '') ? (GETPOST('planned_workloadhour', 'int') > 0 ?GETPOST('planned_workloadhour', 'int') * 3600 : 0) + (GETPOST('planned_workloadmin', 'int') > 0 ?GETPOST('planned_workloadmin', 'int') * 60 : 0) : '');
  44. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  45. $hookmanager->initHooks(array('projecttaskcard', 'globalcard'));
  46. $object = new Task($db);
  47. $extrafields = new ExtraFields($db);
  48. $projectstatic = new Project($db);
  49. // fetch optionals attributes and labels
  50. $extrafields->fetch_name_optionals_label($object->table_element);
  51. $parameters = array('id'=>$id);
  52. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  53. if ($reshook < 0) {
  54. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  55. }
  56. if ($id > 0 || $ref) {
  57. $object->fetch($id, $ref);
  58. }
  59. // Security check
  60. $socid = 0;
  61. restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
  62. /*
  63. * Actions
  64. */
  65. if ($action == 'update' && !GETPOST("cancel") && $user->rights->projet->creer) {
  66. $error = 0;
  67. if (empty($taskref)) {
  68. $error++;
  69. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  70. }
  71. if (!GETPOST("label")) {
  72. $error++;
  73. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  74. }
  75. if (!$error) {
  76. $object->oldcopy = clone $object;
  77. $tmparray = explode('_', GETPOST('task_parent'));
  78. $task_parent = $tmparray[1];
  79. if (empty($task_parent)) {
  80. $task_parent = 0; // If task_parent is ''
  81. }
  82. $object->ref = $taskref ? $taskref : GETPOST("ref", 'alpha', 2);
  83. $object->label = GETPOST("label", "alphanohtml");
  84. if (empty($conf->global->FCKEDITOR_ENABLE_SOCIETE)) {
  85. $object->description = GETPOST('description', "alphanohtml");
  86. } else {
  87. $object->description = GETPOST('description', "restricthtml");
  88. }
  89. $object->fk_task_parent = $task_parent;
  90. $object->planned_workload = $planned_workload;
  91. $object->date_start = dol_mktime(GETPOST('dateohour', 'int'), GETPOST('dateomin', 'int'), 0, GETPOST('dateomonth', 'int'), GETPOST('dateoday', 'int'), GETPOST('dateoyear', 'int'));
  92. $object->date_end = dol_mktime(GETPOST('dateehour', 'int'), GETPOST('dateemin', 'int'), 0, GETPOST('dateemonth', 'int'), GETPOST('dateeday', 'int'), GETPOST('dateeyear', 'int'));
  93. $object->progress = price2num(GETPOST('progress', 'alphanohtml'));
  94. $object->budget_amount = price2num(GETPOST('budget_amount', 'alphanohtml'));
  95. // Fill array 'array_options' with data from add form
  96. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  97. if ($ret < 0) {
  98. $error++;
  99. }
  100. if (!$error) {
  101. $result = $object->update($user);
  102. if ($result < 0) {
  103. setEventMessages($object->error, $object->errors, 'errors');
  104. $action = 'edit';
  105. }
  106. } else {
  107. $action = 'edit';
  108. }
  109. } else {
  110. $action = 'edit';
  111. }
  112. }
  113. if ($action == 'confirm_clone' && $confirm == 'yes') {
  114. //$clone_contacts = GETPOST('clone_contacts') ? 1 : 0;
  115. $clone_prog = GETPOST('clone_prog') ? 1 : 0;
  116. $clone_time = GETPOST('clone_time') ? 1 : 0;
  117. $clone_affectation = GETPOST('clone_affectation') ? 1 : 0;
  118. $clone_change_dt = GETPOST('clone_change_dt') ? 1 : 0;
  119. $clone_notes = GETPOST('clone_notes') ? 1 : 0;
  120. $clone_file = GETPOST('clone_file') ? 1 : 0;
  121. $result = $object->createFromClone($user, $object->id, $object->fk_project, $object->fk_task_parent, $clone_change_dt, $clone_affectation, $clone_time, $clone_file, $clone_notes, $clone_prog);
  122. if ($result <= 0) {
  123. setEventMessages($object->error, $object->errors, 'errors');
  124. } else {
  125. // Load new object
  126. $newobject = new Task($db);
  127. $newobject->fetch($result);
  128. $newobject->fetch_optionals();
  129. $newobject->fetch_thirdparty(); // Load new object
  130. $object = $newobject;
  131. $action = '';
  132. }
  133. }
  134. if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->supprimer) {
  135. $result = $projectstatic->fetch($object->fk_project);
  136. $projectstatic->fetch_thirdparty();
  137. if ($object->delete($user) > 0) {
  138. header('Location: '.DOL_URL_ROOT.'/projet/tasks.php?restore_lastsearch_values=1&id='.$projectstatic->id.($withproject ? '&withproject=1' : ''));
  139. exit;
  140. } else {
  141. setEventMessages($object->error, $object->errors, 'errors');
  142. $action = '';
  143. }
  144. }
  145. // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
  146. if (!empty($project_ref) && !empty($withproject)) {
  147. if ($projectstatic->fetch('', $project_ref) > 0) {
  148. $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  149. if (count($tasksarray) > 0) {
  150. $id = $tasksarray[0]->id;
  151. } else {
  152. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode) ? '' : '&mode='.$mode));
  153. }
  154. }
  155. }
  156. // Build doc
  157. if ($action == 'builddoc' && $user->rights->projet->creer) {
  158. // Save last template used to generate document
  159. if (GETPOST('model')) {
  160. $object->setDocModel($user, GETPOST('model', 'alpha'));
  161. }
  162. $outputlangs = $langs;
  163. if (GETPOST('lang_id', 'aZ09')) {
  164. $outputlangs = new Translate("", $conf);
  165. $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
  166. }
  167. $result = $object->generateDocument($object->model_pdf, $outputlangs);
  168. if ($result <= 0) {
  169. setEventMessages($object->error, $object->errors, 'errors');
  170. $action = '';
  171. }
  172. }
  173. // Delete file in doc form
  174. if ($action == 'remove_file' && $user->rights->projet->creer) {
  175. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  176. $langs->load("other");
  177. $upload_dir = $conf->project->dir_output;
  178. $file = $upload_dir.'/'.dol_sanitizeFileName(GETPOST('file'));
  179. $ret = dol_delete_file($file);
  180. if ($ret) {
  181. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  182. } else {
  183. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  184. }
  185. }
  186. /*
  187. * View
  188. */
  189. $form = new Form($db);
  190. $formother = new FormOther($db);
  191. $formfile = new FormFile($db);
  192. $result = $projectstatic->fetch($object->fk_project);
  193. $title = $object->ref;
  194. if (!empty($withproject)) {
  195. $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': '.$projectstatic->ref : '') ;
  196. }
  197. $help_url = '';
  198. llxHeader('', $title, $help_url);
  199. if ($id > 0 || !empty($ref)) {
  200. $res = $object->fetch_optionals();
  201. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  202. $object->fetchComments();
  203. }
  204. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  205. $projectstatic->fetchComments();
  206. }
  207. if (!empty($projectstatic->socid)) {
  208. $projectstatic->fetch_thirdparty();
  209. }
  210. $object->project = clone $projectstatic;
  211. //$userWrite = $projectstatic->restrictedProjectArea($user, 'write');
  212. if (!empty($withproject)) {
  213. // Tabs for project
  214. $tab = 'tasks';
  215. $head = project_prepare_head($projectstatic);
  216. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'), 0, '', '');
  217. $param = ($mode == 'mine' ? '&mode=mine' : '');
  218. // Project card
  219. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  220. $morehtmlref = '<div class="refidno">';
  221. // Title
  222. $morehtmlref .= $projectstatic->title;
  223. // Thirdparty
  224. if (!empty($projectstatic->thirdparty->id) &&$projectstatic->thirdparty->id > 0) {
  225. $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
  226. }
  227. $morehtmlref .= '</div>';
  228. // Define a complementary filter for search of next/prev ref.
  229. if (empty($user->rights->projet->all->lire)) {
  230. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  231. $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  232. }
  233. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  234. print '<div class="fichecenter">';
  235. print '<div class="fichehalfleft">';
  236. print '<div class="underbanner clearboth"></div>';
  237. print '<table class="border tableforfield centpercent">';
  238. // Usage
  239. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
  240. print '<tr><td class="tdtop">';
  241. print $langs->trans("Usage");
  242. print '</td>';
  243. print '<td>';
  244. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  245. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  246. $htmltext = $langs->trans("ProjectFollowOpportunity");
  247. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  248. print '<br>';
  249. }
  250. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  251. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  252. $htmltext = $langs->trans("ProjectFollowTasks");
  253. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  254. print '<br>';
  255. }
  256. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  257. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  258. $htmltext = $langs->trans("ProjectBillTimeDescription");
  259. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  260. print '<br>';
  261. }
  262. if (isModEnabled('eventorganization')) {
  263. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  264. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  265. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  266. }
  267. print '</td></tr>';
  268. }
  269. // Visibility
  270. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  271. if ($projectstatic->public) {
  272. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  273. print $langs->trans('SharedProject');
  274. } else {
  275. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  276. print $langs->trans('PrivateProject');
  277. }
  278. print '</td></tr>';
  279. // Budget
  280. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  281. if (strcmp($projectstatic->budget_amount, '')) {
  282. print '<span class="amount">'.price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  283. }
  284. print '</td></tr>';
  285. // Date start - end project
  286. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  287. $start = dol_print_date($projectstatic->date_start, 'day');
  288. print ($start ? $start : '?');
  289. $end = dol_print_date($projectstatic->date_end, 'day');
  290. print ' - ';
  291. print ($end ? $end : '?');
  292. if ($projectstatic->hasDelay()) {
  293. print img_warning("Late");
  294. }
  295. print '</td></tr>';
  296. // Other attributes
  297. $cols = 2;
  298. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  299. print '</table>';
  300. print '</div>';
  301. print '<div class="fichehalfright">';
  302. print '<div class="underbanner clearboth"></div>';
  303. print '<table class="border tableforfield centpercent">';
  304. // Description
  305. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  306. print nl2br($projectstatic->description);
  307. print '</td></tr>';
  308. // Categories
  309. if (isModEnabled('categorie')) {
  310. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  311. print $form->showCategories($projectstatic->id, 'project', 1);
  312. print "</td></tr>";
  313. }
  314. print '</table>';
  315. print '</div>';
  316. print '</div>';
  317. print '<div class="clearboth"></div>';
  318. print dol_get_fiche_end();
  319. print '<br>';
  320. }
  321. /*
  322. * Actions
  323. */
  324. /*print '<div class="tabsAction">';
  325. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  326. {
  327. if ($projectstatic->public || $userWrite > 0)
  328. {
  329. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
  330. }
  331. else
  332. {
  333. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  334. }
  335. }
  336. else
  337. {
  338. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  339. }
  340. print '</div>';
  341. */
  342. // To verify role of users
  343. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  344. //$arrayofuseridoftask=$object->getListContactId('internal');
  345. if ($action == 'clone') {
  346. $formquestion = array(
  347. 'text' => $langs->trans("ConfirmClone"),
  348. //array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true),
  349. array('type' => 'checkbox', 'name' => 'clone_change_dt', 'label' => $langs->trans("CloneChanges"), 'value' => true),
  350. array('type' => 'checkbox', 'name' => 'clone_affectation', 'label' => $langs->trans("CloneAffectation"), 'value' => true),
  351. array('type' => 'checkbox', 'name' => 'clone_prog', 'label' => $langs->trans("CloneProgression"), 'value' => true),
  352. array('type' => 'checkbox', 'name' => 'clone_time', 'label' => $langs->trans("CloneTimes"), 'value' => true),
  353. array('type' => 'checkbox', 'name' => 'clone_file', 'label' => $langs->trans("CloneFile"), 'value' => true),
  354. );
  355. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClone"), $langs->trans("ConfirmCloneTask"), "confirm_clone", $formquestion, '', 1, 300, 590);
  356. }
  357. $head = task_prepare_head($object);
  358. if ($action == 'edit' && $user->rights->projet->creer) {
  359. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  360. print '<input type="hidden" name="token" value="'.newToken().'">';
  361. print '<input type="hidden" name="action" value="update">';
  362. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  363. print '<input type="hidden" name="id" value="'.$object->id.'">';
  364. print dol_get_fiche_head($head, 'task_task', $langs->trans("Task"), 0, 'projecttask', 0, '', '');
  365. print '<table class="border centpercent">';
  366. // Ref
  367. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
  368. print '<td><input class="minwidth100" name="taskref" value="'.$object->ref.'"></td></tr>';
  369. // Label
  370. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  371. print '<td><input class="minwidth500" name="label" value="'.$object->label.'"></td></tr>';
  372. // Project
  373. if (empty($withproject)) {
  374. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  375. print $projectstatic->getNomUrl(1);
  376. print '</td></tr>';
  377. // Third party
  378. print '<td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  379. if ($projectstatic->thirdparty->id) {
  380. print $projectstatic->thirdparty->getNomUrl(1);
  381. } else {
  382. print '&nbsp;';
  383. }
  384. print '</td></tr>';
  385. }
  386. // Task parent
  387. print '<tr><td>'.$langs->trans("ChildOfProjectTask").'</td><td>';
  388. $formother->selectProjectTasks($object->fk_task_parent, $projectstatic->id, 'task_parent', ($user->admin ? 0 : 1), 0, 0, 0, $object->id);
  389. print '</td></tr>';
  390. // Date start
  391. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  392. print $form->selectDate($object->date_start, 'dateo', 1, 1, 0, '', 1, 0);
  393. print '</td></tr>';
  394. // Date end
  395. print '<tr><td>'.$langs->trans("Deadline").'</td><td>';
  396. print $form->selectDate($object->date_end ? $object->date_end : -1, 'datee', 1, 1, 0, '', 1, 0);
  397. print '</td></tr>';
  398. // Planned workload
  399. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  400. print $form->select_duration('planned_workload', $object->planned_workload, 0, 'text');
  401. print '</td></tr>';
  402. // Progress declared
  403. print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td>';
  404. print $formother->select_percent($object->progress, 'progress', 0, 5, 0, 100, 1);
  405. print '</td></tr>';
  406. // Description
  407. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  408. print '<td>';
  409. // WYSIWYG editor
  410. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  411. $cked_enabled = (!empty($conf->global->FCKEDITOR_ENABLE_SOCIETE) ? $conf->global->FCKEDITOR_ENABLE_SOCIETE : 0);
  412. if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
  413. $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
  414. }
  415. $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_details', '', false, true, $cked_enabled, $nbrows);
  416. print $doleditor->Create();
  417. print '</td></tr>';
  418. print '<tr><td>'.$langs->trans("Budget").'</td>';
  419. print '<td><input size="5" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : price2num($object->budget_amount)).'"></td>';
  420. print '</tr>';
  421. // Other options
  422. $parameters = array();
  423. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  424. print $hookmanager->resPrint;
  425. if (empty($reshook)) {
  426. print $object->showOptionals($extrafields, 'edit');
  427. }
  428. print '</table>';
  429. print dol_get_fiche_end();
  430. print $form->buttonsSaveCancel("Modify");
  431. print '</form>';
  432. } else {
  433. /*
  434. * Fiche tache en mode visu
  435. */
  436. $param = ($withproject ? '&withproject=1' : '');
  437. $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>' : '';
  438. print dol_get_fiche_head($head, 'task_task', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
  439. if ($action == 'delete') {
  440. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".GETPOST("id", 'int').'&withproject='.$withproject, $langs->trans("DeleteATask"), $langs->trans("ConfirmDeleteATask"), "confirm_delete");
  441. }
  442. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  443. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  444. $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
  445. } else {
  446. $object->next_prev_filter = " fk_projet = ".((int) $projectstatic->id);
  447. }
  448. $morehtmlref = '';
  449. // Project
  450. if (empty($withproject)) {
  451. $morehtmlref .= '<div class="refidno">';
  452. $morehtmlref .= $langs->trans("Project").': ';
  453. $morehtmlref .= $projectstatic->getNomUrl(1);
  454. $morehtmlref .= '<br>';
  455. // Third party
  456. $morehtmlref .= $langs->trans("ThirdParty").': ';
  457. if (!empty($projectstatic->thirdparty) && is_object($projectstatic->thirdparty)) {
  458. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  459. }
  460. $morehtmlref .= '</div>';
  461. }
  462. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  463. print '<div class="fichecenter">';
  464. print '<div class="fichehalfleft">';
  465. print '<div class="underbanner clearboth"></div>';
  466. print '<table class="border centpercent tableforfield">';
  467. // Task parent
  468. print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
  469. if ($object->fk_task_parent > 0) {
  470. $tasktmp = new Task($db);
  471. $tasktmp->fetch($object->fk_task_parent);
  472. print $tasktmp->getNomUrl(1);
  473. }
  474. print '</td></tr>';
  475. // Date start - Date end task
  476. print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("Deadline").'</td><td colspan="3">';
  477. $start = dol_print_date($object->date_start, 'dayhour');
  478. print ($start ? $start : '?');
  479. $end = dol_print_date($object->date_end, 'dayhour');
  480. print ' - ';
  481. print ($end ? $end : '?');
  482. if ($object->hasDelay()) {
  483. print img_warning("Late");
  484. }
  485. print '</td></tr>';
  486. // Planned workload
  487. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td colspan="3">';
  488. if ($object->planned_workload != '') {
  489. print convertSecondToTime($object->planned_workload, 'allhourmin');
  490. }
  491. print '</td></tr>';
  492. // Description
  493. print '<td class="tdtop">'.$langs->trans("Description").'</td><td colspan="3">';
  494. print dol_htmlentitiesbr($object->description);
  495. print '</td></tr>';
  496. print '</table>';
  497. print '</div>';
  498. print '<div class="fichehalfright">';
  499. print '<div class="underbanner clearboth"></div>';
  500. print '<table class="border centpercent tableforfield">';
  501. // Progress declared
  502. print '<tr><td class="titlefield">'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
  503. if ($object->progress != '') {
  504. print $object->progress.' %';
  505. }
  506. print '</td></tr>';
  507. // Progress calculated
  508. print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td colspan="3">';
  509. if ($object->planned_workload != '') {
  510. $tmparray = $object->getSummaryOfTimeSpent();
  511. if ($tmparray['total_duration'] > 0 && !empty($object->planned_workload)) {
  512. print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
  513. } else {
  514. print '0 %';
  515. }
  516. } else {
  517. print '<span class="opacitymedium">'.$langs->trans("WorkloadNotDefined").'</span>';
  518. }
  519. print '</td></tr>';
  520. // Budget
  521. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  522. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  523. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  524. }
  525. print '</td></tr>';
  526. // Other attributes
  527. $cols = 3;
  528. $parameters = array('socid'=>$socid);
  529. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  530. print '</table>';
  531. print '</div>';
  532. print '</div>';
  533. print '<div class="clearboth"></div>';
  534. print dol_get_fiche_end();
  535. }
  536. if ($action != 'edit') {
  537. /*
  538. * Actions
  539. */
  540. print '<div class="tabsAction">';
  541. $parameters = array();
  542. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  543. // modified by hook
  544. if (empty($reshook)) {
  545. // Modify
  546. if ($user->rights->projet->creer) {
  547. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'&withproject='.((int) $withproject).'">'.$langs->trans('Modify').'</a>';
  548. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken().'&withproject='.((int) $withproject).'">'.$langs->trans('Clone').'</a>';
  549. } else {
  550. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Modify').'</a>';
  551. }
  552. // Delete
  553. $permissiontodelete = $user->hasRight('projet', 'supprimer');
  554. if ($permissiontodelete) {
  555. if (!$object->hasChildren() && !$object->hasTimeSpent()) {
  556. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete);
  557. } else {
  558. print dolGetButtonAction($langs->trans("TaskHasChild"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', 0);
  559. }
  560. } else {
  561. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete);
  562. }
  563. print '</div>';
  564. }
  565. print '<div class="fichecenter"><div class="fichehalfleft">';
  566. print '<a name="builddoc"></a>'; // ancre
  567. /*
  568. * Generated documents
  569. */
  570. $filename = dol_sanitizeFileName($projectstatic->ref)."/".dol_sanitizeFileName($object->ref);
  571. $filedir = $conf->project->dir_output."/".dol_sanitizeFileName($projectstatic->ref)."/".dol_sanitizeFileName($object->ref);
  572. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  573. $genallowed = ($user->rights->projet->lire);
  574. $delallowed = ($user->rights->projet->creer);
  575. print $formfile->showdocuments('project_task', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf);
  576. print '</div><div class="fichehalfright">';
  577. // List of actions on element
  578. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  579. $formactions = new FormActions($db);
  580. $defaultthirdpartyid = $socid > 0 ? $socid : $object->project->socid;
  581. $formactions->showactions($object, 'task', $defaultthirdpartyid, 1, '', 10, 'withproject='.$withproject);
  582. print '</div></div>';
  583. }
  584. }
  585. // End of page
  586. llxFooter();
  587. $db->close();