dolibarr/htdocs/core/lib/signature.lib.php

128 lines
4.2 KiB
PHP
Raw Normal View History

<?php
/**
* Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
2021-12-25 17:08:40 +01:00
* Return string with full online Url to accept and sign a quote
*
* @param string $type Type of URL ('proposal', ...)
* @param string $ref Ref of object
* @return string Url string
*/
function showOnlineSignatureUrl($type, $ref)
{
global $conf, $langs;
2018-09-11 17:30:43 +02:00
// Load translation files required by the page
$langs->loadLangs(array("payment", "paybox"));
2018-09-11 17:30:43 +02:00
$servicename = 'Online';
2021-03-26 17:58:00 +01:00
$out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlineSignature", $servicename).'</span><br>';
$url = getOnlineSignatureUrl(0, $type, $ref);
2021-03-26 17:58:00 +01:00
$out .= '<div class="urllink">';
if ($url == $langs->trans("FeatureOnlineSignDisabled")) {
$out .= $url;
} else {
2021-10-18 21:20:58 +02:00
$out .= '<input type="text" id="onlinesignatureurl" class="quatrevingtpercentminusx" value="'.$url.'">';
2021-03-26 17:58:00 +01:00
}
2021-11-22 02:35:55 +01:00
$out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
2021-03-26 17:58:00 +01:00
$out .= '</div>';
$out .= ajax_autoselect("onlinesignatureurl", 0);
return $out;
}
/**
* Return string with full Url
*
2022-01-04 12:56:08 +01:00
* @param int $mode 0=True url, 1=Url formated with colors
* @param string $type Type of URL ('proposal', ...)
* @param string $ref Ref of object
* @param string $localorexternal 0=Url for browser, 1=Url for external access
* @return string Url string
*/
2022-01-04 12:56:08 +01:00
function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1)
{
global $conf, $object, $dolibarr_main_url_root;
$ref = str_replace(' ', '', $ref);
$out = '';
2021-12-25 17:08:40 +01:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
$urltouse = DOL_MAIN_URL_ROOT;
if ($localorexternal) {
$urltouse = $urlwithroot;
}
2022-01-04 12:56:08 +01:00
$securekeyseed = '';
2021-12-25 17:08:40 +01:00
2021-02-23 22:03:23 +01:00
if ($type == 'proposal') {
$securekeyseed = isset($conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
2022-01-04 12:56:08 +01:00
2021-12-25 17:08:40 +01:00
$out = $urltouse.'/public/onlinesign/newonlinesign.php?source=proposal&ref='.($mode ? '<span style="color: #666666">' : '');
2021-02-23 22:03:23 +01:00
if ($mode == 1) {
$out .= 'proposal_ref';
}
if ($mode == 0) {
$out .= urlencode($ref);
}
$out .= ($mode ? '</span>' : '');
2021-12-25 17:08:40 +01:00
if ($mode == 1) {
$out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
} else {
2022-08-18 17:02:20 +02:00
$out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.(empty($conf->multicompany->enabled) ? '' : $object->entity), '0');
2021-12-25 17:08:40 +01:00
}
/*
2021-02-23 22:03:23 +01:00
if ($mode == 1) {
$out .= '&hashp=<span style="color: #666666">hash_of_file</span>';
2021-02-23 22:03:23 +01:00
} else {
include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
$propaltmp = new Propal($db);
$res = $propaltmp->fetch(0, $ref);
2021-02-23 22:03:23 +01:00
if ($res <= 0) {
return 'FailedToGetProposal';
}
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
$ecmfile = new EcmFiles($db);
$ecmfile->fetch(0, '', $propaltmp->last_main_doc);
$hashp = $ecmfile->share;
2021-02-23 22:03:23 +01:00
if (empty($hashp)) {
$out = $langs->trans("FeatureOnlineSignDisabled");
return $out;
2020-05-21 15:05:19 +02:00
} else {
$out .= '&hashp='.$hashp;
}
2021-12-25 17:08:40 +01:00
}*/
}
// For multicompany
if (!empty($out) && !empty($conf->multicompany->enabled)) {
2023-02-14 10:53:59 +01:00
$out .= "&entity=".$object->entity; // Check the entity because we may have the same reference in several entities
2021-02-23 22:03:23 +01:00
}
return $out;
}