dolibarr  9.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  *
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 <http://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 aviable 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  }
111  else
112  {
113  $db->rollback();
114  if (empty($errorsaved)) setEventMessages($langs->trans("Error"), null, 'errors');
115  }
116 }
117 
118 /*
119  * View
120  */
121 
122 $form=new Form($db);
123 $formadmin=new FormAdmin($db);
124 $formother=new FormOther($db);
125 
126 $arrayofjs=array();
127 $arrayofcss=array();
128 
129 $wikihelp='EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
130 llxHeader('',$langs->trans("AgendaSetup"),$wikihelp,'',0,0,$arrayofjs,$arrayofcss);
131 
132 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
133 print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
134 
135 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
136 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
137 print '<input type="hidden" name="action" value="save">';
138 
139 $head=agenda_prepare_head();
140 
141 dol_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
142 
143 print $langs->trans("AgendaExtSitesDesc")."<br>\n";
144 print "<br>\n";
145 
146 
147 $selectedvalue=$conf->global->AGENDA_DISABLE_EXT;
148 if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
149 
150 print "<table class=\"noborder\" width=\"100%\">";
151 
152 print "<tr class=\"liste_titre\">";
153 print '<td>'.$langs->trans("Parameter")."</td>";
154 print '<td align="center">'.$langs->trans("Value")."</td>";
155 print "</tr>";
156 
157 // Show external agenda
158 
159 print '<tr class="oddeven">';
160 print "<td>".$langs->trans("ExtSitesEnableThisTool")."</td>";
161 print '<td align="center">';
162 if ($conf->use_javascript_ajax)
163 {
164  print ajax_constantonoff('AGENDA_DISABLE_EXT',array('enabled'=>array(0=>'.hideifnotset')),null,1);
165 }
166 else
167 {
168  if (empty($conf->global->AGENDA_DISABLE_EXT))
169  {
170  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=1">'.img_picto($langs->trans("Enabled"),'on').'</a>';
171  }
172  else
173  {
174  print '<a href="'.$_SERVER['PHP_SELF'].'?save=1&AGENDA_DISABLE_EXT=0">'.img_picto($langs->trans("Disabled"),'off').'</a>';
175  }
176 }
177 print "</td>";
178 print "</tr>";
179 
180 // Nb of agenda
181 
182 print '<tr class="oddeven">';
183 print "<td>".$langs->trans("ExtSitesNbOfAgenda")."</td>";
184 print '<td align="center">';
185 print '<input class="flat hideifnotset" type="text" size="2" id="AGENDA_EXT_NB" name="AGENDA_EXT_NB" value="'.$conf->global->AGENDA_EXT_NB.'">';
186 print "</td>";
187 print "</tr>";
188 
189 print "</table>";
190 print "<br>";
191 
192 print "<table class=\"noborder\" width=\"100%\">";
193 
194 print "<tr class=\"liste_titre\">";
195 print "<td>".$langs->trans("Parameter")."</td>";
196 print "<td>".$langs->trans("Name")."</td>";
197 print "<td>".$langs->trans("ExtSiteUrlAgenda")." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</td>';
198 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
199 print '<td align="right">'.$langs->trans("Color").'</td>';
200 print "</tr>";
201 
202 $i=1;
203 while ($i <= $MAXAGENDA)
204 {
205  $key=$i;
206  $name='AGENDA_EXT_NAME'.$key;
207  $src='AGENDA_EXT_SRC'.$key;
208  $offsettz='AGENDA_EXT_OFFSETTZ'.$key;
209  $color='AGENDA_EXT_COLOR'.$key;
210  $enabled='AGENDA_EXT_ENABLED'.$key;
211 
212 
213  print '<tr class="oddeven">';
214  // Nb
215  print '<td width="180" class="nowrap">'.$langs->trans("AgendaExtNb",$key)."</td>";
216  // Name
217  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>';
218  // URL
219  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>';
220  // Offset TZ
221  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>';
222  // Color (Possible colors are limited by Google)
223  print '<td class="nowrap" align="right">';
224  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
225  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key)?GETPOST("AGENDA_EXT_COLOR".$key):$conf->global->$color), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset');
226  print '</td>';
227  print "</tr>";
228  $i++;
229 }
230 
231 print '</table>';
232 
233 dol_fiche_end();
234 
235 print '<div class="center">';
236 print '<input type="submit" id="save" name="save" class="button hideifnotset" value="'.$langs->trans("Save").'">';
237 print '</div>';
238 
239 print "</form>\n";
240 
241 // End of page
242 llxFooter();
243 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
agenda_prepare_head()
Prepare array with list of tabs.
Definition: agenda.lib.php:399
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:510
Class to generate html code for admin pages.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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:475
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0)
On/off button for constant.
Definition: ajax.lib.php:484
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
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