dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array('projects', 'other'));
46$hookmanager->initHooks(array('projectcarddocument'));
47
48$action = GETPOST('action', 'alpha');
49$confirm = GETPOST('confirm', 'alpha');
50$id = GETPOSTINT('id');
51$ref = GETPOST('ref', 'alpha');
52$mine = (GETPOST('mode', 'alpha') == 'mine' ? 1 : 0);
53//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
54
55$object = new Project($db);
56
57include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
58if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
59 $object->fetchComments();
60}
61
62if ($id > 0 || !empty($ref)) {
63 $upload_dir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
64}
65
66// Get parameters
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$sortfield = GETPOST('sortfield', 'aZ09comma');
69$sortorder = GETPOST('sortorder', 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
71if (empty($page) || $page == -1) {
72 $page = 0;
73} // If $page is not defined, or '' or -1
74$offset = $limit * $page;
75$pageprev = $page - 1;
76$pagenext = $page + 1;
77
78if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
79 $sortfield = getDolGlobalString('MAIN_DOC_SORT_FIELD');
80}
81if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
82 $sortorder = getDolGlobalString('MAIN_DOC_SORT_ORDER');
83}
84
85if (!$sortorder) {
86 $sortorder = "ASC";
87}
88if (!$sortfield) {
89 $sortfield = "name";
90}
91
92// Security check
93$socid = 0;
94//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 assignment.
95$result = restrictedArea($user, 'projet', $id, 'projet&project');
96
97$permissiontoadd = $user->hasRight('projet', 'creer');
98
99
100/*
101 * Actions
102 */
103
104$parameters = array();
105$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106if ($reshook < 0) {
107 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108}
109
110include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
111
112
113/*
114 * View
115 */
116
117$title = $langs->trans('Documents').' - '.$object->ref.' '.$object->name;
118if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
119 $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
120}
121
122$help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
123
124llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-card_document');
125
126$form = new Form($db);
127
128if ($object->id > 0) {
129 $upload_dir = $conf->project->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
130
131 // To verify role of users
132 //$userAccess = $object->restrictedProjectArea($user,'read');
133 $userWrite = $object->restrictedProjectArea($user, 'write');
134 //$userDelete = $object->restrictedProjectArea($user,'delete');
135 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
136
137 $head = project_prepare_head($object);
138 print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
139
140 // Files list constructor
141 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
142 $totalsize = 0;
143 foreach ($filearray as $key => $file) {
144 $totalsize += $file['size'];
145 }
146
147
148 // Project card
149
150 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
151 $tmpurl = $_SESSION['pageforbacktolist']['project'];
152 $tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
153 $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
154 } else {
155 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
156 }
157
158 $morehtmlref = '<div class="refidno">';
159 // Title
160 $morehtmlref .= $object->title;
161 // Thirdparty
162 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
163 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
164 }
165 $morehtmlref .= '</div>';
166
167 // Define a complementary filter for search of next/prev ref.
168 if (!$user->hasRight('projet', 'all', 'lire')) {
169 $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
170 $object->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
171 }
172
173 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
174
175
176 print '<div class="fichecenter">';
177 print '<div class="underbanner clearboth"></div>';
178
179 print '<table class="border tableforfield centpercent">';
180
181 // Files infos
182 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
183 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
184
185 print "</table>\n";
186
187 print '</div>';
188
189
190 print dol_get_fiche_end();
191
192 $modulepart = 'projet';
193 $permissiontoadd = ($userWrite > 0);
194 $permtoedit = ($userWrite > 0);
195 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
196} else {
197 dol_print_error(null, 'NoRecordFound');
198}
199
200// End of page
201llxFooter();
202$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
dol_dir_list($utf8_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:63
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.