dolibarr 21.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", "paybox", "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{
71 global $dolibarr_main_url_root;
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 $securekeyseed = '';
97
98 if ($type == 'proposal') {
99 $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
100 if (strpos($securekeyseed, "\0") !== false) {
101 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
102 return 'Invalid parameter PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
103 }
104
105 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
106 if ($mode == 1) {
107 $out .= 'proposal_ref';
108 }
109 if ($mode == 0) {
110 $out .= urlencode($ref);
111 }
112 $out .= ($mode ? '</span>' : '');
113 if ($mode == 1) {
114 $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
115 } else {
116 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), '0');
117 }
118 /*
119 if ($mode == 1) {
120 $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
121 } else {
122 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
123 $propaltmp = new Propal($db);
124 $res = $propaltmp->fetch(0, $ref);
125 if ($res <= 0) {
126 return 'FailedToGetProposal';
127 }
128
129 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
130 $ecmfile = new EcmFiles($db);
131
132 $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
133
134 $hashp = $ecmfile->share;
135 if (empty($hashp)) {
136 $out = $langs->trans("FeatureOnlineSignDisabled");
137 return $out;
138 } else {
139 $out .= '&hashp='.$hashp;
140 }
141 }*/
142 } elseif ($type == 'contract') {
143 $securekeyseed = getDolGlobalString('CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN');
144 if (strpos($securekeyseed, "\0") !== false) {
145 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
146 return 'Invalid parameter CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
147 }
148
149 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
150 if ($mode == 1) {
151 $out .= 'contract_ref';
152 }
153 if ($mode == 0) {
154 $out .= urlencode($ref);
155 }
156 $out .= ($mode ? '</span>' : '');
157 if ($mode == 1) {
158 $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
159 } else {
160 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
161 }
162 } elseif ($type == 'fichinter') {
163 $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN');
164 if (strpos($securekeyseed, "\0") !== false) {
165 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
166 return 'Invalid parameter FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
167 }
168
169 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
170 if ($mode == 1) {
171 $out .= 'fichinter_ref';
172 }
173 if ($mode == 0) {
174 $out .= urlencode($ref);
175 }
176 $out .= ($mode ? '</span>' : '');
177 if ($mode == 1) {
178 $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
179 } else {
180 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0');
181 }
182 } else { // For example $type = 'societe_rib'
183 $securekeyseed = getDolGlobalString(dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN');
184 if (strpos($securekeyseed, "\0") !== false) {
185 // String contains a null character that can't be encoded. Return an error to avoid fatal error later.
186 return 'Invalid parameter '.dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN. Contains a null character.';
187 }
188
189 $out = $urltouse.'/public/onlinesign/newonlinesign.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
190 if ($mode == 1) {
191 $out .= $type.'_ref';
192 }
193 if ($mode == 0) {
194 $out .= urlencode($ref);
195 }
196 $out .= ($mode ? '</span>' : '');
197 if ($mode == 1) {
198 $out .= "hash('".$securekeyseed."' + '".$type."' + $type + '_ref)";
199 } else {
200 $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $obj->entity), '0');
201 }
202 }
203
204 // For multicompany
205 if (!empty($out) && isModEnabled('multicompany')) {
206 $out .= "&entity=".(empty($obj->entity) ? '' : (int) $obj->entity); // Check the entity because we may have the same reference in several entities
207 }
208
209 return $out;
210}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $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.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.