dolibarr 24.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';
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
131 if (!empty($src) && !dol_is_url($src)) {
132 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
133 $error++;
134 $errorsaved++;
135 break;
136 }
137
138 //print '-name='.$name.'-color='.$color;
139 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
140 $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
141 if (!($res > 0)) {
142 $error++;
143 }
144 $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
145 if (!($res > 0)) {
146 $error++;
147 }
148 $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
149 if (!($res > 0)) {
150 $error++;
151 }
152 $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
153 if (!($res > 0)) {
154 $error++;
155 }
156 $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
157 if (!($res > 0)) {
158 $error++;
159 }
160 $i++;
161 }
162
163 if (!$error) {
164 $db->commit();
165 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
166 } else {
167 $db->rollback();
168 if (empty($errorsaved)) {
169 setEventMessages($langs->trans("Error"), null, 'errors');
170 }
171 }
172}
173
174/*
175 * View
176 */
177
178$form = new Form($db);
179$formadmin = new FormAdmin($db);
180$formother = new FormOther($db);
181
182$arrayofjs = array();
183$arrayofcss = array();
184
185$wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
186llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-agenda-extsites');
187
188$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>';
189
190print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
191
192print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
193print '<input type="hidden" name="token" value="'.newToken().'">';
194print '<input type="hidden" name="action" value="save">';
195
196$head = agenda_prepare_head();
197
198print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
199
200print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
201print "<br>\n";
202
203
204print '<div class="div-table-responsive">';
205print '<table class="noborder centpercent">'."\n";
206
207print '<tr class="liste_titre">';
208print '<td class="center">'.$langs->trans("AgendaExtNb", "")."</td>";
209print "<td>".$langs->trans("Name")."</td>";
210print "<td>".$langs->trans("ExtSiteUrlAgenda");
211print '<br><span class="hideonsmartphone opacitymedium">('.$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</span></td>';
212print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
213print '<td class="right">'.$langs->trans("Color").'</td>';
214print '<td class="center">'.$langs->trans("Enabled").'</td>';
215print '<td class="center">'.$langs->trans("ActiveByDefault").'</td>';
216print "</tr>";
217
218$i = 1;
219while ($i <= $MAXAGENDA) {
220 $key = $i;
221 $name = 'AGENDA_EXT_NAME' . $key;
222 $src = 'AGENDA_EXT_SRC' . $key;
223 $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
224 $color = 'AGENDA_EXT_COLOR' . $key;
225 $enabled = 'AGENDA_EXT_ENABLED' . $key;
226 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
227
228 print '<tr class="oddeven">';
229
230 // Nb
231 print '<td width="180" class="nowrap center">' . ((int) $key) . "</td>";
232
233 // Name
234 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>';
235
236 // URL
237 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>';
238
239 // Offset TZ
240 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>';
241
242 // Color (Possible colors are limited by Google)
243 print '<td class="nowraponall right">';
244 print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, '', 1, array(), 'hideifnotset');
245 print '</td>';
246
247 // Calendar enabled
248 print '<td class="nowrap center">';
249 if (!empty($conf->use_javascript_ajax)) {
250 print ajax_constantonoff('AGENDA_EXT_ENABLED' . $key, array(), null, 0, 0, 1);
251 } else {
252 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
253 if (getDolGlobalString($default)) {
254 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ENABLED' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
255 } else {
256 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ENABLED' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
257 }
258 }
259 print '</td>';
260
261 // Calendar active by default
262 print '<td class="nowrap center">';
263 if (!empty($conf->use_javascript_ajax)) {
264 $disabled = getDolGlobalString('AGENDA_EXT_ENABLED'.$key) ? 0 : 1;
265 if ($disabled) {
266 print ajax_constantonoff('EMPTYPARAM', array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, '', $disabled);
267 } else {
268 print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key, array(), null, 0, 0, 1, 2, 0, 0, '', '', 'inline-block', 0, '');
269 }
270 } else {
271 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
272 if (getDolGlobalString($default)) {
273 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
274 } else {
275 print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
276 }
277 }
278 print '</td>';
279 print "</tr>";
280 $i++;
281}
282
283print '</table>';
284print '</div>';
285
286print dol_get_fiche_end();
287
288print '<div class="center">';
289print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
290print '</div>';
291
292print "</form>\n";
293
294// End of page
295llxFooter();
296$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
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.