dolibarr 24.0.0-beta
document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36
45// Load translation files required by page
46$langs->loadLangs(array('users', 'other'));
47
48$action = GETPOST('action', 'aZ09');
49$confirm = GETPOST('confirm');
50$id = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('id'));
51$ref = GETPOST('ref', 'alpha');
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userdoc'; // To manage different context of search
53
54if (!isset($id) || empty($id)) {
56}
57'@phan-var-force int<1,max> $id';
58
59// Define value to know what current user can do on users
60$permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
61$permissiontoread = (!empty($user->admin) || $user->hasRight("user", "user", "read"));
62$permissiontoedit = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
63$permissiontodisable = (!empty($user->admin) || $user->hasRight("user", "user", "delete"));
64$permissiontoreadgroup = $permissiontoread;
65$permissiontoeditgroup = $permissiontoedit;
66if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
67 $permissiontoreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
68 $permissiontoeditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write"));
69}
70// Define value to know what current user can do on properties of edited user
71if ($id) {
72 // $user est le user qui edite, $id est l'id de l'utilisateur edite
73 $permissiontoedit = ((($user->id == $id) && $user->hasRight("user", "self", "write")) || (($user->id != $id) && $user->hasRight("user", "user", "write")));
74 $permissiontoeditpassword = ((($user->id == $id) && $user->hasRight("user", "self", "password")) || (($user->id != $id) && $user->hasRight("user", "user", "password")));
75}
76
77$permissiontoadd = $permissiontoedit; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
78$permtoedit = $permissiontoedit;
79
80// Security check
81$socid = 0;
82if ($user->socid > 0) {
83 $socid = $user->socid;
84}
85$feature2 = 'user';
86
87// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
88$hookmanager->initHooks(array('usercard', 'userdoc', 'globalcard'));
89
90$result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
91
92if ($user->id != $id && !$permissiontoread) {
94}
95
96// Get parameters
97$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
98$sortfield = GETPOST('sortfield', 'aZ09comma');
99$sortorder = GETPOST('sortorder', 'aZ09comma');
100$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
101if (empty($page) || $page == -1) {
102 $page = 0;
103}
104$offset = $limit * $page;
105$pageprev = $page - 1;
106$pagenext = $page + 1;
107if (!$sortorder) {
108 $sortorder = "ASC";
109}
110if (!$sortfield) {
111 $sortfield = "position_name";
112}
113
114$object = new User($db);
115$upload_dir = null;
116if ($id > 0 || !empty($ref)) {
117 $result = $object->fetch($id, $ref, '', 1);
118 $object->loadRights();
119 // $upload_dir = $conf->user->multidir_output[$object->entity ?? $conf->entity] . "/" . $object->id ;
120 // For users, the upload_dir is always $conf->user->entity for the moment
121 $upload_dir = $conf->user->dir_output."/".$object->id;
122}
123
124/*
125 * Actions
126 */
127
128$parameters = array('id' => $socid);
129$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
130if ($reshook < 0) {
131 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
132}
133
134if (empty($reshook)) {
135 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
136}
137
138
139/*
140 * View
141 */
142
143$form = new Form($db);
144
145
146$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
147$title = $person_name." - ".$langs->trans('Documents');
148$help_url = '';
149llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-card_document');
150
151if ($object->id && $upload_dir !== null) {
152 /*
153 * Show tabs
154 */
155 if (isModEnabled('notification')) {
156 $langs->load("mails");
157 }
158 $head = user_prepare_head($object);
159
160 print dol_get_fiche_head($head, 'document', $langs->trans("User"), -1, 'user', 0, '', '', 0, '', 1);
161
162 $linkback = '';
163 if ($user->hasRight("user", "user", "read") || $user->admin) {
164 $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
165 }
166
167 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid valignmiddle" rel="noopener">';
168 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
169 $morehtmlref .= '</a>';
170
171 $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
172 $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'refid valignmiddle nohover');
173
174 dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
175
176 print '<div class="fichecenter">';
177 print '<div class="underbanner clearboth"></div>';
178
179 // Build file list
180 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
181 $totalsize = 0;
182 foreach ($filearray as $key => $file) {
183 $totalsize += $file['size'];
184 }
185
186
187 print '<table class="border tableforfield centpercent">';
188
189 // Login
190 print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
191 if (!empty($object->ldap_sid) && $object->status == 0) {
192 print '<td class="error">';
193 print $langs->trans("LoginAccountDisableInDolibarr");
194 print '</td>';
195 } else {
196 print '<td>';
197 $addadmin = '';
198 if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
199 $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "superadmin", 'class="paddingleft valignmiddle"');
200 } elseif (!empty($object->admin)) {
201 $addadmin .= img_picto($langs->trans("AdministratorDesc"), "admin", 'class="paddingleft valignmiddle"');
202 }
203 print showValueWithClipboardCPButton($object->login).$addadmin;
204 print '</td>';
205 }
206 print '</tr>';
207
208 // Number of files
209 print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
210
211 // Total size
212 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
213
214 print '</table>';
215 print '</div>';
216
217 print dol_get_fiche_end();
218
219 $modulepart = 'user';
220 $param = '&id='.$object->id;
221 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
222} else {
223 accessforbidden('', 0, 1);
224}
225
226// End of page
227llxFooter();
228$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 Dolibarr users.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_prepare_head(User $object)
Prepare array with list of tabs.