Highway to PSR2
[openemr.git] / interface / forms / group_attendance / save.php
blob27c90dad281dba3599c6d11ee0f6f713c4a01247
1 <?php
2 /**
3 * interface/forms/group_attendance/save.php
5 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
6 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @package OpenEMR
20 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
21 * @author Amiel Elboim <amielel@matrix.co.il>
22 * @link http://www.open-emr.org
27 require_once("../../globals.php");
28 require_once("functions.php");
30 //Save only if has permission to edit
31 $can_edit = acl_check("groups", "gadd", false, 'write');
32 if (!$can_edit) {
33 formJump();
36 //Get relevant data from group appt (the appt that created the group encounter)
37 $appt_data = get_appt_data($encounter);
39 //Get relevant data from group encounter
40 $group_encounter_data = get_group_encounter_data($encounter);
42 //If saving new form
43 if ($_GET['mode'] == 'new') {
44 //Get the number that should be the new form's id
45 $newid = largest_id_plus_one('form_therapy_groups_attendance');
47 //Insert into 'forms' table
48 addForm($encounter, "Group Attendance Form", $newid, "group_attendance", null, $userauthorized);
50 //Insert into form_therapy_groups_attendance table
51 $sql_for_table_ftga = "INSERT INTO form_therapy_groups_attendance (id, date, group_id, user, groupname, authorized, encounter_id, activity) " .
52 "VALUES(?,NOW(),?,?,?,?,?,?);";
53 $sqlBindArray = array();
54 array_push($sqlBindArray, $newid, $therapy_group, $_SESSION["authUser"], $_SESSION["authProvider"], $userauthorized, $encounter, '1');
55 sqlInsert($sql_for_table_ftga, $sqlBindArray);
57 //Database insertions for participants
58 participant_insertions($newid, $therapy_group, $group_encounter_data, $appt_data);
59 } //If editing a form
60 elseif ($_GET['mode'] == 'update') {
61 //Update form_therapy_groups_attendance table
62 $id = $_GET['id'];
63 $sql_for_form_tga = "UPDATE form_therapy_groups_attendance SET date = NOW(), user = ?, groupname = ?, authorized = ? WHERE id = ?;";
64 $sqlBindArray = array();
65 array_push($sqlBindArray, $_SESSION["authUser"], $_SESSION["authProvider"], $userauthorized, $id);
66 sqlInsert($sql_for_form_tga, $sqlBindArray);
68 //Delete from therapy_groups_participant_attendance table
69 $sql_delete_from_table_tgpa = "DELETE FROM therapy_groups_participant_attendance WHERE form_id = ?;";
70 sqlStatement($sql_delete_from_table_tgpa, array($id));
72 //Database insertions for participants
73 participant_insertions($id, $therapy_group, $group_encounter_data, $appt_data);
76 formJump();