ganttview.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/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.'/core/class/html.formother.class.php';
  30. $id=GETPOST('id','int');
  31. $ref=GETPOST('ref','alpha');
  32. $mode = GETPOST('mode', 'alpha');
  33. $mine = ($mode == 'mine' ? 1 : 0);
  34. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  35. $object = new Project($db);
  36. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  37. // Security check
  38. $socid=0;
  39. if ($user->societe_id > 0) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'projet', $id,'projet&project');
  41. $langs->load("users");
  42. $langs->load("projects");
  43. /*
  44. * Actions
  45. */
  46. // None
  47. /*
  48. * View
  49. */
  50. $form=new Form($db);
  51. $formother=new FormOther($db);
  52. $userstatic=new User($db);
  53. $companystatic=new Societe($db);
  54. $task = new Task($db);
  55. $arrayofcss=array('/includes/jsgantt/jsgantt.css');
  56. if (! empty($conf->use_javascript_ajax))
  57. {
  58. $arrayofjs=array(
  59. '/includes/jsgantt/jsgantt.js',
  60. '/projet/jsgantt_language.js.php?lang='.$langs->defaultlang
  61. );
  62. }
  63. $title=$langs->trans("Project").' - '.$langs->trans("Gantt").' - '.$object->ref.' '.$object->name;
  64. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("Gantt");
  65. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  66. llxHeader("",$title,$help_url,'',0,0,$arrayofjs,$arrayofcss);
  67. if ($id > 0 || ! empty($ref))
  68. {
  69. // To verify role of users
  70. //$userAccess = $object->restrictedProjectArea($user,'read');
  71. $userWrite = $object->restrictedProjectArea($user,'write');
  72. //$userDelete = $object->restrictedProjectArea($user,'delete');
  73. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  74. $tab='gantt';
  75. $head=project_prepare_head($object);
  76. dol_fiche_head($head, $tab, $langs->trans("Project"),0,($object->public?'projectpub':'project'));
  77. $param=($mode=='mine'?'&mode=mine':'');
  78. print '<table class="border" width="100%">';
  79. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
  80. // Ref
  81. print '<tr><td class="titlefield">';
  82. print $langs->trans("Ref");
  83. print '</td><td>';
  84. // Define a complementary filter for search of next/prev ref.
  85. if (! $user->rights->projet->all->lire)
  86. {
  87. $projectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  88. $object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  89. }
  90. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '', $param);
  91. print '</td></tr>';
  92. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
  93. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  94. if (! empty($object->thirdparty->id)) print $object->thirdparty->getNomUrl(1);
  95. else print '&nbsp;';
  96. print '</td>';
  97. print '</tr>';
  98. // Visibility
  99. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  100. if ($object->public) print $langs->trans('SharedProject');
  101. else print $langs->trans('PrivateProject');
  102. print '</td></tr>';
  103. // Statut
  104. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  105. // Date start
  106. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  107. print dol_print_date($object->date_start,'day');
  108. print '</td></tr>';
  109. // Date end
  110. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  111. print dol_print_date($object->date_end,'day');
  112. print '</td></tr>';
  113. print '</table>';
  114. print '</div>';
  115. }
  116. /*
  117. * Buttons actions
  118. */
  119. print '<div class="tabsAction">';
  120. if ($user->rights->projet->all->creer || $user->rights->projet->creer)
  121. {
  122. if ($object->public || $userWrite > 0)
  123. {
  124. print '<a class="butAction" href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id.'&action=create'.$param.'&tab=gantt&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans('AddTask').'</a>';
  125. }
  126. else
  127. {
  128. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
  129. }
  130. }
  131. else
  132. {
  133. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
  134. }
  135. print '</div>';
  136. print '<br>';
  137. // Get list of tasks in tasksarray and taskarrayfiltered
  138. // We need all tasks (even not limited to a user because a task to user
  139. // can have a parent that is not affected to him).
  140. $tasksarray=$task->getTasksArray(0, 0, $object->id, $socid, 0);
  141. // We load also tasks limited to a particular user
  142. //$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : '');
  143. //var_dump($tasksarray);
  144. //var_dump($tasksrole);
  145. if (count($tasksarray)>0)
  146. {
  147. // Show Gant diagram from $taskarray using JSGantt
  148. $dateformat=$langs->trans("FormatDateShortJQuery"); // Used by include ganttchart.inc.php later
  149. $datehourformat=$langs->trans("FormatDateShortJQuery").' '.$langs->trans("FormatHourShortJQuery"); // Used by include ganttchart.inc.php later
  150. $array_contacts=array();
  151. $tasks=array();
  152. $project_dependencies=array();
  153. $taskcursor=0;
  154. foreach($tasksarray as $key => $val)
  155. {
  156. $task->fetch($val->id);
  157. $tasks[$taskcursor]['task_id']=$val->id;
  158. $tasks[$taskcursor]['task_parent']=$val->fk_parent;
  159. $tasks[$taskcursor]['task_is_group']=0;
  160. $tasks[$taskcursor]['task_milestone']=0;
  161. $tasks[$taskcursor]['task_percent_complete']=$val->progress;
  162. //$tasks[$taskcursor]['task_name']=$task->getNomUrl(1);
  163. //print dol_print_date($val->date_start).dol_print_date($val->date_end).'<br>'."\n";
  164. $tasks[$taskcursor]['task_name']=$val->label;
  165. $tasks[$taskcursor]['task_start_date']=$val->date_start;
  166. $tasks[$taskcursor]['task_end_date']=$val->date_end;
  167. $tasks[$taskcursor]['task_color']='b4d1ea';
  168. $idofusers=$task->getListContactId('internal');
  169. $idofthirdparty=$task->getListContactId('external');
  170. $s='';
  171. if (count($idofusers)>0)
  172. {
  173. $s.=$langs->trans("Internals").': ';
  174. $i=0;
  175. foreach($idofusers as $valid)
  176. {
  177. $userstatic->fetch($valid);
  178. if ($i) $s.=',';
  179. $s.=$userstatic->login;
  180. $i++;
  181. }
  182. }
  183. if (count($idofusers)>0 && (count($idofthirdparty)>0)) $s.=' - ';
  184. if (count($idofthirdparty)>0)
  185. {
  186. if ($s) $s.=' - ';
  187. $s.=$langs->trans("Externals").': ';
  188. $i=0;
  189. foreach($idofthirdparty as $valid)
  190. {
  191. $companystatic->fetch($valid);
  192. if ($i) $s.=',';
  193. $s.=$companystatic->name;
  194. $i++;
  195. }
  196. }
  197. if ($s) $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>';
  198. /* For JSGanttImproved if ($s) $tasks[$taskcursor]['task_resources']=join(',',$idofusers); */
  199. //print "xxx".$val->id.$tasks[$taskcursor]['task_resources'];
  200. $taskcursor++;
  201. }
  202. print "\n";
  203. if (! empty($conf->use_javascript_ajax))
  204. {
  205. //var_dump($_SESSION);
  206. print '<div id="tabs" class="ganttcontainer" style="border: 1px solid #ACACAC;">'."\n";
  207. include_once DOL_DOCUMENT_ROOT.'/projet/ganttchart.inc.php';
  208. print '</div>'."\n";
  209. }
  210. else
  211. {
  212. $langs->load("admin");
  213. print $langs->trans("AvailableOnlyIfJavascriptAndAjaxNotDisabled");
  214. }
  215. }
  216. else
  217. {
  218. print $langs->trans("NoTasks");
  219. }
  220. llxFooter();
  221. $db->close();