document.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/document.php
  21. * \ingroup project
  22. * \brief Page de gestion des documents attachees a un projet
  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. $langs->load('projects');
  31. $langs->load('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. // Security check
  39. $socid=0;
  40. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  41. $result=restrictedArea($user,'projet',$id,'projet&project');
  42. $object = new Project($db);
  43. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  44. if ($id > 0 || ! empty($ref)) {
  45. $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
  46. }
  47. // Get parameters
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  52. $offset = $conf->liste_limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (! $sortorder) $sortorder="ASC";
  56. if (! $sortfield) $sortfield="name";
  57. /*
  58. * Actions
  59. */
  60. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  61. /*
  62. * View
  63. */
  64. $title=$langs->trans("Project").' - '.$langs->trans("Document").' - '.$object->ref.' '.$object->name;
  65. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("Document");
  66. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  67. llxHeader('',$title,$help_url);
  68. $form = new Form($db);
  69. if ($object->id > 0)
  70. {
  71. $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref);
  72. // To verify role of users
  73. //$userAccess = $object->restrictedProjectArea($user,'read');
  74. $userWrite = $object->restrictedProjectArea($user,'write');
  75. //$userDelete = $object->restrictedProjectArea($user,'delete');
  76. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  77. $head = project_prepare_head($object);
  78. dol_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public?'projectpub':'project'));
  79. // Files list constructor
  80. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  81. $totalsize=0;
  82. foreach($filearray as $key => $file)
  83. {
  84. $totalsize+=$file['size'];
  85. }
  86. // Project card
  87. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  88. $morehtmlref='<div class="refidno">';
  89. // Title
  90. $morehtmlref.=$object->title;
  91. // Thirdparty
  92. if ($object->thirdparty->id > 0)
  93. {
  94. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project');
  95. }
  96. $morehtmlref.='</div>';
  97. // Define a complementary filter for search of next/prev ref.
  98. if (! $user->rights->projet->all->lire)
  99. {
  100. $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  101. $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  102. }
  103. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  104. print '<div class="fichecenter">';
  105. print '<div class="underbanner clearboth"></div>';
  106. print '<table class="border" width="100%">';
  107. // Files infos
  108. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  109. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  110. print "</table>\n";
  111. print '</div>';
  112. dol_fiche_end();
  113. $modulepart = 'project';
  114. $permission = ($userWrite > 0);
  115. $permtoedit = ($userWrite > 0);
  116. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  117. }
  118. else
  119. {
  120. dol_print_error('','NoRecordFound');
  121. }
  122. llxFooter();
  123. $db->close();