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