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
25/**
26 *   	\file       htdocs/admin/user.php
27 *		\ingroup    core
28 *		\brief      Page to setup user module
29 */
30
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34require_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'));
38if (!$user->admin) {
39	accessforbidden();
40}
41
42$extrafields = new ExtraFields($db);
43
44$action = GETPOST('action', 'aZ09');
45$backtopage = GETPOST('backtopage', 'alpha');
46
47$value = GETPOST('value', 'alpha');
48$label = GETPOST('label', 'alpha');
49$scandir = GETPOST('scandir', 'alpha');
50$type = 'user';
51
52
53/*
54 * Action
55 */
56
57include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
58
59if ($action == 'set_default') {
60	$ret = addDocumentModel($value, $type, $label, $scandir);
61	$res = true;
62} elseif ($action == 'del_default') {
63	$ret = delDocumentModel($value, $type);
64	if ($ret > 0) {
65		if ($conf->global->USER_ADDON_PDF_ODT == "$value") {
66			dolibarr_del_const($db, 'USER_ADDON_PDF_ODT', $conf->entity);
67		}
68	}
69	$res = true;
70} elseif ($action == 'setdoc') {
71	// Set default model
72	if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
73		// La constante qui a ete lue en avant du nouveau set
74		// on passe donc par une variable pour avoir un affichage coherent
75		$conf->global->USER_ADDON_PDF_ODT = $value;
76	}
77
78	// On active le modele
79	$ret = delDocumentModel($value, $type);
80	if ($ret > 0) {
81		$ret = addDocumentModel($value, $type, $label, $scandir);
82	}
83	$res = true;
84} elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
85	$code = $reg[1];
86	if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
87		header("Location: ".$_SERVER["PHP_SELF"]);
88		exit;
89	} else {
90		dol_print_error($db);
91	}
92} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
93	$code = $reg[1];
94	if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
95		header("Location: ".$_SERVER["PHP_SELF"]);
96		exit;
97	} else {
98		dol_print_error($db);
99	}
100} elseif ($action == 'sethideinactiveuser') {
101	//Set hide closed customer into combox or select
102	$status = GETPOST('status', 'alpha');
103
104	if (dolibarr_set_const($db, "USER_HIDE_INACTIVE_IN_COMBOBOX", $status, 'chaine', 0, '', $conf->entity) > 0) {
105		header("Location: ".$_SERVER["PHP_SELF"]);
106		exit;
107	} else {
108		dol_print_error($db);
109	}
110}
111
112
113/*
114 * View
115 */
116
117$form = new Form($db);
118
119$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
120llxHeader('', $langs->trans("UsersSetup"), $help_url);
121
122$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
123print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
124
125
126$head = user_admin_prepare_head();
127
128print dol_get_fiche_head($head, 'card', $langs->trans("MenuUsersAndGroups"), -1, 'user');
129
130print '<div class="div-table-responsive-no-min">';
131print '<table class="noborder centpercent">';
132print '<tr class="liste_titre">';
133print '<td>'.$langs->trans("Parameter").'</td>';
134print '<td align="center" width="20">&nbsp;</td>';
135print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
136print '</tr>';
137
138
139// Mail required for users
140
141print '<tr class="oddeven">';
142print '<td>'.$langs->trans("UserMailRequired").'</td>';
143print '<td align="center" width="20">&nbsp;</td>';
144
145print '<td align="center" width="100">';
146if ($conf->use_javascript_ajax) {
147	print ajax_constantonoff('USER_MAIL_REQUIRED');
148} else {
149	if (empty($conf->global->USER_MAIL_REQUIRED)) {
150		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED&amp;token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
151	} else {
152		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED&amp;token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
153	}
154}
155print '</td></tr>';
156
157// user hide inactive
158
159print '<tr class="oddeven">';
160print '<td>'.$langs->trans("UserHideInactive").'</td>';
161print '<td align="center" width="20">&nbsp;</td>';
162
163print '<td align="center" width="100">';
164if ($conf->use_javascript_ajax) {
165	print ajax_constantonoff('USER_HIDE_INACTIVE_IN_COMBOBOX');
166} else {
167	if (empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) {
168		print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_HIDE_INACTIVE_IN_COMBOBOX">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
169	} else {
170		print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_HIDE_INACTIVE_IN_COMBOBOX">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
171	}
172}
173print '</td></tr>';
174
175print '</table>';
176print '</div>';
177
178print '<br>';
179
180$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
181
182// Defini tableau def des modeles
183$def = array();
184$sql = "SELECT nom";
185$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
186$sql .= " WHERE type = '".$db->escape($type)."'";
187$sql .= " AND entity = ".$conf->entity;
188$resql = $db->query($sql);
189if ($resql) {
190	$i = 0;
191	$num_rows = $db->num_rows($resql);
192	while ($i < $num_rows) {
193		$array = $db->fetch_array($resql);
194		array_push($def, $array[0]);
195		$i++;
196	}
197} else {
198	dol_print_error($db);
199}
200
201print load_fiche_titre($langs->trans("UsersDocModules"), '', '');
202
203print '<div class="div-table-responsive-no-min">';
204print '<table class="noborder centpercent">';
205print '<tr class="liste_titre">';
206print '<td>'.$langs->trans("Name").'</td>';
207print '<td>'.$langs->trans("Description").'</td>';
208print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
209print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
210print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
211print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
212print "</tr>\n";
213
214clearstatcache();
215
216foreach ($dirmodels as $reldir) {
217	foreach (array('', '/doc') as $valdir) {
218		$dir = dol_buildpath($reldir."core/modules/user".$valdir);
219		if (is_dir($dir)) {
220			$handle = opendir($dir);
221			if (is_resource($handle)) {
222				while (($file = readdir($handle)) !== false) {
223					$filelist[] = $file;
224				}
225				closedir($handle);
226				arsort($filelist);
227
228				foreach ($filelist as $file) {
229					if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
230						if (file_exists($dir.'/'.$file)) {
231							$name = substr($file, 4, dol_strlen($file) - 16);
232							$classname = substr($file, 0, dol_strlen($file) - 12);
233
234							require_once $dir.'/'.$file;
235							$module = new $classname($db);
236
237							$modulequalified = 1;
238							if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
239								$modulequalified = 0;
240							}
241							if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
242								$modulequalified = 0;
243							}
244
245							if ($modulequalified) {
246								print '<tr class="oddeven"><td width="100">';
247								print (empty($module->name) ? $name : $module->name);
248								print "</td><td>\n";
249								if (method_exists($module, 'info')) {
250									print $module->info($langs);
251								} else {
252									print $module->description;
253								}
254								print '</td>';
255
256								// Active
257								if (in_array($name, $def)) {
258									print '<td class="center">'."\n";
259									print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&amp;token='.newToken().'&amp;value='.$name.'">';
260									print img_picto($langs->trans("Enabled"), 'switch_on');
261									print '</a>';
262									print '</td>';
263								} else {
264									print '<td class="center">'."\n";
265									print '<a href="'.$_SERVER["PHP_SELF"].'?action=set_default&amp;token='.newToken().'&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
266									print "</td>";
267								}
268
269								// Defaut
270								print '<td class="center">';
271								if (getDolGlobalString('USER_ADDON_PDF_ODT') == $name) {
272									print img_picto($langs->trans("Default"), 'on');
273								} else {
274									print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
275								}
276								print '</td>';
277
278								// Info
279								$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
280								$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
281								if ($module->type == 'pdf') {
282									$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
283								}
284								$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
285								$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
286								$htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
287
288
289								print '<td class="center">';
290								print $form->textwithpicto('', $htmltooltip, 1, 0);
291								print '</td>';
292
293								// Preview
294								print '<td class="center">';
295								if ($module->type == 'pdf') {
296									print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
297								} else {
298									print img_object($langs->trans("PreviewNotAvailable"), 'generic');
299								}
300								print '</td>';
301
302								print "</tr>\n";
303							}
304						}
305					}
306				}
307			}
308		}
309	}
310}
311
312print '</table>';
313print '</div>';
314
315print '<br>';
316
317print dol_get_fiche_end();
318
319// End of page
320llxFooter();
321$db->close();
322