1<?php
2/* Copyright (C) 2008-2015 	Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012-2013	Juanjo Menent		<jmenent@2byte.es>
4 * Copyright (C) 2012		Regis Houssin		<regis.houssin@inodbox.com>
5 * Copyright (C) 2015		Jean-François Ferry	<jfefe@aternatik.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21/**
22 *	    \file       htdocs/admin/agenda_xcal.php
23 *      \ingroup    agenda
24 *      \brief      Page to setup miscellaneous options of agenda module
25 */
26
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
30
31
32if (!$user->admin)
33	accessforbidden();
34
35// Load translation files required by the page
36$langs->loadLangs(array("admin", "other", "agenda"));
37
38$def = array();
39$actionsave = GETPOST('save', 'alpha');
40
41// Sauvegardes parametres
42if ($actionsave)
43{
44	$i = 0;
45
46	$db->begin();
47
48	$i += dolibarr_set_const($db, 'MAIN_AGENDA_XCAL_EXPORTKEY', trim(GETPOST('MAIN_AGENDA_XCAL_EXPORTKEY', 'alpha')), 'chaine', 0, '', $conf->entity);
49	$i += dolibarr_set_const($db, 'MAIN_AGENDA_EXPORT_PAST_DELAY', trim(GETPOST('MAIN_AGENDA_EXPORT_PAST_DELAY', 'alpha')), 'chaine', 0, '', $conf->entity);
50	$i += dolibarr_set_const($db, 'MAIN_AGENDA_EXPORT_CACHE', trim(GETPOST('MAIN_AGENDA_EXPORT_CACHE', 'alpha')), 'chaine', 0, '', $conf->entity);
51	$i += dolibarr_set_const($db, 'AGENDA_EXPORT_FIX_TZ', trim(GETPOST('AGENDA_EXPORT_FIX_TZ', 'alpha')), 'chaine', 0, '', $conf->entity);
52
53	if ($i >= 4)
54	{
55		$db->commit();
56		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
57	} else {
58		$db->rollback();
59		setEventMessages($langs->trans("SaveFailed"), null, 'errors');
60	}
61}
62
63
64
65/**
66 * View
67 */
68
69if (!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100;
70
71$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
72llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
73
74$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
75print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
76
77
78print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
79print '<input type="hidden" name="token" value="'.newToken().'">';
80
81$head = agenda_prepare_head();
82
83print dol_get_fiche_head($head, 'xcal', $langs->trans("Agenda"), -1, 'action');
84
85print '<span class="opacitymedium">'.$langs->trans("AgendaSetupOtherDesc")."</span><br>\n";
86print "<br>\n";
87
88print '<table class="noborder centpercent">';
89
90print '<tr class="liste_titre">';
91print "<td>".$langs->trans("Parameter")."</td>";
92print "<td>".$langs->trans("Value")."</td>";
93//print "<td>".$langs->trans("Examples")."</td>";
94print "<td>&nbsp;</td>";
95print "</tr>";
96
97print '<tr class="oddeven">';
98print '<td class="fieldrequired">'.$langs->trans("PasswordTogetVCalExport")."</td>";
99print '<td><input required="required" type="text" class="flat" id="MAIN_AGENDA_XCAL_EXPORTKEY" name="MAIN_AGENDA_XCAL_EXPORTKEY" value="'.(GETPOST('MAIN_AGENDA_XCAL_EXPORTKEY', 'alpha') ?GETPOST('MAIN_AGENDA_XCAL_EXPORTKEY', 'alpha') : $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY).'" size="40">';
100if (!empty($conf->use_javascript_ajax))
101	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
102print '</td>';
103print "<td>&nbsp;</td>";
104print "</tr>";
105
106print '<tr class="oddeven">';
107print "<td>".$langs->trans("PastDelayVCalExport")."</td>";
108print "<td><input type=\"text\" class=\"flat\" name=\"MAIN_AGENDA_EXPORT_PAST_DELAY\" value=\"".(GETPOST('MAIN_AGENDA_EXPORT_PAST_DELAY', 'alpha') ?GETPOST('MAIN_AGENDA_EXPORT_PAST_DELAY', 'alpha') : $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)."\" size=\"10\"> ".$langs->trans("days")."</td>";
109print "<td>&nbsp;</td>";
110print "</tr>";
111
112print '<tr class="oddeven">';
113print "<td>".$langs->trans("UseACacheDelay")."</td>";
114print "<td><input type=\"text\" class=\"flat\" name=\"MAIN_AGENDA_EXPORT_CACHE\" value=\"".(GETPOST('MAIN_AGENDA_EXPORT_CACHE', 'alpha') ?GETPOST('MAIN_AGENDA_EXPORT_CACHE', 'alpha') : $conf->global->MAIN_AGENDA_EXPORT_CACHE)."\" size=\"10\"></td>";
115print "<td>&nbsp;</td>";
116print "</tr>";
117
118print '</table>';
119
120print '<br>';
121
122print '<table class="noborder centpercent">';
123
124print '<tr class="liste_titre">';
125print '<td width="25%">'.$langs->trans("Parameter")."</td>";
126print "<td>".$langs->trans("Value")."</td>";
127print "</tr>";
128print '<tr class="oddeven">';
129print '<td>'.$langs->trans("FixTZ")."</td>";
130print "<td>";
131print '<input class="flat" type="text" size="4" name="AGENDA_EXPORT_FIX_TZ" value="'.$conf->global->AGENDA_EXPORT_FIX_TZ.'">';
132print ' &nbsp; '.$langs->trans("FillThisOnlyIfRequired");
133print "</td>";
134print "</tr>";
135
136print '</table>';
137
138print dol_get_fiche_end();
139
140print '<div class="center">';
141print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
142print "</div>";
143
144print "</form>\n";
145
146
147clearstatcache();
148
149//if ($mesg) print "<br>$mesg<br>";
150print "<br>";
151
152
153// Define $urlwithroot
154$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
155$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
156//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
157$getentity = ($conf->entity > 1 ? "&entity=".$conf->entity : "");
158
159// Show message
160$message = '';
161$urlvcal = '<a href="'.$urlwithroot.'/public/agenda/agendaexport.php?format=vcal'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : '...').'" target="_blank">';
162$urlvcal .= $urlwithroot.'/public/agenda/agendaexport.php?format=vcal'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : 'KEYNOTDEFINED').'</a>';
163$message .= img_picto('', 'globe').' '.$langs->trans("WebCalUrlForVCalExport", 'vcal', $urlvcal);
164$message .= '<br>';
165$urlical = '<a href="'.$urlwithroot.'/public/agenda/agendaexport.php?format=ical&type=event'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : '...').'" target="_blank">';
166$urlical .= $urlwithroot.'/public/agenda/agendaexport.php?format=ical&type=event'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : 'KEYNOTDEFINED').'</a>';
167$message .= img_picto('', 'globe').' '.$langs->trans("WebCalUrlForVCalExport", 'ical/ics', $urlical);
168$message .= '<br>';
169$urlrss = '<a href="'.$urlwithroot.'/public/agenda/agendaexport.php?format=rss'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : '...').'" target="_blank">';
170$urlrss .= $urlwithroot.'/public/agenda/agendaexport.php?format=rss'.$getentity.'&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY ?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY) : 'KEYNOTDEFINED').'</a>';
171$message .= img_picto('', 'globe').' '.$langs->trans("WebCalUrlForVCalExport", 'rss', $urlrss);
172$message .= '<br>';
173$message .= '<br>';
174print $message;
175
176$message = $langs->trans("AgendaUrlOptions1", $user->login, $user->login).'<br>';
177$message .= $langs->trans("AgendaUrlOptions3", $user->login, $user->login).'<br>';
178$message .= $langs->trans("AgendaUrlOptionsNotAdmin", $user->login, $user->login).'<br>';
179$message .= $langs->trans("AgendaUrlOptions4", $user->login, $user->login).'<br>';
180$message .= $langs->trans("AgendaUrlOptionsProject", $user->login, $user->login).'<br>';
181$message .= $langs->trans("AgendaUrlOptionsNotAutoEvent", 'systemauto', 'systemauto').'<br>';
182$message .= $langs->trans("AgendaUrlOptionsIncludeHolidays", '1', '1').'<br>';
183
184print info_admin($message);
185
186if (!empty($conf->use_javascript_ajax))
187{
188	print "\n".'<script type="text/javascript">';
189	print '$(document).ready(function () {
190            $("#generate_token").click(function() {
191            	$.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
192            		action: \'getrandompassword\',
193            		generic: true
194				},
195				function(token) {
196					$("#MAIN_AGENDA_XCAL_EXPORTKEY").val(token);
197				});
198            });
199    });';
200	print '</script>';
201}
202
203// End of page
204llxFooter();
205$db->close();
206