document.php 8.0 KB

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