dolibarr 21.0.0-alpha
agenda_extsites.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2011-2015 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
5 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37
38if (!$user->admin) {
40}
41
42// Load translation files required by the page
43$langs->loadLangs(array('agenda', 'admin', 'other'));
44
45$def = array();
46$action = GETPOST('action', 'alpha');
47
48if (!getDolGlobalString('AGENDA_EXT_NB')) {
49 $conf->global->AGENDA_EXT_NB = 5;
50}
51$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB');
52
53// List of available colors
54$colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
55
56$reg = array();
57
58
59/*
60 * Actions
61 */
62
63$error = 0;
64$errors = array();
65
66if (preg_match('/set_(.*)/', $action, $reg)) {
67 $db->begin();
68
69 $code = $reg[1];
70 $value = (GETPOST($code) ? GETPOST($code) : 1);
71
72 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
73 if (!($res > 0)) {
74 $error++;
75 $errors[] = $db->lasterror();
76 }
77
78 if ($error) {
79 $db->rollback();
80 setEventMessages('', $errors, 'errors');
81 } else {
82 $db->commit();
83 setEventMessage($langs->trans('SetupSaved'));
84 header('Location: ' . $_SERVER["PHP_SELF"]);
85 exit();
86 }
87} elseif (preg_match('/del_(.*)/', $action, $reg)) {
88 $db->begin();
89
90 $code = $reg[1];
91
92 $res = dolibarr_del_const($db, $code, $conf->entity);
93 if (!($res > 0)) {
94 $error++;
95 $errors[] = $db->lasterror();
96 }
97
98 if ($error) {
99 $db->rollback();
100 setEventMessages('', $errors, 'errors');
101 } else {
102 $db->commit();
103 setEventMessage($langs->trans('SetupSaved'));
104 header('Location: ' . $_SERVER["PHP_SELF"]);
105 exit();
106 }
107} elseif ($action == 'save') {
108 $db->begin();
109
110 $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
111 $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
112
113 $i = 1;
114 $errorsaved = 0;
115
116 // Save agendas
117 while ($i <= $MAXAGENDA) {
118 $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
119 $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
120 $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
121 $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
122 if ($color == '-1') {
123 $color = '';
124 }
125 $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
126
127 if (!empty($src) && !dol_is_url($src)) {
128 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
129 $error++;
130 $errorsaved++;
131 break;
132 }
133
134 //print '-name='.$name.'-color='.$color;
135 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
136 $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
137 if (!($res > 0)) {
138 $error++;
139 }
140 $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
141 if (!($res > 0)) {
142 $error++;
143 }
144 $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
145 if (!($res > 0)) {
146 $error++;
147 }
148 $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
149 if (!($res > 0)) {
150 $error++;
151 }
152 $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
153 if (!($res > 0)) {
154 $error++;
155 }
156 $i++;
157 }
158
159 // Save nb of agenda
160 if (!$error) {
161 $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', GETPOSTINT('AGENDA_EXT_NB'), 'chaine', 0, '', $conf->entity);
162 if (!($res > 0)) {
163 $error++;
164 }
165 if (!getDolGlobalString('AGENDA_EXT_NB')) {
166 $conf->global->AGENDA_EXT_NB = 5;
167 }
168 $MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 5);
169 }
170
171 if (!$error) {
172 $db->commit();
173 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
174 } else {
175 $db->rollback();
176 if (empty($errorsaved)) {
177 setEventMessages($langs->trans("Error"), null, 'errors');
178 }
179 }
180}
181
182/*
183 * View
184 */
185
186$form = new Form($db);
187$formadmin = new FormAdmin($db);
188$formother = new FormOther($db);
189
190$arrayofjs = array();
191$arrayofcss = array();
192
193$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
194llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-agenda-extsites');
195
196$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
197print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
198
199print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
200print '<input type="hidden" name="token" value="'.newToken().'">';
201print '<input type="hidden" name="action" value="save">';
202
203$head = agenda_prepare_head();
204
205print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
206
207print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
208print "<br>\n";
209
210
211$selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT');
212if ($selectedvalue == 1) {
213 $selectedvalue = 0;
214} else {
215 $selectedvalue = 1;
216}
217
218print "<table class=\"noborder\" width=\"100%\">";
219
220print "<tr class=\"liste_titre\">";
221print '<td>'.$langs->trans("Parameter")."</td>";
222print '<td class="center">'.$langs->trans("Value")."</td>";
223print "</tr>";
224
225// Show external agenda
226
227print '<tr class="oddeven">';
228print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
229print '<td class="center">';
230if ($conf->use_javascript_ajax) {
231 print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled' => array(0 => '.hideifnotset')), null, 1);
232} else {
233 if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
234 print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
235 } else {
236 print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
237 }
238}
239print "</td>";
240print "</tr>";
241
242// Nb of agenda
243
244print '<tr class="oddeven">';
245print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
246print '<td class="center">';
247print '<input class="flat hideifnotset width50 center" type="text" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="' . getDolGlobalString('AGENDA_EXT_NB').'">';
248print "</td>";
249print "</tr>";
250
251print "</table>";
252print "<br>";
253
254print '<div class="div-table-responsive">';
255print '<table class="noborder centpercent">'."\n";
256
257print '<tr class="liste_titre">';
258print "<td>".$langs->trans("Parameter")."</td>";
259print "<td>".$langs->trans("Name")."</td>";
260print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
261print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
262print '<td class="right">'.$langs->trans("Color").'</td>';
263print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
264print "</tr>";
265
266$i = 1;
267while ($i <= $MAXAGENDA) {
268 $key = $i;
269 $name = 'AGENDA_EXT_NAME' . $key;
270 $src = 'AGENDA_EXT_SRC' . $key;
271 $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
272 $color = 'AGENDA_EXT_COLOR' . $key;
273 $enabled = 'AGENDA_EXT_ENABLED' . $key;
274 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
275
276 print '<tr class="oddeven">';
277 // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition
278 print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
279 // Name
280 print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_NAME' . $key . '" value="' . (GETPOST('AGENDA_EXT_NAME' . $key) ? GETPOST('AGENDA_EXT_NAME' . $key, 'alpha') : getDolGlobalString($name)) . '" size="28"></td>';
281 // URL
282 print '<td><input type="url" class="flat hideifnotset" name="AGENDA_EXT_SRC' . $key . '" value="' . (GETPOST('AGENDA_EXT_SRC' . $key) ? GETPOST('AGENDA_EXT_SRC' . $key, 'alpha') : getDolGlobalString($src)) . '" size="60"></td>';
283 // Offset TZ
284 print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ' . $key . '" value="' . (GETPOST('AGENDA_EXT_OFFSETTZ' . $key) ? GETPOST('AGENDA_EXT_OFFSETTZ' . $key) : getDolGlobalString($offsettz)) . '" size="2"></td>';
285 // Color (Possible colors are limited by Google)
286 print '<td class="nowraponall right">';
287 print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, array(), 'hideifnotset');
288 print '</td>';
289 // Calendar active by default
290 print '<td class="nowrap right">';
291 if (!empty($conf->use_javascript_ajax)) {
292 print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
293 } else {
294 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
295 if (getDolGlobalString($default)) {
296 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
297 } else {
298 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
299 }
300 }
301 print '</td>';
302 print "</tr>";
303 $i++;
304}
305
306print '</table>';
307print '</div>';
308
309print dol_get_fiche_end();
310
311print '<div class="center">';
312print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
313print '</div>';
314
315print "</form>\n";
316
317// End of page
318llxFooter();
319$db->close();
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.
agenda_prepare_head()
Prepare array with list of tabs.
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:70
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
llxFooter()
Footer empty.
Definition document.php:107
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.