From 9eb8dadfd95b2b627e417a1c56c36e2b14f83ed2 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 15 Oct 2021 16:58:59 +0200 Subject: [PATCH 1/4] WIP : signature of propal --- htdocs/core/ajax/onlineSign.php | 131 +++++++++++++++++++++ htdocs/public/onlinesign/newonlinesign.php | 75 +++++++++++- 2 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 htdocs/core/ajax/onlineSign.php diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php new file mode 100644 index 00000000000..13bd28961d5 --- /dev/null +++ b/htdocs/core/ajax/onlineSign.php @@ -0,0 +1,131 @@ +. + */ + +/** + * \file /htdocs/core/ajax/onlineSign.php + * \brief File to make Ajax action on Knowledge Management + */ + +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +// Do not check anti CSRF attack test +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +// If there is no need to load and show top and left menu +if (!defined("NOLOGIN")) { + define("NOLOGIN", '1'); +} +if (!defined('NOIPCHECK')) { + define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} +include '../../main.inc.php'; + +$action = GETPOST('action', 'aZ09'); +$signature = GETPOST('signaturebase64'); +$ref = GETPOST('ref', 'aZ09'); +$mode = GETPOST('mode', 'aZ09'); +$error = 0; +$response = ""; +/* + * Actions + */ + +// None + + +/* + * View + */ + +if ($action == "importSignature") { + if (!empty($signature) && $signature[0] == "image/png;base64") { + $signature = $signature[1]; + $data = base64_decode($signature); + $upload_dir = DOL_DATA_ROOT."/".$mode."/".$ref."/"; + $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S"); + $filename = "signatures/".$date."_signature.png"; + if (!is_dir($upload_dir."signatures/")) { + if (!mkdir($upload_dir."signatures/")) { + $response ="error mkdir"; + $error++; + } + } + if (!$error) { + $return = file_put_contents($upload_dir.$filename, $data); + if ($return == false) { + $response = 'error file_put_content'; + } else { + if ($mode == "propale") { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; + $object = new Propal($db); + $object->fetch(0, $ref); + + $pdf = pdf_getInstance(); + $pdf->Open(); + $pdf->AddPage(); + $pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); + + $tppl = $pdf->importPage(1); + $pdf->useTemplate($tppl); + $pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); + $pdf->Close(); + $pdf->Output($upload_dir.$ref."_signed-".$date.".pdf", "F"); + + $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; + $sql .= " SET fk_statut = ".((int) $object::STATUS_SIGNED).", note_private = '".$object->note_private."', date_signature='".$db->idate(dol_now())."'"; + $sql .= " WHERE rowid = ".((int) $object->id); + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $db->query($sql); + if (!$resql) { + $error++; + } else { + $num = $db->affected_rows($resql); + } + + if (!$error) { + $db->commit(); + $response = "success"; + } else { + $db->rollback(); + $response = "error sql"; + } + } + } + } + } else { + $response = 'error signature_not_found'; + } +} +echo $response; diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index d034db38be3..6d37684ce8f 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -49,6 +49,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.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", "paybox")); @@ -58,6 +59,8 @@ $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", // Get parameters $action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'alpha'); +$refusepropal = GETPOST('refusepropal', 'alpha'); // Input are: // type ('invoice','order','contractline'), @@ -80,7 +83,9 @@ if (!$action) { exit; } } - +if (!empty($refusepropal)) { + $action = "refusepropal"; +} // Define $urlwithroot //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); @@ -112,14 +117,16 @@ $urlko = preg_replace('/&$/', '', $urlko); // Remove last & $creditor = $mysoc->name; +$object = new Propal($db); +$object->fetch(0, $ref); /* * Actions */ -if ($action == 'dosign') { - // TODO +if ($action == 'refusepropal') { + //TODO: creer suite de cette action } @@ -290,7 +297,69 @@ if ($action != 'dosign') { } print ''."\n"; +print ''; +if ($action == "dosign" && empty($cancel)) { + print '
'; + print ''; + print '
'; + print '
'; + print ''; + print ''; + print ' + '; +} else { + if ($object->status == $object::STATUS_SIGNED) { + print $langs->trans("PropalSigned"); + } elseif ($object->status == $object::STATUS_NOTSIGNED) { + print $langs->trans("PropalNotSigned"); + } else { + print ''; + print ''; + } +} +print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; From 0c2cf9980d7391ad39508921aab4f42aa789e6f0 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 18 Oct 2021 14:28:30 +0200 Subject: [PATCH 2/4] NEW: online propal signature --- htdocs/core/ajax/onlineSign.php | 1 + htdocs/langs/en_US/propal.lang | 9 ++++++- htdocs/langs/fr_FR/propal.lang | 9 ++++++- htdocs/public/onlinesign/newonlinesign.php | 30 +++++++++++++++++----- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index 13bd28961d5..488b5051ea5 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -117,6 +117,7 @@ if ($action == "importSignature") { if (!$error) { $db->commit(); $response = "success"; + setEventMessage("PropalSigned"); } else { $db->rollback(); $response = "error sql"; diff --git a/htdocs/langs/en_US/propal.lang b/htdocs/langs/en_US/propal.lang index edbc08236d3..7141c1d38ae 100644 --- a/htdocs/langs/en_US/propal.lang +++ b/htdocs/langs/en_US/propal.lang @@ -89,4 +89,11 @@ IdProposal=Proposal ID IdProduct=Product ID PrParentLine=Proposal Parent Line LineBuyPriceHT=Buy Price Amount net of tax for line - +SignPropal=Sign proposal +RefusePropal=Refuse proposal +Sign=Sign +PropalAlreadyRefused=Proposal already refused +PropalAlreadySigned=Proposal already signed +PropalSigned=Proposal signed +PropalRefused=Proposal refused +ConfirmRefusePropal=Are you sure you want to refuse this commercial proposal? diff --git a/htdocs/langs/fr_FR/propal.lang b/htdocs/langs/fr_FR/propal.lang index f822d4f1d02..3728eba94d3 100644 --- a/htdocs/langs/fr_FR/propal.lang +++ b/htdocs/langs/fr_FR/propal.lang @@ -89,4 +89,11 @@ IdProposal=ID de la proposition commerciale IdProduct=ID produit PrParentLine=Ligne parent de proposition LineBuyPriceHT=Prix d'achat HT de la ligne - +SignPropal=Signer la proposition commerciale +RefusePropal=Refuser la proposition commerciale +Sign=Signer +PropalAlreadyRefused=Proposition commerciale déjà refusée +PropalAlreadySigned=Proposition commerciale déjà signée +PropalSigned=Proposition commerciale signée +PropalRefused=Proposition commerciale refusée +ConfirmRefusePropal=Êtes-vous sûr de vouloir refuser cette proposition commerciale ? diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index 6d37684ce8f..3177cbcc7a3 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -52,7 +52,7 @@ 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", "paybox")); +$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox","propal")); // Security check // No check on module enabled. Done later according to $validpaymentmethod @@ -124,9 +124,22 @@ $object->fetch(0, $ref); * Actions */ - -if ($action == 'refusepropal') { - //TODO: creer suite de cette action +if ($action == 'confirm_refusepropal') { + $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; + $sql .= " SET fk_statut = ".((int) $object::STATUS_NOTSIGNED).", note_private = '".$object->note_private."', date_signature='".$db->idate(dol_now())."'"; + $sql .= " WHERE rowid = ".((int) $object->id); + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $db->query($sql); + if (!$resql) { + $error++; + } + if (!$error) { + $db->commit(); + setEventMessage("PropalRefused"); + } else { + $db->rollback(); + } + $object->fetch(0, $ref); } @@ -134,6 +147,7 @@ if ($action == 'refusepropal') { * View */ +$form = new Form($db); $head = ''; if (!empty($conf->global->MAIN_SIGN_CSS_URL)) { $head = ''."\n"; @@ -145,6 +159,10 @@ $conf->dol_hide_leftmenu = 1; $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '
' : '').'
'; llxHeader($head, $langs->trans("OnlineSignature"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea, 1); +if ($action == 'refusepropal') { + print $form->formconfirm($_SERVER["PHP_SELF"].'?ref='.$ref, $langs->trans('RefusePropal'), $langs->trans('ConfirmRefusePropal', $object->ref), 'confirm_refusepropal', '', '', 1); +} + // Check link validity for param 'source' if (!empty($source) && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', ''))) { $langs->load("errors"); @@ -351,9 +369,9 @@ if ($action == "dosign" && empty($cancel)) { '; } else { if ($object->status == $object::STATUS_SIGNED) { - print $langs->trans("PropalSigned"); + print $langs->trans("PropalAlreadySigned"); } elseif ($object->status == $object::STATUS_NOTSIGNED) { - print $langs->trans("PropalNotSigned"); + print $langs->trans("PropalAlreadyRefused"); } else { print ''; print ''; From 9fc6be78e0daff593804598473842744146b9db6 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 18 Oct 2021 15:26:18 +0200 Subject: [PATCH 3/4] fix tcpdi.php each to foreach --- dev/dolibarr_changes.txt | 5 ++++- htdocs/includes/tcpdi/tcpdi.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 4f80f06d444..cce6351950c 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -188,7 +188,10 @@ with: with } elseif (($key == '/Index') AND ($v[0] == PDF_TYPE_ARRAY AND count($v[1]) >= 2)) { - +* Fix php fatal error on php 8.0 on tcpdi.php + while (list($k, $v) = each($value[1])) { +with + foreach ($value[1] as $k => $v) { JSGANTT: -------- diff --git a/htdocs/includes/tcpdi/tcpdi.php b/htdocs/includes/tcpdi/tcpdi.php index f4c0bd00391..aaa1d70c095 100644 --- a/htdocs/includes/tcpdi/tcpdi.php +++ b/htdocs/includes/tcpdi/tcpdi.php @@ -483,7 +483,7 @@ class TCPDI extends FPDF_TPL { reset ($value[1]); - while (list($k, $v) = each($value[1])) { + foreach ($value[1] as $k => $v) { $this->_straightOut($k . ' '); $this->pdf_write_value($v); } From a324f74d88456a33cdd2f2d064c3f36bf3cc5b6f Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 18 Oct 2021 15:35:15 +0200 Subject: [PATCH 4/4] update newonlinesign.php with border --- htdocs/public/onlinesign/newonlinesign.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index 3177cbcc7a3..4040bcf1425 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -319,7 +319,7 @@ print ''; if ($action == "dosign" && empty($cancel)) { print '
'; print ''; - print '
'; + print '
'; print '
'; print ''; print '';