1<?php
2/* Copyright (C) 2008-2016	Laurent Destailleur     <eldy@users.sourceforge.net>
3 * Copyright (C) 2011		Regis Houssin           <regis.houssin@inodbox.com>
4 * Copyright (C) 2011-2017  Juanjo Menent           <jmenent@2byte.es>
5 * Copyright (C) 2015		Jean-François Ferry	    <jfefe@aternatik.fr>
6 * Copyright (C) 2016		Charlie Benke		    <charlie@patas-monkey.com>
7 * Copyright (C) 2017       Open-DSI                <support@open-dsi.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23/**
24 *	    \file       htdocs/admin/agenda_other.php
25 *      \ingroup    agenda
26 *      \brief      Autocreate actions for agenda module setup page
27 */
28
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
33
34if (!$user->admin)
35	accessforbidden();
36
37// Load translation files required by the page
38$langs->loadLangs(array('admin', 'other', 'agenda', 'users'));
39
40$action = GETPOST('action', 'aZ09');
41$value = GETPOST('value', 'alpha');
42$param = GETPOST('param', 'alpha');
43$cancel = GETPOST('cancel', 'alpha');
44$scandir = GETPOST('scan_dir', 'alpha');
45$type = 'action';
46
47
48/*
49 *	Actions
50 */
51
52include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
53
54$reg = array();
55if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg))
56{
57	$code = $reg[1];
58	$value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
59	if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
60	{
61		Header("Location: ".$_SERVER["PHP_SELF"]);
62		exit;
63	} else {
64		dol_print_error($db);
65	}
66}
67
68if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg))
69{
70	$code = $reg[1];
71	if (dolibarr_del_const($db, $code, $conf->entity) > 0)
72	{
73		Header("Location: ".$_SERVER["PHP_SELF"]);
74		exit;
75	} else {
76		dol_print_error($db);
77	}
78}
79if ($action == 'set')
80{
81	$getDefaultFilter = GETPOST('AGENDA_DEFAULT_FILTER_TYPE');
82	$defaultfilter = (is_array($getDefaultFilter)) ? implode(',', $getDefaultFilter) : $getDefaultFilter;
83	dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
84	dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity);
85	dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
86	dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
87} elseif ($action == 'specimen')  // For orders
88{
89	$modele = GETPOST('module', 'alpha');
90
91	$commande = new CommandeFournisseur($db);
92	$commande->initAsSpecimen();
93	$commande->thirdparty = $specimenthirdparty;
94
95	// Search template files
96	$file = ''; $classname = ''; $filefound = 0;
97	$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
98	foreach ($dirmodels as $reldir)
99	{
100		$file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
101		if (file_exists($file))
102		{
103			$filefound = 1;
104			$classname = "pdf_".$modele;
105			break;
106		}
107	}
108
109	if ($filefound)
110	{
111		require_once $file;
112
113		$module = new $classname($db, $commande);
114
115		if ($module->write_file($commande, $langs) > 0)
116		{
117			header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
118			return;
119		} else {
120			setEventMessages($module->error, $module->errors, 'errors');
121			dol_syslog($module->error, LOG_ERR);
122		}
123	} else {
124		setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
125		dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
126	}
127}
128
129// Activate a model
130elseif ($action == 'setmodel')
131{
132	//print "sssd".$value;
133	$ret = addDocumentModel($value, $type, $label, $scandir);
134} elseif ($action == 'del')
135{
136	$ret = delDocumentModel($value, $type);
137	if ($ret > 0)
138	{
139		if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
140	}
141}
142
143// Set default model
144elseif ($action == 'setdoc')
145{
146	if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
147	{
148		// La constante qui a ete lue en avant du nouveau set
149		// on passe donc par une variable pour avoir un affichage coherent
150		$conf->global->ACTION_EVENT_ADDON_PDF = $value;
151	}
152
153	// On active le modele
154	$ret = delDocumentModel($value, $type);
155	if ($ret > 0)
156	{
157		$ret = addDocumentModel($value, $type, $label, $scandir);
158	}
159}
160
161
162/**
163 * View
164 */
165
166$formactions = new FormActions($db);
167$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
168
169$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
170llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
171
172$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
173print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
174
175
176
177$head = agenda_prepare_head();
178
179print dol_get_fiche_head($head, 'other', $langs->trans("Agenda"), -1, 'action');
180
181
182/*
183 *  Documents models for supplier orders
184 */
185
186
187// Define array def of models
188$def = array();
189
190$sql = "SELECT nom";
191$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
192$sql .= " WHERE type = 'action'";
193$sql .= " AND entity = ".$conf->entity;
194
195$resql = $db->query($sql);
196if ($resql)
197{
198	$i = 0;
199	$num_rows = $db->num_rows($resql);
200	while ($i < $num_rows)
201	{
202		$array = $db->fetch_array($resql);
203		array_push($def, $array[0]);
204		$i++;
205	}
206} else {
207	dol_print_error($db);
208}
209
210if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
211{
212	print load_fiche_titre($langs->trans("AgendaModelModule"), '', '');
213
214	print '<table class="noborder centpercent">'."\n";
215	print '<tr class="liste_titre">'."\n";
216	print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
217	print '<td>'.$langs->trans("Description").'</td>'."\n";
218	print '<td class="center" width="60">'.$langs->trans("Status").'</td>'."\n";
219	print '<td class="center" width="60">'.$langs->trans("Default").'</td>'."\n";
220	print '<td class="center" width="40">'.$langs->trans("ShortInfo").'</td>';
221	print '<td class="center" width="40">'.$langs->trans("Preview").'</td>';
222	print '</tr>'."\n";
223
224	clearstatcache();
225
226	foreach ($dirmodels as $reldir)
227	{
228		$dir = dol_buildpath($reldir."core/modules/action/doc");
229
230		if (is_dir($dir))
231		{
232			$handle = opendir($dir);
233			if (is_resource($handle))
234			{
235				while (($file = readdir($handle)) !== false)
236				{
237					if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
238					{
239						$name = substr($file, 4, dol_strlen($file) - 16);
240						$classname = substr($file, 0, dol_strlen($file) - 12);
241
242						require_once $dir.'/'.$file;
243						$module = new $classname($db, new ActionComm($db));
244
245						print '<tr class="oddeven">'."\n";
246						print "<td>";
247						print (empty($module->name) ? $name : $module->name);
248						print "</td>\n";
249						print "<td>\n";
250						require_once $dir.'/'.$file;
251						$module = new $classname($db, $specimenthirdparty);
252						if (method_exists($module, 'info'))
253							print $module->info($langs);
254						else print $module->description;
255						print "</td>\n";
256
257						// Active
258						if (in_array($name, $def))
259						{
260							print '<td class="center">'."\n";
261							if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name")
262							{
263								print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action">';
264								print img_picto($langs->trans("Enabled"), 'switch_on');
265								print '</a>';
266							} else {
267								print img_picto($langs->trans("Enabled"), 'switch_on');
268							}
269							print "</td>";
270						} else {
271							print '<td class="center">'."\n";
272							print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
273							print "</td>";
274						}
275
276						// Default
277						print '<td class="center">';
278						if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name")
279						{
280							print img_picto($langs->trans("Default"), 'on');
281						} else {
282							print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
283						}
284						print '</td>';
285
286						// Info
287						$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
288						$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
289						$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
290						$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
291						$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
292						print '<td class="center">';
293						print $form->textwithpicto('', $htmltooltip, 1, 0);
294						print '</td>';
295						print '<td class="center">';
296						print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
297						print '</td>';
298
299						print "</tr>\n";
300					}
301				}
302				closedir($handle);
303			}
304		}
305	}
306	print '</table><br>';
307}
308
309print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
310print '<input type="hidden" name="token" value="'.newToken().'">';
311print '<input type="hidden" name="action" value="set">';
312
313print '<table class="noborder allwidth">'."\n";
314print '<tr class="liste_titre">'."\n";
315print '<td>'.$langs->trans("Parameters").'</td>'."\n";
316print '<td class="center">&nbsp;</td>'."\n";
317print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
318print '</tr>'."\n";
319
320// Manual or automatic
321
322print '<tr class="oddeven">'."\n";
323print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE").'</td>'."\n";
324print '<td class="center">&nbsp;</td>'."\n";
325print '<td class="right">'."\n";
326//print ajax_constantonoff('AGENDA_USE_EVENT_TYPE');	Do not use ajax here, we need to reload page to change other combo list
327if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
328{
329	print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_USE_EVENT_TYPE&amp;token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
330} else {
331	print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_USE_EVENT_TYPE&amp;token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
332}
333print '</td></tr>'."\n";
334
335// AGENDA_DEFAULT_VIEW
336print '<tr class="oddeven">'."\n";
337$htmltext = $langs->trans("ThisValueCanOverwrittenOnUserLevel", $langs->transnoentitiesnoconv("UserGUISetup"));
338print '<td>'.$form->textwithpicto($langs->trans("AGENDA_DEFAULT_VIEW"), $htmltext).'</td>'."\n";
339print '<td class="center">&nbsp;</td>'."\n";
340print '<td class="right">'."\n";
341$tmplist = array(''=>'&nbsp;', 'show_list'=>$langs->trans("ViewList"), 'show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_peruser'=>$langs->trans("ViewPerUser"));
342print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, $conf->global->AGENDA_DEFAULT_VIEW);
343print '</td></tr>'."\n";
344
345if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
346{
347	print '<!-- AGENDA_USE_EVENT_TYPE_DEFAULT -->';
348	print '<tr class="oddeven">'."\n";
349	print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'</td>'."\n";
350	print '<td class="center">&nbsp;</td>'."\n";
351	print '<td class="right nowrap">'."\n";
352	$formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
353	print '</td></tr>'."\n";
354}
355
356// AGENDA_DEFAULT_FILTER_TYPE
357print '<tr class="oddeven">'."\n";
358print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_TYPE").'</td>'."\n";
359print '<td class="center">&nbsp;</td>'."\n";
360print '<td class="right nowrap">'."\n";
361$multiselect = 0;
362if (!empty($conf->global->MAIN_ENABLE_MULTISELECT_TYPE)) {
363	// We use an option here because it adds bugs when used on agenda page "peruser" and "list"
364	$multiselect = (!empty($conf->global->AGENDA_USE_EVENT_TYPE));
365}
366$formactions->select_type_actions($conf->global->AGENDA_DEFAULT_FILTER_TYPE, "AGENDA_DEFAULT_FILTER_TYPE", '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1), 1, $multiselect);
367print '</td></tr>'."\n";
368
369// AGENDA_DEFAULT_FILTER_STATUS
370// TODO Remove to use the default generic feature
371print '<tr class="oddeven">'."\n";
372print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_STATUS").'</td>'."\n";
373print '<td class="center">&nbsp;</td>'."\n";
374print '<td class="right">'."\n";
375$formactions->form_select_status_action('agenda', $conf->global->AGENDA_DEFAULT_FILTER_STATUS, 1, 'AGENDA_DEFAULT_FILTER_STATUS', 1, 2, 'minwidth100');
376print '</td></tr>'."\n";
377
378print '</table>';
379
380print dol_get_fiche_end();
381
382print '<div class="center"><input class="button button-save" type="submit" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
383
384print '</form>';
385
386print "<br>";
387
388// End of page
389llxFooter();
390$db->close();
391