dolibarr  16.0.5
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)) {
45  $conf->global->AGENDA_EXT_NB = 5;
46 }
47 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
48 
49 // List of available colors
50 $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
51 
52 // Security check
53 $id = GETPOST('id', 'int');
54 $object = new User($db);
55 $object->fetch($id, '', '', 1);
56 $object->getrights();
57 
58 // Security check
59 $socid = 0;
60 if ($user->socid > 0) {
61  $socid = $user->socid;
62 }
63 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
64 
65 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
66 
67 // If user is not user that read and no permission to read other users, we stop
68 if (($object->id != $user->id) && (!$user->rights->user->user->lire)) {
70 }
71 
72 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
73 $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard'));
74 
75 /*
76  * Actions
77  */
78 
79 $parameters = array('id'=>$socid);
80 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
81 if ($reshook < 0) {
82  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
83 }
84 
85 if (empty($reshook)) {
86  if ($actionsave) {
87  $db->begin();
88 
89  $errorsaved = 0;
90  $error = 0;
91  $tabparam = array();
92 
93  // Save agendas
94  $i = 1;
95  while ($i <= $MAXAGENDA) {
96  $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
97  $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
98  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
99  $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
100  if ($color == '-1') {
101  $color = '';
102  }
103  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
104 
105  if (!empty($src) && !dol_is_url($src)) {
106  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
107  $error++;
108  $errorsaved++;
109  break;
110  }
111 
112  $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
113  $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
114  $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
115  $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
116  $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
117 
118  $i++;
119  }
120 
121  if (!$error) {
122  $result = dol_set_user_param($db, $conf, $object, $tabparam);
123  if (!($result > 0)) {
124  $error++;
125  }
126  }
127 
128  if (!$error) {
129  $db->commit();
130  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
131  } else {
132  $db->rollback();
133  if (empty($errorsaved)) {
134  setEventMessages($langs->trans("Error"), null, 'errors');
135  }
136  }
137  }
138 }
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 $formadmin = new FormAdmin($db);
146 $formother = new FormOther($db);
147 
148 $arrayofjs = array();
149 $arrayofcss = array();
150 
151 llxHeader('', $langs->trans("UserSetup"), '', '', 0, 0, $arrayofjs, $arrayofcss);
152 
153 
154 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
155 print '<input type="hidden" name="id" value="'.$id.'">';
156 print '<input type="hidden" name="token" value="'.newToken().'">';
157 
158 $head = user_prepare_head($object);
159 
160 print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
161 
162 $linkback = '';
163 
164 if ($user->rights->user->user->lire || $user->admin) {
165  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
166 }
167 
168 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
169 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
170 $morehtmlref .= '</a>';
171 
172 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
173 
174 
175 print '<div class="underbanner clearboth"></div>';
176 
177 print '<br>';
178 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
179 print "<br>\n";
180 
181 $selectedvalue = empty($conf->global->AGENDA_DISABLE_EXT) ? 0 : $conf->global->AGENDA_DISABLE_EXT;
182 if ($selectedvalue == 1) {
183  $selectedvalue = 0;
184 } else {
185  $selectedvalue = 1;
186 }
187 
188 
189 print '<div class="div-table-responsive">';
190 print '<table class="noborder centpercent">';
191 
192 print "<tr class=\"liste_titre\">";
193 print "<td>".$langs->trans("Parameter")."</td>";
194 print "<td>".$langs->trans("Name")."</td>";
195 print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone opacitymedium">'." (".$langs->trans("Example").': https://externalcalendar/agenda/agenda.ics)</div></td>';
196 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
197 print '<td class="right">'.$langs->trans("Color").'</td>';
198 print "</tr>";
199 
200 $i = 1;
201 while ($i <= $MAXAGENDA) {
202  $key = $i;
203  $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
204  $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
205  $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
206  $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
207 
208  print '<tr class="oddeven">';
209  // Nb
210  print '<td class="maxwidth50onsmartphone">'.$langs->trans("AgendaExtNb", $key)."</td>";
211  // Name
212  $name_value = (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : (empty($object->conf->$name) ? '' : $object->conf->$name));
213  print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.$name_value.'"></td>';
214  // URL
215  $src_value = (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : (empty($object->conf->$src) ? '' : $object->conf->$src));
216  print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.$src_value.'"></td>';
217  // Offset TZ
218  $offsettz_value = (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : (empty($object->conf->$offsettz) ? '' : $object->conf->$offsettz));
219  print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.$offsettz_value.'" size="1"></td>';
220  // Color (Possible colors are limited by Google)
221  print '<td class="nowraponall right">';
222  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
223  $color_value = (GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ?GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : (empty($object->conf->$color) ? 'ffffff' : $object->conf->$color));
224  print $formother->selectColor($color_value, "AGENDA_EXT_COLOR_".$id.'_'.$key, 'extsitesconfig', 1, '', 'hideifnotset');
225  print '</td>';
226  print "</tr>";
227  $i++;
228 }
229 
230 print '</table>';
231 print '</div>';
232 
233 $addition_button = array(
234  'name' => 'save',
235  'label_key' => 'Save',
236  'addclass' => 'hideifnotset',
237 );
238 print $form->buttonsSaveCancel("", "", $addition_button);
239 
240 print dol_get_fiche_end();
241 
242 print "</form>\n";
243 
244 // End of page
245 llxFooter();
246 $db->close();
dol_is_url
dol_is_url($url)
Return if path is an URL.
Definition: files.lib.php:501
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
user_prepare_head
user_prepare_head(User $object)
Prepare array with list of tabs.
Definition: usergroups.lib.php:35
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:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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
dol_banner_tab
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.
Definition: functions.lib.php:2046
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:3880
dol_set_user_param
dol_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
Definition: functions2.lib.php:1786
conf
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:300
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59