usergroup.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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/usergroup.php
  25. * \ingroup core
  26. * \brief Page to setup usergroup 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='group';
  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->USERGROUP_ADDON_PDF_ODT == "$value") dolibarr_del_const($db, 'USERGROUP_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, "USERGROUP_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->USERGROUP_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. /*
  128. * View
  129. */
  130. $help_url='EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
  131. llxHeader('',$langs->trans("UsersSetup"),$help_url);
  132. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  133. print load_fiche_titre($langs->trans("UsersSetup"),$linkback,'title_setup');
  134. $head=user_admin_prepare_head();
  135. dol_fiche_head($head,'usergroupcard', $langs->trans("MenuUsersAndGroups"), -1, 'user');
  136. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  137. $form=new Form($db);
  138. // Defini tableau def des modeles
  139. $def = array();
  140. $sql = "SELECT nom";
  141. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  142. $sql.= " WHERE type = '".$type."'";
  143. $sql.= " AND entity = ".$conf->entity;
  144. $resql=$db->query($sql);
  145. if ($resql)
  146. {
  147. $i = 0;
  148. $num_rows=$db->num_rows($resql);
  149. while ($i < $num_rows)
  150. {
  151. $array = $db->fetch_array($resql);
  152. array_push($def, $array[0]);
  153. $i++;
  154. }
  155. }
  156. else
  157. {
  158. dol_print_error($db);
  159. }
  160. print '<table class="noborder" width="100%">';
  161. print '<tr class="liste_titre">';
  162. print '<td>'.$langs->trans("Name").'</td>';
  163. print '<td>'.$langs->trans("Description").'</td>';
  164. print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
  165. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  166. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  167. print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
  168. print "</tr>\n";
  169. clearstatcache();
  170. $var=true;
  171. foreach ($dirmodels as $reldir)
  172. {
  173. foreach (array('','/doc') as $valdir)
  174. {
  175. $dir = dol_buildpath($reldir."core/modules/usergroup".$valdir);
  176. if (is_dir($dir))
  177. {
  178. $handle=opendir($dir);
  179. if (is_resource($handle))
  180. {
  181. while (($file = readdir($handle))!==false)
  182. {
  183. $filelist[]=$file;
  184. }
  185. closedir($handle);
  186. arsort($filelist);
  187. foreach($filelist as $file)
  188. {
  189. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  190. {
  191. if (file_exists($dir.'/'.$file))
  192. {
  193. $name = substr($file, 4, dol_strlen($file) -16);
  194. $classname = substr($file, 0, dol_strlen($file) -12);
  195. require_once $dir.'/'.$file;
  196. $module = new $classname($db);
  197. $modulequalified=1;
  198. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
  199. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
  200. if ($modulequalified)
  201. {
  202. $var = !$var;
  203. print '<tr class="oddeven"><td width="100">';
  204. print (empty($module->name)?$name:$module->name);
  205. print "</td><td>\n";
  206. if (method_exists($module,'info')) print $module->info($langs);
  207. else print $module->description;
  208. print '</td>';
  209. // Active
  210. if (in_array($name, $def))
  211. {
  212. print '<td align="center">'."\n";
  213. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&value='.$name.'">';
  214. print img_picto($langs->trans("Enabled"),'switch_on');
  215. print '</a>';
  216. print '</td>';
  217. }
  218. else
  219. {
  220. print '<td align="center">'."\n";
  221. 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>';
  222. print "</td>";
  223. }
  224. // Defaut
  225. print '<td align="center">';
  226. if ($conf->global->USERGROUP_ADDON_PDF == $name)
  227. {
  228. print img_picto($langs->trans("Default"),'on');
  229. }
  230. else
  231. {
  232. 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>';
  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. {
  240. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  241. }
  242. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  243. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  244. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  245. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  246. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  247. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  248. print '<td align="center">';
  249. print $form->textwithpicto('',$htmltooltip,1,0);
  250. print '</td>';
  251. // Preview
  252. print '<td align="center">';
  253. if ($module->type == 'pdf')
  254. {
  255. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
  256. }
  257. else
  258. {
  259. print img_object($langs->trans("PreviewNotAvailable"),'generic');
  260. }
  261. print '</td>';
  262. print "</tr>\n";
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. print '</table>';
  272. print "<br>";
  273. dol_fiche_end();
  274. llxFooter();
  275. $db->close();