feat: New Clinical Note defaults to today (#6911)
[openemr.git] / library / custom_template / ajax_code.php
blob2b3f2e321809875d8a2946b1e189560fb646a005
1 <?php
3 // +-----------------------------------------------------------------------------+
4 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
5 //
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
19 // A copy of the GNU General Public License is included along with this program:
20 // openemr/interface/login/GnuGPL.html
21 // For more information write to the Free Software
22 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 // Author: Eldho Chacko <eldho@zhservices.com>
25 // Jacob T Paul <jacob@zhservices.com>
26 // Jerry Padgett <sjpadgett@gmail.com>
27 // +------------------------------------------------------------------------------+
30 require_once("../../interface/globals.php");
32 use OpenEMR\Common\Acl\AclMain;
34 $templateid = $_REQUEST['templateid'];
35 $Source = $_REQUEST['source'];
36 $list_id = $_REQUEST['list_id'];
37 $item = $_REQUEST['item'];
38 $multi = $_REQUEST['multi'];
39 $content = $_REQUEST['content'];
41 if ($Source == "add_template") {
42 $arr = explode("|", $multi);
44 for ($i = 0; $i < count($arr) - 1; $i++) {
45 $sql = sqlStatement("SELECT * FROM customlists AS cl LEFT OUTER JOIN template_users AS tu ON cl.cl_list_slno=tu.tu_template_id
46 WHERE cl_list_item_long=? AND cl_list_type=3 AND cl_deleted=0 AND cl_list_id=? AND tu.tu_user_id=?", array($templateid, $arr[$i], $_SESSION['authUserID']));
47 $cnt = sqlNumRows($sql);
48 if ($cnt == 0) {
49 $newid = sqlInsert("INSERT INTO customlists (cl_list_id,cl_list_type,cl_list_item_long,cl_creator) VALUES (?,?,?,?)", array($arr[$i], 3, $templateid, $_SESSION['authUserID']));
50 sqlStatement("INSERT INTO template_users (tu_user_id,tu_template_id) VALUES (?,?)", array($_SESSION['authUserID'], $newid));
52 echo "<select name='template' id='template' onchange='TemplateSentence(this.value)' style='width:180px'>";
53 echo "<option value=''>" . htmlspecialchars(xl('Select category'), ENT_QUOTES) . "</option>";
54 $resTemplates = sqlStatement("SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
55 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_list_id=? AND cl_deleted=0 ORDER BY tu.tu_template_order,
56 c.cl_list_item_long", array($_SESSION['authUserID'], $list_id));
57 while ($rowTemplates = sqlFetchArray($resTemplates)) {
58 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'], ENT_QUOTES) . "'>" . htmlspecialchars($rowTemplates['cl_list_item_long'], ENT_QUOTES) . "</option>";
60 echo "</select>";
62 } elseif ($Source == "save_provider") {
63 $arr = explode("|", $multi);
64 for ($i = 0; $i < count($arr) - 1; $i++) {
65 $cnt = sqlNumRows(sqlStatement("SELECT * FROM template_users WHERE tu_user_id=? AND tu_template_id=?", array($arr[$i], $list_id)));
66 if (!$cnt) {
67 sqlStatement("INSERT INTO template_users (tu_user_id,tu_template_id) VALUES (?,?)", array($arr[$i], $list_id));
70 } elseif ($Source == "add_item") {
71 $row = sqlQuery("SELECT max(cl_order)+1 as order1 FROM customlists WHERE cl_list_id=?", array($templateid));
72 $order = $row['order1'];
73 $newid = sqlInsert("INSERT INTO customlists (cl_list_id,cl_list_type,cl_list_item_long,cl_order,cl_creator) VALUES (?,?,?,?,?)", array($templateid, 4, $item, $order, $_SESSION['authUserID']));
74 sqlStatement("INSERT INTO template_users (tu_user_id,tu_template_id,tu_template_order) VALUES (?,?,?)", array($_SESSION['authUserID'], $newid, $order));
75 } elseif ($Source == "delete_item") {
76 sqlStatement("DELETE FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($item, $_SESSION['authUserID']));
77 } elseif ($Source == "update_item") {
78 $row = sqlQuery("SELECT max(cl_order)+1 as order1 FROM customlists WHERE cl_list_id=?", array($templateid));
79 $order = $row['order1'];
80 $newid = sqlInsert("INSERT INTO customlists (cl_list_id,cl_list_type,cl_list_item_long,cl_order,cl_creator) VALUES (?,?,?,?,?)", array($templateid, 4, $content, $order, $_SESSION['authUserID']));
81 sqlStatement("UPDATE template_users SET tu_template_id=? WHERE tu_template_id=? AND tu_user_id=?", array($newid, $item, $_SESSION['authUserID']));
82 } elseif ($Source == 'item_show') {
83 $sql = "SELECT * FROM customlists WHERE cl_list_id=? AND cl_list_type=4 AND cl_deleted=0";
84 $res = sqlStatement($sql, array($list_id));
85 $selcat = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=? AND cl_list_type=3 AND cl_deleted=0", array($list_id));
86 $selcont = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=? AND cl_list_type=2 AND cl_deleted=0", array($selcat['cl_list_id']));
87 $cnt = sqlNumRows($res);
88 if ($cnt) {
89 echo "<table width='100%'>";
90 echo "<tr class='text'><th colspan=2 style='background-color:var(--white)'>" . htmlspecialchars(xl('Preview of'), " " . $selcat['cl_list_item_long'] . "(" . $selcont['cl_list_item_long'] . ")", ENT_QUOTES) . "</th></tr>";
91 $i = 0;
92 while ($row = sqlFetchArray($res)) {
93 $i++;
94 $class = ($class == 'reportTableOddRow') ? 'reportTableEvenRow' : 'reportTableOddRow';
95 echo "<tr class='text'><td style='background-color:var(--white)'>" . $i . "</td><td style='background-color:#ffffff'>" . htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES) . "</td></tr>";
97 echo "</table>";
98 } else {
99 echo "<table width='100%'>";
100 echo "<tr class='text'><th colspan=2 style='background-color:var(--white)'>" . htmlspecialchars(xl('No items under selected category'), ENT_QUOTES) . "</th></tr>";
101 echo "</table>";
103 $Source = "add_template";
104 } elseif ($Source == 'check_item') {
105 $sql = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?", array($item, $list_id));
106 $cnt = sqlNumRows($sql);
107 if ($cnt) {
108 echo htmlspecialchars(xl("OK"), ENT_QUOTES);
109 } else {
110 echo htmlspecialchars(xl("FAIL"), ENT_QUOTES);
112 $Source = "add_template";
113 } elseif ($Source == 'display_item') {
114 $multi = preg_replace('/\|$/', '', $multi);
115 $val = str_replace("|", ",", $multi);
116 echo "<select multiple name='topersonalizeditem[]' id='topersonalizeditem' size='6' style='width:220px' onchange='display_item()'>";
117 $resTemplates = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=4 AND cl_deleted=0 AND cl_list_id IN (?) ORDER BY cl_list_item_long", [$val]);
118 while ($rowTemplates = sqlFetchArray($resTemplates)) {
119 echo "<option value='" . htmlspecialchars($rowTemplates['cl_list_slno'], ENT_QUOTES) . "'>" . htmlspecialchars($rowTemplates['cl_list_item_long'], ENT_QUOTES) . "</option>";
121 echo "</select>";
122 $Source = "add_template";
123 } elseif ($Source == 'delete_category') {
124 $res = sqlStatement("SELECT * FROM template_users AS tu LEFT OUTER JOIN users AS u ON tu.tu_user_id=u.id WHERE tu_template_id=? AND tu.tu_user_id!=?", array($templateid, $_SESSION['authUserID']));
125 $users = '';
126 $i = 0;
127 while ($row = sqlFetchArray($res)) {
128 $i++;
129 $users .= $i . ")" . $row['fname'] . " " . $row['lname'] . "\n";
131 echo htmlspecialchars($users, ENT_QUOTES);
132 $Source = "add_template";
133 } elseif ($Source == 'delete_full_category') {
134 sqlStatement("UPDATE customlists SET cl_deleted=? WHERE cl_list_slno=?", array(1, $templateid));
135 sqlStatement("DELETE template_users WHERE tu_template_id=?", array($templateid));
136 $res = sqlStatement("SELECT * FROM customlists AS cl WHERE cl_list_id=?", array($templateid));
137 while ($row = sqlFetchArray($res)) {
138 sqlStatement("UPDATE customlists SET cl_deleted=1 WHERE cl_list_slno=?", array($row['cl_list_slno']));
139 sqlStatement("DELETE template_users WHERE tu_template_id=?", array($row['cl_list_slno']));
142 $Source = "add_template";
143 } elseif ($Source == 'checkcontext') {
144 $res = sqlStatement("SELECT * FROM customlists WHERE cl_deleted=0 AND cl_list_type=3 AND cl_list_id=?", array($list_id));
145 if (sqlNumRows($res)) {
146 echo "1";
147 } else {
148 echo "0";
150 $Source = "add_template";
152 if ($Source != "add_template") {
153 $res = sqlStatement(
154 "SELECT * FROM customlists AS cl LEFT OUTER JOIN template_users AS tu ON cl.cl_list_slno=tu.tu_template_id
155 WHERE cl_list_type=4 AND cl_list_id=? AND cl_deleted=0 AND tu.tu_user_id=? ORDER BY tu.tu_template_order",
156 array($templateid, $_SESSION['authUserID'])
158 $i = 0;
159 while ($row = sqlFetchArray($res)) {
160 $i++;
161 echo "<li id='clorder_" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "' style='cursor:pointer'><span>";
162 if (AclMain::aclCheckCore('nationnotes', 'nn_configure')) {
163 echo "<img src='" . $GLOBALS['images_static_relative'] . "/b_edit.png' onclick=update_item_div('" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "')>";
165 echo "<div style='display:inline' id='" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "' onclick=\"moveOptions_11('" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "', 'textarea1');\">" . htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES) . "</div>";
166 if (AclMain::aclCheckCore('nationnotes', 'nn_configure')) {
167 echo "<img src='" . $GLOBALS['images_static_relative'] . "/deleteBtn.png' onclick=\"delete_item('" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "')\">";
168 echo "<div id='update_item" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "' style='display:none'><textarea name='update_item_txt" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "' id='update_item_txt" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "' class='w-100'>" . htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES) . "</textarea><br />";
169 echo "<input type='button' name='update' onclick=update_item('" . $row['cl_list_slno'] . "') value='" . htmlspecialchars(xl('Update'), ENT_QUOTES) . "'><input type='button' name='cancel' value='" . htmlspecialchars(xl('Cancel'), ENT_QUOTES) . "' onclick=cancel_item('" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "')></div>";
171 echo "</span></li>";
173 if (AclMain::aclCheckCore('nationnotes', 'nn_configure') && $templateid) {
174 echo "<li style='cursor:pointer'><span onclick='add_item()'>" . htmlspecialchars(xl('Click to add new components'), ENT_QUOTES);
175 echo "</span><div id='new_item' style='display:none' class='w-100'>";
176 echo "<textarea name='item' id='item' class='w-100'></textarea><br />";
177 echo "<input type='button' name='save' value='" . htmlspecialchars(xl('Save'), ENT_QUOTES) . "' onclick='save_item()'><input type='button' name='cancel' value='" . htmlspecialchars(xl('Cancel'), ENT_QUOTES) . "' onclick=cancel_item('" . htmlspecialchars($row['cl_list_slno'], ENT_QUOTES) . "')></div></li>";