ganttview.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/ganttview.php
  21. * \ingroup projet
  22. * \brief Gantt diagramm 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.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. $id = GETPOST('id', 'intcomma');
  34. $ref = GETPOST('ref', 'alpha');
  35. $mode = GETPOST('mode', 'alpha');
  36. $mine = ($mode == 'mine' ? 1 : 0);
  37. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  38. $object = new Project($db);
  39. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  40. if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
  41. $object->fetchComments();
  42. }
  43. // Security check
  44. $socid = 0;
  45. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  46. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  47. // Load translation files required by the page
  48. $langs->loadlangs(array('users', 'projects'));
  49. /*
  50. * Actions
  51. */
  52. // None
  53. /*
  54. * View
  55. */
  56. $form = new Form($db);
  57. $formother = new FormOther($db);
  58. $userstatic = new User($db);
  59. $companystatic = new Societe($db);
  60. $contactstatic = new Contact($db);
  61. $task = new Task($db);
  62. $arrayofcss = array('/includes/jsgantt/jsgantt.css');
  63. if (!empty($conf->use_javascript_ajax)) {
  64. $arrayofjs = array(
  65. '/includes/jsgantt/jsgantt.js',
  66. '/projet/jsgantt_language.js.php?lang='.$langs->defaultlang
  67. );
  68. }
  69. //$title=$langs->trans("Gantt").($object->ref?' - '.$object->ref.' '.$object->name:'');
  70. $title = $langs->trans("Gantt");
  71. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  72. $title = ($object->ref ? $object->ref.' '.$object->name.' - ' : '').$langs->trans("Gantt");
  73. }
  74. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  75. llxHeader("", $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss);
  76. if (($id > 0 && is_numeric($id)) || !empty($ref)) {
  77. // To verify role of users
  78. //$userAccess = $object->restrictedProjectArea($user,'read');
  79. $userWrite = $object->restrictedProjectArea($user, 'write');
  80. //$userDelete = $object->restrictedProjectArea($user,'delete');
  81. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  82. $tab = 'tasks';
  83. $head = project_prepare_head($object);
  84. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  85. $param = ($mode == 'mine' ? '&mode=mine' : '');
  86. // Project card
  87. if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
  88. $tmpurl = $_SESSION['pageforbacktolist']['project'];
  89. $tmpurl = preg_replace('/__SOCID__/', $object->socid, $tmpurl);
  90. $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  91. } else {
  92. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  93. }
  94. $morehtmlref = '<div class="refidno">';
  95. // Title
  96. $morehtmlref .= $object->title;
  97. // Thirdparty
  98. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  99. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  100. }
  101. $morehtmlref .= '</div>';
  102. // Define a complementary filter for search of next/prev ref.
  103. if (!$user->hasRight('projet', 'all', 'lire')) {
  104. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  105. $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  106. }
  107. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  108. print '<div class="fichecenter">';
  109. print '<div class="fichehalfleft">';
  110. print '<div class="underbanner clearboth"></div>';
  111. print '<table class="border tableforfield centpercent">';
  112. // Usage
  113. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
  114. print '<tr><td class="tdtop">';
  115. print $langs->trans("Usage");
  116. print '</td>';
  117. print '<td>';
  118. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  119. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  120. $htmltext = $langs->trans("ProjectFollowOpportunity");
  121. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  122. print '<br>';
  123. }
  124. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  125. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  126. $htmltext = $langs->trans("ProjectFollowTasks");
  127. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  128. print '<br>';
  129. }
  130. if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
  131. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  132. $htmltext = $langs->trans("ProjectBillTimeDescription");
  133. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  134. print '<br>';
  135. }
  136. if (isModEnabled('eventorganization')) {
  137. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  138. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  139. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  140. }
  141. print '</td></tr>';
  142. }
  143. // Visibility
  144. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  145. if ($object->public) {
  146. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  147. print $langs->trans('SharedProject');
  148. } else {
  149. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  150. print $langs->trans('PrivateProject');
  151. }
  152. print '</td></tr>';
  153. // Budget
  154. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  155. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  156. print price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
  157. }
  158. print '</td></tr>';
  159. // Date start - end project
  160. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  161. $start = dol_print_date($object->date_start, 'day');
  162. print($start ? $start : '?');
  163. $end = dol_print_date($object->date_end, 'day');
  164. print ' - ';
  165. print($end ? $end : '?');
  166. if ($object->hasDelay()) {
  167. print img_warning("Late");
  168. }
  169. print '</td></tr>';
  170. // Other attributes
  171. $cols = 2;
  172. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  173. print '</table>';
  174. print '</div>';
  175. print '<div class="fichehalfright">';
  176. print '<div class="underbanner clearboth"></div>';
  177. print '<table class="border tableforfield centpercent">';
  178. // Description
  179. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  180. print nl2br($object->description);
  181. print '</td></tr>';
  182. // Categories
  183. if (isModEnabled('categorie')) {
  184. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  185. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  186. print "</td></tr>";
  187. }
  188. print '</table>';
  189. print '</div>';
  190. print '</div>';
  191. print '<div class="clearboth"></div>';
  192. print dol_get_fiche_end();
  193. print '<br>';
  194. }
  195. // Link to create task
  196. $linktocreatetaskParam = array();
  197. $linktocreatetaskUserRight = false;
  198. if ($user->hasRight('projet', 'all', 'creer') || $user->hasRight('projet', 'creer')) {
  199. if ($object->public || $userWrite > 0) {
  200. $linktocreatetaskUserRight = true;
  201. } else {
  202. $linktocreatetaskParam['attr']['title'] = $langs->trans("NotOwnerOfProject");
  203. }
  204. }
  205. $linktocreatetask = dolGetButtonTitle($langs->trans('AddTask'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id.'&action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id), '', $linktocreatetaskUserRight, $linktocreatetaskParam);
  206. $linktotasks = dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars paddingleft imgforviewmode', DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id, '', 1, array('morecss'=>'reposition'));
  207. $linktotasks .= dolGetButtonTitle($langs->trans('ViewGantt'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id.'&withproject=1', '', 1, array('morecss'=>'reposition marginleftonly btnTitleSelected'));
  208. //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'generic', 0, '', '', 0, 1);
  209. print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'projecttask');
  210. // Get list of tasks in tasksarray and taskarrayfiltered
  211. // We need all tasks (even not limited to a user because a task to user
  212. // can have a parent that is not affected to him).
  213. $tasksarray = $task->getTasksArray(0, 0, ($object->id ? $object->id : $id), $socid, 0);
  214. // We load also tasks limited to a particular user
  215. //$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(null, $user, $object->id, 0) : '');
  216. //var_dump($tasksarray);
  217. //var_dump($tasksrole);
  218. if (count($tasksarray) > 0) {
  219. // Show Gant diagram from $taskarray using JSGantt
  220. $dateformat = $langs->trans("FormatDateShortJQuery"); // Used by include ganttchart.inc.php later
  221. $datehourformat = $langs->trans("FormatDateShortJQuery").' '.$langs->trans("FormatHourShortJQuery"); // Used by include ganttchart.inc.php later
  222. $array_contacts = array();
  223. $tasks = array();
  224. $task_dependencies = array();
  225. $taskcursor = 0;
  226. foreach ($tasksarray as $key => $val) { // Task array are sorted by "project, position, date"
  227. $task->fetch($val->id, '');
  228. $idparent = ($val->fk_parent ? $val->fk_parent : '-'.$val->fk_project); // If start with -, id is a project id
  229. $tasks[$taskcursor]['task_id'] = $val->id;
  230. $tasks[$taskcursor]['task_alternate_id'] = ($taskcursor + 1); // An id that has same order than position (required by ganttchart)
  231. $tasks[$taskcursor]['task_project_id'] = $val->fk_project;
  232. $tasks[$taskcursor]['task_parent'] = $idparent;
  233. $tasks[$taskcursor]['task_is_group'] = 0;
  234. $tasks[$taskcursor]['task_css'] = 'gtaskblue';
  235. $tasks[$taskcursor]['task_position'] = $val->rang;
  236. $tasks[$taskcursor]['task_planned_workload'] = $val->planned_workload;
  237. if ($val->fk_parent != 0 && $task->hasChildren() > 0) {
  238. $tasks[$taskcursor]['task_is_group'] = 1;
  239. $tasks[$taskcursor]['task_css'] = 'ggroupblack';
  240. //$tasks[$taskcursor]['task_css'] = 'gtaskblue';
  241. } elseif ($task->hasChildren() > 0) {
  242. $tasks[$taskcursor]['task_is_group'] = 1;
  243. //$tasks[$taskcursor]['task_is_group'] = 0;
  244. $tasks[$taskcursor]['task_css'] = 'ggroupblack';
  245. //$tasks[$taskcursor]['task_css'] = 'gtaskblue';
  246. }
  247. $tasks[$taskcursor]['task_milestone'] = '0';
  248. $tasks[$taskcursor]['task_percent_complete'] = $val->progress;
  249. //$tasks[$taskcursor]['task_name']=$task->getNomUrl(1);
  250. //print dol_print_date($val->date_start).dol_print_date($val->date_end).'<br>'."\n";
  251. $tasks[$taskcursor]['task_name'] = $val->ref.' - '.$val->label;
  252. $tasks[$taskcursor]['task_start_date'] = $val->date_start;
  253. $tasks[$taskcursor]['task_end_date'] = $val->date_end;
  254. $tasks[$taskcursor]['task_color'] = 'b4d1ea';
  255. $idofusers = $task->getListContactId('internal');
  256. $idofcontacts = $task->getListContactId('external');
  257. $s = '';
  258. if (count($idofusers) > 0) {
  259. $s .= $langs->trans("Internals").': ';
  260. $i = 0;
  261. foreach ($idofusers as $valid) {
  262. $userstatic->fetch($valid);
  263. if ($i) {
  264. $s .= ', ';
  265. }
  266. $s .= $userstatic->login;
  267. $i++;
  268. }
  269. }
  270. //if (count($idofusers)>0 && (count($idofcontacts)>0)) $s.=' - ';
  271. if (count($idofcontacts) > 0) {
  272. if ($s) {
  273. $s .= ' - ';
  274. }
  275. $s .= $langs->trans("Externals").': ';
  276. $i = 0;
  277. $contactidfound = array();
  278. foreach ($idofcontacts as $valid) {
  279. if (empty($contactidfound[$valid])) {
  280. $res = $contactstatic->fetch($valid);
  281. if ($res > 0) {
  282. if ($i) {
  283. $s .= ', ';
  284. }
  285. $s .= $contactstatic->getFullName($langs);
  286. $contactidfound[$valid] = 1;
  287. $i++;
  288. }
  289. }
  290. }
  291. }
  292. /* For JSGanttImproved */
  293. //if ($s) $tasks[$taskcursor]['task_resources']=implode(',',$idofusers);
  294. $tasks[$taskcursor]['task_resources'] = $s;
  295. if ($s) {
  296. $tasks[$taskcursor]['task_resources'] = '<a href="'.DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$val->id.'&withproject=1" title="'.dol_escape_htmltag($s).'">'.$langs->trans("List").'</a>';
  297. }
  298. //print "xxx".$val->id.$tasks[$taskcursor]['task_resources'];
  299. $tasks[$taskcursor]['note'] = $task->note_public;
  300. $taskcursor++;
  301. }
  302. // Search parent to set task_parent_alternate_id (requird by ganttchart)
  303. foreach ($tasks as $tmpkey => $tmptask) {
  304. foreach ($tasks as $tmptask2) {
  305. if ($tmptask2['task_id'] == $tmptask['task_parent']) {
  306. $tasks[$tmpkey]['task_parent_alternate_id'] = $tmptask2['task_alternate_id'];
  307. break;
  308. }
  309. }
  310. if (empty($tasks[$tmpkey]['task_parent_alternate_id'])) {
  311. $tasks[$tmpkey]['task_parent_alternate_id'] = $tasks[$tmpkey]['task_parent'];
  312. }
  313. }
  314. print "\n";
  315. if (!empty($conf->use_javascript_ajax)) {
  316. //var_dump($_SESSION);
  317. // How the date for data are formated (format used bu jsgantt)
  318. $dateformatinput = 'yyyy-mm-dd';
  319. // How the date for data are formated (format used by dol_print_date)
  320. $dateformatinput2 = 'standard';
  321. //var_dump($dateformatinput);
  322. //var_dump($dateformatinput2);
  323. $moreforfilter = '<div class="liste_titre liste_titre_bydiv centpercent">';
  324. $moreforfilter .= '<div class="divsearchfield">';
  325. //$moreforfilter .= $langs->trans("TasksAssignedTo").': ';
  326. //$moreforfilter .= $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1);
  327. $moreforfilter .= '&nbsp;';
  328. $moreforfilter .= '</div>';
  329. $moreforfilter .= '</div>';
  330. print $moreforfilter;
  331. print '<div class="div-table-responsive">';
  332. print '<div id="tabs" class="gantt" style="width: 80vw;">'."\n";
  333. include_once DOL_DOCUMENT_ROOT.'/projet/ganttchart.inc.php';
  334. print '</div>'."\n";
  335. print '</div>';
  336. } else {
  337. $langs->load("admin");
  338. print $langs->trans("AvailableOnlyIfJavascriptAndAjaxNotDisabled");
  339. }
  340. } else {
  341. print '<div class="opacitymedium">'.$langs->trans("NoTasks").'</div>';
  342. }
  343. // End of page
  344. llxFooter();
  345. $db->close();