dolibarr  7.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  *
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 $langs->load("agenda");
38 $langs->load("admin");
39 $langs->load("other");
40 
41 $def = array();
42 $actiontest=GETPOST('test','alpha');
43 $actionsave=GETPOST('save','alpha');
44 
45 if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
46 $MAXAGENDA=$conf->global->AGENDA_EXT_NB;
47 
48 // List of aviable colors
49 $colorlist=array('BECEDD','DDBECE','BFDDBE','F598B4','F68654','CBF654','A4A4A5');
50 
51 /*
52  * Actions
53  */
54 if ($actionsave)
55 {
56  $db->begin();
57 
58  $disableext=GETPOST('AGENDA_DISABLE_EXT','alpha');
59  $res=dolibarr_set_const($db,'AGENDA_DISABLE_EXT',$disableext,'chaine',0,'',$conf->entity);
60 
61  $i=1; $errorsaved=0;
62  $error=0;
63 
64  // Save agendas
65  while ($i <= $MAXAGENDA)
66  {
67  $name=trim(GETPOST('AGENDA_EXT_NAME'.$i,'alpha'));
68  $src=trim(GETPOST('AGENDA_EXT_SRC'.$i,'alpha'));
69  $offsettz=trim(GETPOST('AGENDA_EXT_OFFSETTZ'.$i,'alpha'));
70  $color=trim(GETPOST('AGENDA_EXT_COLOR'.$i,'alpha'));
71  if ($color=='-1') $color='';
72  $enabled=trim(GETPOST('AGENDA_EXT_ENABLED'.$i,'alpha'));
73 
74  if (! empty($src) && ! dol_is_url($src))
75  {
76  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
77  $error++;
78  $errorsaved++;
79  break;
80  }
81 
82  //print '-name='.$name.'-color='.$color;
83  $res=dolibarr_set_const($db,'AGENDA_EXT_NAME'.$i,$name,'chaine',0,'',$conf->entity);
84  if (! $res > 0) $error++;
85  $res=dolibarr_set_const($db,'AGENDA_EXT_SRC'.$i,$src,'chaine',0,'',$conf->entity);
86  if (! $res > 0) $error++;
87  $res=dolibarr_set_const($db,'AGENDA_EXT_OFFSETTZ'.$i,$offsettz,'chaine',0,'',$conf->entity);
88  if (! $res > 0) $error++;
89  $res=dolibarr_set_const($db,'AGENDA_EXT_COLOR'.$i,$color,'chaine',0,'',$conf->entity);
90  if (! $res > 0) $error++;
91  $res=dolibarr_set_const($db,'AGENDA_EXT_ENABLED'.$i,$enabled,'chaine',0,'',$conf->entity);
92  if (! $res > 0) $error++;
93  $i++;
94  }
95 
96  // Save nb of agenda
97  if (! $error)
98  {
99  $res=dolibarr_set_const($db,'AGENDA_EXT_NB',trim(GETPOST('AGENDA_EXT_NB','int')),'chaine',0,'',$conf->entity);
100  if (! $res > 0) $error++;
101  if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
102  $MAXAGENDA=empty($conf->global->AGENDA_EXT_NB)?5:$conf->global->AGENDA_EXT_NB;
103  }
104 
105  if (! $error)
106  {
107  $db->commit();
108  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
109  }
110  else
111  {
112  $db->rollback();
113  if (empty($errorsaved)) setEventMessages($langs->trans("Error"), null, 'errors');
114  }
115 }
116 
117 /*
118  * View
119  */
120 
121 $form=new Form($db);
122 $formadmin=new FormAdmin($db);
123 $formother=new FormOther($db);
124 
125 $arrayofjs=array();
126 $arrayofcss=array();
127 
128 $wikihelp='EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
129 llxHeader('',$langs->trans("AgendaSetup"),$wikihelp,'',0,0,$arrayofjs,$arrayofcss);
130 
131 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
132 print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
133 
134 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
135 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
136 print '<input type="hidden" name="action" value="save">';
137 
138 $head=agenda_prepare_head();
139 
140 dol_fiche_head($head, 'extsites', $langs->trans("Agenda"), -1, 'action');
141 
142 print $langs->trans("AgendaExtSitesDesc")."<br>\n";
143 print "<br>\n";
144 
145 
146 $selectedvalue=$conf->global->AGENDA_DISABLE_EXT;
147 if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
148 
149 $var=true;
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 $var=true;
204 while ($i <= $MAXAGENDA)
205 {
206  $key=$i;
207  $name='AGENDA_EXT_NAME'.$key;
208  $src='AGENDA_EXT_SRC'.$key;
209  $offsettz='AGENDA_EXT_OFFSETTZ'.$key;
210  $color='AGENDA_EXT_COLOR'.$key;
211  $enabled='AGENDA_EXT_ENABLED'.$key;
212 
213 
214  print '<tr class="oddeven">';
215  // Nb
216  print '<td width="180" class="nowrap">'.$langs->trans("AgendaExtNb",$key)."</td>";
217  // Name
218  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>';
219  // URL
220  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>';
221  // Offset TZ
222  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>';
223  // Color (Possible colors are limited by Google)
224  print '<td class="nowrap" align="right">';
225  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
226  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR".$key)?GETPOST("AGENDA_EXT_COLOR".$key):$conf->global->$color), "AGENDA_EXT_COLOR".$key, 'extsitesconfig', 1, '', 'hideifnotset');
227  print '</td>';
228  print "</tr>";
229  $i++;
230 }
231 
232 print '</table>';
233 
234 dol_fiche_end();
235 
236 print '<div class="center">';
237 print '<input type="submit" id="save" name="save" class="button hideifnotset" value="'.$langs->trans("Save").'">';
238 print '</div>';
239 
240 print "</form>\n";
241 
242 
243 llxFooter();
244 
245 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:439
if(GETPOST('button_removefilter_x','alpha')||GETPOST('button_removefilter.x','alpha')||GETPOST('button_removefilter','alpha')) if($action=="save"&&empty($cancel)) if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg) $wikihelp)
View.
Definition: agenda.php:143
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
print
Draft customers invoices.
Definition: index.php:91
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0)
On/off button for constant.
Definition: ajax.lib.php:500