usergroup.php 8.5 KB

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