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