WIP : signature of propal

This commit is contained in:
lmarcouiller 2021-10-15 16:58:59 +02:00
parent a6c3c6b7ec
commit 9eb8dadfd9
2 changed files with 203 additions and 3 deletions

View File

@ -0,0 +1,131 @@
<?php
/*
* 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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \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;

View File

@ -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 '</td></tr>'."\n";
print '<tr><td align="center">';
if ($action == "dosign" && empty($cancel)) {
print '<div class="tablepublicpayment">';
print '<input type="button" class="button" id="clearsignature" value="'.$langs->trans("ClearSignature").'">';
print '<div id="signature"></div>';
print '</div>';
print '<input type="button" class="button" id="signpropal" value="'.$langs->trans("Sign").'">';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '<script language="JavaScript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jSignature/jSignature.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#signature").jSignature({color:"#000",lineWidth:4});
$("#signature").on("change",function(){
$("#clearsignature").css("display","");
$("#signpropal").attr("disabled",false);
if(!$._data($("#signpropal")[0], "events")){
$("#signpropal").on("click",function(){
var signature = $("#signature").jSignature("getData", "image");
$.ajax({
type: "POST",
url: "'.DOL_URL_ROOT.'/core/ajax/onlineSign.php",
dataType: "text",
data: {
"action" : "importSignature",
"signaturebase64" : signature,
"ref" : "'.$REF.'",
"mode" : "propale",
},
success: function(response) {
if(response == "success"){
console.log("Success on saving signature");
window.location.replace("'.$_SERVER["SELF"].'?ref='.$ref.'");
}else{
console.error(response);
}
},
});
});
}
});
$("#clearsignature").on("click",function(){
$("#signature").jSignature("clear");
$("#signpropal").attr("disabled",true);
$("#clearsignature").css("display","none");
});
$("#clearsignature").css("display","none");
$("#signpropal").attr("disabled",true);
});
</script>';
} else {
if ($object->status == $object::STATUS_SIGNED) {
print $langs->trans("PropalSigned");
} elseif ($object->status == $object::STATUS_NOTSIGNED) {
print $langs->trans("PropalNotSigned");
} else {
print '<input type="submit" class="button" value="'.$langs->trans("SignPropal").'">';
print '<input name="refusepropal" type="submit" class="button" value="'.$langs->trans("RefusePropal").'">';
}
}
print '</td></tr>'."\n";
print '</table>'."\n";
print '</form>'."\n";
print '</div>'."\n";