user.php 11 KB

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