document.php 7.2 KB

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