dolibarr 21.0.0-beta
virtualcard.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32
42// Load translation files required by page
43$langs->loadLangs(array("users", "companies", "admin", "website"));
44
45// Security check
46$id = GETPOSTINT('id');
47$ref = GETPOST('ref', 'alpha');
48$action = GETPOST('action', 'aZ09');
49$dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
50
51if (empty($id) && empty($ref)) {
52 $id = $user->id;
53}
54
55$expand = $_COOKIE['virtualcard_expand'];
56
57$object = new User($db);
58if ($id > 0 || !empty($ref)) {
59 $result = $object->fetch($id, $ref, '', 1);
60 $object->loadRights();
61}
62
63// Security check
64$socid = 0;
65if ($user->socid > 0) {
66 $socid = $user->socid;
67}
68$feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
69
70$result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
71
72// If user is not the user that read and has no permission to read other users, we stop
73if (($object->id != $user->id) && !$user->hasRight('user', 'user', 'lire')) {
75}
76
77$permissiontoedit = ((($object->id == $user->id) && $user->hasRight('user', 'self', 'creer')) || $user->hasRight('user', 'user', 'creer'));
78
79
80/*
81 * Actions
82 */
83
84if ($action == 'update' && $permissiontoedit) {
85 $tmparray = array();
86 $tmparray['USER_PUBLIC_MORE'] = GETPOST('USER_PUBLIC_MORE', 'alphanohtml');
87
88 dol_set_user_param($db, $conf, $object, array('USER_PUBLIC_MORE' => $tmparray['USER_PUBLIC_MORE']));
89}
90
91if ($action == 'setUSER_ENABLE_PUBLIC' && $permissiontoedit) {
92 if (GETPOST('value')) {
93 $tmparray = array('USER_ENABLE_PUBLIC' => 1);
94 } else {
95 $tmparray = array('USER_ENABLE_PUBLIC' => 0);
96 }
97 dol_set_user_param($db, $conf, $object, $tmparray);
98}
99
100
101/*
102 * View
103 */
104
105$form = new Form($db);
106
107$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
108$title = $person_name." - ".$langs->trans('Info');
109$help_url = '';
110
111llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-virtualcard');
112
113
114$title = $langs->trans("User");
115//print dol_get_fiche_head($head, 'info', $title, -1, 'user');
116
117
118print '<div class="fichecenter">';
119
120print '<br>';
121
122$param = '&id='.((int) $object->id);
123if (GETPOSTISSET('dol_openinpopup')) {
124 $param .= '&dol_openinpopup='.urlencode(GETPOST('dol_openinpopup', 'aZ09'));
125}
126
127$enabledisablehtml = $langs->trans("EnablePublicVirtualCard").' ';
128if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
129 // Button off, click to enable
130 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setUSER_ENABLE_PUBLIC&token='.newToken().'&value=1'.$param.'">';
131 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
132 $enabledisablehtml .= '</a>';
133
134 $enabledisablehtml .= '<br><br><div class="opacitymedium justify">'.$langs->trans("UserPublicPageDesc").'</div>';
135} else {
136 // Button on, click to disable
137 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setUSER_ENABLE_PUBLIC&token='.newToken().'&value=0'.$param.'">';
138 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
139 $enabledisablehtml .= '</a>';
140}
141print $enabledisablehtml;
142print '<input type="hidden" id="USER_ENABLE_PUBLIC" name="USER_ENABLE_PUBLIC" value="'.(getDolUserInt('USER_ENABLE_PUBLIC') ? 1 : 0).'">';
143
144
145print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
146
147if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
148 print '<br><br>';
149
150 print '<input type="hidden" name="action" value="update">';
151 print '<input type="hidden" name="id" value="'.$object->id.'">';
152 print '<input type="hidden" name="token" value="'.newToken().'">';
153
154 //print $langs->trans('FollowingLinksArePublic').'<br>';
155 print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('PublicVirtualCardUrl').'</span><br>';
156
157 $fullexternaleurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'external');
158 $fullinternalurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'internal');
159
160 $showUserSocialNetworks = !getDolUserString('USER_PUBLIC_HIDE_SOCIALNETWORKS', '', $object);
161 $showSocieteSocialNetworks = !getDolUserString('USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS', '', $object);
162
163 print '<div class="urllink">';
164 print '<input type="text" id="publicurluser" class="quatrevingtpercentminusx" value="'.$fullexternaleurltovirtualcard.'">';
165 print '<a target="_blank" rel="noopener noreferrer" href="'.$fullexternaleurltovirtualcard.'">'.img_picto('', 'globe', 'class="paddingleft marginrightonly paddingright"').$langs->trans("GoTo").'...</a>';
166 print '</div>';
167 print ajax_autoselect('publicurluser');
168
169 print '<br>';
170 print '<br>';
171
172 // Show/Hide options
173 print '<div class="centpercent margintoponly marginbottomonly">';
174 print img_picto('', 'setup', 'class="pictofixedwidth"').'<a id="lnk" href="#">'.$langs->trans("ShowAdvancedOptions").'...</a>';
175 print '</div>';
176
177 print '<script type="text/javascript">
178 jQuery(document).ready(function() {
179 jQuery("#lnk").click(function(event) {
180 event.preventDefault();
181 console.log("We click on link to show virtual card options");
182 hideoptions(this);
183 });
184 });
185
186 function hideoptions(domelem) {
187 const div = document.getElementById("div_container_sub_exportoptions");
188
189 if (div.style.display === "none") {
190 div.style.display = "block";
191 domelem.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("HideAdvancedoptions")).'";
192 var date = new Date();
193 date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
194 document.cookie = "virtualcard_expand=1; expires=" + date.toUTCString() + "; path=/";
195 } else {
196 div.style.display = "none";
197 domelem.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("ShowAdvancedOptions")).'...";
198 var date = new Date();
199 date.setTime(date.getTime() - (1 * 24 * 60 * 60 * 1000));
200 document.cookie = "virtualcard_expand=0; expires=" + date.toUTCString() + "; path=/";
201 }
202 }
203 </script>';
204
205 // Start div hide/Show
206 print '<div id="div_container_sub_exportoptions" style="'.($expand ? '' : 'display: none;').'">';
207
208 print '<div class="div-table-responsive-no-min">';
209 print '<table class="noborder centpercent">';
210
211 print '<tr class="liste_titre">';
212 print '<td>'.$langs->trans("User").'</td>';
213 print '<td></td>';
214 print "</tr>\n";
215
216 // User photo
217 print '<tr class="oddeven" id="tredit"><td>';
218 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Photo"));
219 print '</td><td>';
220 print ajax_constantonoff("USER_PUBLIC_HIDE_PHOTO", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
221 print "</td></tr>\n";
222
223 // Job position
224 print '<tr class="oddeven" id="tredit"><td>';
225 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PostOrFunction"));
226 print '</td><td>';
227 print ajax_constantonoff("USER_PUBLIC_HIDE_JOBPOSITION", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
228 print "</td></tr>\n";
229
230 // Email
231 print '<tr class="oddeven" id="tredit"><td>';
232 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Email"));
233 print '</td><td>';
234 print ajax_constantonoff("USER_PUBLIC_HIDE_EMAIL", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
235 print "</td></tr>\n";
236
237 // Office phone
238 print '<tr class="oddeven" id="tredit"><td>';
239 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhonePro"));
240 print '</td><td>';
241 print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_PHONE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
242 print "</td></tr>\n";
243
244 // Office fax
245 print '<tr class="oddeven" id="tredit"><td>';
246 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Fax"));
247 print '</td><td>';
248 print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_FAX", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
249 print "</td></tr>\n";
250
251 // User mobile
252 print '<tr class="oddeven" id="tredit"><td>';
253 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhoneMobile"));
254 print '</td><td>';
255 print ajax_constantonoff("USER_PUBLIC_HIDE_USER_MOBILE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
256 print "</td></tr>\n";
257
258 // Social networks
259 print '<tr class="oddeven" id="tredit"><td>';
260 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("SocialNetworksInformation"));
261 print '</td><td>';
262 print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
263 print "</td></tr>\n";
264
265 // Show list of socialnetworks for user
266 if ($showUserSocialNetworks) {
267 $socialnetworks = $object->socialnetworks;
268 if (!empty($socialnetworks)) {
269 foreach ($socialnetworks as $key => $networkVal) {
270 print '<tr class="oddeven">';
271 print '<td> &nbsp; &nbsp; '.$langs->trans("Hide").' '.dol_escape_htmltag($key).'</td><td>';
272 print ajax_constantonoff('USER_PUBLIC_HIDE_SOCIALNETWORKS_'.strtoupper($key), array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
273 print '</td>';
274 print "</tr>";
275 }
276 }
277 }
278
279 // Birth date
280 print '<tr class="oddeven" id="tredit"><td>';
281 print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Birthdate"));
282 print '</td><td>';
283 print ajax_constantonoff("USER_PUBLIC_SHOW_BIRTH", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
284 print "</td></tr>\n";
285
286 // Address
287 print '<tr class="oddeven" id="tredit"><td>';
288 print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Address"));
289 print '</td><td>';
290 print ajax_constantonoff("USER_PUBLIC_SHOW_ADDRESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
291 print "</td></tr>\n";
292
293 print '<tr class="liste_titre">';
294 print '<td>'.$langs->trans("Company").'</td>';
295 print '<td></td>';
296 print "</tr>\n";
297
298 // Company section
299 print '<tr class="oddeven" id="tramount"><td>';
300 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("CompanySection"));
301 print '</td><td>';
302 print ajax_constantonoff("USER_PUBLIC_HIDE_COMPANY", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
303 print "</td></tr>\n";
304
305 if (!getDolUserString('USER_PUBLIC_HIDE_COMPANY', '', $object)) {
306 // Email
307 print '<tr class="oddeven" id="tredit"><td>';
308 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Email"));
309 print '</td><td>';
310 print ajax_constantonoff("SOCIETE_PUBLIC_HIDE_EMAIL", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
311 print "</td></tr>\n";
312
313 // URL
314 print '<tr class="oddeven" id="tredit"><td>';
315 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("URL"));
316 print '</td><td>';
317 print ajax_constantonoff("SOCIETE_PUBLIC_HIDE_URL", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
318 print "</td></tr>\n";
319
320 // Office phone
321 print '<tr class="oddeven" id="tredit"><td>';
322 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Phone"));
323 print '</td><td>';
324 print ajax_constantonoff("SOCIETE_PUBLIC_HIDE_OFFICE_PHONE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
325 print "</td></tr>\n";
326
327 // Office fax
328 print '<tr class="oddeven" id="tredit"><td>';
329 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Fax"));
330 print '</td><td>';
331 print ajax_constantonoff("SOCIETE_PUBLIC_HIDE_OFFICE_FAX", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
332 print "</td></tr>\n";
333
334 // Social networks
335 print '<tr class="oddeven" id="tredit"><td>';
336 print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("SocialNetworksInformation"));
337 print '</td><td>';
338 print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
339 print "</td></tr>\n";
340
341 // Show list of social networks for company
342 if ($showSocieteSocialNetworks) {
343 $listofnetworks = $mysoc->socialnetworks;
344
345 if (!empty($listofnetworks)) {
346 foreach ($listofnetworks as $key => $networkVal) {
347 print '<tr class="oddeven">';
348 print '<td> &nbsp; &nbsp; '.$langs->trans("Hide").' '.dol_escape_htmltag($key).'</td><td>';
349 print ajax_constantonoff('SOCIETE_PUBLIC_HIDE_SOCIALNETWORKS_'.strtoupper($key), array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object);
350 print '</td>';
351 print "</tr>";
352 }
353 }
354 }
355 }
356
357 print '<tr class="liste_titre">';
358 print '<td>'.$langs->trans("Other").'</td>';
359 print '<td></td>';
360 print "</tr>\n";
361
362 // More
363 print '<tr class="oddeven" id="tredit"><td>';
364 print $langs->trans("Text");
365 print '</td><td>';
366 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
367 $extendededitor = 0; // We force no WYSIWYG editor
368 $doleditor = new DolEditor('USER_PUBLIC_MORE', getDolUserString('USER_PUBLIC_MORE', '', $object), '', 160, 'dolibarr_notes', '', false, false, $extendededitor, ROWS_5, '90%');
369 $doleditor->Create();
370 print "</td></tr>\n";
371
372 print '</table>';
373 print '</div>';
374
375 print '<div class="center">';
376 print $form->buttonsSaveCancel("Save", '', array(), 0, '', $dol_openinpopup);
377 print '</div>';
378
379 print '<br>';
380
381 print '</div>'; // End hide/show
382
383 print '<br>';
384
385 // Preview
386 print '<div class="center">';
387 print '<span class="opacitymedium">'.$langs->trans("Preview").'</span><br>';
388 print '<div class="virtualcard-div">';
389 print '<a target="_blank" rel="noopener noreferrer cursorpointer" href="'.$fullexternaleurltovirtualcard.'">'."\n";
390 print '<iframe id="virtualcard-iframe" title="" class="center" src="'.$fullinternalurltovirtualcard.'&mode=preview">';
391 print '</iframe>';
392 print '</a>';
393 print '</div>';
394 print '</div>';
395
396 print '<br>';
397}
398
399
400print '</form>';
401
402print '</div>';
403
404
405// End of page
406llxFooter();
407$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 manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
dol_set_user_param($db, $conf, &$user, $tab)
Save personal parameter.
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.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.