dolibarr  18.0.0
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 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36 
37 if (!$user->admin) {
39 }
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array('agenda', 'admin', 'other'));
43 
44 $def = array();
45 $action = GETPOST('action', 'alpha');
46 
47 if (empty($conf->global->AGENDA_EXT_NB)) {
48  $conf->global->AGENDA_EXT_NB = 5;
49 }
50 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
51 
52 // List of available colors
53 $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
54 
55 
56 /*
57  * Actions
58  */
59 
60 $error = 0;
61 $errors = array();
62 
63 if (preg_match('/set_(.*)/', $action, $reg)) {
64  $db->begin();
65 
66  $code = $reg[1];
67  $value = (GETPOST($code) ? GETPOST($code) : 1);
68 
69  $res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
70  if (!($res > 0)) {
71  $error++;
72  $errors[] = $db->lasterror();
73  }
74 
75  if ($error) {
76  $db->rollback();
77  setEventMessages('', $errors, 'errors');
78  } else {
79  $db->commit();
80  setEventMessage($langs->trans('SetupSaved'));
81  header('Location: ' . $_SERVER["PHP_SELF"]);
82  exit();
83  }
84 } elseif (preg_match('/del_(.*)/', $action, $reg)) {
85  $db->begin();
86 
87  $code = $reg[1];
88 
89  $res = dolibarr_del_const($db, $code, $conf->entity);
90  if (!($res > 0)) {
91  $error++;
92  $errors[] = $db->lasterror();
93  }
94 
95  if ($error) {
96  $db->rollback();
97  setEventMessages('', $errors, 'errors');
98  } else {
99  $db->commit();
100  setEventMessage($langs->trans('SetupSaved'));
101  header('Location: ' . $_SERVER["PHP_SELF"]);
102  exit();
103  }
104 } elseif ($action == 'save') {
105  $db->begin();
106 
107  $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
108  $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
109 
110  $i = 1; $errorsaved = 0;
111 
112  // Save agendas
113  while ($i <= $MAXAGENDA) {
114  $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
115  $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
116  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
117  $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
118  if ($color == '-1') {
119  $color = '';
120  }
121  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
122 
123  if (!empty($src) && !dol_is_url($src)) {
124  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
125  $error++;
126  $errorsaved++;
127  break;
128  }
129 
130  //print '-name='.$name.'-color='.$color;
131  $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
132  if (!($res > 0)) {
133  $error++;
134  }
135  $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
136  if (!($res > 0)) {
137  $error++;
138  }
139  $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
140  if (!($res > 0)) {
141  $error++;
142  }
143  $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
144  if (!($res > 0)) {
145  $error++;
146  }
147  $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
148  if (!($res > 0)) {
149  $error++;
150  }
151  $i++;
152  }
153 
154  // Save nb of agenda
155  if (!$error) {
156  $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
157  if (!($res > 0)) {
158  $error++;
159  }
160  if (empty($conf->global->AGENDA_EXT_NB)) {
161  $conf->global->AGENDA_EXT_NB = 5;
162  }
163  $MAXAGENDA = empty($conf->global->AGENDA_EXT_NB) ? 5 : $conf->global->AGENDA_EXT_NB;
164  }
165 
166  if (!$error) {
167  $db->commit();
168  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
169  } else {
170  $db->rollback();
171  if (empty($errorsaved)) {
172  setEventMessages($langs->trans("Error"), null, 'errors');
173  }
174  }
175 }
176 
177 /*
178  * View
179  */
180 
181 $form = new Form($db);
182 $formadmin = new FormAdmin($db);
183 $formother = new FormOther($db);
184 
185 $arrayofjs = array();
186 $arrayofcss = array();
187 
188 $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
189 llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
190 
191 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
192 print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
193 
194 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196 print '<input type="hidden" name="action" value="save">';
197 
198 $head = agenda_prepare_head();
199 
200 print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
201 
202 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
203 print "<br>\n";
204 
205 
206 $selectedvalue = getDolGlobalInt('AGENDA_DISABLE_EXT');
207 if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
208 
209 print "<table class=\"noborder\" width=\"100%\">";
210 
211 print "<tr class=\"liste_titre\">";
212 print '<td>'.$langs->trans("Parameter")."</td>";
213 print '<td class="center">'.$langs->trans("Value")."</td>";
214 print "</tr>";
215 
216 // Show external agenda
217 
218 print '<tr class="oddeven">';
219 print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
220 print '<td class="center">';
221 if ($conf->use_javascript_ajax) {
222  print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
223 } else {
224  if (empty($conf->global->AGENDA_DISABLE_EXT)) {
225  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
226  } else {
227  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
228  }
229 }
230 print "</td>";
231 print "</tr>";
232 
233 // Nb of agenda
234 
235 print '<tr class="oddeven">';
236 print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
237 print '<td class="center">';
238 print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
239 print "</td>";
240 print "</tr>";
241 
242 print "</table>";
243 print "<br>";
244 
245 print "<table class=\"noborder\" width=\"100%\">";
246 
247 print "<tr class=\"liste_titre\">";
248 print "<td>".$langs->trans("Parameter")."</td>";
249 print "<td>".$langs->trans("Name")."</td>";
250 print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
251 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
252 print '<td class="right">'.$langs->trans("Color").'</td>';
253 print '<td class="right">'.$langs->trans("ActiveByDefault").'</td>';
254 print "</tr>";
255 
256 $i = 1;
257 while ($i <= $MAXAGENDA) {
258  $key = $i;
259  $name = 'AGENDA_EXT_NAME' . $key;
260  $src = 'AGENDA_EXT_SRC' . $key;
261  $offsettz = 'AGENDA_EXT_OFFSETTZ' . $key;
262  $color = 'AGENDA_EXT_COLOR' . $key;
263  $enabled = 'AGENDA_EXT_ENABLED' . $key;
264  $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $key;
265 
266  print '<tr class="oddeven">';
267  // Nb
268  print '<td width="180" class="nowrap">' . $langs->trans("AgendaExtNb", $key) . "</td>";
269  // Name
270  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>';
271  // URL
272  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>';
273  // Offset TZ
274  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>';
275  // Color (Possible colors are limited by Google)
276  print '<td class="nowrap right">';
277  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
278  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR" . $key) ? GETPOST("AGENDA_EXT_COLOR" . $key) : getDolGlobalString($color)), "AGENDA_EXT_COLOR" . $key, 'extsitesconfig', 1, '', 'hideifnotset');
279  print '</td>';
280  // Calendar active by default
281  print '<td class="nowrap right">';
282  if (!empty($conf->use_javascript_ajax)) {
283  print ajax_constantonoff('AGENDA_EXT_ACTIVEBYDEFAULT' . $key);
284  } else {
285  if (getDolGlobalString($default)) {
286  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
287  } else {
288  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_AGENDA_EXT_ACTIVEBYDEFAULT' . $key . '&token='.newToken().'">' . img_picto($langs->trans("Enabled"), 'on') . '</a>';
289  }
290  }
291  print '</td>';
292  print "</tr>";
293  $i++;
294 }
295 
296 print '</table>';
297 
298 print dol_get_fiche_end();
299 
300 print '<div class="center">';
301 print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
302 print '</div>';
303 
304 print "</form>\n";
305 
306 // End of page
307 llxFooter();
308 $db->close();
dol_is_url
dol_is_url($url)
Return if path is an URL.
Definition: files.lib.php:507
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:562
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
agenda_prepare_head
agenda_prepare_head()
Prepare array with list of tabs.
Definition: agenda.lib.php:364
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:609
$wikihelp
if(GETPOSTISSET('MAIN_AGENDA_XCAL_EXPORTKEY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_PAST_DELAY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_CACHE')) if(GETPOSTISSET('AGENDA_EXPORT_FIX_TZ')) if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:90
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
setEventMessage
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
Definition: functions.lib.php:8637
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:4135
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='')
On/off button for constant.
Definition: ajax.lib.php:630
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
dol_get_fiche_head
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.
Definition: functions.lib.php:1979
getDolGlobalString
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:142
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:638
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1164
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156