dolibarr 18.0.6
signature.lib.php
1<?php
28function showOnlineSignatureUrl($type, $ref, $obj = null)
29{
30 global $conf, $langs;
31
32 // Load translation files required by the page
33 $langs->loadLangs(array("payment", "paybox"));
34
35 $servicename = 'Online';
36
37 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
38 $url = getOnlineSignatureUrl(0, $type, $ref, 1, $obj);
39 $out .= '<div class="urllink">';
40 if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
41 $out .= $url;
42 } else {
43 $out .= '<input type="text" id="onlinesignatureurl" class="quatrevingtpercentminusx" value="'.$url.'">';
44 }
45 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
46 $out .= '</div>';
47 $out .= ajax_autoselect("onlinesignatureurl", 0);
48 return $out;
49}
50
51
62function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $obj = null)
63{
64 global $conf, $dolibarr_main_url_root;
65
66 if (empty($obj)) {
67 // For compatibility with 15.0 -> 19.0
68 global $object;
69 if (empty($object)) {
70 $obj = new stdClass();
71 } else {
72 dol_syslog(__METHOD__." using global object is deprecated, please give obj as argument", LOG_WARNING);
73 $obj = $object;
74 }
75 }
76
77 $ref = str_replace(' ', '', $ref);
78 $out = '';
79
80 // Define $urlwithroot
81 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
82 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
83 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
84
85 $urltouse = DOL_MAIN_URL_ROOT;
86 if ($localorexternal) {
87 $urltouse = $urlwithroot;
88 }
89
90 $securekeyseed = '';
91
92 if ($type == 'proposal') {
93 $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
94
95 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
96 if ($mode == 1) {
97 $out .= 'proposal_ref';
98 }
99 if ($mode == 0) {
100 $out .= urlencode($ref);
101 }
102 $out .= ($mode ? '</span>' : '');
103 if ($mode == 1) {
104 $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
105 } else {
106 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), '0');
107 }
108 /*
109 if ($mode == 1) {
110 $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
111 } else {
112 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
113 $propaltmp = new Propal($db);
114 $res = $propaltmp->fetch(0, $ref);
115 if ($res <= 0) {
116 return 'FailedToGetProposal';
117 }
118
119 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
120 $ecmfile = new EcmFiles($db);
121
122 $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
123
124 $hashp = $ecmfile->share;
125 if (empty($hashp)) {
126 $out = $langs->trans("FeatureOnlineSignDisabled");
127 return $out;
128 } else {
129 $out .= '&hashp='.$hashp;
130 }
131 }*/
132 } elseif ($type == 'contract') {
133 $securekeyseed = isset($conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
134 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
135 if ($mode == 1) {
136 $out .= 'contract_ref';
137 }
138 if ($mode == 0) {
139 $out .= urlencode($ref);
140 }
141 $out .= ($mode ? '</span>' : '');
142 if ($mode == 1) {
143 $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
144 } else {
145 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
146 }
147 } elseif ($type == 'fichinter') {
148 $securekeyseed = isset($conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
149 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
150 if ($mode == 1) {
151 $out .= 'fichinter_ref';
152 }
153 if ($mode == 0) {
154 $out .= urlencode($ref);
155 }
156 $out .= ($mode ? '</span>' : '');
157 if ($mode == 1) {
158 $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
159 } else {
160 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
161 }
162 }
163
164 // For multicompany
165 if (!empty($out) && isModEnabled('multicompany')) {
166 $out .= "&entity=".(empty($obj->entity) ? '' : (int) $obj->entity); // Check the entity because we may have the same reference in several entities
167 }
168
169 return $out;
170}
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.