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