dolibarr 21.0.0-alpha
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array('projects', 'other'));
37$hookmanager->initHooks(array('projectcarddocument'));
38
39$action = GETPOST('action', 'alpha');
40$confirm = GETPOST('confirm', 'alpha');
41$id = GETPOSTINT('id');
42$ref = GETPOST('ref', 'alpha');
43$mine = (GETPOST('mode', 'alpha') == 'mine' ? 1 : 0);
44//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
45
46$object = new Project($db);
47
48include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
49if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
50 $object->fetchComments();
51}
52
53if ($id > 0 || !empty($ref)) {
54 $upload_dir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
55}
56
57// Get parameters
58$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62if (empty($page) || $page == -1) {
63 $page = 0;
64} // If $page is not defined, or '' or -1
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68
69if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
70 $sortfield = getDolGlobalString('MAIN_DOC_SORT_FIELD');
71}
72if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
73 $sortorder = getDolGlobalString('MAIN_DOC_SORT_ORDER');
74}
75
76if (!$sortorder) {
77 $sortorder = "ASC";
78}
79if (!$sortfield) {
80 $sortfield = "name";
81}
82
83// Security check
84$socid = 0;
85//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.
86$result = restrictedArea($user, 'projet', $id, 'projet&project');
87
88$permissiontoadd = $user->hasRight('projet', 'creer');
89
90
91/*
92 * Actions
93 */
94
95include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
96
97
98/*
99 * View
100 */
101
102$title = $langs->trans('Documents').' - '.$object->ref.' '.$object->name;
103if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
104 $title = $object->ref.' '.$object->name.' - '.$langs->trans('Document');
105}
106
107$help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
108
109llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project page-card_document');
110
111$form = new Form($db);
112
113if ($object->id > 0) {
114 $upload_dir = $conf->project->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
115
116 // To verify role of users
117 //$userAccess = $object->restrictedProjectArea($user,'read');
118 $userWrite = $object->restrictedProjectArea($user, 'write');
119 //$userDelete = $object->restrictedProjectArea($user,'delete');
120 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
121
122 $head = project_prepare_head($object);
123 print dol_get_fiche_head($head, 'document', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
124
125 // Files list constructor
126 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
127 $totalsize = 0;
128 foreach ($filearray as $key => $file) {
129 $totalsize += $file['size'];
130 }
131
132
133 // Project card
134
135 if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
136 $tmpurl = $_SESSION['pageforbacktolist']['project'];
137 $tmpurl = preg_replace('/__SOCID__/', (string) $object->socid, $tmpurl);
138 $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
139 } else {
140 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
141 }
142
143 $morehtmlref = '<div class="refidno">';
144 // Title
145 $morehtmlref .= $object->title;
146 // Thirdparty
147 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
148 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
149 }
150 $morehtmlref .= '</div>';
151
152 // Define a complementary filter for search of next/prev ref.
153 if (!$user->hasRight('projet', 'all', 'lire')) {
154 $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
155 $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0').")";
156 }
157
158 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
159
160
161 print '<div class="fichecenter">';
162 print '<div class="underbanner clearboth"></div>';
163
164 print '<table class="border tableforfield centpercent">';
165
166 // Files infos
167 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
168 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
169
170 print "</table>\n";
171
172 print '</div>';
173
174
175 print dol_get_fiche_end();
176
177 $modulepart = 'projet';
178 $permissiontoadd = ($userWrite > 0);
179 $permtoedit = ($userWrite > 0);
180 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
181} else {
182 dol_print_error(null, 'NoRecordFound');
183}
184
185// End of page
186llxFooter();
187$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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.
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.