dolibarr  13.0.2
agenda_extsites.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
35 
36 // Load translation files required by page
37 $langs->loadLangs(array('agenda', 'admin', 'other'));
38 
39 $def = array();
40 $actiontest = GETPOST('test', 'alpha');
41 $actionsave = GETPOST('save', 'alpha');
42 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'useragenda'; // To manage different context of search
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 // Security check
51 $id = GETPOST('id', 'int');
52 $object = new User($db);
53 $object->fetch($id, '', '', 1);
54 $object->getrights();
55 
56 // Security check
57 $socid = 0;
58 if ($user->socid > 0) $socid = $user->socid;
59 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
60 
61 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
62 
63 // If user is not user that read and no permission to read other users, we stop
64 if (($object->id != $user->id) && (!$user->rights->user->user->lire))
66 
67 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
68 $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard'));
69 
70 /*
71  * Actions
72  */
73 
74 $parameters = array('id'=>$socid);
75 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
76 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
77 
78 if (empty($reshook)) {
79  if ($actionsave) {
80  $db->begin();
81 
82  $errorsaved = 0;
83  $error = 0;
84  $tabparam = array();
85 
86  // Save agendas
87  $i = 1;
88  while ($i <= $MAXAGENDA) {
89  $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
90  $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
91  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
92  $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
93  if ($color == '-1') {
94  $color = '';
95  }
96  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
97 
98  if (!empty($src) && !dol_is_url($src)) {
99  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
100  $error++;
101  $errorsaved++;
102  break;
103  }
104 
105  $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
106  $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
107  $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
108  $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
109  $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
110 
111  $i++;
112  }
113 
114  if (!$error) {
115  $result = dol_set_user_param($db, $conf, $object, $tabparam);
116  if (!$result > 0) {
117  $error++;
118  }
119  }
120 
121  if (!$error) {
122  $db->commit();
123  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
124  } else {
125  $db->rollback();
126  if (empty($errorsaved)) {
127  setEventMessages($langs->trans("Error"), null, 'errors');
128  }
129  }
130  }
131 }
132 
133 /*
134  * View
135  */
136 
137 $form = new Form($db);
138 $formadmin = new FormAdmin($db);
139 $formother = new FormOther($db);
140 
141 $arrayofjs = array();
142 $arrayofcss = array();
143 
144 llxHeader('', $langs->trans("UserSetup"), '', '', 0, 0, $arrayofjs, $arrayofcss);
145 
146 
147 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
148 print '<input type="hidden" name="id" value="'.$id.'">';
149 print '<input type="hidden" name="token" value="'.newToken().'">';
150 
151 $head = user_prepare_head($object);
152 
153 print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
154 
155 $linkback = '';
156 
157 if ($user->rights->user->user->lire || $user->admin) {
158  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
159 }
160 
161 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
162 
163 
164 print '<div class="underbanner clearboth"></div>';
165 
166 print '<br>';
167 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
168 print "<br>\n";
169 
170 $selectedvalue = $conf->global->AGENDA_DISABLE_EXT;
171 if ($selectedvalue == 1) $selectedvalue = 0; else $selectedvalue = 1;
172 
173 
174 print '<div class="div-table-responsive">';
175 print '<table class="noborder centpercent">';
176 
177 print "<tr class=\"liste_titre\">";
178 print "<td>".$langs->trans("Parameter")."</td>";
179 print "<td>".$langs->trans("Name")."</td>";
180 print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone">'." (".$langs->trans("Example").': http://yoursite/agenda/agenda.ics)</div></td>';
181 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
182 print '<td class="right">'.$langs->trans("Color").'</td>';
183 print "</tr>";
184 
185 $i = 1;
186 while ($i <= $MAXAGENDA)
187 {
188  $key = $i;
189  $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
190  $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
191  $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
192  $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
193 
194 
195  print '<tr class="oddeven">';
196  // Nb
197  print '<td class="maxwidth50onsmartphone">'.$langs->trans("AgendaExtNb", $key)."</td>";
198  // Name
199  print '<td class="maxwidth50onsmartphone"><input type="text" class="flat hideifnotset minwidth100" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : $object->conf->$name).'"></td>';
200  // URL
201  print '<td class="maxwidth50onsmartphone"><input type="url" class="flat hideifnotset" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : $object->conf->$src).'"></td>';
202  // Offset TZ
203  print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : $object->conf->$offsettz).'" size="1"></td>';
204  // Color (Possible colors are limited by Google)
205  print '<td class="nowrap right">';
206  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
207  print $formother->selectColor((GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ?GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : $object->conf->$color), "AGENDA_EXT_COLOR_".$id.'_'.$key, 'extsitesconfig', 1, '', 'hideifnotset');
208  print '</td>';
209  print "</tr>";
210  $i++;
211 }
212 
213 print '</table>';
214 print '</div>';
215 
216 
217 print '<div class="center">';
218 print '<input type="submit" id="save" name="save" class="button hideifnotset button-save" value="'.$langs->trans("Save").'">';
219 print "</div>";
220 
222 
223 print "</form>\n";
224 
225 // End of page
226 llxFooter();
227 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
user_prepare_head($object)
Prepare array with list of tabs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:262
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to generate html code for admin pages.
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
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
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.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59