usergroup.php 8.6 KB

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