PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/document.php

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