dolibarr 25.0.0-alpha
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-2025 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
55$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6);
56
57// List of available colors
58$colorlist = array('BECEDD', 'DDBECE', 'BFDDBE', 'F598B4', 'F68654', 'CBF654', 'A4A4A5');
59
60// Security check
61$id = GETPOSTINT('id');
62
63if (!isset($id) || empty($id)) {
65}
66
67$object = new User($db);
68$object->fetch($id, '', '', 1);
69$object->loadRights();
70
71// Security check
72$socid = 0;
73if ($user->socid > 0) {
74 $socid = $user->socid;
75}
76$feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
77
78// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
79$hookmanager->initHooks(array('usercard', 'useragenda', 'globalcard'));
80
81$result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
82
83// If user is not user that read and no permission to read other users, we stop
84if (($object->id != $user->id) && (!$user->hasRight('user', 'user', 'lire'))) {
86}
87
88/*
89 * Actions
90 */
91
92$parameters = array('id' => $socid);
93$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
94if ($reshook < 0) {
95 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
96}
97
98if (empty($reshook)) {
99 if ($actionsave) {
100 $db->begin();
101
102 $errorsaved = 0;
103 $error = 0;
104 $tabparam = array();
105
106 // Save agendas
107 $i = 1;
108 while ($i <= $MAXAGENDA) {
109 $name = trim(GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$i, 'alpha'));
110 $src = trim(GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$i, 'alpha'));
111 $offsettz = trim(GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i, 'alpha'));
112 $color = trim(GETPOST('AGENDA_EXT_COLOR_'.$id.'_'.$i, 'alpha'));
113 if ($color == '-1') {
114 $color = '';
115 }
116 $enabled = trim(GETPOST('AGENDA_EXT_ENABLED_'.$id.'_'.$i, 'alpha'));
117 $cachedelay = (GETPOSTINT('AGENDA_EXT_CACHE_'.$id.'_'.$i) > 0 ? (string) GETPOSTINT('AGENDA_EXT_CACHE_'.$id.'_'.$i) : '');
118
119 if (!empty($src) && !dol_is_url($src)) {
120 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
121 $error++;
122 $errorsaved++;
123 break;
124 }
125
126 $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
127 $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
128 $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
129 $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
130 $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
131 $tabparam['AGENDA_EXT_CACHE_'.$id.'_'.$i] = $cachedelay;
132
133 $i++;
134 }
135
136 if (!$error) {
137 $result = dol_set_user_param($db, $conf, $object, $tabparam);
138 if (!($result > 0)) {
139 $error++;
140 }
141 }
142
143 if (!$error) {
144 $db->commit();
145 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
146 } else {
147 $db->rollback();
148 if (empty($errorsaved)) {
149 setEventMessages($langs->trans("Error"), null, 'errors');
150 }
151 }
152 }
153}
154
155/*
156 * View
157 */
158
159$form = new Form($db);
160$formadmin = new FormAdmin($db);
161$formother = new FormOther($db);
162
163$arrayofjs = array();
164$arrayofcss = array();
165
166$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
167$title = $person_name." - ".$langs->trans('ExtSites');
168$help_url = '';
169
170llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-user page-agenda_extsites');
171
172
173print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
174print '<input type="hidden" name="id" value="'.$id.'">';
175print '<input type="hidden" name="token" value="'.newToken().'">';
176
177$head = user_prepare_head($object);
178
179print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
180
181$linkback = '';
182
183if ($user->hasRight('user', 'user', 'lire') || $user->admin) {
184 $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
185}
186
187$morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid valignmiddle" tabindex="-1" rel="noopener">';
188$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
189$morehtmlref .= '</a>';
190
191$urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
192$morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'refid valignmiddle nohover');
193
194dol_banner_tab($object, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin, 'rowid', 'ref', $morehtmlref);
195
196print '<div class="fichecenter">';
197
198print '<div class="underbanner clearboth"></div>';
199print '<table class="border tableforfield centpercent">';
200
201// Login
202print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
203if (!empty($object->ldap_sid) && $object->status == 0) {
204 print '<td class="error">';
205 print $langs->trans("LoginAccountDisableInDolibarr");
206 print '</td>';
207} else {
208 print '<td>';
209 $addadmin = '';
210 if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
211 $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "superadmin", 'class="paddingleft valignmiddle"');
212 } elseif (!empty($object->admin)) {
213 $addadmin .= img_picto($langs->trans("AdministratorDesc"), "admin", 'class="paddingleft valignmiddle"');
214 }
215 print showValueWithClipboardCPButton($object->login).$addadmin;
216 print '</td>';
217}
218print '</tr>'."\n";
219
220print '</table>';
221
222print '</div>';
223
224print dol_get_fiche_end();
225
226
227print '<br>';
228print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
229print "<br>\n";
230
231
232print '<div class="div-table-responsive-no-min">';
233print '<table class="noborder centpercent">';
234print '<tr class="liste_titre">';
235print '<td class="center">'.$langs->trans("AgendaExtNb", "")."</td>";
236print "<td>".$langs->trans("Name")."</td>";
237print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone opacitymedium">'." (".$langs->trans("Example").': https://externalcalendar/agenda/agenda.ics)</div></td>';
238print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
239print '<td class="nowrap">'.$form->textwithpicto($langs->trans("AgendaExtCacheDelay"), $langs->trans("AgendaExtCacheDelayDesc", 300), 1).'</td>';
240print '<td class="right">'.$langs->trans("Color").'</td>';
241print "</tr>";
242
243$i = 1;
244while ($i <= $MAXAGENDA) {
245 $key = $i;
246 $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
247 $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
248 $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
249 $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
250 $cachedelay = 'AGENDA_EXT_CACHE_'.$id.'_'.$key;
251
252 print '<tr class="oddeven">';
253 // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition
254 print '<td class="maxwidth50onsmartphone center">';
255 //print $langs->trans("AgendaExtNb", $key);
256 print $key;
257 print "</td>";
258 // Name
259 $name_value = (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : (empty($object->conf->$name) ? '' : $object->conf->$name));
260 print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.$name_value.'"></td>';
261 // URL
262 $src_value = (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : (empty($object->conf->$src) ? '' : $object->conf->$src));
263 print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.$src_value.'"></td>';
264 // Offset TZ
265 $offsettz_value = (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : (empty($object->conf->$offsettz) ? '' : $object->conf->$offsettz));
266 print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.$offsettz_value.'" size="1"></td>';
267 // Cache duration
268 $cachedelay_value = (GETPOSTISSET('AGENDA_EXT_CACHE_'.$id.'_'.$key) ? GETPOSTINT('AGENDA_EXT_CACHE_'.$id.'_'.$key) : (empty($object->conf->$cachedelay) ? '' : (int) $object->conf->$cachedelay));
269 print '<td><input type="number" min="0" class="flat hideifnotset width75" name="AGENDA_EXT_CACHE_'.$id.'_'.$key.'" value="'.$cachedelay_value.'" placeholder="300"></td>';
270 // Color (Possible colors are limited by Google)
271 print '<td class="nowraponall right">';
272 $color_value = (GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ? GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : (empty($object->conf->$color) ? 'ffffff' : $object->conf->$color));
273 print $formother->selectColor($color_value, "AGENDA_EXT_COLOR_".$id.'_'.$key, '', 1, array(), 'hideifnotset');
274 print '</td>';
275 print "</tr>";
276 $i++;
277}
278
279print '</table>';
280print '</div>';
281
282$addition_button = array(
283 'name' => 'save',
284 'label_key' => 'Save',
285 'addclass' => 'hideifnotset',
286);
287print $form->buttonsSaveCancel("", "", $addition_button);
288
289print dol_get_fiche_end();
290
291print "</form>\n";
292
293// End of page
294llxFooter();
295$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage Dolibarr users.
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, $entity=-1)
Save personal parameter.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
Definition html.lib.php:437
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition inc.php:431
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.