document.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.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/document.php
  22. * \ingroup project
  23. * \brief Page de gestion des documents attachees a une tache d'un projet
  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/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('projects', 'other'));
  34. $action = GETPOST('action', 'aZ09');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $mine = GETPOST('mode') == 'mine' ? 1 : 0;
  37. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $withproject = GETPOST('withproject', 'int');
  41. $project_ref = GETPOST('project_ref', 'alpha');
  42. // Get parameters
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST("sortfield", 'alpha');
  45. $sortorder = GETPOST("sortorder", 'alpha');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortorder) {
  54. $sortorder = "ASC";
  55. }
  56. if (!$sortfield) {
  57. $sortfield = "name";
  58. }
  59. $object = new Task($db);
  60. $projectstatic = new Project($db);
  61. if ($id > 0 || $ref) {
  62. $object->fetch($id, $ref);
  63. }
  64. // Security check
  65. $socid = 0;
  66. restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
  67. /*
  68. * Actions
  69. */
  70. // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
  71. if (!empty($project_ref) && !empty($withproject)) {
  72. if ($projectstatic->fetch(0, $project_ref) > 0) {
  73. $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  74. if (count($tasksarray) > 0) {
  75. $id = $tasksarray[0]->id;
  76. $object->fetch($id);
  77. } else {
  78. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
  79. exit;
  80. }
  81. }
  82. }
  83. if ($id > 0 || !empty($ref)) {
  84. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  85. $object->fetchComments();
  86. }
  87. $projectstatic->fetch($object->fk_project);
  88. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  89. $projectstatic->fetchComments();
  90. }
  91. if (!empty($projectstatic->socid)) {
  92. $projectstatic->fetch_thirdparty();
  93. }
  94. $object->project = clone $projectstatic;
  95. $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
  96. }
  97. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. llxHeader('', $langs->trans('Task'));
  103. if ($object->id > 0) {
  104. $projectstatic->fetch_thirdparty();
  105. $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
  106. if (!empty($withproject)) {
  107. // Tabs for project
  108. $tab = 'tasks';
  109. $head = project_prepare_head($projectstatic);
  110. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
  111. $param = ($mode == 'mine' ? '&mode=mine' : '');
  112. // Project card
  113. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  114. $morehtmlref = '<div class="refidno">';
  115. // Title
  116. $morehtmlref .= $projectstatic->title;
  117. // Thirdparty
  118. if ($projectstatic->thirdparty->id > 0) {
  119. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
  120. }
  121. $morehtmlref .= '</div>';
  122. // Define a complementary filter for search of next/prev ref.
  123. if (!$user->rights->projet->all->lire) {
  124. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  125. $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  126. }
  127. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  128. print '<div class="fichecenter">';
  129. print '<div class="fichehalfleft">';
  130. print '<div class="underbanner clearboth"></div>';
  131. print '<table class="border tableforfield centpercent">';
  132. // Usage
  133. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  134. print '<tr><td class="tdtop">';
  135. print $langs->trans("Usage");
  136. print '</td>';
  137. print '<td>';
  138. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  139. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  140. $htmltext = $langs->trans("ProjectFollowOpportunity");
  141. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  142. print '<br>';
  143. }
  144. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  145. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  146. $htmltext = $langs->trans("ProjectFollowTasks");
  147. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  148. print '<br>';
  149. }
  150. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  151. 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"' : '')).'"> ';
  152. $htmltext = $langs->trans("ProjectBillTimeDescription");
  153. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  154. print '<br>';
  155. }
  156. if (!empty($conf->eventorganization->enabled)) {
  157. 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"' : '')).'"> ';
  158. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  159. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  160. }
  161. print '</td></tr>';
  162. }
  163. // Visibility
  164. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  165. if ($projectstatic->public) {
  166. print $langs->trans('SharedProject');
  167. } else {
  168. print $langs->trans('PrivateProject');
  169. }
  170. print '</td></tr>';
  171. // Date start - end
  172. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  173. $start = dol_print_date($projectstatic->date_start, 'day');
  174. print ($start ? $start : '?');
  175. $end = dol_print_date($projectstatic->date_end, 'day');
  176. print ' - ';
  177. print ($end ? $end : '?');
  178. if ($projectstatic->hasDelay()) {
  179. print img_warning("Late");
  180. }
  181. print '</td></tr>';
  182. // Budget
  183. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  184. if (strcmp($projectstatic->budget_amount, '')) {
  185. print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
  186. }
  187. print '</td></tr>';
  188. // Other attributes
  189. $cols = 2;
  190. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  191. print '</table>';
  192. print '</div>';
  193. print '<div class="fichehalfright">';
  194. print '<div class="underbanner clearboth"></div>';
  195. print '<table class="border tableforfield centpercent">';
  196. // Description
  197. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  198. print nl2br($projectstatic->description);
  199. print '</td></tr>';
  200. // Categories
  201. if ($conf->categorie->enabled) {
  202. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  203. print $form->showCategories($projectstatic->id, 'project', 1);
  204. print "</td></tr>";
  205. }
  206. print '</table>';
  207. print '</div>';
  208. print '</div>';
  209. print '<div class="clearboth"></div>';
  210. print dol_get_fiche_end();
  211. print '<br>';
  212. }
  213. $head = task_prepare_head($object);
  214. print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
  215. // Files list constructor
  216. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  217. $totalsize = 0;
  218. foreach ($filearray as $key => $file) {
  219. $totalsize += $file['size'];
  220. }
  221. $param = (GETPOST('withproject') ? '&withproject=1' : '');
  222. $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
  223. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  224. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  225. $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
  226. } else {
  227. $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
  228. }
  229. $morehtmlref = '';
  230. // Project
  231. if (empty($withproject)) {
  232. $morehtmlref .= '<div class="refidno">';
  233. $morehtmlref .= $langs->trans("Project").': ';
  234. $morehtmlref .= $projectstatic->getNomUrl(1);
  235. $morehtmlref .= '<br>';
  236. // Third party
  237. $morehtmlref .= $langs->trans("ThirdParty").': ';
  238. if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
  239. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  240. }
  241. $morehtmlref .= '</div>';
  242. }
  243. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  244. print '<div class="fichecenter">';
  245. print '<div class="underbanner clearboth"></div>';
  246. print '<table class="border tableforfield centpercent">';
  247. // Files infos
  248. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  249. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  250. print "</table>\n";
  251. print '</div>';
  252. print dol_get_fiche_end();
  253. print '<br>';
  254. $param = '';
  255. if ($withproject) {
  256. $param .= '&withproject=1';
  257. }
  258. $modulepart = 'project_task';
  259. $permissiontoadd = $user->rights->projet->creer;
  260. $permtoedit = $user->rights->projet->creer;
  261. $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
  262. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  263. } else {
  264. header('Location: index.php');
  265. exit;
  266. }
  267. // End of page
  268. llxFooter();
  269. $db->close();