virtualcard.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/user/virtualcard.php
  20. * \ingroup core
  21. * \brief Page to setup a virtual card
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  28. // Load translation files required by page
  29. $langs->loadLangs(array("users", "companies", "admin", "website"));
  30. // Security check
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'aZ09');
  34. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  35. if (empty($id) && empty($ref)) {
  36. $id = $user->id;
  37. }
  38. $object = new User($db);
  39. if ($id > 0 || !empty($ref)) {
  40. $result = $object->fetch($id, $ref, '', 1);
  41. $object->getrights();
  42. }
  43. // Security check
  44. $socid = 0;
  45. if ($user->socid > 0) {
  46. $socid = $user->socid;
  47. }
  48. $feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
  49. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  50. // If user is not the user that read and has no permission to read other users, we stop
  51. if (($object->id != $user->id) && !$user->hasRight('user', 'user', 'lire')) {
  52. accessforbidden();
  53. }
  54. /*
  55. * Actions
  56. */
  57. if ($action == 'update') {
  58. $tmparray = array();
  59. $tmparray['USER_PUBLIC_HIDE_PHOTO'] = (GETPOST('USER_PUBLIC_HIDE_PHOTO') ? 1 : 0);
  60. $tmparray['USER_PUBLIC_HIDE_JOBPOSITION'] = (GETPOST('USER_PUBLIC_HIDE_JOBPOSITION') ? 1 : 0);
  61. $tmparray['USER_PUBLIC_HIDE_EMAIL'] = (GETPOST('USER_PUBLIC_HIDE_EMAIL') ? 1 : 0);
  62. $tmparray['USER_PUBLIC_HIDE_OFFICE_PHONE'] = (GETPOST('USER_PUBLIC_HIDE_OFFICE_PHONE') ? 1 : 0);
  63. $tmparray['USER_PUBLIC_HIDE_OFFICE_FAX'] = (GETPOST('USER_PUBLIC_HIDE_OFFICE_FAX') ? 1 : 0);
  64. $tmparray['USER_PUBLIC_HIDE_USER_MOBILE'] = (GETPOST('USER_PUBLIC_HIDE_USER_MOBILE') ? 1 : 0);
  65. $tmparray['USER_PUBLIC_HIDE_SOCIALNETWORKS'] = (GETPOST('USER_PUBLIC_HIDE_SOCIALNETWORKS') ? 1 : 0);
  66. $tmparray['USER_PUBLIC_SHOW_BIRTH'] = (GETPOST('USER_PUBLIC_SHOW_BIRTH') ? 1 : 0);
  67. $tmparray['USER_PUBLIC_SHOW_ADDRESS'] = (GETPOST('USER_PUBLIC_SHOW_ADDRESS') ? 1 : 0);
  68. $tmparray['USER_PUBLIC_HIDE_COMPANY'] = (GETPOST('USER_PUBLIC_HIDE_COMPANY') ? 1 : 0);
  69. $tmparray['USER_PUBLIC_MORE'] = (GETPOST('USER_PUBLIC_MORE') ? GETPOST('USER_PUBLIC_MORE') : '');
  70. dol_set_user_param($db, $conf, $object, $tmparray);
  71. }
  72. if ($action == 'setUSER_ENABLE_PUBLIC') {
  73. if (GETPOST('value')) {
  74. $tmparray = array('USER_ENABLE_PUBLIC' => 1);
  75. } else {
  76. $tmparray = array('USER_ENABLE_PUBLIC' => 0);
  77. }
  78. dol_set_user_param($db, $conf, $object, $tmparray);
  79. }
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
  85. $title = $person_name." - ".$langs->trans('Info');
  86. $help_url = '';
  87. llxHeader('', $title, $help_url);
  88. $head = user_prepare_head($object);
  89. $title = $langs->trans("User");
  90. //print dol_get_fiche_head($head, 'info', $title, -1, 'user');
  91. $linkback = '';
  92. if ($user->hasRight('user', 'user', 'lire') || $user->admin) {
  93. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  94. }
  95. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener">';
  96. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  97. $morehtmlref .= '</a>';
  98. $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
  99. $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
  100. //dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
  101. print '<div class="fichecenter">';
  102. print '<br>';
  103. $param = '&id='.((int) $object->id);
  104. $param .= '&dol_openinpopup=1';
  105. $enabledisablehtml = $langs->trans("EnablePublicVirtualCard").' ';
  106. if (!getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
  107. // Button off, click to enable
  108. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setUSER_ENABLE_PUBLIC&token='.newToken().'&value=1'.$param.'">';
  109. $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
  110. $enabledisablehtml .= '</a>';
  111. $enabledisablehtml .= '<br><br><span class="opacitymedium">'.$langs->trans("UserPublicPageDesc").'</span><br><br>';
  112. } else {
  113. // Button on, click to disable
  114. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setUSER_ENABLE_PUBLIC&token='.newToken().'&value=0'.$param.'">';
  115. $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
  116. $enabledisablehtml .= '</a>';
  117. }
  118. print $enabledisablehtml;
  119. print '<input type="hidden" id="USER_ENABLE_PUBLIC" name="USER_ENABLE_PUBLIC" value="'.(!getDolGlobalString('USER_ENABLE_PUBLIC') ? 0 : 1).'">';
  120. print '<br><br>';
  121. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  122. if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
  123. print '<input type="hidden" name="action" value="update">';
  124. print '<input type="hidden" name="id" value="'.$object->id.'">';
  125. print '<input type="hidden" name="token" value="'.newToken().'">';
  126. //print $langs->trans('FollowingLinksArePublic').'<br>';
  127. print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('PublicVirtualCardUrl').'</span><br>';
  128. $fullexternaleurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'external');
  129. $fullinternalurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'internal');
  130. print '<div class="urllink">';
  131. print '<input type="text" id="publicurluser" class="quatrevingtpercentminusx" value="'.$fullexternaleurltovirtualcard.'">';
  132. print '<a target="_blank" rel="noopener noreferrer" href="'.$fullexternaleurltovirtualcard.'">'.img_picto('', 'globe', 'class="paddingleft marginrightonly paddingright"').$langs->trans("GoTo").'...</a>';
  133. print '</div>';
  134. print ajax_autoselect('publicurluser');
  135. print '<br>';
  136. print '<br>';
  137. // Show/Hide options
  138. print '<div class="centpercent margintoponly marginbottomonly">';
  139. print img_picto('', 'setup', 'class="pictofixedwidth"').'<a id="lnk" href="#">'.$langs->trans("ShowAdvancedOptions").'...</a>';
  140. print '</div>';
  141. print '<script type="text/javascript">
  142. jQuery(document).ready(function() {
  143. jQuery("#lnk").click(function(event) {
  144. event.preventDefault();
  145. console.log("We click on link to show virtual card options");
  146. hideoptions(this);
  147. });
  148. });
  149. function hideoptions(domelem) {
  150. const div = document.getElementById("div_container_sub_exportoptions");
  151. if (div.style.display === "none") {
  152. div.style.display = "block";
  153. domelem.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("HideAdvancedoptions")).'";
  154. } else {
  155. div.style.display = "none";
  156. domelem.innerText="'.dol_escape_js($langs->transnoentitiesnoconv("ShowAdvancedOptions")).'...";
  157. }
  158. }
  159. </script>';
  160. // Start div hide/Show
  161. print '<div id="div_container_sub_exportoptions" style="display: none;">';
  162. print '<div class="div-table-responsive-no-min">';
  163. print '<table class="noborder centpercent">';
  164. print '<tr class="liste_titre">';
  165. print '<td>'.$langs->trans("Options").'</td>';
  166. print '<td>'.$langs->trans("Value").'</td>';
  167. print "</tr>\n";
  168. // User photo
  169. print '<tr class="oddeven" id="tredit"><td>';
  170. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Photo"));
  171. print '</td><td>';
  172. print $form->selectyesno("USER_PUBLIC_HIDE_PHOTO", (getDolUserInt('USER_PUBLIC_HIDE_PHOTO', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_PHOTO', 0, $object) : 0), 1);
  173. print "</td></tr>\n";
  174. // Job position
  175. print '<tr class="oddeven" id="tredit"><td>';
  176. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PostOrFunction"));
  177. print '</td><td>';
  178. print $form->selectyesno("USER_PUBLIC_HIDE_JOBPOSITION", (getDolUserInt('USER_PUBLIC_HIDE_JOBPOSITION', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_JOBPOSITION', 0, $object) : 0), 1);
  179. print "</td></tr>\n";
  180. // Email
  181. print '<tr class="oddeven" id="tredit"><td>';
  182. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Email"));
  183. print '</td><td>';
  184. print $form->selectyesno("USER_PUBLIC_HIDE_EMAIL", (getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_EMAIL', 0, $object) : 0), 1);
  185. print "</td></tr>\n";
  186. // Office phone
  187. print '<tr class="oddeven" id="tredit"><td>';
  188. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhonePro"));
  189. print '</td><td>';
  190. print $form->selectyesno("USER_PUBLIC_HIDE_OFFICE_PHONE", (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_PHONE', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_OFFICE_PHONE', 0, $object) : 0), 1);
  191. print "</td></tr>\n";
  192. // Office fax
  193. print '<tr class="oddeven" id="tredit"><td>';
  194. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Fax"));
  195. print '</td><td>';
  196. print $form->selectyesno("USER_PUBLIC_HIDE_OFFICE_FAX", (getDolUserInt('USER_PUBLIC_HIDE_OFFICE_FAX', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_OFFICE_FAX', 0, $object) : 0), 1);
  197. print "</td></tr>\n";
  198. // User mobile
  199. print '<tr class="oddeven" id="tredit"><td>';
  200. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhoneMobile"));
  201. print '</td><td>';
  202. print $form->selectyesno("USER_PUBLIC_HIDE_USER_MOBILE", (getDolUserInt('USER_PUBLIC_HIDE_USER_MOBILE', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_USER_MOBILE', 0, $object) : 0), 1);
  203. print "</td></tr>\n";
  204. // Social networks
  205. print '<tr class="oddeven" id="tredit"><td>';
  206. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("SocialNetworksInformation"));
  207. print '</td><td>';
  208. print $form->selectyesno("USER_PUBLIC_HIDE_SOCIALNETWORKS", (getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_SOCIALNETWORKS', 0, $object) : 0), 1);
  209. print "</td></tr>\n";
  210. // Birth date
  211. print '<tr class="oddeven" id="tredit"><td>';
  212. print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Birthdate"));
  213. print '</td><td>';
  214. print $form->selectyesno("USER_PUBLIC_SHOW_BIRTH", (getDolUserInt('USER_PUBLIC_SHOW_BIRTH', 0, $object) ? getDolUserInt('USER_PUBLIC_SHOW_BIRTH', 0, $object) : 0), 1);
  215. print "</td></tr>\n";
  216. // Address
  217. print '<tr class="oddeven" id="tredit"><td>';
  218. print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Address"));
  219. print '</td><td>';
  220. print $form->selectyesno("USER_PUBLIC_SHOW_ADDRESS", (getDolUserInt('USER_PUBLIC_SHOW_ADDRESS', 0, $object) ? getDolUserInt('USER_PUBLIC_SHOW_ADDRESS', 0, $object) : 0), 1);
  221. print "</td></tr>\n";
  222. // Company name
  223. print '<tr class="oddeven" id="tramount"><td>';
  224. print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("CompanySection"));
  225. print '</td><td>';
  226. print $form->selectyesno("USER_PUBLIC_HIDE_COMPANY", (getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object) ? getDolUserInt('USER_PUBLIC_HIDE_COMPANY', 0, $object) : 0), 1);
  227. print "</td></tr>\n";
  228. // More
  229. print '<tr class="oddeven" id="tredit"><td>';
  230. print $langs->trans("Text");
  231. print '</td><td>';
  232. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  233. $extendededitor = 0; // We force no WYSIWYG editor
  234. $doleditor = new DolEditor('USER_PUBLIC_MORE', getDolUserString('USER_PUBLIC_MORE', '', $object), '', 160, 'dolibarr_notes', '', false, false, $extendededitor, ROWS_5, '90%');
  235. $doleditor->Create();
  236. print "</td></tr>\n";
  237. print '</table>';
  238. print '</div>';
  239. print '<div class="center">';
  240. print $form->buttonsSaveCancel("Save", '', array(), 0, '', $dol_openinpopup);
  241. print '</div>';
  242. print '<br>';
  243. print '</div>'; // End hide/show
  244. print '<br>';
  245. // Preview
  246. print '<div class="center">';
  247. print '<span class="opacitymedium">'.$langs->trans("Preview").'</span><br>';
  248. print '<div class="virtualcard-div">';
  249. print '<a target="_blank" rel="noopener noreferrer cursorpointer" href="'.$fullexternaleurltovirtualcard.'">'."\n";
  250. print '<iframe id="virtualcard-iframe" title="" class="center" src="'.$fullinternalurltovirtualcard.'&mode=preview">';
  251. print '</iframe>';
  252. print '</a>';
  253. print '</div>';
  254. print '</div>';
  255. print '<br>';
  256. }
  257. print '</form>';
  258. print '</div>';
  259. // End of page
  260. llxFooter();
  261. $db->close();