dolibarr 24.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-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
118 if (!empty($src) && !dol_is_url($src)) {
119 setEventMessages($langs->trans("ErrorParamMustBeAnUrl"), null, 'errors');
120 $error++;
121 $errorsaved++;
122 break;
123 }
124
125 $tabparam['AGENDA_EXT_NAME_'.$id.'_'.$i] = $name;
126 $tabparam['AGENDA_EXT_SRC_'.$id.'_'.$i] = $src;
127 $tabparam['AGENDA_EXT_OFFSETTZ_'.$id.'_'.$i] = $offsettz;
128 $tabparam['AGENDA_EXT_COLOR_'.$id.'_'.$i] = $color;
129 $tabparam['AGENDA_EXT_ENABLED_'.$id.'_'.$i] = $enabled;
130
131 $i++;
132 }
133
134 if (!$error) {
135 $result = dol_set_user_param($db, $conf, $object, $tabparam);
136 if (!($result > 0)) {
137 $error++;
138 }
139 }
140
141 if (!$error) {
142 $db->commit();
143 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
144 } else {
145 $db->rollback();
146 if (empty($errorsaved)) {
147 setEventMessages($langs->trans("Error"), null, 'errors');
148 }
149 }
150 }
151}
152
153/*
154 * View
155 */
156
157$form = new Form($db);
158$formadmin = new FormAdmin($db);
159$formother = new FormOther($db);
160
161$arrayofjs = array();
162$arrayofcss = array();
163
164$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
165$title = $person_name." - ".$langs->trans('ExtSites');
166$help_url = '';
167
168llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-user page-agenda_extsites');
169
170
171print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
172print '<input type="hidden" name="id" value="'.$id.'">';
173print '<input type="hidden" name="token" value="'.newToken().'">';
174
175$head = user_prepare_head($object);
176
177print dol_get_fiche_head($head, 'extsites', $langs->trans("User"), -1, 'user');
178
179$linkback = '';
180
181if ($user->hasRight('user', 'user', 'lire') || $user->admin) {
182 $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
183}
184
185$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" rel="noopener">';
186$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
187$morehtmlref .= '</a>';
188
189$urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
190$morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'refid valignmiddle nohover');
191
192dol_banner_tab($object, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin, 'rowid', 'ref', $morehtmlref);
193
194print '<div class="fichecenter">';
195
196print '<div class="underbanner clearboth"></div>';
197print '<table class="border tableforfield centpercent">';
198
199// Login
200print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
201if (!empty($object->ldap_sid) && $object->status == 0) {
202 print '<td class="error">';
203 print $langs->trans("LoginAccountDisableInDolibarr");
204 print '</td>';
205} else {
206 print '<td>';
207 $addadmin = '';
208 if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
209 $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "superadmin", 'class="paddingleft valignmiddle"');
210 } elseif (!empty($object->admin)) {
211 $addadmin .= img_picto($langs->trans("AdministratorDesc"), "admin", 'class="paddingleft valignmiddle"');
212 }
213 print showValueWithClipboardCPButton($object->login).$addadmin;
214 print '</td>';
215}
216print '</tr>'."\n";
217
218print '</table>';
219
220print '</div>';
221
222print dol_get_fiche_end();
223
224
225print '<br>';
226print '<span class="opacitymedium">'.$langs->trans("AgendaExtSitesDesc")."</span><br>\n";
227print "<br>\n";
228
229
230print '<div class="div-table-responsive-no-min">';
231print '<table class="noborder centpercent">';
232print '<tr class="liste_titre">';
233print '<td class="center">'.$langs->trans("AgendaExtNb", "")."</td>";
234print "<td>".$langs->trans("Name")."</td>";
235print "<td>".$langs->trans("ExtSiteUrlAgenda").'<div class="hideonsmartphone opacitymedium">'." (".$langs->trans("Example").': https://externalcalendar/agenda/agenda.ics)</div></td>';
236print "<td>".$form->textwithpicto($langs->trans("FixTZ"), $langs->trans("FillFixTZOnlyIfRequired"), 1).'</td>';
237print '<td class="right">'.$langs->trans("Color").'</td>';
238print "</tr>";
239
240$i = 1;
241while ($i <= $MAXAGENDA) {
242 $key = $i;
243 $name = 'AGENDA_EXT_NAME_'.$id.'_'.$key;
244 $src = 'AGENDA_EXT_SRC_'.$id.'_'.$key;
245 $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key;
246 $color = 'AGENDA_EXT_COLOR_'.$id.'_'.$key;
247
248 print '<tr class="oddeven">';
249 // Nb @phan-suppress-next-line PhanPluginSuspiciousParamPosition
250 print '<td class="maxwidth50onsmartphone center">';
251 //print $langs->trans("AgendaExtNb", $key);
252 print $key;
253 print "</td>";
254 // Name
255 $name_value = (GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_NAME_'.$id.'_'.$key) : (empty($object->conf->$name) ? '' : $object->conf->$name));
256 print '<td><input type="text" class="flat hideifnotset minwidth100 maxwidth100onsmartphone" name="AGENDA_EXT_NAME_'.$id.'_'.$key.'" value="'.$name_value.'"></td>';
257 // URL
258 $src_value = (GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_SRC_'.$id.'_'.$key) : (empty($object->conf->$src) ? '' : $object->conf->$src));
259 print '<td><input type="url" class="flat hideifnotset width300" name="AGENDA_EXT_SRC_'.$id.'_'.$key.'" value="'.$src_value.'"></td>';
260 // Offset TZ
261 $offsettz_value = (GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) ? GETPOST('AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key) : (empty($object->conf->$offsettz) ? '' : $object->conf->$offsettz));
262 print '<td><input type="text" class="flat hideifnotset" name="AGENDA_EXT_OFFSETTZ_'.$id.'_'.$key.'" value="'.$offsettz_value.'" size="1"></td>';
263 // Color (Possible colors are limited by Google)
264 print '<td class="nowraponall right">';
265 $color_value = (GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) ? GETPOST("AGENDA_EXT_COLOR_".$id.'_'.$key) : (empty($object->conf->$color) ? 'ffffff' : $object->conf->$color));
266 print $formother->selectColor($color_value, "AGENDA_EXT_COLOR_".$id.'_'.$key, '', 1, array(), 'hideifnotset');
267 print '</td>';
268 print "</tr>";
269 $i++;
270}
271
272print '</table>';
273print '</div>';
274
275$addition_button = array(
276 'name' => 'save',
277 'label_key' => 'Save',
278 'addclass' => 'hideifnotset',
279);
280print $form->buttonsSaveCancel("", "", $addition_button);
281
282print dol_get_fiche_end();
283
284print "</form>\n";
285
286// End of page
287llxFooter();
288$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
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition inc.php:426
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.