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
22/**
23 *  \file       htdocs/user/document.php
24 *  \brief      Tab for documents linked to user
25 *  \ingroup    user
26 */
27
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
32require_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;
50if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
51	$canreadgroup = (!empty($user->admin) || $user->rights->user->group_advance->read);
52	$caneditgroup = (!empty($user->admin) || $user->rights->user->group_advance->write);
53}
54// Define value to know what current user can do on properties of edited user
55if ($id) {
56	// $user est le user qui edite, $id est l'id de l'utilisateur edite
57	$caneditfield = ((($user->id == $id) && $user->rights->user->self->creer)
58	|| (($user->id != $id) && $user->rights->user->user->creer));
59	$caneditpassword = ((($user->id == $id) && $user->rights->user->self->password)
60	|| (($user->id != $id) && $user->rights->user->user->password));
61}
62
63$permissiontoadd = $caneditfield;
64$permtoedit = $caneditfield;
65
66// Security check
67$socid = 0;
68if ($user->socid > 0) {
69	$socid = $user->socid;
70}
71$feature2 = 'user';
72
73$result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
74
75if ($user->id <> $id && !$canreaduser) {
76	accessforbidden();
77}
78
79// Get parameters
80$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
81$sortfield = GETPOST("sortfield", 'alpha');
82$sortorder = GETPOST("sortorder", 'alpha');
83$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
84if (empty($page) || $page == -1) {
85	$page = 0;
86}
87$offset = $limit * $page;
88$pageprev = $page - 1;
89$pagenext = $page + 1;
90if (!$sortorder) {
91	$sortorder = "ASC";
92}
93if (!$sortfield) {
94	$sortfield = "position_name";
95}
96
97$object = new User($db);
98if ($id > 0 || !empty($ref)) {
99	$result = $object->fetch($id, $ref, '', 1);
100	$object->getrights();
101	//$upload_dir = $conf->user->multidir_output[$object->entity] . "/" . $object->id ;
102	// For users, the upload_dir is always $conf->user->entity for the moment
103	$upload_dir = $conf->user->dir_output."/".$object->id;
104}
105
106// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
107$hookmanager->initHooks(array('usercard', 'userdoc', 'globalcard'));
108
109
110/*
111 * Actions
112 */
113
114$parameters = array('id'=>$socid);
115$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
116if ($reshook < 0) {
117	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120if (empty($reshook)) {
121	include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
122}
123
124
125/*
126 * View
127 */
128
129$form = new Form($db);
130
131llxHeader('', $langs->trans("UserCard").' - '.$langs->trans("Files"));
132
133if ($object->id) {
134	/*
135	 * Affichage onglets
136	 */
137	if (!empty($conf->notification->enabled)) {
138		$langs->load("mails");
139	}
140	$head = user_prepare_head($object);
141
142	$form = new Form($db);
143
144	print dol_get_fiche_head($head, 'document', $langs->trans("User"), -1, 'user');
145
146	$linkback = '';
147	if ($user->rights->user->user->lire || $user->admin) {
148		$linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
149	}
150
151	dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
152
153	print '<div class="fichecenter">';
154	print '<div class="underbanner clearboth"></div>';
155
156	// Build file list
157	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
158	$totalsize = 0;
159	foreach ($filearray as $key => $file) {
160		$totalsize += $file['size'];
161	}
162
163
164	print '<table class="border tableforfield centpercent">';
165
166	// Login
167	print '<tr><td class="titlefield">'.$langs->trans("Login").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
168
169	// Nunber of files
170	print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
171
172	// Total size
173	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
174
175	print '</table>';
176	print '</div>';
177
178	print dol_get_fiche_end();
179
180	$modulepart = 'user';
181	$param = '&id='.$object->id;
182	include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
183} else {
184	accessforbidden('', 0, 1);
185}
186
187// End of page
188llxFooter();
189$db->close();
190