Minor addition to message center help file (#1745)
[openemr.git] / portal / sign / lib / save-signature.php
blobc4fd7f21f456fa5328e45558018c0066aed456ee
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @package OpenEMR
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
27 $ignoreAuth = true;
28 require_once("../../../interface/globals.php");
29 require_once 'sigconvert.php';
30 $errors = array ();
31 $signer = filter_input(INPUT_POST, 'signer', FILTER_DEFAULT);
32 $type = filter_input(INPUT_POST, 'type', FILTER_DEFAULT);
33 $pid = filter_input(INPUT_POST, 'pid', FILTER_DEFAULT);
34 $output = filter_input(INPUT_POST, 'output', FILTER_UNSAFE_RAW);
35 $user = filter_input(INPUT_POST, 'user', FILTER_UNSAFE_RAW);
37 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
38 if ($type == 'admin-signature') {
39 $signer = $user;
42 if (! json_decode($output)) {
43 exit();
46 /* Don't need at present
47 if( $pid > 0 ) $resizedFile = './../../patient_documents/signed/current/' . $pid . '_master.png';
48 else $resizedFile = './../../patient_documents/signed/current/' . $signer . '_master.png';
50 $svgsig = '';
51 if (empty($errors)) {
52 try {
53 $svg = new sigToSvg($output, array (
54 'penWidth' => 6
55 ));
56 $svgsig = $svg->getImage();
57 $r = $svg->max[1] / $svg->max[0];
58 $x = round($svg->max[0] * $r);
59 $y = round($svg->max[1] * $r);
60 $img = sigJsonToImage($output, array (
61 'imageSize' => array (
62 $svg->max[0],
63 $svg->max[1]
65 ));
66 ob_start();
67 imagepng($img);
68 $image = ob_get_contents();
69 ob_clean();
70 $image_png = smart_resize_image(null, $image, $svg->max[0], 75, true, 'return', false, false, 100, false);
71 //imagepng( $image_png, $resizedFile, 0 );
72 imagepng($image_png);
73 $image = ob_get_contents();
74 ob_end_clean();
75 imagedestroy($img);
76 imagedestroy($image_png);
77 $image_data = base64_encode($image);
78 } catch (Exception $e) {
79 die($e->getMessage());
83 // No validation errors exist, so we can start the database stuff
84 if (empty($errors)) {
85 $sig_hash = sha1($output);
86 $created = time();
87 $ip = $_SERVER['REMOTE_ADDR'];
88 $status = 'filed';
89 $lastmod = date('Y-m-d H:i:s');
90 $r = sqlStatement("SELECT COUNT( DISTINCT TYPE ) x FROM onsite_signatures where pid = ? and user = ? ", array ($pid, $user));
91 $c = sqlFetchArray($r);
92 $isit = $c['x'] * 1;
93 if ($isit) {
94 $qstr = "UPDATE onsite_signatures SET pid=?,lastmod=?,status=?, user=?, signature=?, sig_hash=?, ip=?,sig_image=? WHERE pid=? && user=?";
95 $rcnt = sqlStatement($qstr, array($pid,$lastmod,$status,$user,$svgsig,$sig_hash,$ip,$image_data,$pid,$user));
96 } else {
97 $qstr = "INSERT INTO onsite_signatures (pid,lastmod,status,type,user,signator, signature, sig_hash, ip, created, sig_image) VALUES (?,?,?,?,?,?,?,?,?,?,?) ";
98 sqlStatement($qstr, array($pid , $lastmod, $status,$type, $user, $signer, $svgsig, $sig_hash, $ip, $created, $image_data));
102 print json_encode('Done');