dolibarr 25.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-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';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
44
45if (!$user->admin) {
47}
48
49// Load translation files required by the page
50$langs->loadLangs(array('agenda', 'admin', 'other'));
51
52$def = array();
53$action = GETPOST('action', 'alpha');
54
55$MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 6);
56
57// List of available colors
58$colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
59
60$reg = array();
61
62
63/*
64 * Actions
65 */
66
67$error = 0;
68$errors = array();
69
70if (preg_match('/set_(.*)/', $action, $reg)) {
71 $db->begin();
72
73 $code = $reg[1];
74 $value = (GETPOST($code) ? GETPOST($code) : 1);
75
76 $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
77 if (!($res > 0)) {
78 $error++;
79 $errors[] = $db->lasterror();
80 }
81
82 if ($error) {
83 $db->rollback();
84 setEventMessages('', $errors, 'errors');
85 } else {
86 $db->commit();
87 setEventMessage($langs->trans('SetupSaved'));
88 header('Location: ' . $_SERVER["PHP_SELF"]);
89 exit();
90 }
91} elseif (preg_match('/del_(.*)/', $action, $reg)) {
92 $db->begin();
93
94 $code = $reg[1];
95
96 $res = dolibarr_del_const($db, $code, $conf->entity);
97 if (!($res > 0)) {
98 $error++;
99 $errors[] = $db->lasterror();
100 }
101
102 if ($error) {
103 $db->rollback();
104 setEventMessages('', $errors, 'errors');
105 } else {
106 $db->commit();
107 setEventMessage($langs->trans('SetupSaved'));
108 header('Location: ' . $_SERVER["PHP_SELF"]);
109 exit();
110 }
111} elseif ($action == 'save') {
112 $db->begin();
113
114 $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
115 $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
116
117 $i = 1;
118 $errorsaved = 0;
119
120 // Save agendas
121 while ($i <= $MAXAGENDA) {
122 $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
123 $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
124 $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
125 $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
126 if ($color == '-1') {
127 $color = '';
128 }
129 $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
130 $cachedelay = (GETPOSTINT('AGENDA_EXT_CACHE'.$i) > 0 ? (string) GETPOSTINT('AGENDA_EXT_CACHE'.$i) : '');
131
132 if (!empty($src) && !dol_is_url($src)) {
133 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
134 $error++;
135 $errorsaved++;
136 break;
137 }
138
139 //print '-name='.$name.'-color='.$color;
140 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
141 $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
142 if (!($res > 0)) {
143 $error++;
144 }
145 $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
146 if (!($res > 0)) {
147 $error++;
148 }
149 $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
150 if (!($res > 0)) {
151 $error++;
152 }
153 $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
154 if (!($res > 0)) {
155 $error++;
156 }
157 if (GETPOSTISSET('AGENDA_EXT_ENABLED'.$i)) {
158 $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
159 if (!($res > 0)) {
160 $error++;
161 }
162 }
163 $res = dolibarr_set_const($db, 'AGENDA_EXT_CACHE'.$i, $cachedelay, 'chaine', 0, '', $conf->entity);
164 if (!($res > 0)) {
165 $error++;
166 }
167 $i++;
168 }
169
170 if (!$error) {
171 $db->commit();
172 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
173 } else {
174 $db->rollback();
175 if (empty($errorsaved)) {
176 setEventMessages($langs->trans("Error"), null, 'errors');
177 }
178 }
179}
180
181/*
182 * View
183 */
184
185$form = new Form($db);
186$formadmin = new FormAdmin($db);
187$formother = new FormOther($db);
188
189$arrayofjs = array();
190$arrayofcss = array();
191
192$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
193llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-agenda-extsites');
194
195$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
196
197print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
198
199print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
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 '<div class="info">'.$langs->trans("AgendaExtSitesDesc")."</div><br>\n";
208print "<br>\n";
209
210
211print '<div class="div-table-responsive">';
212print '<table class="noborder centpercent">'."\n";
213
214print '<tr class="liste_titre">';
215print '<td class="center">'.$langs->trans("AgendaExtNb", "")."</td>";
216print "<td>".$langs->trans("Name")."</td>";
217print "<td>".$langs->trans("ExtSiteUrlAgenda");
218print '<br><span class="hideonsmartphone opacitymedium">('.$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</span></td>';
219print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
220print '<td class="nowrap">'.$form->textwithpicto($langs->trans("AgendaExtCacheDelay"), $langs->trans("AgendaExtCacheDelayDesc", 300), 1).'</td>';
221print '<td class="center">'.$langs->trans("Color").'</td>';
222print '<td class="center">'.$langs->trans("Enabled").'</td>';
223print '<td class="center">'.$langs->trans("ActiveByDefault").'</td>';
224print "</tr>";
225
226$i = 1;
227while ($i <= $MAXAGENDA) {
228 $key = $i;
229 $name = 'AGENDA_EXT_NAME' . $key;
230 $src = 'AGENDA_EXT_SRC' . $key;
231 $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
232 $color = 'AGENDA_EXT_COLOR' . $key;
233 $cachedelay = 'AGENDA_EXT_CACHE' . $key;
234 $enabled = 'AGENDA_EXT_ENABLED' . $key;
235 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
236
237 print '<tr class="oddeven">';
238
239 // Nb
240 print '<td width="180" class="nowrap center">' . ((int) $key) . "</td>";
241
242 // Name
243 print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME' . $key . '" value="' . (GETPOST('AGENDA_EXT_NAME' . $key) ? GETPOST('AGENDA_EXT_NAME' . $key, 'alpha') : getDolGlobalString($name)) . '" size="28"></td>';
244
245 // URL
246 print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC' . $key . '" value="' . (GETPOST('AGENDA_EXT_SRC' . $key) ? GETPOST('AGENDA_EXT_SRC' . $key, 'alpha') : getDolGlobalString($src)) . '" size="60"></td>';
247
248 // Offset TZ
249 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>';
250
251 // Cache duration
252 print '<td><input type="number" min="0" class="flat hideifnotset width75" name="AGENDA_EXT_CACHE' . $key . '" value="' . (GETPOSTISSET('AGENDA_EXT_CACHE' . $key) ? GETPOSTINT('AGENDA_EXT_CACHE' . $key) : getDolGlobalString($cachedelay)) . '" placeholder="300"></td>' . "\n";
253
254 // Color (Possible colors are limited by Google)
255 print '<td class="nowraponall right">';
256 print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, '', 1, array(), 'hideifnotset');
257 print '</td>';
258
259 // Calendar enabled
260 print '<td class="nowrap center">';
261 if (!empty($conf->use_javascript_ajax)) {
262 print ajax_constantonoff('AGENDA_EXT_ENABLED' . $key, array(), null, 0, 0, 1);
263 } else {
264 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
265 if (getDolGlobalString($default)) {
266 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ENABLED' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
267 } else {
268 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ENABLED' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
269 }
270 }
271 print '</td>';
272
273 // Calendar active by default
274 print '<td class="nowrap center">';
275 if (!empty($conf->use_javascript_ajax)) {
276 $disabled = getDolGlobalString('AGENDA_EXT_ENABLED'.$key) ? 0 : 1;
277 if ($disabled) {
278 print ajax_constantonoff('EMPTYPARAM', array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, '', $disabled);
279 } else {
280 print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key, array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, '');
281 }
282 } else {
283 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
284 if (getDolGlobalString($default)) {
285 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
286 } else {
287 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
288 }
289 }
290 print '</td>';
291 print "</tr>";
292 $i++;
293}
294
295print '</table>';
296print '</div>';
297
298print dol_get_fiche_end();
299
300print '<div class="center">';
301print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
302print '</div>';
303
304print "</form>\n";
305
306// End of page
307llxFooter();
308$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.