document.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 <http://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. {
  47. $canreadgroup=(! empty($user->admin) || $user->rights->user->group_advance->read);
  48. $caneditgroup=(! empty($user->admin) || $user->rights->user->group_advance->write);
  49. }
  50. // Define value to know what current user can do on properties of edited user
  51. if ($id)
  52. {
  53. // $user est le user qui edite, $id est l'id de l'utilisateur edite
  54. $caneditfield=((($user->id == $id) && $user->rights->user->self->creer)
  55. || (($user->id != $id) && $user->rights->user->user->creer));
  56. $caneditpassword=((($user->id == $id) && $user->rights->user->self->password)
  57. || (($user->id != $id) && $user->rights->user->user->password));
  58. }
  59. // Security check
  60. $socid=0;
  61. if ($user->societe_id > 0) $socid = $user->societe_id;
  62. $feature2='user';
  63. if ($user->id == $id) { $feature2=''; $canreaduser=1; } // A user can always read its own card
  64. if (!$canreaduser) {
  65. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  66. }
  67. if ($user->id <> $id && ! $canreaduser) accessforbidden();
  68. // Get parameters
  69. $sortfield = GETPOST("sortfield",'alpha');
  70. $sortorder = GETPOST("sortorder",'alpha');
  71. $page = GETPOST("page",'int');
  72. if (empty($page) || $page == -1) { $page = 0; }
  73. $offset = $conf->liste_limit * $page;
  74. $pageprev = $page - 1;
  75. $pagenext = $page + 1;
  76. if (! $sortorder) $sortorder="ASC";
  77. if (! $sortfield) $sortfield="position_name";
  78. $object = new User($db);
  79. if ($id > 0 || ! empty($ref))
  80. {
  81. $result = $object->fetch($id, $ref, '', 1);
  82. $object->getrights();
  83. //$upload_dir = $conf->user->multidir_output[$object->entity] . "/" . $object->id ;
  84. // For users, the upload_dir is always $conf->user->entity for the moment
  85. $upload_dir = $conf->user->dir_output. "/" . $object->id ;
  86. }
  87. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  88. $hookmanager->initHooks(array('usercard','userdoc','globalcard'));
  89. /*
  90. * Actions
  91. */
  92. $parameters=array('id'=>$socid);
  93. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  94. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  95. if (empty($reshook)) {
  96. include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  103. llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Files"),$help_url);
  104. if ($object->id)
  105. {
  106. /*
  107. * Affichage onglets
  108. */
  109. if (! empty($conf->notification->enabled)) $langs->load("mails");
  110. $head = user_prepare_head($object);
  111. $form=new Form($db);
  112. dol_fiche_head($head, 'document', $langs->trans("User"), -1, 'user');
  113. $linkback = '';
  114. if ($user->rights->user->user->lire || $user->admin) {
  115. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  116. }
  117. dol_banner_tab($object,'id',$linkback,$user->rights->user->user->lire || $user->admin);
  118. print '<div class="fichecenter">';
  119. print '<div class="underbanner clearboth"></div>';
  120. // Build file list
  121. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  122. $totalsize=0;
  123. foreach($filearray as $key => $file)
  124. {
  125. $totalsize+=$file['size'];
  126. }
  127. print '<table class="border" width="100%">';
  128. // Login
  129. print '<tr><td class="titlefield">'.$langs->trans("Login").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  130. // Nbre files
  131. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  132. //Total taille
  133. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize,1,1).'</td></tr>';
  134. print '</table>';
  135. print '</div>';
  136. dol_fiche_end();
  137. $modulepart = 'user';
  138. $permission = $user->rights->user->user->creer;
  139. $permtoedit = $user->rights->user->user->creer;
  140. $param = '&id=' . $object->id;
  141. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  142. }
  143. else
  144. {
  145. accessforbidden('',0,0);
  146. }
  147. // End of page
  148. llxFooter();
  149. $db->close();