usergroup.php 8.4 KB

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