dolibarr 23.0.3
usergroup.php
Go to the documentation of this file.
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array("admin", "members", "users"));
48if (!$user->admin) {
50}
51
52$extrafields = new ExtraFields($db);
53
54$action = GETPOST('action', 'aZ09');
55$value = GETPOST('value', 'alpha');
56$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
57
58$type = 'group';
59
60/*
61 * Action
62 */
63
64include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
65
66if ($action == 'set_default') {
67 $ret = addDocumentModel($value, $type, $label, $scandir);
68 $res = true;
69} elseif ($action == 'del_default') {
70 $ret = delDocumentModel($value, $type);
71 if ($ret > 0) {
72 if (getDolGlobalString('USERGROUP_ADDON_PDF_ODT') == "$value") {
73 dolibarr_del_const($db, 'USERGROUP_ADDON_PDF_ODT', $conf->entity);
74 }
75 }
76 $res = true;
77} elseif ($action == 'setdoc') {
78 // Set default model
79 if (dolibarr_set_const($db, "USERGROUP_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
80 // La constante qui a ete lue en avant du nouveau set
81 // on passe donc par une variable pour avoir un affichage coherent
82 $conf->global->USERGROUP_ADDON_PDF_ODT = $value;
83 }
84
85 // On active le modele
86 $ret = delDocumentModel($value, $type);
87 if ($ret > 0) {
88 $ret = addDocumentModel($value, $type, $label, $scandir);
89 }
90 $res = true;
91} elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
92 $code = $reg[1];
93 if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
94 header("Location: ".$_SERVER["PHP_SELF"]);
95 exit;
96 } else {
97 dol_print_error($db);
98 }
99} elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
100 $code = $reg[1];
101 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
102 header("Location: ".$_SERVER["PHP_SELF"]);
103 exit;
104 } else {
105 dol_print_error($db);
106 }
107}
108/*
109 * View
110 */
111
112$help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
113llxHeader('', $langs->trans("UsersSetup"), $help_url, '', 0, 0, '', '', '', 'mod-admin page-usergroup');
114
115$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
116
117print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
118
119
121
122print dol_get_fiche_head($head, 'usergroupcard', $langs->trans("MenuUsersAndGroups"), -1, 'user');
123
124
125$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
126
127$form = new Form($db);
128
129// Defini tableau def des modeles
130$def = array();
131$sql = "SELECT nom";
132$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
133$sql .= " WHERE type = '".$db->escape($type)."'";
134$sql .= " AND entity = ".((int) $conf->entity);
135$resql = $db->query($sql);
136if ($resql) {
137 $i = 0;
138 $num_rows = $db->num_rows($resql);
139 while ($i < $num_rows) {
140 $array = $db->fetch_array($resql);
141 if (is_array($array)) {
142 array_push($def, $array[0]);
143 }
144 $i++;
145 }
146} else {
147 dol_print_error($db);
148}
149
150print load_fiche_titre($langs->trans("GroupsDocModules"), '', '');
151
152print '<table class="noborder centpercent">';
153print '<tr class="liste_titre">';
154print '<td>'.$langs->trans("Name").'</td>';
155print '<td>'.$langs->trans("Description").'</td>';
156print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
157print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
158print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
159print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
160print "</tr>\n";
161
162clearstatcache();
163
164foreach ($dirmodels as $reldir) {
165 foreach (array('', '/doc') as $valdir) {
166 $dir = dol_buildpath($reldir."core/modules/usergroup".$valdir);
167 if (is_dir($dir)) {
168 $handle = opendir($dir);
169 if (is_resource($handle)) {
170 $filelist = array();
171 while (($file = readdir($handle)) !== false) {
172 $filelist[] = $file;
173 }
174 closedir($handle);
175 arsort($filelist);
176
177 foreach ($filelist as $file) {
178 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
179 if (file_exists($dir.'/'.$file)) {
180 $name = substr($file, 4, dol_strlen($file) - 16);
181 $classname = substr($file, 0, dol_strlen($file) - 12);
182
183 require_once $dir.'/'.$file;
184 $module = new $classname($db);
185 '@phan-var-force ModelePDFUserGroup $module';
186
187 $modulequalified = 1;
188 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
189 $modulequalified = 0;
190 }
191 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
192 $modulequalified = 0;
193 }
194
195 if ($modulequalified) {
196 print '<tr class="oddeven"><td width="100">';
197 print(empty($module->name) ? $name : $module->name);
198 print "</td><td>\n";
199 if (method_exists($module, 'info')) {
200 print $module->info($langs); // @phan-suppress-current-line PhanUndeclaredMethod
201 } else {
202 print $module->description;
203 }
204 print '</td>';
205
206 // Active
207 if (in_array($name, $def)) {
208 print '<td class="center">'."\n";
209 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&token='.newToken().'&value='.urlencode($name).'">';
210 print img_picto($langs->trans("Enabled"), 'switch_on');
211 print '</a>';
212 print '</td>';
213 } else {
214 print '<td class="center">'."\n";
215 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>';
216 print "</td>";
217 }
218
219 // Default
220 print '<td class="center">';
221 if (getDolGlobalString('USERGROUP_ADDON_PDF') == $name) {
222 print img_picto($langs->trans("Default"), 'on');
223 } else {
224 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>';
225 }
226 print '</td>';
227
228 // Info
229 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
230 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
231 if ($module->type == 'pdf') {
232 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
233 }
234 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
235 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
236 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
237
238
239 print '<td class="center">';
240 print $form->textwithpicto('', $htmltooltip, 1, 'info');
241 print '</td>';
242
243 // Preview
244 print '<td class="center">';
245 if ($module->type == 'pdf') {
246 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
247 } else {
248 print img_object($langs->transnoentitiesnoconv("PreviewNotAvailable"), 'generic');
249 }
250 print '</td>';
251
252 print "</tr>\n";
253 }
254 }
255 }
256 }
257 }
258 }
259 }
260}
261
262print '</table>';
263print "<br>";
264
265print dol_get_fiche_end();
266
267// End of page
268llxFooter();
269$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_admin_prepare_head()
Prepare array with list of tabs.