dolibarr  16.0.5
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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35 
36 if (!$user->admin) {
38 }
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array('agenda', 'admin', 'other'));
42 
43 $def = array();
44 $action = GETPOST('action', 'alpha');
45 
46 if (empty($conf->global->AGENDA_EXT_NB)) {
47  $conf->global->AGENDA_EXT_NB = 5;
48 }
49 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
50 
51 // List of available colors
52 $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
53 
54 
55 /*
56  * Actions
57  */
58 
59 $error = 0;
60 $errors = array();
61 
62 if (preg_match('/set_(.*)/', $action, $reg)) {
63  $db->begin();
64 
65  $code = $reg[1];
66  $value = (GETPOST($code) ? GETPOST($code) : 1);
67 
68  $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
69  if (!($res > 0)) {
70  $error++;
71  $errors[] = $db->lasterror();
72  }
73 
74  if ($error) {
75  $db->rollback();
76  setEventMessages('', $errors, 'errors');
77  } else {
78  $db->commit();
79  setEventMessage($langs->trans('SetupSaved'));
80  header('Location: ' . $_SERVER["PHP_SELF"]);
81  exit();
82  }
83 } elseif (preg_match('/del_(.*)/', $action, $reg)) {
84  $db->begin();
85 
86  $code = $reg[1];
87 
88  $res = dolibarr_del_const($db, $code, $conf->entity);
89  if (!($res > 0)) {
90  $error++;
91  $errors[] = $db->lasterror();
92  }
93 
94  if ($error) {
95  $db->rollback();
96  setEventMessages('', $errors, 'errors');
97  } else {
98  $db->commit();
99  setEventMessage($langs->trans('SetupSaved'));
100  header('Location: ' . $_SERVER["PHP_SELF"]);
101  exit();
102  }
103 } elseif ($action == 'save') {
104  $db->begin();
105 
106  $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
107  $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
108 
109  $i = 1; $errorsaved = 0;
110 
111  // Save agendas
112  while ($i <= $MAXAGENDA) {
113  $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
114  $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
115  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
116  $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
117  if ($color == '-1') {
118  $color = '';
119  }
120  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
121 
122  if (!empty($src) && !dol_is_url($src)) {
123  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
124  $error++;
125  $errorsaved++;
126  break;
127  }
128 
129  //print '-name='.$name.'-color='.$color;
130  $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
131  if (!($res > 0)) {
132  $error++;
133  }
134  $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
135  if (!($res > 0)) {
136  $error++;
137  }
138  $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
139  if (!($res > 0)) {
140  $error++;
141  }
142  $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
143  if (!($res > 0)) {
144  $error++;
145  }
146  $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
147  if (!($res > 0)) {
148  $error++;
149  }
150  $i++;
151  }
152 
153  // Save nb of agenda
154  if (!$error) {
155  $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
156  if (!($res > 0)) {
157  $error++;
158  }
159  if (empty($conf->global->AGENDA_EXT_NB)) {
160  $conf->global->AGENDA_EXT_NB = 5;
161  }
162  $MAXAGENDA = empty($conf->global->AGENDA_EXT_NB) ? 5 : $conf->global->AGENDA_EXT_NB;
163  }
164 
165  if (!$error) {
166  $db->commit();
167  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
168  } else {
169  $db->rollback();
170  if (empty($errorsaved)) {
171  setEventMessages($langs->trans("Error"), null, 'errors');
172  }
173  }
174 }
175 
176 /*
177  * View
178  */
179 
180 $form = new Form($db);
181 $formadmin = new FormAdmin($db);
182 $formother = new FormOther($db);
183 
184 $arrayofjs = array();
185 $arrayofcss = array();
186 
187 $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
188 llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
189 
190 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
191 print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
192 
193 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
194 print '<input type="hidden" name="token" value="'.newToken().'">';
195 print '<input type="hidden" name="action" value="save">';
196 
197 $head = agenda_prepare_head();
198 
199 print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
200 
201 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
202 print "<br>\n";
203 
204 
205 $selectedvalue=$conf->global->AGENDA_DISABLE_EXT;
206 if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
207 
208 print "<table class=\"noborder\" width=\"100%\">";
209 
210 print "<tr class=\"liste_titre\">";
211 print '<td>'.$langs->trans("Parameter")."</td>";
212 print '<td class="center">'.$langs->trans("Value")."</td>";
213 print "</tr>";
214 
215 // Show external agenda
216 
217 print '<tr class="oddeven">';
218 print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
219 print '<td class="center">';
220 if ($conf->use_javascript_ajax) {
221  print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
222 } else {
223  if (empty($conf->global->AGENDA_DISABLE_EXT)) {
224  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
225  } else {
226  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
227  }
228 }
229 print "</td>";
230 print "</tr>";
231 
232 // Nb of agenda
233 
234 print '<tr class="oddeven">';
235 print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
236 print '<td class="center">';
237 print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
238 print "</td>";
239 print "</tr>";
240 
241 print "</table>";
242 print "<br>";
243 
244 print "<table class=\"noborder\" width=\"100%\">";
245 
246 print "<tr class=\"liste_titre\">";
247 print "<td>".$langs->trans("Parameter")."</td>";
248 print "<td>".$langs->trans("Name")."</td>";
249 print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
250 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
251 print '<td class="right">'.$langs->trans("Color").'</td>';
252 print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
253 print "</tr>";
254 
255 $i = 1;
256 while ($i <= $MAXAGENDA) {
257  $key = $i;
258  $name = 'AGENDA_EXT_NAME' . $key;
259  $src = 'AGENDA_EXT_SRC' . $key;
260  $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
261  $color = 'AGENDA_EXT_COLOR' . $key;
262  $enabled = 'AGENDA_EXT_ENABLED' . $key;
263  $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
264 
265  print '<tr class="oddeven">';
266  // Nb
267  print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
268  // Name
269  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>';
270  // URL
271  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>';
272  // Offset TZ
273  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>';
274  // Color (Possible colors are limited by Google)
275  print '<td class="nowrap right">';
276  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
277  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, '', 'hideifnotset');
278  print '</td>';
279  // Calendar active by default
280  print '<td class="nowrap right">';
281  if ($conf->use_javascript_ajax) {
282  print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
283  } else {
284  if (empty($conf->global->{$default})) {
285  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
286  } else {
287  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
288  }
289  }
290  print '</td>';
291  print "</tr>";
292  $i++;
293 }
294 
295 print '</table>';
296 
297 print dol_get_fiche_end();
298 
299 print '<div class="center">';
300 print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
301 print '</div>';
302 
303 print "</form>\n";
304 
305 // End of page
306 llxFooter();
307 $db->close();
dol_is_url
dol_is_url($url)
Return if path is an URL.
Definition: files.lib.php:501
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
agenda_prepare_head
agenda_prepare_head()
Prepare array with list of tabs.
Definition: agenda.lib.php:363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8108
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59