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";