dolibarr  17.0.4
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 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 
35 // Load translation files required by page
36 $langs->loadLangs(array('users', 'other'));
37 
38 $action = GETPOST('action', 'aZ09');
39 $confirm = GETPOST('confirm');
40 $id = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('id', 'int'));
41 $ref = GETPOST('ref', 'alpha');
42 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userdoc'; // To manage different context of search
43 
44 // Define value to know what current user can do on users
45 $canadduser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
46 $canreaduser = (!empty($user->admin) || $user->hasRight("user", "user", "read"));
47 $canedituser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
48 $candisableuser = (!empty($user->admin) || $user->hasRight("user", "user", "delete"));
49 $canreadgroup = $canreaduser;
50 $caneditgroup = $canedituser;
51 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
52  $canreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
53  $caneditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write"));
54 }
55 // Define value to know what current user can do on properties of edited user
56 if ($id) {
57  // $user est le user qui edite, $id est l'id de l'utilisateur edite
58  $caneditfield = ((($user->id == $id) && $user->hasRight("user", "self", "write"))
59  || (($user->id != $id) && $user->hasRight("user", "user", "write")));
60  $caneditpassword = ((($user->id == $id) && $user->hasRight("user", "self", "password"))
61  || (($user->id != $id) && $user->hasRight("user", "user", "passsword")));
62 }
63 
64 $permissiontoadd = $caneditfield; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
65 $permtoedit = $caneditfield;
66 
67 // Security check
68 $socid = 0;
69 if ($user->socid > 0) {
70  $socid = $user->socid;
71 }
72 $feature2 = 'user';
73 
74 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
75 
76 if ($user->id <> $id && !$canreaduser) {
78 }
79 
80 // Get parameters
81 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
82 $sortfield = GETPOST('sortfield', 'aZ09comma');
83 $sortorder = GETPOST('sortorder', 'aZ09comma');
84 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
85 if (empty($page) || $page == -1) {
86  $page = 0;
87 }
88 $offset = $limit * $page;
89 $pageprev = $page - 1;
90 $pagenext = $page + 1;
91 if (!$sortorder) {
92  $sortorder = "ASC";
93 }
94 if (!$sortfield) {
95  $sortfield = "position_name";
96 }
97 
98 $object = new User($db);
99 if ($id > 0 || !empty($ref)) {
100  $result = $object->fetch($id, $ref, '', 1);
101  $object->getrights();
102  //$upload_dir = $conf->user->multidir_output[$object->entity] . "/" . $object->id ;
103  // For users, the upload_dir is always $conf->user->entity for the moment
104  $upload_dir = $conf->user->dir_output."/".$object->id;
105 }
106 
107 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
108 $hookmanager->initHooks(array('usercard', 'userdoc', 'globalcard'));
109 
110 
111 
112 /*
113  * Actions
114  */
115 
116 $parameters = array('id'=>$socid);
117 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
118 if ($reshook < 0) {
119  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
120 }
121 
122 if (empty($reshook)) {
123  include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
124 }
125 
126 
127 /*
128  * View
129  */
130 
131 $form = new Form($db);
132 
133 
134 $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
135 $title = $person_name." - ".$langs->trans('Documents');
136 $help_url = '';
137 llxHeader('', $title, $help_url);
138 
139 if ($object->id) {
140  /*
141  * Affichage onglets
142  */
143  if (isModEnabled('notification')) {
144  $langs->load("mails");
145  }
146  $head = user_prepare_head($object);
147 
148  print dol_get_fiche_head($head, 'document', $langs->trans("User"), -1, 'user');
149 
150  $linkback = '';
151  if ($user->hasRight("user", "user", "read") || $user->admin) {
152  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
153  }
154 
155  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
156  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
157  $morehtmlref .= '</a>';
158 
159  dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
160 
161  print '<div class="fichecenter">';
162  print '<div class="underbanner clearboth"></div>';
163 
164  // Build file list
165  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
166  $totalsize = 0;
167  foreach ($filearray as $key => $file) {
168  $totalsize += $file['size'];
169  }
170 
171 
172  print '<table class="border tableforfield centpercent">';
173 
174  // Login
175  print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
176  if (!empty($object->ldap_sid) && $object->statut == 0) {
177  print '<td class="error">';
178  print $langs->trans("LoginAccountDisableInDolibarr");
179  print '</td>';
180  } else {
181  print '<td>';
182  $addadmin = '';
183  if (property_exists($object, 'admin')) {
184  if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
185  $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
186  } elseif (!empty($object->admin)) {
187  $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
188  }
189  }
190  print showValueWithClipboardCPButton($object->login).$addadmin;
191  print '</td>';
192  }
193  print '</tr>';
194 
195  // Nunber of files
196  print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
197 
198  // Total size
199  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
200 
201  print '</table>';
202  print '</div>';
203 
204  print dol_get_fiche_end();
205 
206  $modulepart = 'user';
207  $param = '&id='.$object->id;
208  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
209 } else {
210  accessforbidden('', 0, 1);
211 }
212 
213 // End of page
214 llxFooter();
215 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
llxFooter()
Footer empty.
Definition: document.php:89
dol_dir_list($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:61
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.