view.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <?php
  2. /* Copyright (C) 2020-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/public/users/view.php
  19. * \ingroup user
  20. * \brief Public file to user profile
  21. */
  22. if (!defined('NOLOGIN')) {
  23. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  24. }
  25. if (!defined('NOCSRFCHECK')) {
  26. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  27. }
  28. if (!defined('NOIPCHECK')) {
  29. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  30. }
  31. if (!defined('NOBROWSERNOTIF')) {
  32. define('NOBROWSERNOTIF', '1');
  33. }
  34. // Load Dolibarr environment
  35. require '../../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/vcard.class.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("companies", "other", "recruitment"));
  41. // Get parameters
  42. $action = GETPOST('action', 'aZ09');
  43. $mode = GETPOST('mode', 'aZ09');
  44. $cancel = GETPOST('cancel', 'alpha');
  45. $backtopage = '';
  46. $id = GETPOST('id', 'int');
  47. $securekey = GETPOST('securekey', 'alpha');
  48. $suffix = GETPOST('suffix');
  49. $object = new User($db);
  50. $object->fetch($id, '', '', 1);
  51. // Define $urlwithroot
  52. //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  53. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  54. $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
  55. // Security check
  56. global $dolibarr_main_instance_unique_id;
  57. $encodedsecurekey = dol_hash($dolibarr_main_instance_unique_id.'uservirtualcard'.$object->id.'-'.$object->login, 'md5');
  58. if ($encodedsecurekey != $securekey) {
  59. httponly_accessforbidden('Bad value for securitykey or public profile not enabled');
  60. }
  61. if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
  62. httponly_accessforbidden('Bad value for securitykey or public profile not enabled');
  63. }
  64. /*
  65. * Actions
  66. */
  67. if ($cancel) {
  68. if (!empty($backtopage)) {
  69. header("Location: ".$backtopage);
  70. exit;
  71. }
  72. $action = 'view';
  73. }
  74. /*
  75. * View
  76. */
  77. $form = new Form($db);
  78. $v = new vCard();
  79. $company = $mysoc;
  80. $modulepart = 'userphotopublic';
  81. $dir = $conf->user->dir_output;
  82. // 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)
  83. // Define logo and logosmall
  84. $logo = '';
  85. $logosmall = '';
  86. if (!empty($object->photo)) {
  87. if (dolIsAllowedForPreview($object->photo)) {
  88. $logosmall = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.getImageFileNameForSize($object->photo, '_small');
  89. $logo = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.$object->photo;
  90. //$originalfile = get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.$object->photo;
  91. }
  92. }
  93. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  94. // Define urllogo
  95. $urllogo = '';
  96. $urllogofull = '';
  97. if (!empty($logosmall) && is_readable($dir.'/'.$logosmall)) {
  98. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.($conf->entity > 1 ? '&amp;entity='.$conf->entity : '').'&amp;securekey='.urlencode($securekey).'&amp;file='.urlencode($logosmall);
  99. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart='.$modulepart.($conf->entity > 1 ? '&entity='.$conf->entity : '').'&securekey='.urlencode($securekey).'&file='.urlencode($logosmall);
  100. } elseif (!empty($logo) && is_readable($dir.'/'.$logo)) {
  101. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.($conf->entity > 1 ? '&amp;entity='.$conf->entity : '').'&amp;securekey='.urlencode($securekey).'&amp;file='.urlencode($logo);
  102. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart='.$modulepart.($conf->entity > 1 ? '&entity='.$conf->entity : '').'&securekey='.urlencode($securekey).'&file='.urlencode($logo);
  103. }
  104. // Clean data we don't want on public page
  105. if (getDolUserInt('USER_PUBLIC_HIDE_PHOTO', 0, $object)) {
  106. $logo = '';
  107. $logosmall = '';
  108. $urllogo = '';
  109. $urllogofull = '';
  110. }
  111. if (getDolUserInt('USER_PUBLIC_HIDE_JOBPOSITION', 0, $object)) {
  112. $object->job = '';
  113. }
  114. if (getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object)) {
  115. $object->email = '';
  116. }
  117. if (getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object)) {
  118. $object->job = '';
  119. }
  120. if (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_PHONE', 0, $object)) {
  121. $object->office_phone = '';
  122. }
  123. if (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_FAX', 0, $object)) {
  124. $object->office_fax = '';
  125. }
  126. if (getDolUserInt('USER_PUBLIC_HIDE_USER_MOBILE', 0, $object)) {
  127. $object->user_mobile = '';
  128. }
  129. if (getDolUserInt('USER_PUBLIC_HIDE_BIRTH', 0, $object)) {
  130. $object->birth = '';
  131. }
  132. if (getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS', 0, $object)) {
  133. $object->socialnetworks = '';
  134. }
  135. if (getDolUserInt('USER_PUBLIC_HIDE_ADDRESS', 0, $object)) {
  136. $object->address = '';
  137. $object->town = '';
  138. $object->zip = '';
  139. $object->state = '';
  140. $object->country = '';
  141. }
  142. if (getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object)) {
  143. $company = null;
  144. }
  145. // Output vcard
  146. if ($mode == 'vcard') {
  147. // We create VCard
  148. $output = $v->buildVCardString($object, $company, $langs, $urllogofull);
  149. $filename = trim(urldecode($v->getFileName())); // "Nom prenom.vcf"
  150. $filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
  151. //$filename = dol_sanitizeFileName($filename);
  152. top_httphead('text/vcard; name="'.$filename.'"');
  153. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  154. header("Content-Length: ".dol_strlen($output));
  155. header("Connection: close");
  156. print $output;
  157. $db->close();
  158. exit;
  159. }
  160. $head = '';
  161. if (!empty($conf->global->MAIN_USER_PROFILE_CSS_URL)) {
  162. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->MAIN_USER_PROFILE_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  163. }
  164. $conf->dol_hide_topmenu = 1;
  165. $conf->dol_hide_leftmenu = 1;
  166. if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
  167. $langs->load("errors");
  168. print '<div class="error">'.$langs->trans('ErrorPublicInterfaceNotEnabled').'</div>';
  169. $db->close();
  170. exit();
  171. }
  172. $arrayofjs = array();
  173. $arrayofcss = array();
  174. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  175. llxHeader($head, $object->getFullName($langs).' - '.$langs->trans("PublicVirtualCard"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'.(GETPOST('mode')=='preview' ? ' scalepreview cursorpointer virtualcardpreview' : ''), $replacemainarea, 1, 1);
  176. print '<span id="dolpaymentspan"></span>'."\n";
  177. print '<div class="center">'."\n";
  178. print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  179. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  180. print '<input type="hidden" name="action" value="dosubmit">'."\n";
  181. print '<input type="hidden" name="securekey" value="'.$securekey.'">'."\n";
  182. print '<input type="hidden" name="entity" value="'.$entity.'" />';
  183. print "\n";
  184. print '<!-- Form to view job -->'."\n";
  185. // Output html code for logo
  186. print '<div class="backgreypublicpayment">';
  187. print '<div class="logopublicpayment">';
  188. // Name
  189. print '<div class="double colortext">'.$object->getFullName($langs).'</div>';
  190. // User position
  191. if ($object->job && !getDolUserInt('USER_PUBLIC_HIDE_JOBPOSITION', 0, $object)) {
  192. print '<div class="">';
  193. print dol_escape_htmltag($object->job);
  194. print '</div>';
  195. }
  196. if (!getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object)) {
  197. print '<div class="bold">';
  198. print dol_escape_htmltag($mysoc->name);
  199. print '</div>';
  200. }
  201. print '</div>';
  202. /*if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  203. print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  204. }*/
  205. print '</div>';
  206. if (!empty($conf->global->USER_IMAGE_PUBLIC_INTERFACE)) {
  207. print '<div class="backimagepublicrecruitment">';
  208. print '<img id="idUSER_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->USER_IMAGE_PUBLIC_INTERFACE.'">';
  209. print '</div>';
  210. }
  211. $urlforqrcode = $object->getOnlineVirtualCardUrl('vcard');
  212. $socialnetworksdict = getArrayOfSocialNetworks();
  213. // Show barcode
  214. $showbarcode = GETPOST('nobarcode') ? 0 : 1;
  215. if ($showbarcode) {
  216. $qrcodecontent = $output = $v->buildVCardString($object, $company, $langs);
  217. print '<br>';
  218. print '<div class="floatleft inline-block valignmiddle paddingleft paddingright">';
  219. print '<img style="max-width: 100%" src="'.$dolibarr_main_url_root.'/viewimage.php?modulepart=barcode&entity='.((int) $conf->entity).'&generator=tcpdfbarcode&encoding=QRCODE&code='.urlencode($qrcodecontent).'">';
  220. print '</div>';
  221. print '<br>';
  222. }
  223. // Me section
  224. $usersection = '';
  225. // User email
  226. if ($object->email && !getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object)) {
  227. $usersection .= '<div class="flexitemsmall">';
  228. $usersection .= dol_print_email($object->email, 0, 0, 1, 0, 1, 1);
  229. $usersection .= '</div>';
  230. }
  231. // User url
  232. if ($object->url && !getDolUserInt('USER_PUBLIC_HIDE_URL', 0, $object)) {
  233. $usersection .= '<div class="flexitemsmall">';
  234. $usersection .= img_picto('', 'globe', 'class="pictofixedwidth"');
  235. $usersection .= dol_print_url($object->url, '_blank', 0, 0, '');
  236. $usersection .= '</div>';
  237. }
  238. // User phone
  239. if ($object->office_phone && !getDolUserInt('USER_PUBLIC_HIDE_OFFICE_PHONE', 0, $object)) {
  240. $usersection .= '<div class="flexitemsmall">';
  241. $usersection .= img_picto('', 'phone', 'class="pictofixedwidth"');
  242. $usersection .= dol_print_phone($object->office_phone, $object->country_code, 0, $mysoc->id, 'tel', ' ', 0, '');
  243. $usersection .= '</div>';
  244. }
  245. if ($object->office_fax && !getDolUserInt('USER_PUBLIC_HIDE_OFFICE_FAX', 0, $object)) {
  246. $usersection .= '<div class="flexitemsmall">';
  247. $usersection .= img_picto('', 'phoning_fax', 'class="pictofixedwidth"');
  248. $usersection .= dol_print_phone($object->office_fax, $object->country_code, 0, $mysoc->id, 'fax', ' ', 0, '');
  249. $usersection .= '</div>';
  250. }
  251. if ($object->user_mobile && !getDolUserInt('USER_PUBLIC_HIDE_USER_MOBILE', 0, $object)) {
  252. $usersection .= '<div class="flexitemsmall">';
  253. $usersection .= img_picto('', 'phone', 'class="pictofixedwidth"');
  254. $usersection .= dol_print_phone($object->user_mobile, $object->country_code, 0, $mysoc->id, 'tel', ' ', 0, '');
  255. $usersection .= '</div>';
  256. }
  257. // Social networks
  258. if (!empty($object->socialnetworks) && is_array($object->socialnetworks) && count($object->socialnetworks) > 0) {
  259. if (!getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS', 0, $object)) {
  260. foreach ($object->socialnetworks as $key => $value) {
  261. if ($value) {
  262. $usersection .= '<div class="flexitemsmall">'.dol_print_socialnetworks($value, 0, $mysoc->id, $key, $socialnetworksdict).'</div>';
  263. }
  264. }
  265. }
  266. }
  267. if ($usersection) {
  268. // Show photo
  269. if ($urllogo) {
  270. print '<img class="userphotopublicvcard" id="dolpaymentlogo" src="'.$urllogofull.'">';
  271. }
  272. print '<table id="dolpaymenttable" summary="Job position offer" class="center">'."\n";
  273. // Output payment summary form
  274. print '<tr><td class="left">';
  275. print '<div class="nowidthimp nopaddingtoponsmartphone" id="tablepublicpayment">';
  276. print $usersection;
  277. print '</div>'."\n";
  278. print "\n";
  279. print '</td></tr>'."\n";
  280. print '</table>'."\n";
  281. } else {
  282. // Show photo
  283. if ($urllogo) {
  284. print '<br><center><img class="userphotopublicvcard" style="position: unset !important;" id="dolpaymentlogo" src="'.$urllogofull.'"></center>';
  285. }
  286. }
  287. if (!getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object)) {
  288. $companysection = '';
  289. if ($mysoc->email) {
  290. $companysection .= '<div class="flexitemsmall">';
  291. $companysection .= img_picto('', 'email', 'class="pictofixedwidth"');
  292. $companysection .= dol_print_email($mysoc->email, 0, 0, 1);
  293. $companysection .= '</div>';
  294. }
  295. if ($mysoc->url) {
  296. $companysection .= '<div class="flexitemsmall">';
  297. $companysection .= img_picto('', 'globe', 'class="pictofixedwidth"');
  298. $companysection .= dol_print_url($mysoc->url, '_blank', 0, 0, '');
  299. $companysection .= '</div>';
  300. }
  301. if ($mysoc->phone) {
  302. $companysection .= '<div class="flexitemsmall">';
  303. $companysection .= img_picto('', 'phone', 'class="pictofixedwidth"');
  304. $companysection .= dol_print_phone($mysoc->phone, $mysoc->country_code, 0, $mysoc->id, 'tel', ' ', 0, '');
  305. $companysection .= '</div>';
  306. }
  307. if ($mysoc->fax) {
  308. $companysection .= '<div class="flexitemsmall">';
  309. $companysection .= img_picto('', 'phoning_fax', 'class="pictofixedwidth"');
  310. $companysection .= dol_print_phone($mysoc->fax, $mysoc->country_code, 0, $mysoc->id, 'fax', ' ', 0, '');
  311. $companysection .= '</div>';
  312. }
  313. // Social networks
  314. if (!empty($mysoc->socialnetworks) && is_array($mysoc->socialnetworks) && count($mysoc->socialnetworks) > 0) {
  315. foreach ($mysoc->socialnetworks as $key => $value) {
  316. if ($value) {
  317. $companysection .= '<div class="flexitemsmall">'.dol_print_socialnetworks($value, 0, $mysoc->id, $key, $socialnetworksdict).'</div>';
  318. }
  319. }
  320. }
  321. // 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)
  322. // Define logo and logosmall
  323. $logosmall = $mysoc->logo_squarred_small ? $mysoc->logo_squarred_small : $mysoc->logo_small;
  324. $logo = $mysoc->logo_squarred ? $mysoc->logo_squarred : $mysoc->logo;
  325. $paramlogo = 'ONLINE_USER_LOGO_'.$suffix;
  326. if (!empty($conf->global->$paramlogo)) {
  327. $logosmall = $conf->global->$paramlogo;
  328. } elseif (!empty($conf->global->ONLINE_USER_LOGO)) {
  329. $logosmall = $conf->global->ONLINE_USER_LOGO;
  330. }
  331. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  332. // Define urllogo
  333. $urllogo = '';
  334. $urllogofull = '';
  335. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  336. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany'.($conf->entity > 1 ? '&amp;entity='.$conf->entity : '').'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  337. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany'.($conf->entity > 1 ? '&entity='.$conf->entity : '').'&file='.urlencode('logos/thumbs/'.$logosmall);
  338. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  339. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany'.($conf->entity > 1 ? '&amp;entity='.$conf->entity : '').'&amp;file='.urlencode('logos/'.$logo);
  340. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany'.($conf->entity > 1 ? '&entity='.$conf->entity : '').'&file='.urlencode('logos/'.$logo);
  341. }
  342. // Output html code for logo
  343. if ($urllogo) {
  344. print '<div class="logopublicpayment center">';
  345. if (!empty($mysoc->url)) {
  346. print '<a href="'.$mysoc->url.'" target="_blank" rel="noopener">';
  347. }
  348. print '<img class="userphotopublicvcard" id="dolpaymentlogo" src="'.$urllogofull.'">';
  349. if (!empty($mysoc->url)) {
  350. print '</a>';
  351. }
  352. print '</div>';
  353. }
  354. print '<table id="dolpaymenttable" summary="Job position offer" class="center">'."\n";
  355. // Output payment summary form
  356. print '<tr><td class="left">';
  357. print '<div class="nowidthimp nopaddingtoponsmartphone" id="tablepublicpayment">';
  358. // Add company info
  359. if ($mysoc->name) {
  360. print '<div class="center bold">';
  361. print dol_escape_htmltag($mysoc->name);
  362. print '</div>';
  363. print '<br>';
  364. }
  365. print $companysection;
  366. print '</div>'."\n";
  367. print "\n";
  368. print '</td></tr>'."\n";
  369. print '</table>'."\n";
  370. }
  371. // Description
  372. $text = getDolUserString('USER_PUBLIC_MORE', '', $object);
  373. print $text;
  374. print '</form>'."\n";
  375. print '</div>'."\n";
  376. print '<br>';
  377. print '<div class="backgreypublicpayment">';
  378. print '<div class="center">';
  379. print '<a href="'.$urlforqrcode.'">';
  380. // Download / AddToContacts
  381. print img_picto($langs->trans("Download").' VCF', 'add').' ';
  382. print $langs->trans("Download").' VCF';
  383. print '</a>';
  384. print '</div>';
  385. //print '<div>';
  386. //print '</div>';
  387. print '</div>';
  388. $fullexternaleurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'external');
  389. $fullinternalurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'internal');
  390. print '<script>';
  391. print 'jQuery(document).ready(function() {
  392. jQuery(".virtualcardpreview").click(function(event) {
  393. event.preventDefault();
  394. console.log("We click on the card");
  395. window.open("'.$fullexternaleurltovirtualcard.'");
  396. });
  397. });';
  398. print '</script>';
  399. llxFooter('', 'public');
  400. $db->close();