dolibarr  16.0.5
document.php
Go to the documentation of this file.
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 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('projects', 'other'));
35 $hookmanager->initHooks(array('projectcarddocument'));
36 
37 $action = GETPOST('action', 'alpha');
38 $confirm = GETPOST('confirm', 'alpha');
39 $id = GETPOST('id', 'int');
40 $ref = GETPOST('ref', 'alpha');
41 $mine = (GETPOST('mode', 'alpha') == 'mine' ? 1 : 0);
42 //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
43 
44 $object = new Project($db);
45 
46 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
47 if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
48  $object->fetchComments();
49 }
50 
51 if ($id > 0 || !empty($ref)) {
52  $upload_dir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
53 }
54 
55 // Get parameters
56 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'aZ09comma');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60 if (empty($page) || $page == -1) {
61  $page = 0;
62 } // If $page is not defined, or '' or -1
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 
67 if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
68  $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
69 }
70 if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
71  $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
72 }
73 
74 if (!$sortorder) {
75  $sortorder = "ASC";
76 }
77 if (!$sortfield) {
78  $sortfield = "name";
79 }
80 
81 // Security check
82 $socid = 0;
83 //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.
84 $result = restrictedArea($user, 'projet', $id, 'projet&project');
85 
86 $permissiontoadd = $user->rights->projet->creer;
87 
88 
89 /*
90  * Actions
91  */
92 
93 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
94 
95 
96 /*
97  * View
98  */
99 
100 $title = $langs->trans('Project').' - '.$langs->trans('Document').' - '.$object->ref.' '.$object->name;
101 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
102  $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
103 }
104 
105 $help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
106 
107 llxHeader('', $title, $help_url);
108 
109 $form = new Form($db);
110 
111 if ($object->id > 0) {
112  $upload_dir = $conf->project->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
113 
114  // To verify role of users
115  //$userAccess = $object->restrictedProjectArea($user,'read');
116  $userWrite = $object->restrictedProjectArea($user, 'write');
117  //$userDelete = $object->restrictedProjectArea($user,'delete');
118  //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
119 
120  $head = project_prepare_head($object);
121  print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
122 
123  // Files list constructor
124  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
125  $totalsize = 0;
126  foreach ($filearray as $key => $file) {
127  $totalsize += $file['size'];
128  }
129 
130 
131  // Project card
132 
133  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
134 
135  $morehtmlref = '<div class="refidno">';
136  // Title
137  $morehtmlref .= $object->title;
138  // Thirdparty
139  if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
140  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
141  }
142  $morehtmlref .= '</div>';
143 
144  // Define a complementary filter for search of next/prev ref.
145  if (empty($user->rights->projet->all->lire)) {
146  $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
147  $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
148  }
149 
150  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
151 
152 
153  print '<div class="fichecenter">';
154  print '<div class="underbanner clearboth"></div>';
155 
156  print '<table class="border tableforfield centpercent">';
157 
158  // Files infos
159  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
160  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
161 
162  print "</table>\n";
163 
164  print '</div>';
165 
166 
167  print dol_get_fiche_end();
168 
169  $modulepart = 'projet';
170  $permissiontoadd = ($userWrite > 0);
171  $permtoedit = ($userWrite > 0);
172  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
173 } else {
174  dol_print_error('', 'NoRecordFound');
175 }
176 
177 // End of page
178 llxFooter();
179 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
project_prepare_head
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
Definition: project.lib.php:38
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52