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