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