dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2025 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';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
44
45
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'members', 'users'));
48
49$extrafields = new ExtraFields($db); // may be used by some inc.php files
50
51$action = GETPOST('action', 'aZ09');
52$backtopage = GETPOST('backtopage', 'alpha');
53$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
54
55$value = GETPOST('value', 'alpha');
56$label = GETPOST('label', 'alpha');
57
58$scandir = GETPOST('scandir', 'alpha');
59$type = 'user';
60
61if (empty($user->admin)) {
63}
64
65
66/*
67 * Action
68 */
69
70include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
71
72$reg = array();
73
74if ($action == 'set_default') {
75 $ret = addDocumentModel($value, $type, $label, $scandir);
76 $res = true;
77} elseif ($action == 'del_default') {
78 $ret = delDocumentModel($value, $type);
79 if ($ret > 0) {
80 if (getDolGlobalString("USER_ADDON_PDF_ODT") == "$value") {
81 dolibarr_del_const($db, 'USER_ADDON_PDF_ODT', $conf->entity);
82 }
83 }
84 $res = true;
85} elseif ($action == 'setdoc') {
86 // Set default model
87 if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
88 // La constante qui a ete lue en avant du nouveau set
89 // on passe donc par une variable pour avoir un affichage coherent
90 $conf->global->USER_ADDON_PDF_ODT = $value;
91 }
92
93 // On active le modele
94 $ret = delDocumentModel($value, $type);
95 if ($ret > 0) {
96 $ret = addDocumentModel($value, $type, $label, $scandir);
97 }
98 $res = true;
99} elseif ($action == 'unsetdoc') {
100 // We disable the template
101 dolibarr_del_const($db, "USER_ADDON_PDF_ODT", $conf->entity);
102} elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
103 $code = $reg[1];
104 if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
105 header("Location: ".$_SERVER["PHP_SELF"]);
106 exit;
107 } else {
108 dol_print_error($db);
109 }
110} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
111 $code = $reg[1];
112 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
113 header("Location: ".$_SERVER["PHP_SELF"]);
114 exit;
115 } else {
116 dol_print_error($db);
117 }
118} elseif ($action == 'sethideinactiveuser') {
119 //Set hide closed customer into combox or select
120 $status = GETPOST('status', 'alpha');
121
122 if (dolibarr_set_const($db, "USER_HIDE_INACTIVE_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) {
123 header("Location: ".$_SERVER["PHP_SELF"]);
124 exit;
125 } else {
126 dol_print_error($db);
127 }
128}
129
130
131/*
132 * View
133 */
134
135$form = new Form($db);
136
137dol_mkdir(DOL_DATA_ROOT.'/doctemplates/users');
138dol_mkdir(DOL_DATA_ROOT.'/doctemplates/usergroups');
139
140$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
141llxHeader('', $langs->trans("UsersSetup"), $help_url, '', 0, 0, '', '', '', 'mod-admin page-user');
142
143$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>';
144
145print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
146
147
149
150print dol_get_fiche_head($head, 'card', $langs->trans("MenuUsersAndGroups"), -1, 'user');
151
152print '<br>';
153
154print '<div class="div-table-responsive-no-min">';
155print '<table class="noborder centpercent">';
156print '<tr class="liste_titre">';
157print '<td>'.$langs->trans("Parameter").'</td>';
158print '<td align="center" width="20">&nbsp;</td>';
159print '<td align="center" width="100"></td>'."\n";
160print '</tr>';
161
162
163// Mail required for users
164
165print '<tr class="oddeven">';
166print '<td>'.$langs->trans("UserMailRequired").'</td>';
167print '<td class="center" width="20">&nbsp;</td>';
168
169print '<td class="center" width="100">';
170if ($conf->use_javascript_ajax) {
171 print ajax_constantonoff('USER_MAIL_REQUIRED');
172} else {
173 if (!getDolGlobalString('USER_MAIL_REQUIRED')) {
174 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
175 } else {
176 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
177 }
178}
179print '</td></tr>';
180
181// user hide inactive
182
183print '<tr class="oddeven">';
184print '<td>'.$langs->trans("UserHideInactive").'</td>';
185print '<td class="center" width="20">&nbsp;</td>';
186
187print '<td class="center" width="100">';
188if ($conf->use_javascript_ajax) {
189 print ajax_constantonoff('USER_HIDE_INACTIVE_IN_COMBOBOX');
190} else {
191 if (!getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX')) {
192 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
193 } else {
194 print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_HIDE_INACTIVE_IN_COMBOBOX&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
195 }
196}
197print '</td></tr>';
198
199print '</table>';
200print '</div>';
201
202
203print '<br>';
204
205
206$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
207
208// Defini tableau def des modeles
209$def = array();
210$sql = "SELECT nom";
211$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
212$sql .= " WHERE type = '".$db->escape($type)."'";
213$sql .= " AND entity = ".((int) $conf->entity);
214$resql = $db->query($sql);
215if ($resql) {
216 $i = 0;
217 $num_rows = $db->num_rows($resql);
218 while ($i < $num_rows) {
219 $array = $db->fetch_array($resql);
220 if (is_array($array)) {
221 array_push($def, $array[0]);
222 }
223 $i++;
224 }
225} else {
226 dol_print_error($db);
227}
228
229print load_fiche_titre($langs->trans("UsersDocModules"), '', '');
230
231print '<div class="div-table-responsive-no-min">';
232print '<table class="noborder centpercent">';
233print '<tr class="liste_titre">';
234print '<td>'.$langs->trans("Name").'</td>';
235print '<td>'.$langs->trans("Description").'</td>';
236print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
237print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
238print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
239print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
240print "</tr>\n";
241
242clearstatcache();
243
244foreach ($dirmodels as $reldir) {
245 foreach (array('', '/doc') as $valdir) {
246 $dir = dol_buildpath($reldir."core/modules/user".$valdir);
247 if (is_dir($dir)) {
248 $handle = opendir($dir);
249 if (is_resource($handle)) {
250 $filelist = array();
251 while (($file = readdir($handle)) !== false) {
252 $filelist[] = $file;
253 }
254 closedir($handle);
255 arsort($filelist);
256
257 foreach ($filelist as $file) {
258 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
259 if (file_exists($dir.'/'.$file)) {
260 $name = substr($file, 4, dol_strlen($file) - 16);
261 $classname = substr($file, 0, dol_strlen($file) - 12);
262
263 require_once $dir.'/'.$file;
264 $module = new $classname($db);
265 '@phan-var-force ModelePDFUser $module';
268 $modulequalified = 1;
269 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
270 $modulequalified = 0;
271 }
272 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
273 $modulequalified = 0;
274 }
275
276 if ($modulequalified) {
277 print '<tr class="oddeven"><td width="100">';
278 print(empty($module->name) ? $name : $module->name);
279 print "</td><td>\n";
280 if (method_exists($module, 'info')) {
281 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
282 } else {
283 print $module->description;
284 }
285 print '</td>';
286
287 // Active
288 if (in_array($name, $def)) {
289 print '<td class="center">'."\n";
290 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&token='.newToken().'&value='.urlencode($name).'">';
291 print img_picto($langs->trans("Enabled"), 'switch_on');
292 print '</a>';
293 print '</td>';
294 } else {
295 print '<td class="center">'."\n";
296 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set_default&token='.newToken().'&value='.urlencode($name).'&scandir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">';
297 print img_picto($langs->trans("Disabled"), 'switch_off');
298 print '</a>';
299 print "</td>";
300 }
301
302 // Default
303 print '<td class="center">';
304 if (getDolGlobalString('USER_ADDON_PDF_ODT') == $name) {
305 //print img_picto($langs->trans("Default"), 'on');
306 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>';
307 } else {
308 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>';
309 }
310 print '</td>';
311
312 // Info
313 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
314 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
315 if ($module->type == 'pdf') {
316 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
317 }
318 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
319 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
320 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
321
322
323 print '<td class="center">';
324 print $form->textwithpicto('', $htmltooltip, 1, 'info');
325 print '</td>';
326
327 // Preview
328 print '<td class="center">';
329 if ($module->type == 'pdf') {
330 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
331 } else {
332 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
333 }
334 print '</td>';
335
336 print "</tr>\n";
337 }
338 }
339 }
340 }
341 }
342 }
343 }
344}
345
346print '</table>';
347print '</div>';
348
349print '<br>';
350
351print dol_get_fiche_end();
352
353// End of page
354llxFooter();
355$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 standard extra fields.
Class to manage generation of HTML components Only common components must be here.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128
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.