fix: bug (#7552)
[openemr.git] / library / custom_template / add_context.php
blobf89a7762d4d6bdcab246a2bc6d7544a3e2958aae
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>
27 // +------------------------------------------------------------------------------+
31 require_once("../../interface/globals.php");
33 use OpenEMR\Core\Header;
35 if (trim($_POST['contextname'] ?? '') != '' && $_POST['action'] == 'add') {
36 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0 AND cl_list_item_long=?", array($_POST['contextname']));
37 if (!sqlNumRows($res)) {
38 $id = sqlInsert("INSERT INTO customlists (cl_list_type,cl_list_item_long) VALUES(?,?)", array(2,$_POST['contextname']));
39 sqlStatement("UPDATE customlists SET cl_list_id=? WHERE cl_list_slno=?", array($id,$id));
41 } elseif ($_POST['action'] ?? '' == 'delete' && $_POST['item'] != '') {
42 sqlStatement("UPDATE customlists SET cl_deleted=1 WHERE cl_list_type=2 AND cl_list_slno=?", array($_POST['item']));
43 } elseif ($_POST['action'] ?? '' == 'update' && $_POST['item'] != '') {
44 sqlStatement("UPDATE customlists SET cl_list_item_long=? WHERE cl_deleted=0 AND cl_list_type=2 AND cl_list_slno=?", array($_POST['updatecontextname'],$_POST['item']));
47 <html>
48 <head>
49 <?php Header::setupHeader('opener'); ?>
50 <style>
51 .bottom {
52 border-bottom: 1px solid var(--black);
54 .top {
55 border-top: 1px solid var(--black);
57 .left {
58 border-left: 1px solid var(--black);
60 .right {
61 border-right:1px solid var(--black);
63 .class1 {
64 background-color: #add9e9;
66 .class2 {
67 background-color: #b1c0a5;
69 </style>
70 <script>
71 $(function () {
72 $('#contextadd').hide();
73 $('#contextupdate').hide();
74 $('#addcontextbtn').click(function() {
75 $('#contextadd').show(600);
76 $('#contextlist').hide(600);
77 $('#addcontextbtn').hide(600);
78 return false;
79 });
80 $('#cancel').click(function() {
81 $('#contextadd').hide(600);
82 $('#contextlist').show(600);
83 $('#addcontextbtn').show(600);
84 return false;
85 });
86 $('#ucancel').click(function() {
87 $('#contextupdate').hide(600);
88 $('#contextlist').show(600);
89 $('#addcontextbtn').show(600);
90 return false;
91 });
92 });
93 function checkSubmit(){
94 top.restoreSession();
95 if(document.getElementById('contextname').value){
96 document.getElementById('action').value='add';
97 document.designation_managment.submit();
99 else{
100 alert("<?php echo addslashes(xl('Context name can\'t be empty'));?>");
103 function deleteme(id){
104 top.restoreSession();
105 msg = '';
106 CheckContextLive(id);
107 stat = document.getElementById('stat').value;
108 if(stat==1){
109 msg = "<?php echo addslashes(xl('This context contains categories, which will be deleted. Do you still want to continue?'));?>";
111 else{
112 msg = "<?php echo addslashes(xl('Do you want to delete this?'));?>";
114 if(confirm(msg)){
115 document.getElementById('action').value='delete';
116 document.getElementById('item').value=id;
117 document.designation_managment.submit();
120 function editme(id,val){
121 top.restoreSession();
122 $('#contextupdate').show(600);
123 $('#contextlist').hide(600);
124 $('#addcontextbtn').hide(600);
125 document.getElementById('item').value=id;
126 document.getElementById('updatecontextname').value=val;
128 function checkUpdate(){
129 top.restoreSession();
130 if(document.getElementById('updatecontextname').value){
131 document.getElementById('action').value='update';
132 document.designation_managment.submit();
134 else{
135 alert("<?php echo addslashes(xl('Context name can\'t be empty'));?>");
138 function CheckContextLive(id){
139 top.restoreSession();
140 $.ajax({
141 type: "POST",
142 url: "ajax_code.php",
143 dataType: "html",
144 data: {
145 list_id: id,
146 source: "checkcontext"
148 async: false,
149 success: function(thedata){
150 document.getElementById('stat').value=thedata;
152 error:function(){
153 alert("fail");
156 return;
158 </script>
160 </head>
161 <body class="body_top">
162 <form name="designation_managment" action="" method="post">
163 <table cellpadding='2' cellspacing='0' border="0" align="center">
165 <tr height="30">
166 <td class='title_bar' colspan="4" align="center"><u><?php echo htmlspecialchars(xl('Add Context'), ENT_QUOTES);?></u></td>
167 <td class='title_bar' align="center"><a href="#" id="addcontextbtn" class="btn btn-primary"><span><?php echo htmlspecialchars(xl('Add'), ENT_QUOTES);?></span></a></td>
168 </tr>
169 <tr id="contextlist">
170 <td colspan="4">
171 <table>
172 <tr>
173 <td align="center" class="title_bar_top top right bottom left">#</td>
174 <td align="center" class="title_bar_top top right bottom"><?php echo htmlspecialchars(xl('Context'), ENT_QUOTES);?></td>
175 <td align="center" class="title_bar_top top right bottom"><?php echo htmlspecialchars(xl('Edit'), ENT_QUOTES);?></td>
176 <td align="center" class="title_bar_top top right bottom"><?php echo htmlspecialchars(xl('Delete'), ENT_QUOTES);?></td>
177 </tr>
178 <?php
179 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
180 $i = 0;
181 while ($row = sqlFetchArray($res)) {
182 $i++;
183 $class = ($class ?? '' == 'class1') ? 'class2' : 'class1';
185 <tr class="text <?php echo $class;?>">
186 <td class="right bottom left"><?php echo htmlspecialchars($i, ENT_QUOTES);?></td>
187 <td class="right bottom"><?php echo htmlspecialchars(xl($row['cl_list_item_long']), ENT_QUOTES);?></td>
188 <td class="right bottom"><a href="#" onclick='editme("<?php echo htmlspecialchars($row['cl_list_slno'], ENT_QUOTES);?>","<?php echo htmlspecialchars($row['cl_list_item_long'], ENT_QUOTES);?>")'><img src='<?php echo $GLOBALS['images_static_relative']; ?>/b_edit.png' border=0></a></td>
189 <td class="right bottom"><a href="#" onclick="deleteme(<?php echo htmlspecialchars($row['cl_list_slno'], ENT_QUOTES);?>)"><img src='<?php echo $GLOBALS['images_static_relative']; ?>/deleteBtn.png' border=0></a></td>
190 </tr>
191 <?php
194 </table>
195 </td>
196 </tr>
197 <tr id="contextadd">
198 <td colspan="3"><input type="text" name="contextname" id="contextname"></td>
199 <td colspan="1"><a href="#" onclick="checkSubmit()" class="btn btn-primary"><span><?php echo htmlspecialchars(xl('Save'), ENT_QUOTES);?><a href="#" id="cancel" class="btn btn-secondary"><span><?php echo htmlspecialchars(xl('Cancel'), ENT_QUOTES);?></span></a></span></a></td>
200 </tr>
201 <tr id="contextupdate">
202 <td colspan="3"><input type="text" name="updatecontextname" id="updatecontextname"></td>
203 <td colspan="1"><a href="#" onclick="checkUpdate()" class="btn btn-primary"><span><?php echo htmlspecialchars(xl('Update'), ENT_QUOTES);?><a href="#" id="ucancel" class="btn btn-secondary"><span><?php echo htmlspecialchars(xl('Cancel'), ENT_QUOTES);?></span></a></span></a></td>
204 </tr>
205 <input type="hidden" name="action" id="action">
206 <input type="hidden" name="item" id="item">
207 <input type="hidden" name="stat" id="stat">
208 </table>
209 </form>
210 </body>
211 </html>