user.php 11 KB

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