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

/htdocs/projet/document.php

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