dolibarr 24.0.0-beta
signature.lib.php
1<?php
31function showOnlineSignatureUrl($type, $ref, $obj = null, $mode = '')
32{
33 global $langs;
34
35 // Load translation files required by the page
36 $langs->loadLangs(array("payment", "stripe"));
37
38 $servicename = 'Online';
39
40 $out = '';
41 if ($mode != 'short') {
42 $out .= img_picto('', 'globe', 'class="pictofixedwidth"');
43 }
44 $out .= '<span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
45 $url = getOnlineSignatureUrl(0, $type, $ref, 1, $obj);
46 $out .= '<div class="urllink">';
47 if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
48 $out .= $url;
49 } else {
50 $out .= '<input type="text" id="onlinesignatureurl" class="'.($mode == 'short' ? 'centpercentminusx' : 'quatrevingtpercentminusx').'" value="'.$url.'">';
51 }
52 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
53 $out .= '</div>';
54 $out .= ajax_autoselect("onlinesignatureurl", '');
55 return $out;
56}
57
58
69function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $obj = null)
70{
72
73 if (empty($obj)) {
74 // For compatibility with 15.0 -> 19.0
75 global $object;
76 if (empty($object)) {
77 $obj = new stdClass();
78 } else {
79 dol_syslog(__FUNCTION__." using global object is deprecated, please give obj as argument", LOG_WARNING);
80 $obj = $object;
81 }
82 }
83
84 $out = '';
85
86 // Define $urlwithroot
87 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
88 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
89 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
90
91 $urltouse = DOL_MAIN_URL_ROOT;
92 if ($localorexternal) {
93 $urltouse = $urlwithroot;
94 }
95
96 global $dolibarr_main_instance_unique_id;
97 $defaultsalt = substr(dol_hash('dolibarr'.$dolibarr_main_instance_unique_id, 'sha256'), 0, 32); // Fallback if no specific salt was set
98
99 $securekeyseed = '';
100
101 if ($type == 'proposal') {
102 $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt);
103 if (strpos($securekeyseed, "\0") !== false) {
104 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
105 return 'Invalid parameter PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
106 }
107
108 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
109 if ($mode == 1) {
110 $out .= 'proposal_ref';
111 }
112 if ($mode == 0) {
113 $out .= urlencode($ref);
114 }
115 $out .= ($mode ? '</span>' : '');
116 if ($mode == 1) {
117 $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
118 } else {
119 $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), 'hash'));
120 }
121 /*
122 if ($mode == 1) {
123 $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
124 } else {
125 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
126 $propaltmp = new Propal($db);
127 $res = $propaltmp->fetch(0, $ref);
128 if ($res <= 0) {
129 return 'FailedToGetProposal';
130 }
131
132 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
133 $ecmfile = new EcmFiles($db);
134
135 $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
136
137 $hashp = $ecmfile->share;
138 if (empty($hashp)) {
139 $out = $langs->trans("FeatureOnlineSignDisabled");
140 return $out;
141 } else {
142 $out .= '&hashp='.$hashp;
143 }
144 }*/
145 } elseif ($type == 'contract') {
146 $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt);
147 if (strpos($securekeyseed, "\0") !== false) {
148 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
149 return 'Invalid parameter CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
150 }
151
152 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
153 if ($mode == 1) {
154 $out .= 'contract_ref';
155 }
156 if ($mode == 0) {
157 $out .= urlencode($ref);
158 }
159 $out .= ($mode ? '</span>' : '');
160 if ($mode == 1) {
161 $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
162 } else {
163 $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash'));
164 }
165 } elseif ($type == 'fichinter') {
166 $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt);
167 if (strpos($securekeyseed, "\0") !== false) {
168 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
169 return 'Invalid parameter FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
170 }
171
172 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
173 if ($mode == 1) {
174 $out .= 'fichinter_ref';
175 }
176 if ($mode == 0) {
177 $out .= urlencode($ref);
178 }
179 $out .= ($mode ? '</span>' : '');
180 if ($mode == 1) {
181 $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
182 } else {
183 $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash'));
184 }
185 } else { // For example $type = 'societe_rib'
186 $securekeyseed = getDolGlobalString(dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt);
187 if (strpos($securekeyseed, "\0") !== false) {
188 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
189 return 'Invalid parameter '.dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
190 }
191
192 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
193 if ($mode == 1) {
194 $out .= $type.'_ref';
195 }
196 if ($mode == 0) {
197 $out .= urlencode($ref);
198 }
199 $out .= ($mode ? '</span>' : '');
200 if ($mode == 1) {
201 $out .= "hash('".$securekeyseed."' + '".$type."' + $type + '_ref)";
202 } else {
203 $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash'));
204 }
205 }
206
207 // For multicompany
208 if (!empty($out) && isModEnabled('multicompany')) {
209 $out .= "&entity=".(empty($obj->entity) ? '' : (int) $obj->entity); // Check the entity because we may have the same reference in several entities
210 }
211
212 return $out;
213}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.