PageRenderTime 36ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks/document.php

http://github.com/Dolibarr/dolibarr
PHP | 336 lines | 218 code | 66 blank | 52 comment | 53 complexity | 68fbf074f85d1c304c4fa89131be64fc MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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. $permissiontoadd = $$user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  68. /*
  69. * Actions
  70. */
  71. // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
  72. if (!empty($project_ref) && !empty($withproject)) {
  73. if ($projectstatic->fetch(0, $project_ref) > 0) {
  74. $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  75. if (count($tasksarray) > 0) {
  76. $id = $tasksarray[0]->id;
  77. $object->fetch($id);
  78. } else {
  79. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
  80. exit;
  81. }
  82. }
  83. }
  84. if ($id > 0 || !empty($ref)) {
  85. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  86. $object->fetchComments();
  87. }
  88. $projectstatic->fetch($object->fk_project);
  89. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  90. $projectstatic->fetchComments();
  91. }
  92. if (!empty($projectstatic->socid)) {
  93. $projectstatic->fetch_thirdparty();
  94. }
  95. $object->project = clone $projectstatic;
  96. $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
  97. }
  98. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  99. /*
  100. * View
  101. */
  102. $form = new Form($db);
  103. llxHeader('', $langs->trans('Task'));
  104. if ($object->id > 0) {
  105. $projectstatic->fetch_thirdparty();
  106. $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
  107. if (!empty($withproject)) {
  108. // Tabs for project
  109. $tab = 'tasks';
  110. $head = project_prepare_head($projectstatic);
  111. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
  112. $param = ($mode == 'mine' ? '&mode=mine' : '');
  113. // Project card
  114. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  115. $morehtmlref = '<div class="refidno">';
  116. // Title
  117. $morehtmlref .= $projectstatic->title;
  118. // Thirdparty
  119. if ($projectstatic->thirdparty->id > 0) {
  120. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
  121. }
  122. $morehtmlref .= '</div>';
  123. // Define a complementary filter for search of next/prev ref.
  124. if (empty($user->rights->projet->all->lire)) {
  125. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  126. $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  127. }
  128. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  129. print '<div class="fichecenter">';
  130. print '<div class="fichehalfleft">';
  131. print '<div class="underbanner clearboth"></div>';
  132. print '<table class="border tableforfield centpercent">';
  133. // Usage
  134. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  135. print '<tr><td class="tdtop">';
  136. print $langs->trans("Usage");
  137. print '</td>';
  138. print '<td>';
  139. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  140. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  141. $htmltext = $langs->trans("ProjectFollowOpportunity");
  142. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  143. print '<br>';
  144. }
  145. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  146. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  147. $htmltext = $langs->trans("ProjectFollowTasks");
  148. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  149. print '<br>';
  150. }
  151. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  152. 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"' : '')).'"> ';
  153. $htmltext = $langs->trans("ProjectBillTimeDescription");
  154. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  155. print '<br>';
  156. }
  157. if (!empty($conf->eventorganization->enabled)) {
  158. 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"' : '')).'"> ';
  159. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  160. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  161. }
  162. print '</td></tr>';
  163. }
  164. // Visibility
  165. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  166. if ($projectstatic->public) {
  167. print $langs->trans('SharedProject');
  168. } else {
  169. print $langs->trans('PrivateProject');
  170. }
  171. print '</td></tr>';
  172. // Date start - end
  173. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  174. $start = dol_print_date($projectstatic->date_start, 'day');
  175. print ($start ? $start : '?');
  176. $end = dol_print_date($projectstatic->date_end, 'day');
  177. print ' - ';
  178. print ($end ? $end : '?');
  179. if ($projectstatic->hasDelay()) {
  180. print img_warning("Late");
  181. }
  182. print '</td></tr>';
  183. // Budget
  184. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  185. if (strcmp($projectstatic->budget_amount, '')) {
  186. print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
  187. }
  188. print '</td></tr>';
  189. // Other attributes
  190. $cols = 2;
  191. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  192. print '</table>';
  193. print '</div>';
  194. print '<div class="fichehalfright">';
  195. print '<div class="underbanner clearboth"></div>';
  196. print '<table class="border tableforfield centpercent">';
  197. // Description
  198. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  199. print nl2br($projectstatic->description);
  200. print '</td></tr>';
  201. // Categories
  202. if ($conf->categorie->enabled) {
  203. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  204. print $form->showCategories($projectstatic->id, 'project', 1);
  205. print "</td></tr>";
  206. }
  207. print '</table>';
  208. print '</div>';
  209. print '</div>';
  210. print '<div class="clearboth"></div>';
  211. print dol_get_fiche_end();
  212. print '<br>';
  213. }
  214. $head = task_prepare_head($object);
  215. print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
  216. // Files list constructor
  217. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  218. $totalsize = 0;
  219. foreach ($filearray as $key => $file) {
  220. $totalsize += $file['size'];
  221. }
  222. $param = (GETPOST('withproject') ? '&withproject=1' : '');
  223. $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
  224. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  225. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  226. $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
  227. } else {
  228. $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
  229. }
  230. $morehtmlref = '';
  231. // Project
  232. if (empty($withproject)) {
  233. $morehtmlref .= '<div class="refidno">';
  234. $morehtmlref .= $langs->trans("Project").': ';
  235. $morehtmlref .= $projectstatic->getNomUrl(1);
  236. $morehtmlref .= '<br>';
  237. // Third party
  238. $morehtmlref .= $langs->trans("ThirdParty").': ';
  239. if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
  240. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  241. }
  242. $morehtmlref .= '</div>';
  243. }
  244. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  245. print '<div class="fichecenter">';
  246. print '<div class="underbanner clearboth"></div>';
  247. print '<table class="border tableforfield centpercent">';
  248. // Files infos
  249. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  250. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  251. print "</table>\n";
  252. print '</div>';
  253. print dol_get_fiche_end();
  254. print '<br>';
  255. $param = '';
  256. if ($withproject) {
  257. $param .= '&withproject=1';
  258. }
  259. $modulepart = 'project_task';
  260. $permissiontoadd = $user->rights->projet->creer;
  261. $permtoedit = $user->rights->projet->creer;
  262. $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
  263. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  264. } else {
  265. header('Location: index.php');
  266. exit;
  267. }
  268. // End of page
  269. llxFooter();
  270. $db->close();