index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/user/group/index.php
  22. * \ingroup core
  23. * \brief Page of user groups
  24. */
  25. require '../../main.inc.php';
  26. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  27. {
  28. if (! $user->rights->user->group_advance->read && ! $user->admin)
  29. accessforbidden();
  30. }
  31. // Users/Groups management only in master entity if transverse mode
  32. if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
  33. {
  34. accessforbidden();
  35. }
  36. $langs->load("users");
  37. $sall=GETPOST('sall', 'alphanohtml');
  38. $search_group=GETPOST('search_group');
  39. $optioncss = GETPOST('optioncss','alpha');
  40. // Load variable for pagination
  41. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  42. $sortfield = GETPOST('sortfield','alpha');
  43. $sortorder = GETPOST('sortorder','alpha');
  44. $page = GETPOST('page','int');
  45. if (empty($page) || $page == -1) { $page = 0; }
  46. $offset = $limit * $page;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. if (! $sortfield) $sortfield="g.nom";
  50. if (! $sortorder) $sortorder="ASC";
  51. // List of fields to search into when doing a "search in all"
  52. $fieldstosearchall = array(
  53. 'g.nom'=>"Group",
  54. 'g.note'=>"Note"
  55. );
  56. /*
  57. * Actions
  58. */
  59. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  60. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
  61. $parameters=array();
  62. $reshook=$hookmanager->executeHooks('doActions',$parameters); // Note that $action and $object may have been modified by some hooks
  63. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  64. if (empty($reshook))
  65. {
  66. // Selection of new fields
  67. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  68. // Purge search criteria
  69. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  70. {
  71. $search_label="";
  72. $search_date_creation="";
  73. $search_date_update="";
  74. $search_array_options=array();
  75. }
  76. }
  77. /*
  78. * View
  79. */
  80. llxHeader();
  81. $sql = "SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
  82. $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g";
  83. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
  84. if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
  85. {
  86. $sql.= " WHERE g.entity IS NOT NULL";
  87. }
  88. else
  89. {
  90. $sql.= " WHERE g.entity IN (0,".$conf->entity.")";
  91. }
  92. if (! empty($search_group))
  93. {
  94. $sql .= " AND (g.nom LIKE '%".$db->escape($search_group)."%' OR g.note LIKE '%".$db->escape($search_group)."%')";
  95. }
  96. if ($sall) $sql.= " AND (g.nom LIKE '%".$db->escape($sall)."%' OR g.note LIKE '%".$db->escape($sall)."%')";
  97. $sql.= " GROUP BY g.rowid, g.nom, g.entity, g.datec";
  98. $sql.= $db->order($sortfield,$sortorder);
  99. $resql = $db->query($sql);
  100. if ($resql)
  101. {
  102. $num = $db->num_rows($resql);
  103. $nbtotalofrecords = $num;
  104. $i = 0;
  105. $param="&search_group=".urlencode($search_group)."&amp;sall=".urlencode($sall);
  106. if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
  107. $text = $langs->trans("ListOfGroups");
  108. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  109. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  110. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  111. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  112. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  113. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  114. print '<input type="hidden" name="page" value="'.$page.'">';
  115. print '<input type="hidden" name="mode" value="'.$mode.'">';
  116. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  117. print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit);
  118. if ($sall)
  119. {
  120. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  121. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  122. }
  123. if ($sall)
  124. {
  125. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  126. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  127. }
  128. $moreforfilter='';
  129. //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  130. //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  131. print '<div class="div-table-responsive">';
  132. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  133. print '<tr class="liste_titre">';
  134. print_liste_field_titre($langs->trans("Group"),$_SERVER["PHP_SELF"],"g.nom",$param,"","",$sortfield,$sortorder);
  135. //multicompany
  136. if(! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
  137. {
  138. print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],"g.entity",$param,"",'align="center"',$sortfield,$sortorder);
  139. }
  140. print_liste_field_titre($langs->trans("NbOfUsers"),$_SERVER["PHP_SELF"],"nb",$param,"",'align="center"',$sortfield,$sortorder);
  141. print_liste_field_titre($langs->trans("DateCreationShort"),$_SERVER["PHP_SELF"],"g.datec",$param,"",'align="right"',$sortfield,$sortorder);
  142. print "</tr>\n";
  143. $var=True;
  144. while ($i < $num)
  145. {
  146. $obj = $db->fetch_object($resql);
  147. print '<tr class="oddeven">';
  148. print '<td><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowGroup"),"group").' '.$obj->name.'</a>';
  149. if (! $obj->entity)
  150. {
  151. print img_picto($langs->trans("GlobalGroup"),'redstar');
  152. }
  153. print "</td>";
  154. //multicompany
  155. if (! empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
  156. {
  157. $mc->getInfo($obj->entity);
  158. print '<td align="center">'.$mc->label.'</td>';
  159. }
  160. print '<td align="center">'.$obj->nb.'</td>';
  161. print '<td align="right" class="nowrap">'.dol_print_date($db->jdate($obj->datec),"dayhour").'</td>';
  162. print "</tr>\n";
  163. $i++;
  164. }
  165. print "</table>";
  166. print '</div>';
  167. print "</form>\n";
  168. $db->free();
  169. }
  170. else
  171. {
  172. dol_print_error($db);
  173. }
  174. llxFooter();
  175. $db->close();