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