Merge branch '15.0' of git@github.com:Dolibarr/dolibarr.git into 16.0

Conflicts:
	htdocs/core/ajax/onlineSign.php
This commit is contained in:
Laurent Destailleur 2022-08-14 21:41:25 +02:00
commit ebc8823202
3 changed files with 50 additions and 19 deletions

View File

@ -1507,12 +1507,13 @@ class Propal extends CommonObject
/**
* Load a proposal from database. Get also lines.
*
* @param int $rowid id of object to load
* @param string $ref Ref of proposal
* @param string $ref_ext Ref ext of proposal
* @return int >0 if OK, <0 if KO
* @param int $rowid Id of object to load
* @param string $ref Ref of proposal
* @param string $ref_ext Ref ext of proposal
* @param int $forceentity Entity id to force when searching on ref or ref_ext
* @return int >0 if OK, <0 if KO
*/
public function fetch($rowid, $ref = '', $ref_ext = '')
public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0)
{
$sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
$sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
@ -1551,10 +1552,15 @@ class Propal extends CommonObject
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid';
if ($ref) {
$sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid
if (!empty($ref)) {
if (!empty($forceentity)) {
$sql .= " WHERE p.entity = ".(int) $forceentity; // Check only the current entity because we may have the same reference in several entities
} else {
$sql .= " WHERE p.entity IN (".getEntity('propal').")";
}
$sql .= " AND p.ref='".$this->db->escape($ref)."'";
} else {
// Dont't use entity if you use rowid
$sql .= " WHERE p.rowid = ".((int) $rowid);
}

View File

@ -70,7 +70,7 @@ $type = $mode;
// Check securitykey
$securekeyseed = '';
if ($type == 'proposal') {
$securekeyseed = isset($conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN) ? $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN : '';
$securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
}
if (empty($SECUREKEY) || !dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) {
@ -133,19 +133,44 @@ if ($action == "importSignature") {
$sourcefile = $upload_dir.$ref.".pdf";
if (dol_is_file($sourcefile)) {
// We build the new PDF
$pdf = pdf_getInstance();
$pdf->Open();
$pdf->AddPage();
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF
if (class_exists('TCPDF')) {
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
}
$pdf->SetFont(pdf_getPDFFont($langs));
for ($i=1; $i<($pagecount+1); $i++) {
if ($i>1) $pdf->AddPage();
$tppl=$pdf->importPage($i);
$pdf->useTemplate($tppl);
if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
$pdf->SetCompression(false);
}
$pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset.
$pdf->Close();
//$pdf->Open();
$pagecount = $pdf->setSourceFile($sourcefile); // original PDF
$s = array(); // Array with size of each page. Exemple array(w'=>210, 'h'=>297);
for ($i=1; $i<($pagecount+1); $i++) {
try {
$tppl = $pdf->importPage($i);
$s = $pdf->getTemplatesize($tppl);
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
$pdf->useTemplate($tppl);
} catch (Exception $e) {
dol_syslog("Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
$response = $e->getMessage();
$error++;
}
}
// A signature image file is 720 x 180 (ratio 1/4) but we use only the size into PDF
// TODO Get position of box from PDF template
$xforimgstart = (empty($s['w']) ? 120 : round($s['w'] / 2) + 15);
$yforimgstart = (empty($s['h']) ? 240 : $s['h'] - 60);
$wforimg = $s['w'] - 20 - $xforimgstart;
$pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
//$pdf->Close();
$pdf->Output($newpdffilename, "F");
// Index the new file and update the last_main_doc property of object.

View File

@ -39,7 +39,7 @@ if (!defined('NOBROWSERNOTIF')) {
// For MultiCompany module.
// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
// TODO This should be useless. Because entity must be retrieve from object ref and not from url.
// Because 2 entities can have the same ref.
$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
if (is_numeric($entity)) {
define("DOLENTITY", $entity);
@ -126,7 +126,7 @@ $type = $source;
if ($source == 'proposal') {
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
$object = new Propal($db);
$result= $object->fetch(0, $ref);
$result= $object->fetch(0, $ref, '', $entity);
} else {
accessforbidden('Bad value for source');
exit;