diff --git a/htdocs/adherents/admin/website.php b/htdocs/adherents/admin/website.php index 08e9f617750..14379166247 100644 --- a/htdocs/adherents/admin/website.php +++ b/htdocs/adherents/admin/website.php @@ -178,7 +178,7 @@ if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) { //print $langs->trans('FollowingLinksArePublic').'
'; print img_picto('', 'globe').' '.$langs->trans('BlankSubscriptionForm').'
'; if (isModEnabled('multicompany')) { - $entity_qr = '?entity='.$conf->entity; + $entity_qr = '?entity='.((int) $conf->entity); } else { $entity_qr = ''; } diff --git a/htdocs/core/class/vcard.class.php b/htdocs/core/class/vcard.class.php index dbe505a894b..91e3a5565e1 100644 --- a/htdocs/core/class/vcard.class.php +++ b/htdocs/core/class/vcard.class.php @@ -1,4 +1,7 @@ * Copyright (C) 2005-2017 Laurent Destailleur * Copyright (C) 2020 Tobias Sekan @@ -367,6 +370,90 @@ class vCard return $this->filename; } + /** + * Return a VCARD string + * + * @param Object $object Object + * @param Societe $company Company + * @param Translate $langs Lang object + * @return string String + */ + public function buildVCardString($object, $company, $langs) + { + $this->setProdId('Dolibarr '.DOL_VERSION); + + $this->setUid('DOLIBARR-USERID-'.$object->id); + $this->setName($object->lastname, $object->firstname, "", $object->civility_code, ""); + $this->setFormattedName($object->getFullName($langs, 1)); + + $this->setPhoneNumber($object->office_phone, "TYPE=WORK;VOICE"); + $this->setPhoneNumber($object->personal_mobile, "TYPE=HOME;VOICE"); + $this->setPhoneNumber($object->user_mobile, "TYPE=CELL;VOICE"); + $this->setPhoneNumber($object->office_fax, "TYPE=WORK;FAX"); + + $country = $object->country_code ? $object->country : ''; + + $this->setAddress("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK;POSTAL"); + $this->setLabel("", "", $object->address, $object->town, $object->state, $object->zip, $country, "TYPE=WORK"); + + $this->setEmail($object->email, "TYPE=WORK"); + $this->setNote($object->note_public); + $this->setTitle($object->job); + + if ($company->id > 0) { + $this->setURL($company->url, "TYPE=WORK"); + if (!$object->office_phone) { + $this->setPhoneNumber($company->phone, "TYPE=WORK;VOICE"); + } + if (!$object->office_fax) { + $this->setPhoneNumber($company->fax, "TYPE=WORK;FAX"); + } + if (!$object->zip) { + $this->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL"); + } + + // when company e-mail is empty, use only user e-mail + if (empty(trim($company->email))) { + // was set before, don't set twice + } elseif (empty(trim($object->email))) { + // when user e-mail is empty, use only company e-mail + $this->setEmail($company->email, "TYPE=WORK"); + } else { + $tmpuser2 = explode("@", trim($object->email)); + $tmpcompany = explode("@", trim($company->email)); + + if (strtolower(end($tmpuser2)) == strtolower(end($tmpcompany))) { + // when e-mail domain of user and company are the same, use user e-mail at first (and company e-mail at second) + $this->setEmail($object->email, "TYPE=WORK"); + + // support by Microsoft Outlook (2019 and possible earlier) + $this->setEmail($company->email, 'INTERNET'); + } else { + // when e-mail of user and company complete different use company e-mail at first (and user e-mail at second) + $this->setEmail($company->email, "TYPE=WORK"); + + // support by Microsoft Outlook (2019 and possible earlier) + $this->setEmail($object->email, 'INTERNET'); + } + } + + // Si user lie a un tiers non de type "particulier" + if ($company->typent_code != 'TE_PRIVATE') { + $this->setOrg($company->name); + } + } + + // Personal informations + $this->setPhoneNumber($object->personal_mobile, "TYPE=HOME;VOICE"); + if ($object->birth) { + $this->setBirthday($object->birth); + } + + // Return VCard string + return $this->getVCard(); + } + + /* Example from Microsoft Outlook 2019 BEGIN:VCARD diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7ac6150c5ac..ac774209d30 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -101,31 +101,41 @@ function getDolGlobalInt($key, $default = 0) } /** - * Return dolibarr user constant string value + * Return Dolibarr user constant string value * * @param string $key key to return value, return '' if not set * @param string $default value to return + * @param User $tmpuser To get another user than current user * @return string */ -function getDolUserString($key, $default = '') +function getDolUserString($key, $default = '', $tmpuser = null) { - global $user; + if (empty($tmpuser)) { + global $user; + $tmpuser = $user; + } + // return $conf->global->$key ?? $default; - return (string) (empty($user->conf->$key) ? $default : $user->conf->$key); + return (string) (empty($tmpuser->conf->$key) ? $default : $$tmpuser->conf->$key); } /** - * Return dolibarr user constant int value + * Return Dolibarr user constant int value * * @param string $key key to return value, return 0 if not set * @param int $default value to return + * @param User $tmpuser To get another user than current user * @return int */ -function getDolUserInt($key, $default = 0) +function getDolUserInt($key, $default = 0, $tmpuser = null) { - global $user; + if (empty($tmpuser)) { + global $user; + $tmpuser = $user; + } + // return $conf->global->$key ?? $default; - return (int) (empty($user->conf->$key) ? $default : $user->conf->$key); + return (int) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key); } /** @@ -1717,7 +1727,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = * * @param string $name A name for the html component * @param string $label Label shown in Popup title top bar - * @param string $buttonstring button string + * @param string $buttonstring button string (HTML text we can click on) * @param string $url Relative Url to open. For example '/project/card.php' * @param string $disabled Disabled text * @param string $morecss More CSS @@ -1725,7 +1735,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = * Value is 'keyforpopupid:Name_of_html_component_to_set_with id,Name_of_html_component_to_set_with_label' * @return string HTML component with button */ -function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '', $morecss = 'button bordertransp', $backtopagejsfields = '') +function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '', $morecss = 'classlink button bordertransp', $backtopagejsfields = '') { global $conf; @@ -1753,7 +1763,7 @@ function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $di //print ''; $out .= ''; - $out .= 'use_javascript_ajax)) { $out .= ' href="'.DOL_URL_ROOT.$url.'" target="_blank"'; } @@ -2239,6 +2249,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } } + // Show barcode if ($showbarcode) { $morehtmlleft .= '
'.$form->showbarcode($object, 100, 'photoref valignmiddle').'
'; } @@ -2988,9 +2999,10 @@ function dol_print_size($size, $shortvalue = 0, $shortunit = 0) * @param string $target Target for link * @param int $max Max number of characters to show * @param int $withpicto With picto + * @param string $morecss More CSS * @return string HTML Link */ -function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0) +function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0, $morecss = 'float') { global $langs; @@ -3013,7 +3025,12 @@ function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0) } $link .= dol_trunc($url, $max); $link .= '
'; - return '
'.($withpicto ?img_picto($langs->trans("Url"), 'globe').' ' : '').$link.'
'; + + if ($morecss == 'float') { + return '
'.($withpicto ?img_picto($langs->trans("Url"), 'globe').' ' : '').$link.'
'; + } else { + return ''.($withpicto ?img_picto($langs->trans("Url"), 'globe').' ' : '').$link.''; + } } /** @@ -4067,7 +4084,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'autofill', 'folder', 'folder-open', 'folder-plus', 'generate', 'globe', 'globe-americas', 'graph', 'grip', 'grip_title', 'group', 'help', 'holiday', - 'images', 'incoterm', 'info', 'intervention', 'inventory', 'intracommreport', 'knowledgemanagement', + 'id-card', 'images', 'incoterm', 'info', 'intervention', 'inventory', 'intracommreport', 'knowledgemanagement', 'label', 'language', 'line', 'link', 'list', 'list-alt', 'listlight', 'loan', 'lock', 'lot', 'long-arrow-alt-right', 'margin', 'map-marker-alt', 'member', 'meeting', 'money-bill-alt', 'movement', 'mrp', 'note', 'next', 'off', 'on', 'order', @@ -4134,7 +4151,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'supplier'=>'building', 'technic'=>'cogs', 'timespent'=>'clock', 'title_setup'=>'tools', 'title_accountancy'=>'money-check-alt', 'title_bank'=>'university', 'title_hrm'=>'umbrella-beach', 'title_agenda'=>'calendar-alt', - 'uncheck'=>'times', 'uparrow'=>'share', 'url'=>'external-link-alt', 'vat'=>'money-check-alt', 'vcard'=>'address-card', + 'uncheck'=>'times', 'uparrow'=>'share', 'url'=>'external-link-alt', 'vat'=>'money-check-alt', 'vcard'=>'arrow-alt-circle-down', 'jabber'=>'comment-o', 'website'=>'globe-americas', 'workstation'=>'pallet', 'webhook'=>'bullseye', 'world'=>'globe', 'private'=>'user-lock', 'conferenceorbooth'=>'chalkboard-teacher', 'eventorganization'=>'project-diagram' diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 692d01f9ef0..6b51cf76150 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1784,7 +1784,7 @@ function weight_convert($weight, &$from_unit, $to_unit) * @param DoliDB $db Handler database * @param Conf $conf Object conf * @param User $user Object user - * @param array $tab Array (key=>value) with all parameters to save + * @param array $tab Array (key=>value) with all parameters to save/update * @return int <0 if KO, >0 if OK * * @see dolibarr_get_const(), dolibarr_set_const(), dolibarr_del_const() diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index 757e9f1dedf..2f691153292 100644 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -129,3 +129,6 @@ IPLastLogin=IP last login IPPreviousLogin=IP previous login ShowAllPerms=Show all permission rows HideAllPerms=Hide all permission rows +UserPublicPageDesc=You can enable a virtual card for this user. An url with the user profile and a barcode will be available to allow anybody with a smartphone to scan it and add your contact to its address book. +EnablePublicVirtualCard=Enable the public virtual user card +PublicVirtualCardUrl=Public virtual user card \ No newline at end of file diff --git a/htdocs/public/users/view.php b/htdocs/public/users/view.php new file mode 100644 index 00000000000..2bc5e8e9245 --- /dev/null +++ b/htdocs/public/users/view.php @@ -0,0 +1,381 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/public/users/view.php + * \ingroup user + * \brief Public file to user profile + */ + +if (!defined('NOLOGIN')) { + define("NOLOGIN", 1); // This means this output page does not require to be logged. +} +if (!defined('NOCSRFCHECK')) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. +} +if (!defined('NOIPCHECK')) { + define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} + +// Load Dolibarr environment +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array("companies", "other", "recruitment")); + +// Get parameters +$action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'alpha'); +$backtopage = ''; + +$id = GETPOST('id', 'int'); +$securekey = GETPOST('securekey', 'alpha'); +$suffix = GETPOST('suffix'); + +$object = new User($db); +$object->fetch($id, '', '', 1); + +// Define $urlwithroot +//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); +//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost. + +// Security check +global $dolibarr_main_instance_unique_id; +$encodedsecurekey = dol_hash($dolibarr_main_instance_unique_id.'uservirtualcard'.$object->id.'-'.$object->login, 'md5'); +if ($encodedsecurekey != $securekey) { + httponly_accessforbidden('User profile page not found or not allowed'); +} + + +/* + * Actions + */ + +if ($cancel) { + if (!empty($backtopage)) { + header("Location: ".$backtopage); + exit; + } + $action = 'view'; +} + +/* +if ($action == "view" || $action == "presend" || $action == "dosubmit") { + $error = 0; + $display_ticket = false; + if (!strlen($ref)) { + $error++; + array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref"))); + $action = ''; + } + if (!strlen($email)) { + $error++; + array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email"))); + $action = ''; + } else { + if (!isValidEmail($email)) { + $error++; + array_push($object->errors, $langs->trans("ErrorEmailInvalid")); + $action = ''; + } + } + + if (!$error) { + $ret = $object->fetch('', $ref); + } + + if ($error || $errors) { + setEventMessages($object->error, $object->errors, 'errors'); + if ($action == "dosubmit") { + $action = 'presend'; + } else { + $action = ''; + } + } +} +*/ +//var_dump($action); +//$object->doActions($action); + +// Actions to send emails (for ticket, we need to manage the addfile and removefile only) +/*$triggersendname = 'USER_SENTBYMAIL'; +$paramname = 'id'; +$autocopy = 'MAIN_MAIL_AUTOCOPY_USER_TO'; // used to know the automatic BCC to add +$trackid = 'use'.$object->id; +include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; +*/ + + +/* + * View + */ + +$form = new Form($db); +$company = $mysoc; + +if ($action == 'vcard') { + // We create VCard + $v = new vCard(); + $output = $v->buildVCardString($object, $company, $langs); + + $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf" + $filenameurlencoded = dol_sanitizeFileName(urlencode($filename)); + //$filename = dol_sanitizeFileName($filename); + + top_httphead('text/x-vcard; name="'.$filename.'"'); + + header("Content-Disposition: attachment; filename=\"".$filename."\""); + header("Content-Length: ".dol_strlen($output)); + header("Connection: close"); + + print $output; + + $db->close(); + + exit; +} + +$head = ''; +if (!empty($conf->global->MAIN_USER_PROFILE_CSS_URL)) { + $head = ''."\n"; +} + +$conf->dol_hide_topmenu = 1; +$conf->dol_hide_leftmenu = 1; + +if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) { + $langs->load("errors"); + print '
'.$langs->trans('ErrorPublicInterfaceNotEnabled').'
'; + $db->close(); + exit(); +} + +$arrayofjs = array(); +$arrayofcss = array(); + +$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
' : '').'
'; +llxHeader($head, $langs->trans("UserProfile").' '.$object->getFullName($langs), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1, 1); + +print ''."\n"; +print '
'."\n"; +print '
'."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''; +print "\n"; +print ''."\n"; + +$modulepart = 'user'; +$imagesize = 'small'; +$dir = $conf->user->dir_output; +$email = $object->email; + +// Show logo (search order: logo defined by ONLINE_SIGN_LOGO_suffix, then ONLINE_SIGN_LOGO_, then small company logo, large company logo, theme logo, common logo) +// Define logo and logosmall +$logo = ''; +$logosmall = ''; +if (!empty($object->photo)) { + if (dolIsAllowedForPreview($object->photo)) { + $logosmall = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.getImageFileNameForSize($object->photo, '_small'); + $logo = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.$object->photo; + //$originalfile = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.$object->photo; + } +} +//print ''."\n"; +// Define urllogo +$urllogo = ''; +$urllogofull = ''; +if (!empty($logosmall) && is_readable($conf->user->dir_output.'/'.$logosmall)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file='.urlencode($logosmall); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file='.urlencode($logosmall); +} elseif (!empty($logo) && is_readable($conf->user->dir_output.'/'.$logo)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file='.urlencode($logo); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file='.urlencode($logo); +} + +// Output html code for logo +print '
'; +print '
'; + +// Show photo +if ($urllogo) { + /*if (!empty($mysoc->url)) { + print ''; + }*/ + print ''; + /*if (!empty($mysoc->url)) { + print ''; + }*/ +} +print '
'; +/*if (empty($conf->global->MAIN_HIDE_POWERED_BY)) { + print ''; +}*/ +print '
'; + + +if (!empty($conf->global->USER_IMAGE_PUBLIC_INTERFACE)) { + print '
'; + print ''; + print '
'; +} + +$urlforqrcode = $_SERVER["PHP_SELF"].'?action=vcard&id='.((int) $object->id).'&securekey='.urlencode($securekey); + +// Show barcode +$showbarcode = GETPOST('nobarcode') ? 0 : 1; +if ($showbarcode) { + print '
'; + print '
'; + print 'QRCODE...
'; + print $urlforqrcode; + print '
'; + print '
'; + print '
'; +} + + +print '
'.$langs->trans("Me").'
'."\n"; +print ''."\n"; + +// Output payment summary form +print ''."\n"; + +print '
'; + +print '
'; + +print '
'; + +// Add contact info +print '...'; + +print '
'; + + +print '
'."\n"; +print "\n"; + +print '
'."\n"; + + + + +print '
'.$langs->trans("MyCompany").'
'."\n"; +print ''."\n"; + +// Output payment summary form +print ''."\n"; + +print '
'; + +print '
'; + +// Add company info + + +// Show logo (search order: logo defined by ONLINE_SIGN_LOGO_suffix, then ONLINE_SIGN_LOGO_, then small company logo, large company logo, theme logo, common logo) +// Define logo and logosmall +$logosmall = $mysoc->logo_small; +$logo = $mysoc->logo; +$paramlogo = 'ONLINE_USER_LOGO_'.$suffix; +if (!empty($conf->global->$paramlogo)) { + $logosmall = $conf->global->$paramlogo; +} elseif (!empty($conf->global->ONLINE_USER_LOGO)) { + $logosmall = $conf->global->ONLINE_USER_LOGO; +} +//print ''."\n"; +// Define urllogo +$urllogo = ''; +$urllogofull = ''; +if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall); +} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); + $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo); +} +// Output html code for logo +if ($urllogo) { + print '
'; + if (!empty($mysoc->url)) { + print ''; + } + print ''; + if (!empty($mysoc->url)) { + print ''; + } + print '
'; +} + + +if ($mysoc->email) { + print '
'; + print img_picto('', 'email', 'class="pictofixedwidth"').dol_print_email($mysoc->email, 0, 0, 1); + print '
'; +} + +if ($mysoc->url) { + print '
'; + print img_picto('', 'globe', 'class="pictofixedwidth"'); + //print 'rr'; + print dol_print_url($mysoc->url, '_blank', 0, 0, ''); + print '
'; +} + + +print '
'."\n"; +print "\n"; + +print '
'."\n"; + + + +// Description +$text = getDolUserString('USER_PUBLIC_MORE', '', $object); +print $text; + + +print '
'."\n"; +print '
'."\n"; +print '
'; + + +//htmlPrintOnlinePaymentFooter($mysoc, $langs); + +print ''; + +llxFooter('', 'public'); + +$db->close(); diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 4f44ab20bad..983e571e399 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -910,7 +910,9 @@ textarea.centpercent { .nomarginright { margin-: unset; } - +.nowidthimp { + width: unset !important; +} .cursordefault { cursor: default; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 41c20074d6a..89358053ef3 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -1147,6 +1147,9 @@ textarea.centpercent { .nomarginright { margin-: unset; } +.nowidthimp { + width: unset !important; +} .cursordefault { cursor: default; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index f26d61da521..8fceddf313b 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1432,10 +1432,18 @@ if ($action == 'create' || $action == 'adduserldap') { if ($action != 'edit') { print dol_get_fiche_head($head, 'user', $title, -1, 'user'); - $morehtmlref = ''; + $morehtmlref = ''; $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); $morehtmlref .= ''; + //$urltovirtualcard = $object->getOnlineVirtualCardUrl(); + $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id); + + $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->trans("PublicVirtualCardUrl"), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover'); + /*$morehtmlref .= ''; + $morehtmlref .= img_picto($langs->trans("PublicVirtualCardUrl"), 'id-card', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= '';*/ + dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref); print '
'; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a4d4c7acfe6..9104dd5cfd4 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3786,6 +3786,30 @@ class User extends CommonObject } } + /** + * Return string with full Url to virtual card + * + * @return string Url string + */ + public function getOnlineVirtualCardUrl() + { + global $dolibarr_main_instance_unique_id, $dolibarr_main_url_root; + global $conf; + + $encodedsecurekey = dol_hash($dolibarr_main_instance_unique_id.'uservirtualcard'.$this->id.'-'.$this->login, 'md5'); + if (isModEnabled('multicompany')) { + $entity_qr = '&entity='.((int) $conf->entity); + } else { + $entity_qr = ''; + } + // Define $urlwithroot + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + return $urlwithroot.'/public/users/view.php?id='.$this->id.'&securekey='.$encodedsecurekey.$entity_qr; + } + /** * Load all objects into $this->users * diff --git a/htdocs/user/info.php b/htdocs/user/info.php index dfb1fe23d0b..3f5d1aea604 100644 --- a/htdocs/user/info.php +++ b/htdocs/user/info.php @@ -51,7 +51,7 @@ $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user'); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2); // If user is not user that read and no permission to read other users, we stop -if (($object->id != $user->id) && (!$user->rights->user->user->lire)) { +if (($object->id != $user->id) && empty($user->rights->user->user->lire)) { accessforbidden(); } diff --git a/htdocs/user/vcard.php b/htdocs/user/vcard.php index 6e7035d99ec..576d2b90a5b 100644 --- a/htdocs/user/vcard.php +++ b/htdocs/user/vcard.php @@ -21,8 +21,8 @@ /** * \file htdocs/user/vcard.php - * \ingroup societe - * \brief Onglet vcard d'un user + * \ingroup user + * \brief Page to return a user vcard */ // Load Dolibarr environment @@ -31,9 +31,6 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php'; -$user2 = new User($db); - - $id = GETPOST('id', 'int'); // Security check @@ -44,106 +41,38 @@ if ($user->socid > 0) { $feature2 = 'user'; $result = restrictedArea($user, 'user', $id, 'user', $feature2); - -$result = $user2->fetch($id); +$object = new User($db); +$result = $object->fetch($id); if ($result <= 0) { - dol_print_error($user2->error); + dol_print_error($object->error); exit; } -$physicalperson = 1; - +// Data from linked company $company = new Societe($db); -if ($user2->socid) { - $result = $company->fetch($user2->socid); +if ($object->socid > 0) { + $result = $company->fetch($object->socid); } + +/* + * View + */ + // We create VCard $v = new vCard(); -$v->setProdId('Dolibarr '.DOL_VERSION); - -$v->setUid('DOLIBARR-USERID-'.$user2->id); -$v->setName($user2->lastname, $user2->firstname, "", $user2->civility_code, ""); -$v->setFormattedName($user2->getFullName($langs, 1)); - -$v->setPhoneNumber($user2->office_phone, "TYPE=WORK;VOICE"); -$v->setPhoneNumber($user2->personal_mobile, "TYPE=HOME;VOICE"); -$v->setPhoneNumber($user2->user_mobile, "TYPE=CELL;VOICE"); -$v->setPhoneNumber($user2->office_fax, "TYPE=WORK;FAX"); - -$country = $user2->country_code ? $user2->country : ''; - -$v->setAddress("", "", $user2->address, $user2->town, $user2->state, $user2->zip, $country, "TYPE=WORK;POSTAL"); -$v->setLabel("", "", $user2->address, $user2->town, $user2->state, $user2->zip, $country, "TYPE=WORK"); - -$v->setEmail($user2->email, "TYPE=WORK"); -$v->setNote($user2->note_public); -$v->setTitle($user2->job); - -// Data from linked company -if ($company->id) { - $v->setURL($company->url, "TYPE=WORK"); - if (!$user2->office_phone) { - $v->setPhoneNumber($company->phone, "TYPE=WORK;VOICE"); - } - if (!$user2->office_fax) { - $v->setPhoneNumber($company->fax, "TYPE=WORK;FAX"); - } - if (!$user2->zip) { - $v->setAddress("", "", $company->address, $company->town, $company->state, $company->zip, $company->country, "TYPE=WORK;POSTAL"); - } - - // when company e-mail is empty, use only user e-mail - if (empty(trim($company->email))) { - // was set before, don't set twice - } elseif (empty(trim($user2->email))) { - // when user e-mail is empty, use only company e-mail - $v->setEmail($company->email, "TYPE=WORK"); - } else { - $tmpuser2 = explode("@", trim($user2->email)); - $tmpcompany = explode("@", trim($company->email)); - - if (strtolower(end($tmpuser2)) == strtolower(end($tmpcompany))) { - // when e-mail domain of user and company are the same, use user e-mail at first (and company e-mail at second) - $v->setEmail($user2->email, "TYPE=WORK"); - - // support by Microsoft Outlook (2019 and possible earlier) - $v->setEmail($company->email, 'INTERNET'); - } else { - // when e-mail of user and company complete different use company e-mail at first (and user e-mail at second) - $v->setEmail($company->email, "TYPE=WORK"); - - // support by Microsoft Outlook (2019 and possible earlier) - $v->setEmail($user2->email, 'INTERNET'); - } - } - - // Si user lie a un tiers non de type "particulier" - if ($company->typent_code != 'TE_PRIVATE') { - $v->setOrg($company->name); - } -} - -// Personal informations -$v->setPhoneNumber($user2->personal_mobile, "TYPE=HOME;VOICE"); -if ($user2->birth) { - $v->setBirthday($user2->birth); -} - -$db->close(); - -// Renvoi la VCard au navigateur - -$output = $v->getVCard(); +$output = $v->buildVCardString($object, $company, $langs); $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf" $filenameurlencoded = dol_sanitizeFileName(urlencode($filename)); //$filename = dol_sanitizeFileName($filename); +top_httphead('text/x-vcard; name="'.$filename.'"'); header("Content-Disposition: attachment; filename=\"".$filename."\""); header("Content-Length: ".dol_strlen($output)); header("Connection: close"); -header("Content-Type: text/x-vcard; name=\"".$filename."\""); print $output; + +$db->close(); diff --git a/htdocs/user/virtualcard.php b/htdocs/user/virtualcard.php new file mode 100644 index 00000000000..30dc32ad01c --- /dev/null +++ b/htdocs/user/virtualcard.php @@ -0,0 +1,248 @@ + + * Copyright (C) 2005-2015 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/user/virtualcard.php + * \ingroup core + * \brief Page to setup a virtual card + */ + +// Load Dolibarr environment +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; + +// Load translation files required by page +$langs->load("users"); + +// Security check +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'aZ09'); + +$object = new User($db); +if ($id > 0 || !empty($ref)) { + $result = $object->fetch($id, $ref, '', 1); + $object->getrights(); +} + +// Security check +$socid = 0; +if ($user->socid > 0) { + $socid = $user->socid; +} +$feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user'); + +$result = restrictedArea($user, 'user', $id, 'user&user', $feature2); + +// If user is not the user that read and has no permission to read other users, we stop +if (($object->id != $user->id) && empty($user->rights->user->user->lire)) { + accessforbidden(); +} + +/* + * Actions + */ + +if ($action == 'update') { + $tmparray = array(); + $tmparray['USER_PUBLIC_COMPANY_NAME'] = (GETPOST('USER_PUBLIC_COMPANY_NAME') ? 1 : 0); + $tmparray['USER_PUBLIC_JOBPOSITION'] = (GETPOST('USER_PUBLIC_JOBPOSITION') ? 1 : 0); + $tmparray['USER_PUBLIC_EMAIL'] = (GETPOST('USER_PUBLIC_EMAIL') ? 1 : 0); + $tmparray['USER_PUBLIC_PHONE'] = (GETPOST('USER_PUBLIC_PHONE') ? 1 : 0); + $tmparray['USER_PUBLIC_SOCIALNETWORKS'] = (GETPOST('USER_PUBLIC_SOCIALNETWORKS') ? 1 : 0); + $tmparray['USER_PUBLIC_MORE'] = (GETPOST('USER_PUBLIC_MORE') ? GETPOST('USER_PUBLIC_MORE') : ''); + + dol_set_user_param($db, $conf, $object, $tmparray); +} + +if ($action == 'setUSER_ENABLE_PUBLIC') { + if (GETPOST('value')) { + $tmparray = array('USER_ENABLE_PUBLIC' => 1); + } else { + $tmparray = array('USER_ENABLE_PUBLIC' => 0); + } + dol_set_user_param($db, $conf, $object, $tmparray); +} + + +/* + * View + */ + +$form = new Form($db); + +$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname; +$title = $person_name." - ".$langs->trans('Info'); +$help_url = ''; +llxHeader('', $title, $help_url); + +$head = user_prepare_head($object); + +$title = $langs->trans("User"); +//print dol_get_fiche_head($head, 'info', $title, -1, 'user'); + + +$linkback = ''; + +if ($user->rights->user->user->lire || $user->admin) { + $linkback = ''.$langs->trans("BackToList").''; +} + +$morehtmlref = ''; +$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); +$morehtmlref .= ''; + +//dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref); + + +print '
'; + +print '
'; + +/* + print ''.$langs->trans("VCard").'
'; + +print ''; +print img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); +print ''; + + +print '
'; +//print '
'; + +print '
'; +*/ + +print ''.$langs->trans("UserPublicPageDesc").'

'; + +$param = '&id='.((int) $object->id); + +$enabledisablehtml = $langs->trans("EnablePublicVirtualCard").' '; +if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) { + // Button off, click to enable + $enabledisablehtml .= ''; + $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off'); + $enabledisablehtml .= ''; +} else { + // Button on, click to disable + $enabledisablehtml .= ''; + $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on'); + $enabledisablehtml .= ''; +} +print $enabledisablehtml; +print ''; + +print '

'; + +print '
'; +print ''; +print ''; +print ''; + +if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) { + print '
'; + //print $langs->trans('FollowingLinksArePublic').'
'; + print img_picto('', 'globe').' '.$langs->trans('PublicVirtualCardUrl').'
'; + + $fullexternaleurltovirtualcard = $object->getOnlineVirtualCardUrl(); + + print ''; + print ajax_autoselect('publicurluser'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + print ''; + print "\n"; + + // Company name + print '\n"; + + // Job position + print '\n"; + + // Email + print '\n"; + + // Phone + print '\n"; + + // Social networks + print '\n"; + + // More + print '\n"; + + print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; + print $langs->trans("Company"); + print ''; + //print ''; + print $form->selectyesno("USER_PUBLIC_COMPANY_NAME", (getDolUserInt('USER_PUBLIC_COMPANY_NAME', 0, $object) ? getDolUserInt('USER_PUBLIC_COMPANY_NAME', 0, $object) : 0), 1); + print "
'; + print $langs->trans("PostOrFunction"); + print ''; + print $form->selectyesno("USER_PUBLIC_JOBPOSITION", (getDolUserInt('USER_PUBLIC_JOBPOSITION', 0, $object) ? getDolUserInt('USER_PUBLIC_JOBPOSITION', 0, $object) : 0), 1); + print "
'; + print $langs->trans("Email"); + print ''; + print $form->selectyesno("USER_PUBLIC_EMAIL", (getDolUserInt('USER_PUBLIC_EMAIL', 0, $object) ? getDolUserInt('USER_PUBLIC_EMAIL', 0, $object) : 0), 1); + print "
'; + print $langs->trans("Phone"); + print ''; + print $form->selectyesno("USER_PUBLIC_PHONE", (getDolUserInt('USER_PUBLIC_PHONE', 0, $object) ? getDolUserInt('USER_PUBLIC_PHONE', 0, $object) : 0), 1); + print "
'; + print $langs->trans("SocialNetworks"); + print ''; + print $form->selectyesno("USER_PUBLIC_SOCIALNETWORKS", (getDolUserInt('USER_PUBLIC_SOCIALNETWORKS', 0, $object) ? getDolUserInt('USER_PUBLIC_SOCIALNETWORKS', 0, $object) : 0), 1); + print "
'; + print $langs->trans("More"); + print ''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('USER_PUBLIC_MORE', getDolUserString('USER_PUBLIC_MORE', '', $object), '', 160, 'dolibarr_notes', '', false, false, isModEnabled('fckeditor'), ROWS_5, '90%'); + $doleditor->Create(); + print "
'; + print '
'; + + print '
'; + print ''; + print '
'; +} + + +print dol_get_fiche_end(); + +print '
'; + + +print '
'; + + +print dol_get_fiche_end(); + +// End of page +llxFooter(); +$db->close();