dolibarr  17.0.4
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 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
36 
37 // Load translation files required by page
38 $langs->loadLangs(array('agenda', 'admin', 'other'));
39 
40 $def = array();
41 $actiontest = GETPOST('test', 'alpha');
42 $actionsave = GETPOST('save', 'alpha');
43 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'useragenda'; // To manage different context of search
44 
45 if (empty($conf->global->AGENDA_EXT_NB)) {
46  $conf->global->AGENDA_EXT_NB = 5;
47 }
48 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
49 
50 // List of available colors
51 $colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
52 
53 // Security check
54 $id = GETPOST('id', 'int');
55 $object = new User($db);
56 $object->fetch($id, '', '', 1);
57 $object->getrights();
58 
59 // Security check
60 $socid = 0;
61 if ($user->socid > 0) {
62  $socid = $user->socid;
63 }
64 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
65 
66 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
67 
68 // If user is not user that read and no permission to read other users, we stop
69 if (($object->id != $user->id) && (!$user->rights->user->user->lire)) {
71 }
72 
73 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
74 $hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard'));
75 
76 /*
77  * Actions
78  */
79 
80 $parameters = array('id'=>$socid);
81 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
82 if ($reshook < 0) {
83  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
84 }
85 
86 if (empty($reshook)) {
87  if ($actionsave) {
88  $db->begin();
89 
90  $errorsaved = 0;
91  $error = 0;
92  $tabparam = array();
93 
94  // Save agendas
95  $i = 1;
96  while ($i <= $MAXAGENDA) {
97  $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
98  $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
99  $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
100  $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
101  if ($color == '-1') {
102  $color = '';
103  }
104  $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
105 
106  if (!empty($src) && !dol_is_url($src)) {
107  setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
108  $error++;
109  $errorsaved++;
110  break;
111  }
112 
113  $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
114  $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
115  $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
116  $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
117  $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
118 
119  $i++;
120  }
121 
122  if (!$error) {
123  $result = dol_set_user_param($db, $conf, $object, $tabparam);
124  if (!($result > 0)) {
125  $error++;
126  }
127  }
128 
129  if (!$error) {
130  $db->commit();
131  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
132  } else {
133  $db->rollback();
134  if (empty($errorsaved)) {
135  setEventMessages($langs->trans("Error"), null, 'errors');
136  }
137  }
138  }
139 }
140 
141 /*
142  * View
143  */
144 
145 $form = new Form($db);
146 $formadmin = new FormAdmin($db);
147 $formother = new FormOther($db);
148 
149 $arrayofjs = array();
150 $arrayofcss = array();
151 
152 $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
153 $title = $person_name." - ".$langs->trans('ExtSites');
154 $help_url = '';
155 
156 llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss);
157 
158 
159 print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
160 print '<input type="hidden" name="id" value="'.$id.'">';
161 print '<input type="hidden" name="token" value="'.newToken().'">';
162 
163 $head = user_prepare_head($object);
164 
165 print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
166 
167 $linkback = '';
168 
169 if ($user->rights->user->user->lire || $user->admin) {
170  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
171 }
172 
173 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
174 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
175 $morehtmlref .= '</a>';
176 
177 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
178 
179 print '<div class="fichecenter">';
180 
181 print '<div class="underbanner clearboth"></div>';
182 print '<table class="border tableforfield centpercent">';
183 
184 // Login
185 print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
186 if (!empty($object->ldap_sid) && $object->statut == 0) {
187  print '<td class="error">';
188  print $langs->trans("LoginAccountDisableInDolibarr");
189  print '</td>';
190 } else {
191  print '<td>';
192  $addadmin = '';
193  if (property_exists($object, 'admin')) {
194  if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
195  $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
196  } elseif (!empty($object->admin)) {
197  $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
198  }
199  }
200  print showValueWithClipboardCPButton($object->login).$addadmin;
201  print '</td>';
202 }
203 print '</tr>'."\n";
204 
205 print '</table>';
206 
207 print '</div>';
208 
209 print dol_get_fiche_end();
210 
211 
212 print '<br>';
213 print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
214 print "<br>\n";
215 
216 $selectedvalue = empty($conf->global->AGENDA_DISABLE_EXT) ? 0 : $conf->global->AGENDA_DISABLE_EXT;
217 if ($selectedvalue == 1) {
218  $selectedvalue = 0;
219 } else {
220  $selectedvalue = 1;
221 }
222 
223 
224 print '<div class="div-table-responsive">';
225 print '<table class="noborder centpercent">';
226 
227 print "<tr class=\"liste_titre\">";
228 print "<td>".$langs->trans("Parameter")."</td>";
229 print "<td>".$langs->trans("Name")."</td>";
230 print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone opacitymedium">'." (".$langs->trans("Example").': https://externalcalendar/agenda/agenda.ics)</div></td>';
231 print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
232 print '<td class="right">'.$langs->trans("Color").'</td>';
233 print "</tr>";
234 
235 $i = 1;
236 while ($i <= $MAXAGENDA) {
237  $key = $i;
238  $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
239  $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
240  $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
241  $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
242 
243  print '<tr class="oddeven">';
244  // Nb
245  print '<td class="maxwidth50onsmartphone">'.$langs->trans("AgendaExtNb", $key)."</td>";
246  // Name
247  $name_value = (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : (empty($object->conf->$name) ? '' : $object->conf->$name));
248  print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.$name_value.'"></td>';
249  // URL
250  $src_value = (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ?GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : (empty($object->conf->$src) ? '' : $object->conf->$src));
251  print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.$src_value.'"></td>';
252  // Offset TZ
253  $offsettz_value = (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : (empty($object->conf->$offsettz) ? '' : $object->conf->$offsettz));
254  print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.$offsettz_value.'" size="1"></td>';
255  // Color (Possible colors are limited by Google)
256  print '<td class="nowraponall right">';
257  //print $formadmin->selectColor($conf->global->$color, "google_agenda_color".$key, $colorlist);
258  $color_value = (GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ?GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : (empty($object->conf->$color) ? 'ffffff' : $object->conf->$color));
259  print $formother->selectColor($color_value, "AGENDA_EXT_COLOR_".$id.'_'.$key, 'extsitesconfig', 1, '', 'hideifnotset');
260  print '</td>';
261  print "</tr>";
262  $i++;
263 }
264 
265 print '</table>';
266 print '</div>';
267 
268 $addition_button = array(
269  'name' => 'save',
270  'label_key' => 'Save',
271  'addclass' => 'hideifnotset',
272 );
273 print $form->buttonsSaveCancel("", "", $addition_button);
274 
275 print dol_get_fiche_end();
276 
277 print "</form>\n";
278 
279 // End of page
280 llxFooter();
281 $db->close();
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)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage Dolibarr users.
Definition: user.class.php:47
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_is_url($url)
Return if path is an URL.
Definition: files.lib.php:505
dol_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:292
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_prepare_head(User $object)
Prepare array with list of tabs.