user.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/user.php
  25. * \ingroup core
  26. * \brief Page to setup user module
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('admin', 'members', 'users'));
  34. if (! $user->admin) accessforbidden();
  35. $extrafields = new ExtraFields($db);
  36. $action = GETPOST('action','alpha');
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. $value = GETPOST('value','alpha');
  39. $type='user';
  40. /*
  41. * Action
  42. */
  43. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  44. if ($action == 'set_default')
  45. {
  46. $ret = addDocumentModel($value, $type, $label, $scandir);
  47. $res = true;
  48. }
  49. elseif ($action == 'del_default')
  50. {
  51. $ret = delDocumentModel($value, $type);
  52. if ($ret > 0)
  53. {
  54. if ($conf->global->USER_ADDON_PDF_ODT == "$value") dolibarr_del_const($db, 'USER_ADDON_PDF_ODT',$conf->entity);
  55. }
  56. $res = true;
  57. }
  58. // Set default model
  59. elseif ($action == 'setdoc')
  60. {
  61. if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT",$value,'chaine',0,'',$conf->entity))
  62. {
  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. {
  71. $ret = addDocumentModel($value, $type, $label, $scandir);
  72. }
  73. $res = true;
  74. }
  75. elseif (preg_match('/set_([a-z0-9_\-]+)/i',$action,$reg))
  76. {
  77. $code=$reg[1];
  78. if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0)
  79. {
  80. header("Location: ".$_SERVER["PHP_SELF"]);
  81. exit;
  82. }
  83. else
  84. {
  85. dol_print_error($db);
  86. }
  87. }
  88. elseif (preg_match('/del_([a-z0-9_\-]+)/i',$action,$reg))
  89. {
  90. $code=$reg[1];
  91. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  92. {
  93. header("Location: ".$_SERVER["PHP_SELF"]);
  94. exit;
  95. }
  96. else
  97. {
  98. dol_print_error($db);
  99. }
  100. }
  101. //Set hide closed customer into combox or select
  102. elseif ($action == 'sethideinactiveuser')
  103. {
  104. $status = GETPOST('status','alpha');
  105. if (dolibarr_set_const($db, "USER_HIDE_INACTIVE_IN_COMBOBOX",$status,'chaine',0,'',$conf->entity) > 0)
  106. {
  107. header("Location: ".$_SERVER["PHP_SELF"]);
  108. exit;
  109. }
  110. else
  111. {
  112. dol_print_error($db);
  113. }
  114. }
  115. /*
  116. * View
  117. */
  118. $form = new Form($db);
  119. $help_url='EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
  120. llxHeader('',$langs->trans("UsersSetup"),$help_url);
  121. $linkback='<a href="'.($backtopage?$backtopage:DOL_URL_ROOT.'/admin/modules.php').'">'.$langs->trans("BackToModuleList").'</a>';
  122. print load_fiche_titre($langs->trans("UsersSetup"),$linkback,'title_setup');
  123. $head=user_admin_prepare_head();
  124. dol_fiche_head($head,'card', $langs->trans("MenuUsersAndGroups"), -1, 'user');
  125. print '<table class="noborder" width="100%">';
  126. print '<tr class="liste_titre">';
  127. print '<td>'.$langs->trans("Description").'</td>';
  128. print '<td align="center" width="20">&nbsp;</td>';
  129. print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
  130. print '</tr>';
  131. // Mail required for members
  132. print '<tr class="oddeven">';
  133. print '<td>'.$langs->trans("UserMailRequired").'</td>';
  134. print '<td align="center" width="20">&nbsp;</td>';
  135. print '<td align="center" width="100">';
  136. if ($conf->use_javascript_ajax)
  137. {
  138. print ajax_constantonoff('USER_MAIL_REQUIRED');
  139. }
  140. else
  141. {
  142. if (empty($conf->global->USER_MAIL_REQUIRED))
  143. {
  144. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  145. }
  146. else
  147. {
  148. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  149. }
  150. }
  151. print '</td></tr>';
  152. print '</table>';
  153. print '<br>';
  154. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  155. $form=new Form($db);
  156. // Defini tableau def des modeles
  157. $def = array();
  158. $sql = "SELECT nom";
  159. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  160. $sql.= " WHERE type = '".$type."'";
  161. $sql.= " AND entity = ".$conf->entity;
  162. $resql=$db->query($sql);
  163. if ($resql)
  164. {
  165. $i = 0;
  166. $num_rows=$db->num_rows($resql);
  167. while ($i < $num_rows)
  168. {
  169. $array = $db->fetch_array($resql);
  170. array_push($def, $array[0]);
  171. $i++;
  172. }
  173. }
  174. else
  175. {
  176. dol_print_error($db);
  177. }
  178. print '<table class="noborder" width="100%">';
  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. {
  190. foreach (array('','/doc') as $valdir)
  191. {
  192. $dir = dol_buildpath($reldir."core/modules/user".$valdir);
  193. if (is_dir($dir))
  194. {
  195. $handle=opendir($dir);
  196. if (is_resource($handle))
  197. {
  198. while (($file = readdir($handle))!==false)
  199. {
  200. $filelist[]=$file;
  201. }
  202. closedir($handle);
  203. arsort($filelist);
  204. foreach($filelist as $file)
  205. {
  206. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  207. {
  208. if (file_exists($dir.'/'.$file))
  209. {
  210. $name = substr($file, 4, dol_strlen($file) -16);
  211. $classname = substr($file, 0, dol_strlen($file) -12);
  212. require_once $dir.'/'.$file;
  213. $module = new $classname($db);
  214. $modulequalified=1;
  215. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  216. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  217. if ($modulequalified)
  218. {
  219. print '<tr class="oddeven"><td width="100">';
  220. print (empty($module->name)?$name:$module->name);
  221. print "</td><td>\n";
  222. if (method_exists($module,'info')) print $module->info($langs);
  223. else print $module->description;
  224. print '</td>';
  225. // Active
  226. if (in_array($name, $def))
  227. {
  228. print '<td align="center">'."\n";
  229. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&value='.$name.'">';
  230. print img_picto($langs->trans("Enabled"),'switch_on');
  231. print '</a>';
  232. print '</td>';
  233. }
  234. else
  235. {
  236. print '<td align="center">'."\n";
  237. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set_default&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  238. print "</td>";
  239. }
  240. // Defaut
  241. print '<td align="center">';
  242. if ($conf->global->USER_ADDON_PDF == $name)
  243. {
  244. print img_picto($langs->trans("Default"),'on');
  245. }
  246. else
  247. {
  248. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  249. }
  250. print '</td>';
  251. // Info
  252. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  253. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  254. if ($module->type == 'pdf')
  255. {
  256. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  257. }
  258. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  259. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  260. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  261. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  262. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  263. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  264. print '<td align="center">';
  265. print $form->textwithpicto('',$htmltooltip,1,0);
  266. print '</td>';
  267. // Preview
  268. print '<td align="center">';
  269. if ($module->type == 'pdf')
  270. {
  271. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
  272. }
  273. else
  274. {
  275. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  276. }
  277. print '</td>';
  278. print "</tr>\n";
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. print '</table>';
  288. print "<br>";
  289. dol_fiche_end();
  290. // End of page
  291. llxFooter();
  292. $db->close();