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
104include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
105
106
107/*
108 * View
109 */
110
111$title = $langs->trans('Documents').' - '.$object->ref.' '.$object->name;
112if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
113 $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
114}
115
116$help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
117
118llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-card_document');
119
120$form = new Form($db);
121
122if ($object->id > 0) {
123 $upload_dir = $conf->project->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
124
125 // To verify role of users
126 //$userAccess = $object->restrictedProjectArea($user,'read');
127 $userWrite = $object->restrictedProjectArea($user, 'write');
128 //$userDelete = $object->restrictedProjectArea($user,'delete');
129 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
130
131 $head = project_prepare_head($object);
132 print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
133
134 // Files list constructor
135 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
136 $totalsize = 0;
137 foreach ($filearray as $key => $file) {
138 $totalsize += $file['size'];
139 }
140
141
142 // Project card
143
144 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
145 $tmpurl = $_SESSION['pageforbacktolist']['project'];
146 $tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
147 $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
148 } else {
149 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
150 }
151
152 $morehtmlref = '<div class="refidno">';
153 // Title
154 $morehtmlref .= $object->title;
155 // Thirdparty
156 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
157 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
158 }
159 $morehtmlref .= '</div>';
160
161 // Define a complementary filter for search of next/prev ref.
162 if (!$user->hasRight('projet', 'all', 'lire')) {
163 $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
164 $object->next_prev_filter = "rowid:IN:(".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0').")";
165 }
166
167 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
168
169
170 print '<div class="fichecenter">';
171 print '<div class="underbanner clearboth"></div>';
172
173 print '<table class="border tableforfield centpercent">';
174
175 // Files infos
176 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
177 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
178
179 print "</table>\n";
180
181 print '</div>';
182
183
184 print dol_get_fiche_end();
185
186 $modulepart = 'projet';
187 $permissiontoadd = ($userWrite > 0);
188 $permtoedit = ($userWrite > 0);
189 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
190} else {
191 dol_print_error(null, 'NoRecordFound');
192}
193
194// End of page
195llxFooter();
196$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
llxFooter()
Footer empty.
Definition document.php:107
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.
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.