POS default selection for encounter (#1088)
[openemr.git] / library / custom_template / ajax_code.php
blob2d2e096f91261c8f5961cd05ed69a1aa08df9beb
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // 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.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
26 // +------------------------------------------------------------------------------+
30 require_once("../../interface/globals.php");
32 $templateid = $_REQUEST['templateid'];
33 $Source = $_REQUEST['source'];
34 $list_id = $_REQUEST['list_id'];
35 $item = $_REQUEST['item'];
36 $multi = $_REQUEST['multi'];
37 $content = $_REQUEST['content'];
39 if($Source=="add_template"){
40 $arr = explode("|",$multi);
42 for($i=0;$i<sizeof($arr)-1;$i++){
43 $sql = sqlStatement("SELECT * FROM customlists AS cl LEFT OUTER JOIN template_users AS tu ON cl.cl_list_slno=tu.tu_template_id
44 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['authId']));
45 $cnt = sqlNumRows($sql);
46 if($cnt==0){
47 $newid=sqlInsert("INSERT INTO customlists (cl_list_id,cl_list_type,cl_list_item_long,cl_creator) VALUES (?,?,?,?)",array($arr[$i],3,$templateid,$_SESSION['authId']));
48 sqlInsert("INSERT INTO template_users (tu_user_id,tu_template_id) VALUES (?,?)",array($_SESSION['authId'],$newid));
50 echo "<select name='template' id='template' onchange='TemplateSentence(this.value)' style='width:180px'>";
51 echo "<option value=''>".htmlspecialchars(xl('Select category'),ENT_QUOTES)."</option>";
52 $resTemplates = sqlStatement("SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
53 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_list_id=? AND cl_deleted=0 ORDER BY tu.tu_template_order,
54 c.cl_list_item_long",array($_SESSION['authId'],$list_id));
55 while($rowTemplates = sqlFetchArray($resTemplates)){
56 echo "<option value='".htmlspecialchars($rowTemplates['cl_list_slno'],ENT_QUOTES)."'>".htmlspecialchars($rowTemplates['cl_list_item_long'],ENT_QUOTES)."</option>";
58 echo "</select>";
61 else if($Source=="save_provider"){
62 $arr = explode("|",$multi);
63 for($i=0;$i<sizeof($arr)-1;$i++){
64 $cnt = sqlNumRows(sqlStatement("SELECT * FROM template_users WHERE tu_user_id=? AND tu_template_id=?",array($arr[$i],$list_id)));
65 if(!$cnt){
66 sqlInsert("INSERT INTO template_users (tu_user_id,tu_template_id) VALUES (?,?)",array($arr[$i],$list_id));
70 else if($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['authId']));
74 sqlInsert("INSERT INTO template_users (tu_user_id,tu_template_id,tu_template_order) VALUES (?,?,?)",array($_SESSION['authId'],$newid,$order));
76 else if($Source=="delete_item"){
77 sqlStatement("DELETE FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($item,$_SESSION['authId']));
79 else if($Source=="update_item"){
80 $row = sqlQuery("SELECT max(cl_order)+1 as order1 FROM customlists WHERE cl_list_id=?",array($templateid));
81 $order = $row['order1'];
82 $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['authId']));
83 sqlStatement("UPDATE template_users SET tu_template_id=? WHERE tu_template_id=? AND tu_user_id=?",array($newid,$item,$_SESSION['authId']));
85 else if($Source=='item_show'){
86 $sql = "SELECT * FROM customlists WHERE cl_list_id=? AND cl_list_type=4 AND cl_deleted=0";
87 $res = sqlStatement($sql,array($list_id));
88 $selcat = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=? AND cl_list_type=3 AND cl_deleted=0",array($list_id));
89 $selcont = sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=? AND cl_list_type=2 AND cl_deleted=0",array($selcat['cl_list_id']));
90 $cnt =sqlNumRows($res);
91 if($cnt){
92 echo "<table width='100%'>";
93 echo "<tr class='text'><th colspan=2 style='background-color:#ffffff'>".htmlspecialchars(xl('Preview of')," ".$selcat['cl_list_item_long']."(".$selcont['cl_list_item_long'].")",ENT_QUOTES)."</th></tr>";
94 $i=0;
95 while($row=sqlFetchArray($res)){
96 $i++;
97 $class = ($class=='reportTableOddRow') ? 'reportTableEvenRow' : 'reportTableOddRow';
98 echo "<tr class='text'><td style='background-color:#ffffff'>".$i."</td><td style='background-color:#ffffff'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</td></tr>";
100 echo "</table>";
102 else{
103 echo "<table width='100%'>";
104 echo "<tr class='text'><th colspan=2 style='background-color:#ffffff'>".htmlspecialchars(xl('No items under selected category'),ENT_QUOTES)."</th></tr>";
105 echo "</table>";
107 $Source="add_template";
109 else if($Source=='check_item'){
110 $sql=sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($item,$list_id));
111 $cnt=sqlNumRows($sql);
112 if($cnt){
113 echo htmlspecialchars(xl("OK"),ENT_QUOTES);
115 else{
116 echo htmlspecialchars(xl("FAIL"),ENT_QUOTES);
118 $Source="add_template";
120 else if($Source=='display_item'){
121 $multi = preg_replace('/\|$/','',$multi);
122 $val = str_replace("|",",",$multi);
123 echo "<select multiple name='topersonalizeditem[]' id='topersonalizeditem' size='6' style='width:220px' onchange='display_item()'>";
124 $resTemplates = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=4 AND cl_deleted=0 AND cl_list_id IN ($val) ORDER BY cl_list_item_long");
125 while($rowTemplates = sqlFetchArray($resTemplates)){
126 echo "<option value='".htmlspecialchars($rowTemplates['cl_list_slno'],ENT_QUOTES)."'>".htmlspecialchars($rowTemplates['cl_list_item_long'],ENT_QUOTES)."</option>";
128 echo "</select>";
129 $Source="add_template";
131 else if($Source=='delete_category'){
132 $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['authId']));
133 $users ='';
134 $i=0;
135 while($row=sqlFetchArray($res)){
136 $i++;
137 $users .= $i.")".$row['fname']." ".$row['lname']."\n";
139 echo htmlspecialchars($users,ENT_QUOTES);
140 $Source="add_template";
142 else if($Source=='delete_full_category'){
143 sqlStatement("UPDATE customlists SET cl_deleted=? WHERE cl_list_slno=?",array(1,$templateid));
144 sqlStatement("DELETE template_users WHERE tu_template_id=?",array($templateid));
145 $res = sqlStatement("SELECT * FROM customlists AS cl WHERE cl_list_id=?",array($templateid));
146 while($row=sqlFetchArray($res)){
147 sqlStatement("UPDATE customlists SET cl_deleted=1 WHERE cl_list_slno=?",array($row['cl_list_slno']));
148 sqlStatement("DELETE template_users WHERE tu_template_id=?",array($row['cl_list_slno']));
151 $Source="add_template";
153 else if($Source=='checkcontext'){
154 $res = sqlStatement("SELECT * FROM customlists WHERE cl_deleted=0 AND cl_list_type=3 AND cl_list_id=?",array($list_id));
155 if(sqlNumRows($res)){
156 echo "1";
158 else{
159 echo "0";
161 $Source="add_template";
163 if($Source!="add_template"){
164 $res= sqlStatement("SELECT * FROM customlists AS cl LEFT OUTER JOIN template_users AS tu ON cl.cl_list_slno=tu.tu_template_id
165 WHERE cl_list_type=4 AND cl_list_id=? AND cl_deleted=0 AND tu.tu_user_id=? ORDER BY tu.tu_template_order",
166 array($templateid,$_SESSION['authId']));
167 $i=0;
168 while($row = sqlFetchArray($res)){
169 $i++;
170 echo "<li id='clorder_".htmlspecialchars($row['cl_list_slno'],ENT_QUOTES)."' style='cursor:pointer'><span>";
171 if(acl_check('nationnotes', 'nn_configure')){
172 echo "<img src='../../images/b_edit.png' onclick=update_item_div('".htmlspecialchars($row['cl_list_slno'],ENT_QUOTES)."')>";
174 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>";
175 if(acl_check('nationnotes', 'nn_configure')){
176 echo "<img src='../../images/deleteBtn.png' onclick=\"delete_item('".htmlspecialchars($row['cl_list_slno'],ENT_QUOTES)."')\">";
177 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)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</textarea></br>";
178 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>";
180 echo "</span></li>";
182 if(acl_check('nationnotes', 'nn_configure') && $templateid){
183 echo "<li style='cursor:pointer'><span onclick='add_item()'>".htmlspecialchars(xl('Click to add new components'),ENT_QUOTES);
184 echo "</span><div id='new_item' style='display:none'>";
185 echo "<textarea name='item' id='item'></textarea></br>";
186 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>";