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/>.
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
28 require_once("../../../interface/globals.php");
29 require_once 'sigconvert.php';
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') {
42 if (! json_decode($output)) {
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';
53 $svg = new sigToSvg($output, array (
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 (
68 $image = ob_get_contents();
70 $image_png = smart_resize_image(null, $image, $svg->max
[0], 75, true, 'return', false, false, 100, false);
71 //imagepng( $image_png, $resizedFile, 0 );
73 $image = ob_get_contents();
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
85 $sig_hash = sha1($output);
87 $ip = $_SERVER['REMOTE_ADDR'];
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);
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));
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');