removed FILTER_SANITIZE_STRING from filter_input since OpenEMR does html escaping...
[openemr.git] / interface / therapy_groups / therapy_groups_controllers / participants_controller.php
blob632e923e8b3a5361fe7b08854cce4b0cd7e6a7ed
1 <?php
3 /**
4 * interface/therapy_groups/therapy_groups_controllers/participants_controller.php contains the participants controller for therapy groups.
6 * This is the controller for the groups' participant view.
8 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
9 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
24 * @author Amiel Elboim <amielel@matrix.co.il>
25 * @link http://www.open-emr.org
28 require_once dirname(__FILE__) . '/base_controller.php';
29 require_once dirname(__FILE__) . '/therapy_groups_controller.php';
30 require_once("{$GLOBALS['srcdir']}/pid.inc");
32 class ParticipantsController extends BaseController{
34 public function __construct(){
35 $this->groupParticipantsModel = $this->loadModel('therapy_groups_participants');
36 $this->groupEventsModel = $this->loadModel('Therapy_Groups_Events');
37 $this->groupModel = $this->loadModel('therapy_groups');
40 public function index($groupId ,$data = array()){
42 if(isset($_POST['save'])){
44 for($k = 0; $k < count($_POST['pid']); $k++){
46 $patient['pid'] = $_POST['pid'][$k];
47 $patient['group_patient_status'] = $_POST['group_patient_status'][$k];
48 $patient['group_patient_start'] = $_POST['group_patient_start'][$k];
49 $patient['group_patient_end'] = $_POST['group_patient_end'][$k];
50 $patient['group_patient_comment'] = $_POST['group_patient_comment'][$k];
52 $filters = array(
53 'group_patient_status' => FILTER_VALIDATE_INT,
54 'group_patient_start' => FILTER_DEFAULT,
55 'group_patient_end' => FILTER_SANITIZE_SPECIAL_CHARS,
56 'group_patient_comment' => FILTER_SANITIZE_SPECIAL_CHARS,
58 //filter and sanitize all post data.
59 $participant = filter_var_array($patient, $filters);
60 $this->groupParticipantsModel->updateParticipant($participant,$patient['pid'], $_POST['group_id']);
61 unset($_GET['editParticipants']);
65 if(isset($_GET['deleteParticipant'])){
67 $this->groupParticipantsModel->removeParticipant($_GET['group_id'],$_GET['pid']);
70 $data['events'] = $this->groupEventsModel->getGroupEvents($groupId);
71 $data['readonly'] = 'disabled';
72 $data['participants'] = $this->groupParticipantsModel->getParticipants($groupId);
73 $data['statuses'] = TherapyGroupsController::prepareParticipantStatusesList();
74 $data['groupId'] = $groupId;
75 $groupData = $this->groupModel->getGroup($groupId);
76 $data['groupName'] = $groupData['group_name'];
78 if(isset($_GET['editParticipants'])){
79 $data['readonly'] = '';
82 TherapyGroupsController::setSession($groupId);
84 $this->loadView('groupDetailsParticipants', $data);
88 public function add($groupId){
90 if(isset($_POST['save_new'])){
92 $alreadyRegistered = $this->groupParticipantsModel->isAlreadyRegistered($_POST['pid'], $groupId);
93 if($alreadyRegistered){
94 $this->index($groupId, array('participant_data' => $_POST, 'addStatus' => 'failed','message' => xlt('The patient already registered to the group')));
96 // adding group id to $_POST
97 $_POST = array('group_id' => $groupId) + $_POST;
99 $filters = array(
100 'group_id' => FILTER_VALIDATE_INT,
101 'pid' => FILTER_VALIDATE_INT,
102 'group_patient_start' => FILTER_DEFAULT,
103 'group_patient_comment' => FILTER_SANITIZE_SPECIAL_CHARS,
106 $participant_data = filter_var_array($_POST, $filters);
108 $participant_data['group_patient_status'] = 10;
109 $participant_data['group_patient_end'] = 'NULL';
111 $this->groupParticipantsModel->saveParticipant($participant_data);
114 $this->index($groupId, array('participant_data' => null));