dolibarr  13.0.2
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  *
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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33 
34 // Load translation files required by page
35 $langs->loadLangs(array('users', 'other'));
36 
37 $action = GETPOST('action', 'aZ09');
38 $confirm = GETPOST('confirm');
39 $id = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('id', 'int'));
40 $ref = GETPOST('ref', 'alpha');
41 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userdoc'; // To manage different context of search
42 
43 // Define value to know what current user can do on users
44 $canadduser = (!empty($user->admin) || $user->rights->user->user->creer);
45 $canreaduser = (!empty($user->admin) || $user->rights->user->user->lire);
46 $canedituser = (!empty($user->admin) || $user->rights->user->user->creer);
47 $candisableuser = (!empty($user->admin) || $user->rights->user->user->supprimer);
48 $canreadgroup = $canreaduser;
49 $caneditgroup = $canedituser;
50 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS))
51 {
52  $canreadgroup = (!empty($user->admin) || $user->rights->user->group_advance->read);
53  $caneditgroup = (!empty($user->admin) || $user->rights->user->group_advance->write);
54 }
55 // Define value to know what current user can do on properties of edited user
56 if ($id)
57 {
58  // $user est le user qui edite, $id est l'id de l'utilisateur edite
59  $caneditfield = ((($user->id == $id) && $user->rights->user->self->creer)
60  || (($user->id != $id) && $user->rights->user->user->creer));
61  $caneditpassword = ((($user->id == $id) && $user->rights->user->self->password)
62  || (($user->id != $id) && $user->rights->user->user->password));
63 }
64 
65 // Security check
66 $socid = 0;
67 if ($user->socid > 0) $socid = $user->socid;
68 $feature2 = 'user';
69 
70 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
71 
72 if ($user->id <> $id && !$canreaduser) accessforbidden();
73 
74 // Get parameters
75 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
76 $sortfield = GETPOST("sortfield", 'alpha');
77 $sortorder = GETPOST("sortorder", 'alpha');
78 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
79 if (empty($page) || $page == -1) { $page = 0; }
80 $offset = $limit * $page;
81 $pageprev = $page - 1;
82 $pagenext = $page + 1;
83 if (!$sortorder) $sortorder = "ASC";
84 if (!$sortfield) $sortfield = "position_name";
85 
86 $object = new User($db);
87 if ($id > 0 || !empty($ref))
88 {
89  $result = $object->fetch($id, $ref, '', 1);
90  $object->getrights();
91  //$upload_dir = $conf->user->multidir_output[$object->entity] . "/" . $object->id ;
92  // For users, the upload_dir is always $conf->user->entity for the moment
93  $upload_dir = $conf->user->dir_output."/".$object->id;
94 }
95 
96 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
97 $hookmanager->initHooks(array('usercard', 'userdoc', 'globalcard'));
98 
99 
100 /*
101  * Actions
102  */
103 
104 $parameters = array('id'=>$socid);
105 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107 
108 if (empty($reshook)) {
109  include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
110 }
111 
112 
113 /*
114  * View
115  */
116 
117 $form = new Form($db);
118 
119 llxHeader('', $langs->trans("UserCard").' - '.$langs->trans("Files"));
120 
121 if ($object->id)
122 {
123  /*
124  * Affichage onglets
125  */
126  if (!empty($conf->notification->enabled)) $langs->load("mails");
127  $head = user_prepare_head($object);
128 
129  $form = new Form($db);
130 
131  print dol_get_fiche_head($head, 'document', $langs->trans("User"), -1, 'user');
132 
133  $linkback = '';
134  if ($user->rights->user->user->lire || $user->admin) {
135  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
136  }
137 
138  dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
139 
140  print '<div class="fichecenter">';
141  print '<div class="underbanner clearboth"></div>';
142 
143  // Build file list
144  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
145  $totalsize = 0;
146  foreach ($filearray as $key => $file)
147  {
148  $totalsize += $file['size'];
149  }
150 
151 
152  print '<table class="border tableforfield centpercent">';
153 
154  // Login
155  print '<tr><td class="titlefield">'.$langs->trans("Login").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
156 
157  // Nunber of files
158  print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
159 
160  // Total size
161  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
162 
163  print '</table>';
164  print '</div>';
165 
167 
168 
169  $modulepart = 'user';
170  $permission = $user->rights->user->user->creer;
171  $permtoedit = $user->rights->user->user->creer;
172  $param = '&id='.$object->id;
173  include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
174 } else {
175  accessforbidden('', 0, 1);
176 }
177 
178 // End of page
179 llxFooter();
180 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
user_prepare_head($object)
Prepare array with list of tabs.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=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 Calling this function terminate execution ...
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59