';
if ($modecompta == 'CREANCES-DETTES') {
print '
'.price(price2num($total_ht_income, 'MT')).'
';
+} else {
+ print '
';
}
print '
'.price(price2num($total_ttc_income, 'MT')).'
';
print '
';
print '
'.$langs->trans("Outcome").'
';
if ($modecompta == 'CREANCES-DETTES') {
print '
'.price(price2num(-$total_ht_outcome, 'MT')).'
';
+} else {
+ print '
';
}
print '
'.price(price2num(-$total_ttc_outcome, 'MT')).'
';
print '
';
print '
'.$langs->trans("Profit").'
';
if ($modecompta == 'CREANCES-DETTES') {
print '
'.price(price2num($total_ht, 'MT')).'
';
+} else {
+ print '
';
}
print '
'.price(price2num($total_ttc, 'MT')).'
';
print '
';
diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php
index 994ba5c42f3..56cc79662ae 100644
--- a/htdocs/core/ajax/onlineSign.php
+++ b/htdocs/core/ajax/onlineSign.php
@@ -53,6 +53,7 @@ if (is_numeric($entity)) {
define("DOLENTITY", $entity);
}
include '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$action = GETPOST('action', 'aZ09');
@@ -69,7 +70,7 @@ $type = $mode;
// Check securitykey
$securekeyseed = '';
if ($type == 'proposal') {
- $securekeyseed = $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN;
+ $securekeyseed = getDolGlobalString('PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN');
}
if (!dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) {
@@ -122,28 +123,71 @@ if ($action == "importSignature") {
}
if (!$error) {
- $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf";
+ // Defined modele of doc
+ $last_main_doc_file = $object->last_main_doc;
+ $directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc
- $pdf = pdf_getInstance();
- $pdf->Open();
- $pdf->AddPage();
- $pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); // original PDF
+ if (preg_match('/\.pdf/i', $last_main_doc_file)) {
+ // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile
+ $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf";
+ $sourcefile = $upload_dir.$ref.".pdf";
- for ($i=1;$i<($pagecount+1);$i++) {
- if ($i>1) $pdf->AddPage();
- $tppl=$pdf->importPage($i);
- $pdf->useTemplate($tppl);
+ if (dol_is_file($sourcefile)) {
+ // We build the new PDF
+ $pdf = pdf_getInstance();
+ if (class_exists('TCPDF')) {
+ $pdf->setPrintHeader(false);
+ $pdf->setPrintFooter(false);
+ }
+ $pdf->SetFont(pdf_getPDFFont($langs));
+
+ if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
+ $pdf->SetCompression(false);
+ }
+
+
+ //$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)); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset.
+ //$pdf->Close();
+ $pdf->Output($newpdffilename, "F");
+
+ // Index the new file and update the last_main_doc property of object.
+ $object->indexFile($newpdffilename, 1);
+ }
+ } elseif (preg_match('/\.odt/i', $last_main_doc_file)) {
+ // Adding signature on .ODT not yet supported
+ // TODO
+ } else {
+ // Document format not supported to insert online signature.
+ // We should just create an image file with the signature.
}
+ }
- $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->Output($newpdffilename, "F");
-
+ if (!$error) {
$db->begin();
- // Index the new file and update the last_main_doc property of object.
- $object->indexFile($newpdffilename, 1);
-
$online_sign_ip = getUserRemoteIP();
$online_sign_name = ''; // TODO Ask name on form to sign
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index bd8ab4c22f4..513717b56de 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -941,7 +941,8 @@ abstract class CommonObject
// Add entry into index
if ($initsharekey) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
- // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first
+
+ // TODO We can't, we dont' have full path of file, only last_main_doc and ->element, so we must first rebuild full path $destfull
/*
$ecmfile->filepath = $rel_dir;
$ecmfile->filename = $filename;
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index 2b19e0db134..97edefd01e1 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -1013,7 +1013,9 @@ class Conf
}
if (empty($handler_file_found)) {
- throw new Exception('Missing log handler file '.$handler.'.php');
+ // If log handler has been removed of is badly setup, we must be able to continue code.
+ //throw new Exception('Missing log handler file '.$handler.'.php');
+ continue;
}
require_once $handler_file_found;
diff --git a/htdocs/core/lib/signature.lib.php b/htdocs/core/lib/signature.lib.php
index 6a8d824872d..33b0a1e8e5e 100644
--- a/htdocs/core/lib/signature.lib.php
+++ b/htdocs/core/lib/signature.lib.php
@@ -91,7 +91,7 @@ function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1)
if ($mode == 1) {
$out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)";
} else {
- $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref.$object->entity, '0');
+ $out .= '&securekey='.dol_hash($securekeyseed.$type.$ref, '0');
}
/*
if ($mode == 1) {
diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php
index 1c38f52cbfc..ae95b78ec8d 100644
--- a/htdocs/core/modules/import/import_xlsx.modules.php
+++ b/htdocs/core/modules/import/import_xlsx.modules.php
@@ -863,7 +863,7 @@ class ImportXlsx extends ModeleImports
if (empty($keyfield)) {
$keyfield = 'rowid';
}
- $sqlSelect .= "WHERE " . $keyfield . " = " .((int) $lastinsertid);
+ $sqlSelect .= " WHERE " . $keyfield . " = " .((int) $lastinsertid);
$resql = $this->db->query($sqlSelect);
if ($resql) {
diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php
index 8629ec7bbc6..c78a88e07c7 100644
--- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php
+++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php
@@ -467,6 +467,24 @@ class KnowledgeRecord extends CommonObject
$this->error .= $this->db->lasterror();
$errorflag = -1;
}
+
+ // Delete all child tables
+ if (!$error) {
+ $elements = array('categorie_knowledgemanagement');
+ foreach ($elements as $table) {
+ if (!$error) {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
+ $sql .= " WHERE fk_knowledgemanagement = ".(int) $this->id;
+
+ $result = $this->db->query($sql);
+ if (!$result) {
+ $error++;
+ $this->errors[] = $this->db->lasterror();
+ }
+ }
+ }
+ }
+
return $this->deleteCommon($user, $notrigger);
//return $this->deleteCommon($user, $notrigger, 1);
}
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 49c70b05641..cb3513c63ba 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -16,7 +16,7 @@
* Copyright (C) 2016 Charlie Benke
* Copyright (C) 2016 Meziane Sof
* Copyright (C) 2017 Josep Lluís Amador
- * Copyright (C) 2019-2021 Frédéric France
+ * Copyright (C) 2019-2022 Frédéric France
* Copyright (C) 2019-2020 Thibault FOUCART
* Copyright (C) 2020 Pierre Ardoin
*
@@ -1796,7 +1796,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '
'.$langs->trans("Description").'
';
// We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
- $doleditor = new DolEditor('desc', $object->description, '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
+ $doleditor = new DolEditor('desc', GETPOSTISSET('desc') ? GETPOST('desc', 'restricthtml') : $object->description, '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
$doleditor->Create();
print "
";
@@ -1806,7 +1806,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
print '
';
}
diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php
index 9ebea80aeb3..5dca1604f58 100644
--- a/htdocs/public/onlinesign/newonlinesign.php
+++ b/htdocs/public/onlinesign/newonlinesign.php
@@ -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);
@@ -51,7 +51,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
// Load translation files
$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal"));
@@ -125,6 +124,7 @@ $creditor = $mysoc->name;
$type = $source;
if ($source == 'proposal') {
+ require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
$object = new Propal($db);
$object->fetch(0, $ref, '', $entity);
} else {
@@ -139,7 +139,7 @@ if ($source == 'proposal') {
$securekeyseed = $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN;
}
-if (!dol_verifyHash($securekeyseed.$type.$ref.$object->entity, $SECUREKEY, '0')) {
+if (!dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) {
http_response_code(403);
print 'Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref);
exit(-1);
@@ -318,9 +318,19 @@ if ($source == 'proposal') {
// Object
$text = ''.$langs->trans("SignatureProposalRef", $object->ref).'';
- print '
'.$langs->trans("Designation");
+ print '
'.$langs->trans("Designation");
print '
'.$text;
+
+ $last_main_doc_file = $object->last_main_doc;
+
if ($object->status == $object::STATUS_VALIDATED) {
+ if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) {
+ // It seems document has never been generated, or was generated and then deleted.
+ // So we try to regenerate it with its default template.
+ $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used.
+ $object->generateDocument($defaulttemplate, $langs);
+ }
+
$directdownloadlink = $object->getLastMainDocLink('proposal');
if ($directdownloadlink) {
print ' ';
@@ -328,13 +338,11 @@ if ($source == 'proposal') {
print $langs->trans("DownloadDocument").'';
}
} else {
- $last_main_doc_file = $object->last_main_doc;
-
if ($object->status == $object::STATUS_NOTSIGNED) {
$directdownloadlink = $object->getLastMainDocLink('proposal');
if ($directdownloadlink) {
print ' ';
- print img_mime($object->last_main_doc, '');
+ print img_mime($last_main_doc_file, '');
print $langs->trans("DownloadDocument").'';
}
} elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) {
@@ -359,8 +367,6 @@ if ($source == 'proposal') {
print '';
print '';
print '
'."\n";
-
- // TODO Add link to download PDF (similar code than for invoice)
}
diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php
index c9b8f13c877..57e23350a2c 100644
--- a/htdocs/public/payment/paymentok.php
+++ b/htdocs/public/payment/paymentok.php
@@ -364,6 +364,7 @@ if ($ispaymentok) {
}
if (empty($user->rights->facture)) {
$user->rights->facture = new stdClass();
+ $user->rights->facture->invoice_advance = new stdClass();
}
if (empty($user->rights->adherent)) {
$user->rights->adherent = new stdClass();
@@ -371,6 +372,7 @@ if ($ispaymentok) {
}
$user->rights->societe->creer = 1;
$user->rights->facture->creer = 1;
+ $user->rights->facture->invoice_advance->validate = 1;
$user->rights->adherent->cotisation->creer = 1;
if (array_key_exists('MEM', $tmptag) && $tmptag['MEM'] > 0) {