user.php 12 KB

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