dolibarr  9.0.0
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  *
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 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
29 
30 if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
31 {
32  if (! $user->rights->user->group_advance->read && ! $user->admin)
34 }
35 
36 // Users/Groups management only in master entity if transverse mode
37 if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
38 {
40 }
41 
42 // Load translation files required by page
43 $langs->load("users");
44 
45 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
46 $search_group=GETPOST('search_group');
47 $optioncss = GETPOST('optioncss','alpha');
48 
49 // Defini si peux lire/modifier utilisateurs et permisssions
50 $caneditperms=($user->admin || $user->rights->user->user->creer);
51 // Advanced permissions
52 if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
53 {
54  $caneditperms=($user->admin || $user->rights->user->group_advance->write);
55 }
56 
57 // Load variable for pagination
58 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
59 $sortfield = GETPOST('sortfield','alpha');
60 $sortorder = GETPOST('sortorder','alpha');
61 $page = GETPOST('page','int');
62 if (empty($page) || $page == -1) { $page = 0; }
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 
67 if (! $sortfield) $sortfield="g.nom";
68 if (! $sortorder) $sortorder="ASC";
69 
70 // List of fields to search into when doing a "search in all"
71 $fieldstosearchall = array(
72  'g.nom'=>"Group",
73  'g.note'=>"Note"
74 );
75 
76 
77 /*
78  * Actions
79  */
80 
81 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
82 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
83 
84 $parameters=array();
85 $reshook=$hookmanager->executeHooks('doActions',$parameters); // Note that $action and $object may have been modified by some hooks
86 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87 
88 if (empty($reshook))
89 {
90  // Selection of new fields
91  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
92 
93  // Purge search criteria
94  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
95  {
96  $search_label="";
97  $search_date_creation="";
98  $search_date_update="";
99  $search_array_options=array();
100  }
101 }
102 
103 
104 
105 /*
106  * View
107  */
108 
109 llxHeader();
110 
111 $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";
112 $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g";
113 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
114 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid";
115 if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
116 {
117  $sql.= " WHERE g.entity IS NOT NULL";
118 }
119 else
120 {
121  $sql.= " WHERE g.entity IN (0,".$conf->entity.")";
122 }
123 if (! empty($search_group)) natural_search(array("g.nom", "g.note"), $search_group);
124 if ($sall) $sql.= natural_search(array("g.nom", "g.note"), $sall);
125 $sql.= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec";
126 $sql.= $db->order($sortfield,$sortorder);
127 
128 $resql = $db->query($sql);
129 if ($resql)
130 {
131  $num = $db->num_rows($resql);
132 
133  $nbtotalofrecords = $num;
134 
135  $i = 0;
136 
137  $param="&search_group=".urlencode($search_group)."&amp;sall=".urlencode($sall);
138  if ($optioncss != '') $param.='&amp;optioncss='.$optioncss;
139 
140  $text = $langs->trans("ListOfGroups");
141 
142  $newcardbutton='';
143  if ($caneditperms)
144  {
145  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu="><span class="valignmiddle">'.$langs->trans('NewGroup').'</span>';
146  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
147  $newcardbutton.= '</a>';
148  }
149 
150  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
151  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
152  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
153  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
154  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
155  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
156  print '<input type="hidden" name="page" value="'.$page.'">';
157  print '<input type="hidden" name="mode" value="'.$mode.'">';
158  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
159 
160  print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'title_generic', 0, $newcardbutton, '', $limit);
161 
162  if ($sall)
163  {
164  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
165  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
166  }
167 
168  $moreforfilter='';
169 
170  //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
171  //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
172 
173  print '<div class="div-table-responsive">';
174  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
175 
176  print '<tr class="liste_titre">';
177  print_liste_field_titre("Group",$_SERVER["PHP_SELF"],"g.nom",$param,"","",$sortfield,$sortorder);
178  //multicompany
179  if(! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
180  {
181  print_liste_field_titre("Entity",$_SERVER["PHP_SELF"],"g.entity",$param,"",'align="center"',$sortfield,$sortorder);
182  }
183  print_liste_field_titre("NbOfUsers",$_SERVER["PHP_SELF"],"nb",$param,"",'align="center"',$sortfield,$sortorder);
184  print_liste_field_titre("NbOfPermissions",$_SERVER["PHP_SELF"],"nbpermissions",$param,"",'align="center"',$sortfield,$sortorder);
185  print_liste_field_titre("DateCreationShort",$_SERVER["PHP_SELF"],"g.datec",$param,"",'align="right"',$sortfield,$sortorder);
186  print "</tr>\n";
187 
188  $grouptemp = new UserGroup($db);
189 
190  while ($i < $num)
191  {
192  $obj = $db->fetch_object($resql);
193 
194  $grouptemp->id = $obj->rowid;
195  $grouptemp->name = $obj->name;
196  $grouptemp->note = $obj->note;
197 
198  print '<tr class="oddeven">';
199  print '<td>';
200  print $grouptemp->getNomUrl(1);
201  if (! $obj->entity)
202  {
203  print img_picto($langs->trans("GlobalGroup"),'redstar');
204  }
205  print "</td>";
206  //multicompany
207  if (! empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
208  {
209  $mc->getInfo($obj->entity);
210  print '<td align="center">'.$mc->label.'</td>';
211  }
212  print '<td align="center">'.$obj->nb.'</td>';
213  print '<td align="center">'.$obj->nbpermissions.'</td>';
214  print '<td align="right" class="nowrap">'.dol_print_date($db->jdate($obj->datec),"dayhour").'</td>';
215  print "</tr>\n";
216  $i++;
217  }
218  print "</table>";
219 
220  print '</div>';
221  print "</form>\n";
222 
223  $db->free($resql);
224 }
225 else
226 {
227  dol_print_error($db);
228 }
229 
230 // End of page
231 llxFooter();
232 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage user groups.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
llxHeader()
Empty header.
Definition: wrapper.php:44
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_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)