signature.lib.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. * @param Object $obj object (needed to make multicompany good links)
  25. * @return string Url string
  26. */
  27. function showOnlineSignatureUrl($type, $ref, $obj = null)
  28. {
  29. global $conf, $langs;
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("payment", "paybox"));
  32. $servicename = 'Online';
  33. $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
  34. $url = getOnlineSignatureUrl(0, $type, $ref, 1, $obj);
  35. $out .= '<div class="urllink">';
  36. if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
  37. $out .= $url;
  38. } else {
  39. $out .= '<input type="text" id="onlinesignatureurl" class="quatrevingtpercentminusx" value="'.$url.'">';
  40. }
  41. $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
  42. $out .= '</div>';
  43. $out .= ajax_autoselect("onlinesignatureurl", 0);
  44. return $out;
  45. }
  46. /**
  47. * Return string with full Url
  48. *
  49. * @param int $mode 0=True url, 1=Url formated with colors
  50. * @param string $type Type of URL ('proposal', ...)
  51. * @param string $ref Ref of object
  52. * @param string $localorexternal 0=Url for browser, 1=Url for external access
  53. * @param Object $obj object (needed to make multicompany good links)
  54. * @return string Url string
  55. */
  56. function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $obj = null)
  57. {
  58. global $conf, $dolibarr_main_url_root;
  59. if (empty($obj)) {
  60. // For compatibility with 15.0 -> 19.0
  61. global $object;
  62. if (empty($object)) {
  63. $obj = new stdClass();
  64. } else {
  65. dol_syslog(__FUNCTION__." using global object is deprecated, please give obj as argument", LOG_WARNING);
  66. $obj = $object;
  67. }
  68. }
  69. $ref = str_replace(' ', '', $ref);
  70. $out = '';
  71. // Define $urlwithroot
  72. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  73. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  74. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  75. $urltouse = DOL_MAIN_URL_ROOT;
  76. if ($localorexternal) {
  77. $urltouse = $urlwithroot;
  78. }
  79. $securekeyseed = '';
  80. if ($type == 'proposal') {
  81. $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
  82. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
  83. if ($mode == 1) {
  84. $out .= 'proposal_ref';
  85. }
  86. if ($mode == 0) {
  87. $out .= urlencode($ref);
  88. }
  89. $out .= ($mode ? '</span>' : '');
  90. if ($mode == 1) {
  91. $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
  92. } else {
  93. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), '0');
  94. }
  95. /*
  96. if ($mode == 1) {
  97. $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
  98. } else {
  99. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  100. $propaltmp = new Propal($db);
  101. $res = $propaltmp->fetch(0, $ref);
  102. if ($res <= 0) {
  103. return 'FailedToGetProposal';
  104. }
  105. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  106. $ecmfile = new EcmFiles($db);
  107. $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
  108. $hashp = $ecmfile->share;
  109. if (empty($hashp)) {
  110. $out = $langs->trans("FeatureOnlineSignDisabled");
  111. return $out;
  112. } else {
  113. $out .= '&hashp='.$hashp;
  114. }
  115. }*/
  116. } elseif ($type == 'contract') {
  117. $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
  118. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
  119. if ($mode == 1) {
  120. $out .= 'contract_ref';
  121. }
  122. if ($mode == 0) {
  123. $out .= urlencode($ref);
  124. }
  125. $out .= ($mode ? '</span>' : '');
  126. if ($mode == 1) {
  127. $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
  128. } else {
  129. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
  130. }
  131. } elseif ($type == 'fichinter') {
  132. $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
  133. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
  134. if ($mode == 1) {
  135. $out .= 'fichinter_ref';
  136. }
  137. if ($mode == 0) {
  138. $out .= urlencode($ref);
  139. }
  140. $out .= ($mode ? '</span>' : '');
  141. if ($mode == 1) {
  142. $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
  143. } else {
  144. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
  145. }
  146. } else { // For example $type = 'societe_rib'
  147. $securekeyseed = getDolGlobalString(dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN');
  148. $out = $urltouse.'/public/onlinesign/newonlinesign.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
  149. if ($mode == 1) {
  150. $out .= $type.'_ref';
  151. }
  152. if ($mode == 0) {
  153. $out .= urlencode($ref);
  154. }
  155. $out .= ($mode ? '</span>' : '');
  156. if ($mode == 1) {
  157. $out .= "hash('".$securekeyseed."' + '".$type."' + $type + '_ref)";
  158. } else {
  159. $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $object->entity), '0');
  160. }
  161. }
  162. // For multicompany
  163. if (!empty($out) && isModEnabled('multicompany')) {
  164. $out .= "&entity=".(empty($obj->entity) ? '' : (int) $obj->entity); // Check the entity because we may have the same reference in several entities
  165. }
  166. return $out;
  167. }