dolibarr  13.0.2
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 
35 if (!$user->admin) accessforbidden();
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('agenda', 'admin', 'other'));
39 
40 $def = array();
41 $actiontest = GETPOST('test', 'alpha');
42 $actionsave = GETPOST('save', 'alpha');
43 
44 if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5;
45 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
46 
47 // List of available colors
48 $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
49 
50 
51 /*
52  * Actions
53  */
54 
55 if ($actionsave)
56 {
57  $db->begin();
58 
59  $disableext = GETPOST('AGENDA_DISABLE_EXT', 'alpha');
60  $res = dolibarr_set_const($db, 'AGENDA_DISABLE_EXT', $disableext, 'chaine', 0, '', $conf->entity);
61 
62  $i = 1; $errorsaved = 0;
63  $error = 0;
64 
65  // Save agendas
66  while ($i <= $MAXAGENDA)
67  {
68  $name = trim(GETPOST('AGENDA_EXT_NAME'.$i, 'alpha'));
69  $src = trim(GETPOST('AGENDA_EXT_SRC'.$i, 'alpha'));
70  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i, 'alpha'));
71  $color = trim(GETPOST('AGENDA_EXT_COLOR'.$i, 'alpha'));
72  if ($color == '-1') $color = '';
73  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED'.$i, 'alpha'));
74 
75  if (!empty($src) && !dol_is_url($src))
76  {
77  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
78  $error++;
79  $errorsaved++;
80  break;
81  }
82 
83  //print '-name='.$name.'-color='.$color;
84  $res = dolibarr_set_const($db, 'AGENDA_EXT_NAME'.$i, $name, 'chaine', 0, '', $conf->entity);
85  if (!($res > 0)) $error++;
86  $res = dolibarr_set_const($db, 'AGENDA_EXT_SRC'.$i, $src, 'chaine', 0, '', $conf->entity);
87  if (!($res > 0)) $error++;
88  $res = dolibarr_set_const($db, 'AGENDA_EXT_OFFSETTZ'.$i, $offsettz, 'chaine', 0, '', $conf->entity);
89  if (!($res > 0)) $error++;
90  $res = dolibarr_set_const($db, 'AGENDA_EXT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
91  if (!($res > 0)) $error++;
92  $res = dolibarr_set_const($db, 'AGENDA_EXT_ENABLED'.$i, $enabled, 'chaine', 0, '', $conf->entity);
93  if (!($res > 0)) $error++;
94  $i++;
95  }
96 
97  // Save nb of agenda
98  if (!$error)
99  {
100  $res = dolibarr_set_const($db, 'AGENDA_EXT_NB', trim(GETPOST('AGENDA_EXT_NB', 'int')), 'chaine', 0, '', $conf->entity);
101  if (!($res > 0)) $error++;
102  if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5;
103  $MAXAGENDA = empty($conf->global->AGENDA_EXT_NB) ? 5 : $conf->global->AGENDA_EXT_NB;
104  }
105 
106  if (!$error)
107  {
108  $db->commit();
109  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
110  } else {
111  $db->rollback();
112  if (empty($errorsaved)) setEventMessages($langs->trans("Error"), null, 'errors');
113  }
114 }
115 
116 /*
117  * View
118  */
119 
120 $form = new Form($db);
121 $formadmin = new FormAdmin($db);
122 $formother = new FormOther($db);
123 
124 $arrayofjs = array();
125 $arrayofcss = array();
126 
127 $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
128 llxHeader('', $langs->trans("AgendaSetup"), $wikihelp, '', 0, 0, $arrayofjs, $arrayofcss);
129 
130 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
131 print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
132 
133 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
134 print '<input type="hidden" name="token" value="'.newToken().'">';
135 print '<input type="hidden" name="action" value="save">';
136 
137 $head = agenda_prepare_head();
138 
139 print dol_get_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
140 
141 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
142 print "<br>\n";
143 
144 
145 $selectedvalue = $conf->global->AGENDA_DISABLE_EXT;
146 if ($selectedvalue == 1) $selectedvalue = 0; else $selectedvalue = 1;
147 
148 print "<table class=\"noborder\" width=\"100%\">";
149 
150 print "<tr class=\"liste_titre\">";
151 print '<td>'.$langs->trans("Parameter")."</td>";
152 print '<td class="center">'.$langs->trans("Value")."</td>";
153 print "</tr>";
154 
155 // Show external agenda
156 
157 print '<tr class="oddeven">';
158 print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
159 print '<td class="center">';
160 if ($conf->use_javascript_ajax)
161 {
162  print ajax_constantonoff('AGENDA_DISABLE_EXT', array('enabled'=>array(0=>'.hideifnotset')), null, 1);
163 } else {
164  if (empty($conf->global->AGENDA_DISABLE_EXT))
165  {
166  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
167  } else {
168  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
169  }
170 }
171 print "</td>";
172 print "</tr>";
173 
174 // Nb of agenda
175 
176 print '<tr class="oddeven">';
177 print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
178 print '<td class="center">';
179 print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
180 print "</td>";
181 print "</tr>";
182 
183 print "</table>";
184 print "<br>";
185 
186 print "<table class=\"noborder\" width=\"100%\">";
187 
188 print "<tr class=\"liste_titre\">";
189 print "<td>".$langs->trans("Parameter")."</td>";
190 print "<td>".$langs->trans("Name")."</td>";
191 print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
192 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
193 print '<td class="right">'.$langs->trans("Color").'</td>';
194 print "</tr>";
195 
196 $i = 1;
197 while ($i <= $MAXAGENDA)
198 {
199  $key = $i;
200  $name = 'AGENDA_EXT_NAME'.$key;
201  $src = 'AGENDA_EXT_SRC'.$key;
202  $offsettz = 'AGENDA_EXT_OFFSETTZ'.$key;
203  $color = 'AGENDA_EXT_COLOR'.$key;
204  $enabled = 'AGENDA_EXT_ENABLED'.$key;
205 
206 
207  print '<tr class="oddeven">';
208  // Nb
209  print '<td width="180" class="nowrap">'.$langs->trans("AgendaExtNb", $key)."</td>";
210  // Name
211  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') : $conf->global->$name).'" size="28"></td>';
212  // URL
213  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') : $conf->global->$src).'" size="60"></td>';
214  // Offset TZ
215  print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ'.$key.'" value="'.(GETPOST('AGENDA_EXT_OFFSETTZ'.$key) ?GETPOST('AGENDA_EXT_OFFSETTZ'.$key) : $conf->global->$offsettz).'" size="2"></td>';
216  // Color (Possible colors are limited by Google)
217  print '<td class="nowrap right">';
218  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
219  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key) ?GETPOST("AGENDA_EXT_COLOR".$key) : $conf->global->$color), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset');
220  print '</td>';
221  print "</tr>";
222  $i++;
223 }
224 
225 print '</table>';
226 
228 
229 print '<div class="center">';
230 print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
231 print '</div>';
232 
233 print "</form>\n";
234 
235 // End of page
236 llxFooter();
237 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
agenda_prepare_head()
Prepare array with list of tabs.
Definition: agenda.lib.php:358
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:575
Class to generate html code for admin pages.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $wikihelp
View.
Definition: agenda.php:120
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
dol_is_url($url)
Return if path is an URL.
Definition: files.lib.php:481
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
Classe permettant la generation de composants html autre Only common components are here...
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 ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59