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