dolibarr 24.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-2025 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
54$object = new Project($db);
55
56include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
57if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
58 $object->fetchComments();
59}
60
61if ($id > 0 || !empty($ref)) {
62 $upload_dir = $conf->project->multidir_output[$object->entity ?? $conf->entity]."/".dol_sanitizeFileName($object->ref);
63}
64
65// Get parameters
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67$sortfield = GETPOST('sortfield', 'aZ09comma');
68$sortorder = GETPOST('sortorder', 'aZ09comma');
69$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
70if (empty($page) || $page == -1) {
71 $page = 0;
72} // If $page is not defined, or '' or -1
73$offset = $limit * $page;
74$pageprev = $page - 1;
75$pagenext = $page + 1;
76
77if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
78 $sortfield = getDolGlobalString('MAIN_DOC_SORT_FIELD');
79}
80if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
81 $sortorder = getDolGlobalString('MAIN_DOC_SORT_ORDER');
82}
83
84if (!$sortorder) {
85 $sortorder = "ASC";
86}
87if (!$sortfield) {
88 $sortfield = "name";
89}
90
91// Security check
92$socid = 0;
93//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.
94$result = restrictedArea($user, 'projet', $id, 'projet&project');
95
96$permissiontoadd = $user->hasRight('projet', 'creer');
97
98
99/*
100 * Actions
101 */
102
103$parameters = array();
104$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105if ($reshook < 0) {
106 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107}
108
109include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
110
111
112/*
113 * View
114 */
115
116$title = $langs->trans('Documents').' - '.$object->ref.' '.$object->name;
117if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
118 $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
119}
120
121$help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
122
123llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-card_document');
124
125$form = new Form($db);
126
127if ($object->id > 0) {
128 $upload_dir = $conf->project->multidir_output[$object->entity ?? $conf->entity].'/'.dol_sanitizeFileName($object->ref);
129
130 // To verify role of users
131 //$userAccess = $object->restrictedProjectArea($user,'read');
132 $userWrite = $object->restrictedProjectArea($user, 'write');
133 //$userDelete = $object->restrictedProjectArea($user,'delete');
134 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
135
136 $head = project_prepare_head($object);
137 print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
138
139 // Files list constructor
140 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
141 $totalsize = 0;
142 foreach ($filearray as $key => $file) {
143 $totalsize += $file['size'];
144 }
145
146
147 // Project card
148
149 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
150 $tmpurl = $_SESSION['pageforbacktolist']['project'];
151 $tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
152 $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
153 } else {
154 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
155 }
156
157 $morehtmlref = '<div class="refidno">';
158 // Title
159 $morehtmlref .= $object->title;
160 // Thirdparty
161 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
162 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
163 }
164 $morehtmlref .= '</div>';
165
166 // Define a complementary filter for search of next/prev ref.
167 if (!$user->hasRight('projet', 'all', 'lire')) {
168 $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
169 $object->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
170 }
171
172 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
173
174
175 print '<div class="fichecenter">';
176 print '<div class="underbanner clearboth"></div>';
177
178 print '<table class="border tableforfield centpercent">';
179
180 // Files infos
181 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
182 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
183
184 print "</table>\n";
185
186 print '</div>';
187
188
189 print dol_get_fiche_end();
190
191 $modulepart = 'projet';
192 $permissiontoadd = ($userWrite > 0);
193 $permtoedit = ($userWrite > 0);
194 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
195} else {
196 dol_print_error(null, 'NoRecordFound');
197}
198
199// End of page
200llxFooter();
201$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.