document.php 12 KB

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