user.php 11 KB

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