dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.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
46if (!$user->admin) {
48}
49
50// Load translation files required by the page
51$langs->loadLangs(array('agenda', 'admin', 'other'));
52
53$def = array();
54$action = GETPOST('action', 'alpha');
55
56if (!getDolGlobalString('AGENDA_EXT_NB')) {
57 $conf->global->AGENDA_EXT_NB = 5;
58}
59$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB');
60
61// List of available colors
62$colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
63
64$reg = array();
65
66
67/*
68 * Actions
69 */
70
71$error = 0;
72$errors = array();
73
74if (preg_match('/set_(.*)/', $action, $reg)) {
75 $db->begin();
76
77 $code = $reg[1];
78 $value = (GETPOST($code) ? GETPOST($code) : 1);
79
80 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
81 if (!($res > 0)) {
82 $error++;
83 $errors[] = $db->lasterror();
84 }
85
86 if ($error) {
87 $db->rollback();
88 setEventMessages('', $errors, 'errors');
89 } else {
90 $db->commit();
91 setEventMessage($langs->trans('SetupSaved'));
92 header('Location: ' . $_SERVER["PHP_SELF"]);
93 exit();
94 }
95} elseif (preg_match('/del_(.*)/', $action, $reg)) {
96 $db->begin();
97
98 $code = $reg[1];
99
100 $res = dolibarr_del_const($db, $code, $conf->entity);
101 if (!($res > 0)) {
102 $error++;
103 $errors[] = $db->lasterror();
104 }
105
106 if ($error) {
107 $db->rollback();
108 setEventMessages('', $errors, 'errors');
109 } else {
110 $db->commit();
111 setEventMessage($langs->trans('SetupSaved'));
112 header('Location: ' . $_SERVER["PHP_SELF"]);
113 exit();
114 }
115} elseif ($action == 'save') {
116 $db->begin();
117
118 $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
119 $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
120
121 $i = 1;
122 $errorsaved = 0;
123
124 // Save agendas
125 while ($i <= $MAXAGENDA) {
126 $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
127 $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
128 $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
129 $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
130 if ($color == '-1') {
131 $color = '';
132 }
133 $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
134
135 if (!empty($src) && !dol_is_url($src)) {
136 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
137 $error++;
138 $errorsaved++;
139 break;
140 }
141
142 //print '-name='.$name.'-color='.$color;
143 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
144 $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
145 if (!($res > 0)) {
146 $error++;
147 }
148 $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
149 if (!($res > 0)) {
150 $error++;
151 }
152 $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
153 if (!($res > 0)) {
154 $error++;
155 }
156 $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
157 if (!($res > 0)) {
158 $error++;
159 }
160 $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
161 if (!($res > 0)) {
162 $error++;
163 }
164 $i++;
165 }
166
167 // Save nb of agenda
168 if (!$error) {
169 $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', GETPOSTINT('AGENDA_EXT_NB'), 'chaine', 0, '', $conf->entity);
170 if (!($res > 0)) {
171 $error++;
172 }
173 if (!getDolGlobalString('AGENDA_EXT_NB')) {
174 $conf->global->AGENDA_EXT_NB = 5;
175 }
176 $MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 5);
177 }
178
179 if (!$error) {
180 $db->commit();
181 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
182 } else {
183 $db->rollback();
184 if (empty($errorsaved)) {
185 setEventMessages($langs->trans("Error"), null, 'errors');
186 }
187 }
188}
189
190/*
191 * View
192 */
193
194$form = new Form($db);
195$formadmin = new FormAdmin($db);
196$formother = new FormOther($db);
197
198$arrayofjs = array();
199$arrayofcss = array();
200
201$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
202llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-agenda-extsites');
203
204$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
205print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
206
207print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
208print '<input type="hidden" name="token" value="'.newToken().'">';
209print '<input type="hidden" name="action" value="save">';
210
211$head = agenda_prepare_head();
212
213print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
214
215print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
216print "<br>\n";
217
218
219$selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT');
220if ($selectedvalue == 1) {
221 $selectedvalue = 0;
222} else {
223 $selectedvalue = 1;
224}
225
226print "<table class=\"noborder centpercent\">";
227
228print "<tr class=\"liste_titre\">";
229print '<td>'.$langs->trans("Parameter")."</td>";
230print '<td class="center"></td>';
231print "</tr>";
232
233// Show external agenda
234
235print '<tr class="oddeven">';
236print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
237print '<td class="center">';
238if ($conf->use_javascript_ajax) {
239 print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled' => array(0 => '.hideifnotset')), null, 1);
240} else {
241 if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
242 print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
243 } else {
244 print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
245 }
246}
247print "</td>";
248print "</tr>";
249
250// Nb of agenda
251
252print '<tr class="oddeven">';
253print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
254print '<td class="center">';
255print '<input class="flat hideifnotset width50 center" type="text" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="' . getDolGlobalString('AGENDA_EXT_NB').'">';
256print "</td>";
257print "</tr>";
258
259print "</table>";
260print "<br>";
261
262print '<div class="div-table-responsive">';
263print '<table class="noborder centpercent">'."\n";
264
265print '<tr class="liste_titre">';
266print "<td>".$langs->trans("Parameter")."</td>";
267print "<td>".$langs->trans("Name")."</td>";
268print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
269print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
270print '<td class="right">'.$langs->trans("Color").'</td>';
271print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
272print "</tr>";
273
274$i = 1;
275while ($i <= $MAXAGENDA) {
276 $key = $i;
277 $name = 'AGENDA_EXT_NAME' . $key;
278 $src = 'AGENDA_EXT_SRC' . $key;
279 $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
280 $color = 'AGENDA_EXT_COLOR' . $key;
281 $enabled = 'AGENDA_EXT_ENABLED' . $key;
282 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
283
284 print '<tr class="oddeven">';
285 // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition
286 print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
287 // Name
288 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>';
289 // URL
290 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>';
291 // Offset TZ
292 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>';
293 // Color (Possible colors are limited by Google)
294 print '<td class="nowraponall right">';
295 print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, array(), 'hideifnotset');
296 print '</td>';
297 // Calendar active by default
298 print '<td class="nowrap right">';
299 if (!empty($conf->use_javascript_ajax)) {
300 print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
301 } else {
302 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
303 if (getDolGlobalString($default)) {
304 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
305 } else {
306 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
307 }
308 }
309 print '</td>';
310 print "</tr>";
311 $i++;
312}
313
314print '</table>';
315print '</div>';
316
317print dol_get_fiche_end();
318
319print '<div class="center">';
320print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
321print '</div>';
322
323print "</form>\n";
324
325// End of page
326llxFooter();
327$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:71
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.