GLOB_BRACE recursive compatibly fix.
[openemr.git] / portal / messaging / handle_note.php
blob250b5c7c7d14fa554342f69a8f4031a0a8fba37c
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
23 session_start();
24 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
25 $ignoreAuth = true;
26 require_once(dirname(__FILE__) . "/../../interface/globals.php");
27 } else {
28 session_destroy();
29 $ignoreAuth = false;
30 require_once(dirname(__FILE__) . "/../../interface/globals.php");
31 if (! isset($_SESSION['authUserID'])) {
32 $landingpage = "index.php";
33 header('Location: ' . $landingpage);
34 exit();
38 require_once(dirname(__FILE__) . "/../lib/portal_mail.inc");
39 require_once("$srcdir/pnotes.inc");
41 $task = $_POST['task'];
42 if (! $task) {
43 return 'no task';
46 $noteid = $_POST['noteid'] ? $_POST['noteid'] : 0;
47 $notejson = $_POST['notejson'] ? json_decode($_POST['notejson'], true) : 0;
48 $reply_noteid = $_POST['replyid'] ? $_POST['replyid'] : 0;
49 $owner = isset($_POST['owner']) ? $_POST['owner'] : $_SESSION['pid'];
50 $note = $_POST['inputBody'];
51 $title = $_POST['title'];
52 $sid = $_POST['sender_id'];
53 $sn = $_POST['sender_name'];
54 $rid = $_POST['recipient_id'];
55 $rn = $_POST['recipient_name'];
56 $header = '';
58 switch ($task) {
59 case "forward":
60 $pid = isset($_POST['pid']) ? $_POST['pid'] : 0;
61 addPnote($pid, $note, 1, 1, $title, $sid, '', 'New');
62 updatePortalMailMessageStatus($noteid, 'Sent');
63 echo 'ok';
64 break;
65 case "add":
66 // each user has their own copy of message
67 sendMail($owner, $note, $title, $header, $noteid, $sid, $sn, $rid, $rn, 'New');
68 sendMail($rid, $note, $title, $header, $noteid, $sid, $sn, $rid, $rn, 'New', $reply_noteid);
69 echo 'ok';
70 break;
71 case "reply":
72 sendMail($owner, $note, $title, $header, $noteid, $sid, $sn, $rid, $rn, 'Reply', '');
73 sendMail($rid, $note, $title, $header, $noteid, $sid, $sn, $rid, $rn, 'New', $reply_noteid);
74 echo 'ok';
75 break;
76 case "delete":
77 updatePortalMailMessageStatus($noteid, 'Delete');
78 echo 'ok';
79 break;
80 case "massdelete":
81 foreach ($notejson as $deleteid) {
82 updatePortalMailMessageStatus($deleteid, 'Delete');
83 echo 'ok';
85 break;
86 case "setread":
87 if ($noteid > 0) {
88 updatePortalMailMessageStatus($noteid, 'Read');
89 echo 'ok';
90 } else {
91 echo 'missing note id';
93 break;
94 case "getinbox":
95 if ($owner) {
96 $result = getMails($owner, 'inbox', '', '');
97 echo json_encode($result);
98 } else {
99 echo 'error';
101 break;
102 case "getsent":
103 if ($owner) {
104 $result = getMails($owner, 'sent', '', '');
105 echo json_encode($result);
106 } else {
107 echo 'error';
109 break;
110 case "getall":
111 if ($owner) {
112 $result = getMails($owner, 'all', '', '');
113 echo json_encode($result);
114 } else {
115 echo 'error';
117 break;
118 case "getdeleted":
119 if ($owner) {
120 $result = getMails($owner, 'deleted', '', '');
121 echo json_encode($result);
122 } else {
123 echo 'error';
125 break;
126 default:
127 echo 'failed';
128 break;
131 if (isset($_REQUEST["submit"])) {
132 header("Location: {$_REQUEST["submit"]}");