document.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  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/document.php
  21. * \ingroup project
  22. * \brief Page to managed related documents linked to a project
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('projects', 'other'));
  33. $hookmanager->initHooks(array('projectcarddocument'));
  34. $action = GETPOST('action', 'alpha');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $mine = (GETPOST('mode', 'alpha') == 'mine' ? 1 : 0);
  39. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  40. $object = new Project($db);
  41. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  42. if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
  43. $object->fetchComments();
  44. }
  45. if ($id > 0 || !empty($ref)) {
  46. $upload_dir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  47. }
  48. // Get parameters
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
  60. $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
  61. }
  62. if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
  63. $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
  64. }
  65. if (!$sortorder) {
  66. $sortorder = "ASC";
  67. }
  68. if (!$sortfield) {
  69. $sortfield = "name";
  70. }
  71. // Security check
  72. $socid = 0;
  73. //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.
  74. $result = restrictedArea($user, 'projet', $id, 'projet&project');
  75. $permissiontoadd = $user->hasRight('projet', 'creer');
  76. /*
  77. * Actions
  78. */
  79. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  80. /*
  81. * View
  82. */
  83. $title = $langs->trans('Documents').' - '.$object->ref.' '.$object->name;
  84. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  85. $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
  86. }
  87. $help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
  88. llxHeader('', $title, $help_url);
  89. $form = new Form($db);
  90. if ($object->id > 0) {
  91. $upload_dir = $conf->project->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  92. // To verify role of users
  93. //$userAccess = $object->restrictedProjectArea($user,'read');
  94. $userWrite = $object->restrictedProjectArea($user, 'write');
  95. //$userDelete = $object->restrictedProjectArea($user,'delete');
  96. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  97. $head = project_prepare_head($object);
  98. print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  99. // Files list constructor
  100. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  101. $totalsize = 0;
  102. foreach ($filearray as $key => $file) {
  103. $totalsize += $file['size'];
  104. }
  105. // Project card
  106. if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
  107. $tmpurl = $_SESSION['pageforbacktolist']['project'];
  108. $tmpurl = preg_replace('/__SOCID__/', $object->socid, $tmpurl);
  109. $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  110. } else {
  111. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  112. }
  113. $morehtmlref = '<div class="refidno">';
  114. // Title
  115. $morehtmlref .= $object->title;
  116. // Thirdparty
  117. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  118. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  119. }
  120. $morehtmlref .= '</div>';
  121. // Define a complementary filter for search of next/prev ref.
  122. if (!$user->hasRight('projet', 'all', 'lire')) {
  123. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  124. $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  125. }
  126. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  127. print '<div class="fichecenter">';
  128. print '<div class="underbanner clearboth"></div>';
  129. print '<table class="border tableforfield centpercent">';
  130. // Files infos
  131. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  132. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  133. print "</table>\n";
  134. print '</div>';
  135. print dol_get_fiche_end();
  136. $modulepart = 'projet';
  137. $permissiontoadd = ($userWrite > 0);
  138. $permtoedit = ($userWrite > 0);
  139. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  140. } else {
  141. dol_print_error('', 'NoRecordFound');
  142. }
  143. // End of page
  144. llxFooter();
  145. $db->close();