signature.lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Copyright (C) 2013 Marcos García <marcosgdf@gmail.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. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * Return string with full online Url to accept and sign a quote
  21. *
  22. * @param string $type Type of URL ('proposal', ...)
  23. * @param string $ref Ref of object
  24. * @return string Url string
  25. */
  26. function showOnlineSignatureUrl($type, $ref)
  27. {
  28. global $conf, $langs;
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("payment", "paybox"));
  31. $servicename = 'Online';
  32. $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
  33. $url = getOnlineSignatureUrl(0, $type, $ref);
  34. $out .= '<div class="urllink">';
  35. if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
  36. $out .= $url;
  37. } else {
  38. $out .= '<input type="text" id="onlinesignatureurl" class="quatrevingtpercentminusx" value="'.$url.'">';
  39. }
  40. $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
  41. $out .= '</div>';
  42. $out .= ajax_autoselect("onlinesignatureurl", 0);
  43. return $out;
  44. }
  45. /**
  46. * Return string with full Url
  47. *
  48. * @param int $mode 0=True url, 1=Url formated with colors
  49. * @param string $type Type of URL ('proposal', ...)
  50. * @param string $ref Ref of object
  51. * @param string $localorexternal 0=Url for browser, 1=Url for external access
  52. * @return string Url string
  53. */
  54. function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1)
  55. {
  56. global $conf, $object, $dolibarr_main_url_root;
  57. $ref = str_replace(' ', '', $ref);
  58. $out = '';
  59. // Define $urlwithroot
  60. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  61. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  62. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  63. $urltouse = DOL_MAIN_URL_ROOT;
  64. if ($localorexternal) {
  65. $urltouse = $urlwithroot;
  66. }
  67. $securekeyseed = '';
  68. if ($type == 'proposal') {
  69. $securekeyseed = isset($conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
  70. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
  71. if ($mode == 1) {
  72. $out .= 'proposal_ref';
  73. }
  74. if ($mode == 0) {
  75. $out .= urlencode($ref);
  76. }
  77. $out .= ($mode ? '</span>' : '');
  78. if ($mode == 1) {
  79. $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
  80. } else {
  81. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $object->entity), '0');
  82. }
  83. /*
  84. if ($mode == 1) {
  85. $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
  86. } else {
  87. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  88. $propaltmp = new Propal($db);
  89. $res = $propaltmp->fetch(0, $ref);
  90. if ($res <= 0) {
  91. return 'FailedToGetProposal';
  92. }
  93. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  94. $ecmfile = new EcmFiles($db);
  95. $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
  96. $hashp = $ecmfile->share;
  97. if (empty($hashp)) {
  98. $out = $langs->trans("FeatureOnlineSignDisabled");
  99. return $out;
  100. } else {
  101. $out .= '&hashp='.$hashp;
  102. }
  103. }*/
  104. } elseif ($type == 'contract') {
  105. $securekeyseed = isset($conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
  106. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
  107. if ($mode == 1) {
  108. $out .= 'contract_ref';
  109. }
  110. if ($mode == 0) {
  111. $out .= urlencode($ref);
  112. }
  113. $out .= ($mode ? '</span>' : '');
  114. if ($mode == 1) {
  115. $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
  116. } else {
  117. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $object->entity), '0');
  118. }
  119. } elseif ($type == 'fichinter') {
  120. $securekeyseed = isset($conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
  121. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
  122. if ($mode == 1) {
  123. $out .= 'fichinter_ref';
  124. }
  125. if ($mode == 0) {
  126. $out .= urlencode($ref);
  127. }
  128. $out .= ($mode ? '</span>' : '');
  129. if ($mode == 1) {
  130. $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
  131. } else {
  132. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $object->entity), '0');
  133. }
  134. }
  135. // For multicompany
  136. if (!empty($out) && isModEnabled('multicompany')) {
  137. $out .= "&entity=".$object->entity; // Check the entity because we may have the same reference in several entities
  138. }
  139. return $out;
  140. }