dolibarr  16.0.5
user.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('admin', 'members', 'users'));
38 
39 $extrafields = new ExtraFields($db);
40 
41 $action = GETPOST('action', 'aZ09');
42 $backtopage = GETPOST('backtopage', 'alpha');
43 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
44 
45 $value = GETPOST('value', 'alpha');
46 $label = GETPOST('label', 'alpha');
47 
48 $scandir = GETPOST('scandir', 'alpha');
49 $type = 'user';
50 
51 if (empty($user->admin)) {
53 }
54 
55 
56 /*
57  * Action
58  */
59 
60 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
61 
62 $reg = array();
63 
64 if ($action == 'set_default') {
65  $ret = addDocumentModel($value, $type, $label, $scandir);
66  $res = true;
67 } elseif ($action == 'del_default') {
68  $ret = delDocumentModel($value, $type);
69  if ($ret > 0) {
70  if ($conf->global->USER_ADDON_PDF_ODT == "$value") {
71  dolibarr_del_const($db, 'USER_ADDON_PDF_ODT', $conf->entity);
72  }
73  }
74  $res = true;
75 } elseif ($action == 'setdoc') {
76  // Set default model
77  if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
78  // La constante qui a ete lue en avant du nouveau set
79  // on passe donc par une variable pour avoir un affichage coherent
80  $conf->global->USER_ADDON_PDF_ODT = $value;
81  }
82 
83  // On active le modele
84  $ret = delDocumentModel($value, $type);
85  if ($ret > 0) {
86  $ret = addDocumentModel($value, $type, $label, $scandir);
87  }
88  $res = true;
89 } elseif ($action == 'unsetdoc') {
90  // We disable the template
91  dolibarr_del_const($db, "USER_ADDON_PDF_ODT", $conf->entity);
92 } elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
93  $code = $reg[1];
94  if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
95  header("Location: ".$_SERVER["PHP_SELF"]);
96  exit;
97  } else {
98  dol_print_error($db);
99  }
100 } elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
101  $code = $reg[1];
102  if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
103  header("Location: ".$_SERVER["PHP_SELF"]);
104  exit;
105  } else {
106  dol_print_error($db);
107  }
108 } elseif ($action == 'sethideinactiveuser') {
109  //Set hide closed customer into combox or select
110  $status = GETPOST('status', 'alpha');
111 
112  if (dolibarr_set_const($db, "USER_HIDE_INACTIVE_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) {
113  header("Location: ".$_SERVER["PHP_SELF"]);
114  exit;
115  } else {
116  dol_print_error($db);
117  }
118 }
119 
120 
121 /*
122  * View
123  */
124 
125 $form = new Form($db);
126 
127 dol_mkdir(DOL_DATA_ROOT.'/doctemplates/users');
128 dol_mkdir(DOL_DATA_ROOT.'/doctemplates/usergroups');
129 
130 $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
131 llxHeader('', $langs->trans("UsersSetup"), $help_url);
132 
133 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
134 print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
135 
136 
137 $head = user_admin_prepare_head();
138 
139 print dol_get_fiche_head($head, 'card', $langs->trans("MenuUsersAndGroups"), -1, 'user');
140 
141 print '<div class="div-table-responsive-no-min">';
142 print '<table class="noborder centpercent">';
143 print '<tr class="liste_titre">';
144 print '<td>'.$langs->trans("Parameter").'</td>';
145 print '<td align="center" width="20">&nbsp;</td>';
146 print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
147 print '</tr>';
148 
149 
150 // Mail required for users
151 
152 print '<tr class="oddeven">';
153 print '<td>'.$langs->trans("UserMailRequired").'</td>';
154 print '<td align="center" width="20">&nbsp;</td>';
155 
156 print '<td align="center" width="100">';
157 if ($conf->use_javascript_ajax) {
158  print ajax_constantonoff('USER_MAIL_REQUIRED');
159 } else {
160  if (empty($conf->global->USER_MAIL_REQUIRED)) {
161  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
162  } else {
163  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
164  }
165 }
166 print '</td></tr>';
167 
168 // user hide inactive
169 
170 print '<tr class="oddeven">';
171 print '<td>'.$langs->trans("UserHideInactive").'</td>';
172 print '<td align="center" width="20">&nbsp;</td>';
173 
174 print '<td align="center" width="100">';
175 if ($conf->use_javascript_ajax) {
176  print ajax_constantonoff('USER_HIDE_INACTIVE_IN_COMBOBOX');
177 } else {
178  if (empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) {
179  print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
180  } else {
181  print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
182  }
183 }
184 print '</td></tr>';
185 
186 print '</table>';
187 print '</div>';
188 
189 print '<br>';
190 
191 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
192 
193 // Defini tableau def des modeles
194 $def = array();
195 $sql = "SELECT nom";
196 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
197 $sql .= " WHERE type = '".$db->escape($type)."'";
198 $sql .= " AND entity = ".$conf->entity;
199 $resql = $db->query($sql);
200 if ($resql) {
201  $i = 0;
202  $num_rows = $db->num_rows($resql);
203  while ($i < $num_rows) {
204  $array = $db->fetch_array($resql);
205  array_push($def, $array[0]);
206  $i++;
207  }
208 } else {
209  dol_print_error($db);
210 }
211 
212 print load_fiche_titre($langs->trans("UsersDocModules"), '', '');
213 
214 print '<div class="div-table-responsive-no-min">';
215 print '<table class="noborder centpercent">';
216 print '<tr class="liste_titre">';
217 print '<td>'.$langs->trans("Name").'</td>';
218 print '<td>'.$langs->trans("Description").'</td>';
219 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
220 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
221 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
222 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
223 print "</tr>\n";
224 
225 clearstatcache();
226 
227 foreach ($dirmodels as $reldir) {
228  foreach (array('', '/doc') as $valdir) {
229  $dir = dol_buildpath($reldir."core/modules/user".$valdir);
230  if (is_dir($dir)) {
231  $handle = opendir($dir);
232  if (is_resource($handle)) {
233  while (($file = readdir($handle)) !== false) {
234  $filelist[] = $file;
235  }
236  closedir($handle);
237  arsort($filelist);
238 
239  foreach ($filelist as $file) {
240  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
241  if (file_exists($dir.'/'.$file)) {
242  $name = substr($file, 4, dol_strlen($file) - 16);
243  $classname = substr($file, 0, dol_strlen($file) - 12);
244 
245  require_once $dir.'/'.$file;
246  $module = new $classname($db);
247 
248  $modulequalified = 1;
249  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
250  $modulequalified = 0;
251  }
252  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
253  $modulequalified = 0;
254  }
255 
256  if ($modulequalified) {
257  print '<tr class="oddeven"><td width="100">';
258  print (empty($module->name) ? $name : $module->name);
259  print "</td><td>\n";
260  if (method_exists($module, 'info')) {
261  print $module->info($langs);
262  } else {
263  print $module->description;
264  }
265  print '</td>';
266 
267  // Active
268  if (in_array($name, $def)) {
269  print '<td class="center">'."\n";
270  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&token='.newToken().'&value='.urlencode($name).'">';
271  print img_picto($langs->trans("Enabled"), 'switch_on');
272  print '</a>';
273  print '</td>';
274  } else {
275  print '<td class="center">'."\n";
276  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set_default&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
277  print img_picto($langs->trans("Disabled"), 'switch_off');
278  print '</a>';
279  print "</td>";
280  }
281 
282  // Defaut
283  print '<td class="center">';
284  if (getDolGlobalString('USER_ADDON_PDF_ODT') == $name) {
285  //print img_picto($langs->trans("Default"), 'on');
286  print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Default"), 'on').'</a>';
287  } else {
288  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
289  }
290  print '</td>';
291 
292  // Info
293  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
294  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
295  if ($module->type == 'pdf') {
296  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
297  }
298  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
299  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
300  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
301 
302 
303  print '<td class="center">';
304  print $form->textwithpicto('', $htmltooltip, 1, 0);
305  print '</td>';
306 
307  // Preview
308  print '<td class="center">';
309  if ($module->type == 'pdf') {
310  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
311  } else {
312  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
313  }
314  print '</td>';
315 
316  print "</tr>\n";
317  }
318  }
319  }
320  }
321  }
322  }
323  }
324 }
325 
326 print '</table>';
327 print '</div>';
328 
329 print '<br>';
330 
331 print dol_get_fiche_end();
332 
333 // End of page
334 llxFooter();
335 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
user_admin_prepare_head
user_admin_prepare_head()
Prepare array with list of tabs.
Definition: usergroups.lib.php:251
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59