usergroup.php 10 KB

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