document.php 7.5 KB

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