dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'members', 'users'));
48
49$action = GETPOST('action', 'aZ09');
50$backtopage = GETPOST('backtopage', 'alpha');
51$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
52
53$value = GETPOST('value', 'alpha');
54$label = GETPOST('label', 'alpha');
55
56$scandir = GETPOST('scandir', 'alpha');
57$type = 'user';
58
59if (empty($user->admin)) {
61}
62
63
64/*
65 * Action
66 */
67
68include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
69
70$reg = array();
71
72if ($action == 'set_default') {
73 $ret = addDocumentModel($value, $type, $label, $scandir);
74 $res = true;
75} elseif ($action == 'del_default') {
76 $ret = delDocumentModel($value, $type);
77 if ($ret > 0) {
78 if (getDolGlobalString("USER_ADDON_PDF_ODT") == "$value") {
79 dolibarr_del_const($db, 'USER_ADDON_PDF_ODT', $conf->entity);
80 }
81 }
82 $res = true;
83} elseif ($action == 'setdoc') {
84 // Set default model
85 if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
86 // The constant that was read before the new set
87 // so we go through a variable to get a consistent display
88 $conf->global->USER_ADDON_PDF_ODT = $value;
89 }
90
91 // On active le modele
92 $ret = delDocumentModel($value, $type);
93 if ($ret > 0) {
94 $ret = addDocumentModel($value, $type, $label, $scandir);
95 }
96 $res = true;
97} elseif ($action == 'unsetdoc') {
98 // We disable the template
99 dolibarr_del_const($db, "USER_ADDON_PDF_ODT", $conf->entity);
100} elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
101 $code = $reg[1];
102 if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
103 header("Location: ".$_SERVER["PHP_SELF"]);
104 exit;
105 } else {
106 dol_print_error($db);
107 }
108} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
109 $code = $reg[1];
110 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
111 header("Location: ".$_SERVER["PHP_SELF"]);
112 exit;
113 } else {
114 dol_print_error($db);
115 }
116} elseif ($action == 'sethideinactiveuser') {
117 //Set hide closed customer into combox or select
118 $status = GETPOST('status', 'alpha');
119
120 if (dolibarr_set_const($db, "USER_HIDE_INACTIVE_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) {
121 header("Location: ".$_SERVER["PHP_SELF"]);
122 exit;
123 } else {
124 dol_print_error($db);
125 }
126} elseif ($action == 'setusesearchtoselectuser') {
127 // Set the "search to select" mode of the user combo (0=no, 1/2/3=nb of chars to type before search, 'infinite'=infinite list)
128 $usersearch = GETPOST('activate_usesearchtoselectuser', 'aZ09');
129
130 if (dolibarr_set_const($db, "USER_USE_SEARCH_TO_SELECT", $usersearch, 'chaine', 0, '', $conf->entity) > 0) {
131 header("Location: ".$_SERVER["PHP_SELF"]);
132 exit;
133 } else {
134 dol_print_error($db);
135 }
136}
137
138
139/*
140 * View
141 */
142
143$form = new Form($db);
144
145dol_mkdir(DOL_DATA_ROOT.'/doctemplates/users');
146dol_mkdir(DOL_DATA_ROOT.'/doctemplates/usergroups');
147
148$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
149llxHeader('', $langs->trans("UsersSetup"), $help_url, '', 0, 0, '', '', '', 'mod-admin page-user');
150
151$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
152
153print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
154
155
157
158print dol_get_fiche_head($head, 'card', $langs->trans("MenuUsersAndGroups"), -1, 'user');
159
160print '<br>';
161
162print '<div class="div-table-responsive-no-min">';
163print '<table class="noborder centpercent">';
164print '<tr class="liste_titre">';
165print '<td>'.$langs->trans("Parameter").'</td>';
166print '<td align="center" width="20">&nbsp;</td>';
167print '<td align="center" width="100"></td>'."\n";
168print '</tr>';
169
170
171// Mail required for users
172
173print '<tr class="oddeven">';
174print '<td>'.$langs->trans("UserMailRequired").'</td>';
175print '<td class="center" width="20">&nbsp;</td>';
176
177print '<td class="center" width="100">';
178if ($conf->use_javascript_ajax) {
179 print ajax_constantonoff('USER_MAIL_REQUIRED');
180} else {
181 if (!getDolGlobalString('USER_MAIL_REQUIRED')) {
182 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
183 } else {
184 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
185 }
186}
187print '</td></tr>';
188
189// user hide inactive
190
191print '<tr class="oddeven">';
192print '<td>'.$langs->trans("UserHideInactive").'</td>';
193print '<td class="center" width="20">&nbsp;</td>';
194
195print '<td class="center" width="100">';
196if ($conf->use_javascript_ajax) {
197 print ajax_constantonoff('USER_HIDE_INACTIVE_IN_COMBOBOX');
198} else {
199 if (!getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX')) {
200 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
201 } else {
202 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
203 }
204}
205print '</td></tr>';
206
207// Use Ajax "search to select" form to select a user
208
209print '<tr class="oddeven">';
210print '<td>'.$form->textwithpicto($langs->trans("UseSearchToSelectUser"), $langs->trans("UseSearchToSelectUserTooltip"), 1).'</td>';
211print '<td class="center" width="20">&nbsp;</td>';
212print '<td class="center nowraponall" width="100">';
213if (empty($conf->use_javascript_ajax)) {
214 print $langs->trans("NotAvailableWhenAjaxDisabled");
215} else {
216 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
217 print '<input type="hidden" name="token" value="'.newToken().'">';
218 print '<input type="hidden" name="action" value="setusesearchtoselectuser">';
219 $arrval = array(
220 '0' => $langs->trans("No"),
221 '1' => $langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 1).')',
222 '2' => $langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 2).')',
223 '3' => $langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 3).')',
224 'infinite' => $langs->trans("UseSearchToSelectUserInfinite"),
225 );
226 print $form->selectarray("activate_usesearchtoselectuser", $arrval, getDolGlobalString('USER_USE_SEARCH_TO_SELECT'), 0, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth200');
227 print ' <input type="submit" class="button small reposition" value="'.$langs->trans("Modify").'">';
228 print '</form>';
229}
230print '</td></tr>';
231
232print '</table>';
233print '</div>';
234
235
236print '<br>';
237
238
239$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
240
241// Define array def of models
242$def = array();
243$sql = "SELECT nom";
244$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
245$sql .= " WHERE type = '".$db->escape($type)."'";
246$sql .= " AND entity = ".((int) $conf->entity);
247$resql = $db->query($sql);
248if ($resql) {
249 $i = 0;
250 $num_rows = $db->num_rows($resql);
251 while ($i < $num_rows) {
252 $array = $db->fetch_array($resql);
253 if (is_array($array)) {
254 array_push($def, $array[0]);
255 }
256 $i++;
257 }
258} else {
259 dol_print_error($db);
260}
261
262print load_fiche_titre($langs->trans("UsersDocModules"), '', '');
263
264print '<div class="div-table-responsive-no-min">';
265print '<table class="noborder centpercent">';
266print '<tr class="liste_titre">';
267print '<td>'.$langs->trans("Name").'</td>';
268print '<td>'.$langs->trans("Description").'</td>';
269print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
270print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
271print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
272print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
273print "</tr>\n";
274
275clearstatcache();
276
277foreach ($dirmodels as $reldir) {
278 foreach (array('', '/doc') as $valdir) {
279 $dir = dol_buildpath($reldir."core/modules/user".$valdir);
280 if (is_dir($dir)) {
281 $handle = opendir($dir);
282 if (is_resource($handle)) {
283 $filelist = array();
284 while (($file = readdir($handle)) !== false) {
285 $filelist[] = $file;
286 }
287 closedir($handle);
288 arsort($filelist);
289
290 foreach ($filelist as $file) {
291 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
292 if (file_exists($dir.'/'.$file)) {
293 $name = dol_substr($file, 4, dol_strlen($file) - 16);
294 $classname = dol_substr($file, 0, dol_strlen($file) - 12);
295
296 require_once $dir.'/'.$file;
297 $module = new $classname($db);
298 '@phan-var-force ModelePDFUser $module';
301 $modulequalified = 1;
302 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
303 $modulequalified = 0;
304 }
305 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
306 $modulequalified = 0;
307 }
308
309 if ($modulequalified) {
310 print '<tr class="oddeven"><td width="100">';
311 print(empty($module->name) ? $name : $module->name);
312 print "</td><td>\n";
313 if (method_exists($module, 'info')) {
314 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
315 } else {
316 print $module->description;
317 }
318 print '</td>';
319
320 // Active
321 if (in_array($name, $def)) {
322 print '<td class="center">'."\n";
323 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&token='.newToken().'&value='.urlencode($name).'">';
324 print img_picto($langs->trans("Enabled"), 'switch_on');
325 print '</a>';
326 print '</td>';
327 } else {
328 print '<td class="center">'."\n";
329 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set_default&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
330 print img_picto($langs->trans("Disabled"), 'switch_off');
331 print '</a>';
332 print "</td>";
333 }
334
335 // Default
336 print '<td class="center">';
337 if (getDolGlobalString('USER_ADDON_PDF_ODT') == $name) {
338 //print img_picto($langs->trans("Default"), 'on');
339 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>';
340 } else {
341 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>';
342 }
343 print '</td>';
344
345 // Info
346 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
347 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
348 if ($module->type == 'pdf') {
349 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
350 }
351 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
352 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
353 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
354
355
356 print '<td class="center">';
357 print $form->textwithpicto('', $htmltooltip, 1, 'info');
358 print '</td>';
359
360 // Preview
361 print '<td class="center">';
362 if ($module->type == 'pdf') {
363 print '<a href="'.dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'specimen', 'module' => $name], true).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
364 } else {
365 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
366 }
367 print '</td>';
368
369 print "</tr>\n";
370 }
371 }
372 }
373 }
374 }
375 }
376 }
377}
378
379print '</table>';
380print '</div>';
381
382print '<br>';
383
384print dol_get_fiche_end();
385
386// End of page
387llxFooter();
388$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_admin_prepare_head()
Prepare array with list of tabs.