dolibarr  16.0.5
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  *
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 
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("admin", "members", "users"));
37 if (!$user->admin) {
39 }
40 
41 $extrafields = new ExtraFields($db);
42 
43 $action = GETPOST('action', 'aZ09');
44 $value = GETPOST('value', 'alpha');
45 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
46 
47 $type = 'group';
48 
49 /*
50  * Action
51  */
52 
53 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
54 
55 if ($action == 'set_default') {
56  $ret = addDocumentModel($value, $type, $label, $scandir);
57  $res = true;
58 } elseif ($action == 'del_default') {
59  $ret = delDocumentModel($value, $type);
60  if ($ret > 0) {
61  if (getDolGlobalString('USERGROUP_ADDON_PDF_ODT') == "$value") {
62  dolibarr_del_const($db, 'USERGROUP_ADDON_PDF_ODT', $conf->entity);
63  }
64  }
65  $res = true;
66 } elseif ($action == 'setdoc') {
67  // Set default model
68  if (dolibarr_set_const($db, "USERGROUP_ADDON_PDF_ODT", $value, 'chaine', 0, '', $conf->entity)) {
69  // La constante qui a ete lue en avant du nouveau set
70  // on passe donc par une variable pour avoir un affichage coherent
71  $conf->global->USERGROUP_ADDON_PDF_ODT = $value;
72  }
73 
74  // On active le modele
75  $ret = delDocumentModel($value, $type);
76  if ($ret > 0) {
77  $ret = addDocumentModel($value, $type, $label, $scandir);
78  }
79  $res = true;
80 } elseif (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
81  $code = $reg[1];
82  if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
83  header("Location: ".$_SERVER["PHP_SELF"]);
84  exit;
85  } else {
86  dol_print_error($db);
87  }
88 } elseif (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
89  $code = $reg[1];
90  if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
91  header("Location: ".$_SERVER["PHP_SELF"]);
92  exit;
93  } else {
94  dol_print_error($db);
95  }
96 }
97 /*
98  * View
99  */
100 
101 $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios';
102 llxHeader('', $langs->trans("UsersSetup"), $help_url);
103 
104 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
105 print load_fiche_titre($langs->trans("UsersSetup"), $linkback, 'title_setup');
106 
107 
108 $head = user_admin_prepare_head();
109 
110 print dol_get_fiche_head($head, 'usergroupcard', $langs->trans("MenuUsersAndGroups"), -1, 'user');
111 
112 
113 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
114 
115 $form = new Form($db);
116 
117 // Defini tableau def des modeles
118 $def = array();
119 $sql = "SELECT nom";
120 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
121 $sql .= " WHERE type = '".$db->escape($type)."'";
122 $sql .= " AND entity = ".$conf->entity;
123 $resql = $db->query($sql);
124 if ($resql) {
125  $i = 0;
126  $num_rows = $db->num_rows($resql);
127  while ($i < $num_rows) {
128  $array = $db->fetch_array($resql);
129  array_push($def, $array[0]);
130  $i++;
131  }
132 } else {
133  dol_print_error($db);
134 }
135 
136 print load_fiche_titre($langs->trans("GroupsDocModules"), '', '');
137 
138 print '<table class="noborder centpercent">';
139 print '<tr class="liste_titre">';
140 print '<td>'.$langs->trans("Name").'</td>';
141 print '<td>'.$langs->trans("Description").'</td>';
142 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
143 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
144 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
145 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
146 print "</tr>\n";
147 
148 clearstatcache();
149 
150 foreach ($dirmodels as $reldir) {
151  foreach (array('', '/doc') as $valdir) {
152  $dir = dol_buildpath($reldir."core/modules/usergroup".$valdir);
153  if (is_dir($dir)) {
154  $handle = opendir($dir);
155  if (is_resource($handle)) {
156  while (($file = readdir($handle)) !== false) {
157  $filelist[] = $file;
158  }
159  closedir($handle);
160  arsort($filelist);
161 
162  foreach ($filelist as $file) {
163  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
164  if (file_exists($dir.'/'.$file)) {
165  $name = substr($file, 4, dol_strlen($file) - 16);
166  $classname = substr($file, 0, dol_strlen($file) - 12);
167 
168  require_once $dir.'/'.$file;
169  $module = new $classname($db);
170 
171  $modulequalified = 1;
172  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
173  $modulequalified = 0;
174  }
175  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
176  $modulequalified = 0;
177  }
178 
179  if ($modulequalified) {
180  print '<tr class="oddeven"><td width="100">';
181  print (empty($module->name) ? $name : $module->name);
182  print "</td><td>\n";
183  if (method_exists($module, 'info')) {
184  print $module->info($langs);
185  } else {
186  print $module->description;
187  }
188  print '</td>';
189 
190  // Active
191  if (in_array($name, $def)) {
192  print '<td class="center">'."\n";
193  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del_default&token='.newToken().'&value='.urlencode($name).'">';
194  print img_picto($langs->trans("Enabled"), 'switch_on');
195  print '</a>';
196  print '</td>';
197  } else {
198  print '<td class="center">'."\n";
199  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>';
200  print "</td>";
201  }
202 
203  // Defaut
204  print '<td class="center">';
205  if (getDolGlobalString('USERGROUP_ADDON_PDF') == $name) {
206  print img_picto($langs->trans("Default"), 'on');
207  } else {
208  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>';
209  }
210  print '</td>';
211 
212  // Info
213  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
214  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
215  if ($module->type == 'pdf') {
216  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
217  }
218  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
219  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
220  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
221 
222 
223  print '<td class="center">';
224  print $form->textwithpicto('', $htmltooltip, 1, 0);
225  print '</td>';
226 
227  // Preview
228  print '<td class="center">';
229  if ($module->type == 'pdf') {
230  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
231  } else {
232  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
233  }
234  print '</td>';
235 
236  print "</tr>\n";
237  }
238  }
239  }
240  }
241  }
242  }
243  }
244 }
245 
246 print '</table>';
247 print "<br>";
248 
249 print dol_get_fiche_end();
250 
251 // End of page
252 llxFooter();
253 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
user_admin_prepare_head
user_admin_prepare_head()
Prepare array with list of tabs.
Definition: usergroups.lib.php:251
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59