dolibarr  13.0.2
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
6  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.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 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
30 
31 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS))
32 {
33  if (!$user->rights->user->group_advance->read && !$user->admin)
35 }
36 
37 // Users/Groups management only in master entity if transverse mode
38 if (!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
39 {
41 }
42 
43 // Load translation files required by page
44 $langs->load("users");
45 
46 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
47 $search_group = GETPOST('search_group');
48 $optioncss = GETPOST('optioncss', 'alpha');
49 
50 // Defini si peux lire/modifier utilisateurs et permisssions
51 $caneditperms = ($user->admin || $user->rights->user->user->creer);
52 // Advanced permissions
53 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS))
54 {
55  $caneditperms = ($user->admin || $user->rights->user->group_advance->write);
56 }
57 
58 // Load variable for pagination
59 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
60 $sortfield = GETPOST('sortfield', 'aZ09comma');
61 $sortorder = GETPOST('sortorder', 'aZ09comma');
62 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
63 if (empty($page) || $page == -1) { $page = 0; }
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 
68 if (!$sortfield) $sortfield = "g.nom";
69 if (!$sortorder) $sortorder = "ASC";
70 
71 // List of fields to search into when doing a "search in all"
72 $fieldstosearchall = array(
73  'g.nom'=>"Group",
74  'g.note'=>"Note"
75 );
76 
77 
78 /*
79  * Actions
80  */
81 
82 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
83 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; }
84 
85 $parameters = array();
86 $reshook = $hookmanager->executeHooks('doActions', $parameters); // Note that $action and $object may have been modified by some hooks
87 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88 
89 if (empty($reshook))
90 {
91  // Selection of new fields
92  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
93 
94  // Purge search criteria
95  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
96  {
97  $search_label = "";
98  $search_date_creation = "";
99  $search_date_update = "";
100  $search_array_options = array();
101  }
102 }
103 
104 
105 
106 /*
107  * View
108  */
109 
110 llxHeader();
111 
112 $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb, COUNT(DISTINCT ugr.fk_id) as nbpermissions";
113 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
114 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
115 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid";
116 if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity)))
117 {
118  $sql .= " WHERE g.entity IS NOT NULL";
119 } else {
120  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
121 }
122 if (!empty($search_group)) natural_search(array("g.nom", "g.note"), $search_group);
123 if ($sall) $sql .= natural_search(array("g.nom", "g.note"), $sall);
124 $sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec";
125 $sql .= $db->order($sortfield, $sortorder);
126 
127 $resql = $db->query($sql);
128 if ($resql)
129 {
130  $num = $db->num_rows($resql);
131 
132  $nbtotalofrecords = $num;
133 
134  $i = 0;
135 
136  $param = "&amp;search_group=".urlencode($search_group)."&amp;sall=".urlencode($sall);
137  if ($optioncss != '') $param .= '&amp;optioncss='.$optioncss;
138 
139  $text = $langs->trans("ListOfGroups");
140 
141  $newcardbutton = '';
142  if ($caneditperms)
143  {
144  $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu=');
145  }
146 
147  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
148  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
149  print '<input type="hidden" name="token" value="'.newToken().'">';
150  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
151  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
152  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
153  print '<input type="hidden" name="mode" value="'.$mode.'">';
154  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
155 
156  print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1);
157 
158  if ($sall)
159  {
160  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
161  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
162  }
163 
164  $moreforfilter = '';
165 
166  //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
167  //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
168 
169  print '<div class="div-table-responsive">';
170  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
171 
172  print '<tr class="liste_titre">';
173  print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder);
174  //multicompany
175  if (!empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
176  {
177  print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center ');
178  }
179  print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center ');
180  print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center ');
181  print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center ');
182  print_liste_field_titre("", $_SERVER["PHP_SELF"]);
183  print "</tr>\n";
184 
185  $grouptemp = new UserGroup($db);
186 
187  while ($i < $num)
188  {
189  $obj = $db->fetch_object($resql);
190 
191  $grouptemp->id = $obj->rowid;
192  $grouptemp->name = $obj->name;
193  $grouptemp->note = $obj->note;
194 
195  print '<tr class="oddeven">';
196  print '<td>';
197  print $grouptemp->getNomUrl(1);
198  if (!$obj->entity)
199  {
200  print img_picto($langs->trans("GlobalGroup"), 'redstar');
201  }
202  print "</td>";
203  //multicompany
204  if (!empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
205  {
206  $mc->getInfo($obj->entity);
207  print '<td class="center">'.$mc->label.'</td>';
208  }
209  print '<td class="center">'.$obj->nb.'</td>';
210  print '<td class="center">'.$obj->nbpermissions.'</td>';
211  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), "dayhour").'</td>';
212  print '<td></td>';
213  print "</tr>\n";
214  $i++;
215  }
216  print "</table>";
217 
218  print '</div>';
219  print "</form>\n";
220 
221  $db->free($resql);
222 } else {
223  dol_print_error($db);
224 }
225 
226 // End of page
227 llxFooter();
228 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Class to manage user groups.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59