dolibarr  19.0.0-dev
signature.lib.php
1 <?php
27 function showOnlineSignatureUrl($type, $ref)
28 {
29  global $conf, $langs;
30 
31  // Load translation files required by the page
32  $langs->loadLangs(array("payment", "paybox"));
33 
34  $servicename = 'Online';
35 
36  $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
37  $url = getOnlineSignatureUrl(0, $type, $ref);
38  $out .= '<div class="urllink">';
39  if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
40  $out .= $url;
41  } else {
42  $out .= '<input type="text" id="onlinesignatureurl" class="quatrevingtpercentminusx" value="'.$url.'">';
43  }
44  $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
45  $out .= '</div>';
46  $out .= ajax_autoselect("onlinesignatureurl", 0);
47  return $out;
48 }
49 
50 
60 function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1)
61 {
62  global $conf, $object, $dolibarr_main_url_root;
63 
64  $ref = str_replace(' ', '', $ref);
65  $out = '';
66 
67  // Define $urlwithroot
68  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
69  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
70  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
71 
72  $urltouse = DOL_MAIN_URL_ROOT;
73  if ($localorexternal) {
74  $urltouse = $urlwithroot;
75  }
76 
77  $securekeyseed = '';
78 
79  if ($type == 'proposal') {
80  $securekeyseed = isset($conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
81 
82  $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
83  if ($mode == 1) {
84  $out .= 'proposal_ref';
85  }
86  if ($mode == 0) {
87  $out .= urlencode($ref);
88  }
89  $out .= ($mode ? '</span>' : '');
90  if ($mode == 1) {
91  $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
92  } else {
93  $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (is_null($object) ? '' : $object->entity) : ''), '0');
94  }
95  /*
96  if ($mode == 1) {
97  $out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
98  } else {
99  include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
100  $propaltmp = new Propal($db);
101  $res = $propaltmp->fetch(0, $ref);
102  if ($res <= 0) {
103  return 'FailedToGetProposal';
104  }
105 
106  include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
107  $ecmfile = new EcmFiles($db);
108 
109  $ecmfile->fetch(0, '', $propaltmp->last_main_doc);
110 
111  $hashp = $ecmfile->share;
112  if (empty($hashp)) {
113  $out = $langs->trans("FeatureOnlineSignDisabled");
114  return $out;
115  } else {
116  $out .= '&hashp='.$hashp;
117  }
118  }*/
119  } elseif ($type == 'contract') {
120  $securekeyseed = isset($conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->CONTRACT_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
121  $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=contract&ref='.($mode ? '<span style="color: #666666">' : '');
122  if ($mode == 1) {
123  $out .= 'contract_ref';
124  }
125  if ($mode == 0) {
126  $out .= urlencode($ref);
127  }
128  $out .= ($mode ? '</span>' : '');
129  if ($mode == 1) {
130  $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)";
131  } else {
132  $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (is_null($object) ? '' : $object->entity) : ''), '0');
133  }
134  } elseif ($type == 'fichinter') {
135  $securekeyseed = isset($conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
136  $out = $urltouse.'/public/onlinesign/newonlinesign.php?source=fichinter&ref='.($mode ? '<span style="color: #666666">' : '');
137  if ($mode == 1) {
138  $out .= 'fichinter_ref';
139  }
140  if ($mode == 0) {
141  $out .= urlencode($ref);
142  }
143  $out .= ($mode ? '</span>' : '');
144  if ($mode == 1) {
145  $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)";
146  } else {
147  $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (is_null($object) ? '' : $object->entity) : ''), '0');
148  }
149  }
150 
151  // For multicompany
152  if (!empty($out) && isModEnabled('multicompany')) {
153  $out .= "&entity=".(is_null($object) ? '' : $object->entity); // Check the entity because we may have the same reference in several entities
154  }
155 
156  return $out;
157 }
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.
isModEnabled($module)
Is Dolibarr module enabled.