22 if (!defined(
'NOTOKENRENEWAL')) {
23 define(
'NOTOKENRENEWAL',
'1');
25 if (!defined(
'NOREQUIREHTML')) {
26 define(
'NOREQUIREHTML',
'1');
28 if (!defined(
'NOREQUIREAJAX')) {
29 define(
'NOREQUIREAJAX',
'1');
35 if (!defined(
'NOCSRFCHECK')) {
36 define(
'NOCSRFCHECK',
'1');
39 if (!defined(
'NOREQUIREMENU')) {
40 define(
'NOREQUIREMENU',
'1');
43 if (!defined(
"NOLOGIN")) {
44 define(
"NOLOGIN",
'1');
46 if (!defined(
'NOIPCHECK')) {
47 define(
'NOIPCHECK',
'1');
49 if (!defined(
'NOBROWSERNOTIF')) {
50 define(
'NOBROWSERNOTIF',
'1');
52 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
53 if (is_numeric($entity)) {
54 define(
"DOLENTITY", $entity);
56 include
'../../main.inc.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
59 $action =
GETPOST(
'action',
'aZ09');
61 $signature =
GETPOST(
'signaturebase64');
63 $mode =
GETPOST(
'mode',
'aZ09');
64 $SECUREKEY =
GETPOST(
"securekey");
73 if ($type ==
'proposal') {
77 if (empty($SECUREKEY) || !
dol_verifyHash($securekeyseed.$type.$ref.(empty($conf->multicompany->enabled) ?
'' : $entity), $SECUREKEY,
'0')) {
78 http_response_code(403);
79 print
'Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).
' does not match expected value for ref='.
dol_escape_htmltag($ref);
95 if ($action ==
"importSignature") {
96 if (!empty($signature) && $signature[0] ==
"image/png;base64") {
97 $signature = $signature[1];
98 $data = base64_decode($signature);
100 if ($mode ==
"propale" || $mode ==
'proposal') {
101 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
102 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
103 $object =
new Propal($db);
104 $object->fetch(0, $ref);
106 $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
107 $upload_dir .=
'/'.dol_sanitizeFileName($object->ref).
'/';
110 $filename =
"signatures/".$date.
"_signature.png";
111 if (!is_dir($upload_dir.
"signatures/")) {
112 if (!
dol_mkdir($upload_dir.
"signatures/")) {
113 $response =
"Error mkdir. Failed to create dir ".$upload_dir.
"signatures/";
119 $return = file_put_contents($upload_dir.$filename, $data);
120 if ($return ==
false) {
122 $response =
'Error file_put_content: failed to create signature file.';
128 $last_main_doc_file = $object->last_main_doc;
129 $directdownloadlink = $object->getLastMainDocLink(
'proposal');
131 if (preg_match(
'/\.pdf/i', $last_main_doc_file)) {
133 $newpdffilename = $upload_dir.$ref.
"_signed-".$date.
".pdf";
134 $sourcefile = $upload_dir.$ref.
".pdf";
139 if (class_exists(
'TCPDF')) {
140 $pdf->setPrintHeader(
false);
141 $pdf->setPrintFooter(
false);
146 $pdf->SetCompression(
false);
151 $pagecount = $pdf->setSourceFile($sourcefile);
154 for ($i=1; $i<($pagecount+1); $i++) {
156 $tppl = $pdf->importPage($i);
157 $s = $pdf->getTemplatesize($tppl);
158 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
159 $pdf->useTemplate($tppl);
161 dol_syslog(
"Error when manipulating some PDF by onlineSign: ".$e->getMessage(), LOG_ERR);
162 $response = $e->getMessage();
169 $xforimgstart = (empty($s[
'w']) ? 120 : round($s[
'w'] / 2) + 15);
170 $yforimgstart = (empty($s[
'h']) ? 240 : $s[
'h'] - 60);
171 $wforimg = $s[
'w'] - 20 - $xforimgstart;
173 $pdf->Image($upload_dir.$filename, $xforimgstart, $yforimgstart, $wforimg, round($wforimg / 4));
175 $pdf->Output($newpdffilename,
"F");
178 $object->indexFile($newpdffilename, 1);
180 } elseif (preg_match(
'/\.odt/i', $last_main_doc_file)) {
193 $online_sign_name =
'';
195 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"propal";
196 $sql .=
" SET fk_statut = ".((int) $object::STATUS_SIGNED).
", note_private = '".$db->escape($object->note_private).
"',";
197 $sql .=
" date_signature = '".$db->idate(
dol_now()).
"',";
198 $sql .=
" online_sign_ip = '".$db->escape($online_sign_ip).
"'";
199 if ($online_sign_name) {
200 $sql .=
", online_sign_name = '".$db->escape($online_sign_name).
"'";
202 $sql .=
" WHERE rowid = ".((int) $object->id);
205 $resql = $db->query($sql);
209 $num = $db->affected_rows(
$resql);
214 $response =
"success";
216 if (method_exists($object,
'call_trigger')) {
218 $user =
new User($db);
219 $user->fetch($object->user_valid_id);
220 $result = $object->call_trigger(
'PROPAL_CLOSE_SIGNED', $user);
228 $response =
"error sql";
234 $response =
'error signature_not_found';
239 http_response_code(501);