POS default selection for encounter (#1088)
[openemr.git] / library / custom_template / personalize.php
blob5c797bea8231636550301260c6c748071ea42915
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");
31 $list_id= $_REQUEST['list_id'] ? $_REQUEST['list_id']: $_REQUEST['filter_context'];
33 function Delete_Rows($id){
34 sqlStatement("DELETE FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($id,$_SESSION['authId']));
36 function Insert_Rows($id,$order=""){
37 sqlStatement("REPLACE INTO template_users (tu_template_id,tu_user_id,tu_template_order) VALUES (?,?,?)",array($id,$_SESSION['authId'],$order));
40 if(isset($_REQUEST['submitform']) && $_REQUEST['submitform']=='save'){
41 $topersonalized = $_REQUEST['topersonalized'];
42 $personalized = $_REQUEST['personalized'];
43 foreach($topersonalized as $key=>$value){
44 $arr=explode("|",$value);
45 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($arr[0],$_SESSION['authId']));
46 if(sqlNumRows($res)){
47 Delete_Rows($arr[0]);
48 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0",array($arr[0]));
49 while($row=sqlFetchArray($qry)){
50 Delete_Rows($row['cl_list_slno']);
55 //Add new Categories
56 foreach($personalized as $key=>$value){
57 $arr=explode("|",$value);
58 if($arr[1]){
59 $res = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($arr[0],$_SESSION['authId']));
60 Insert_Rows($arr[0]);
61 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0",array($arr[0]));
62 while($row=sqlFetchArray($qry)){
63 $qryTU = sqlStatement("SELECT * FROM template_users WHERE tu_template_id=? AND tu_user_id=?",array($row['cl_list_slno'],$arr[1]));
64 while($rowTU=sqlFetchArray($qryTU)){
65 Insert_Rows($rowTU['tu_template_id'],$rowTU['tu_template_order']);
69 else{
70 Insert_Rows($arr[0]);
71 $qry = sqlStatement("SELECT * FROM customlists WHERE cl_list_id=? AND cl_deleted=0",array($arr[0]));
72 while($row=sqlFetchArray($qry)){
73 Insert_Rows($row['cl_list_slno'],$row['cl_order']);
79 <html>
80 <head>
81 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
82 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
83 <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
84 <script src="ckeditor/_samples/sample.js" type="text/javascript"></script>
85 <link href="ckeditor/_samples/sample.css" rel="stylesheet" type="text/css" />
86 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
87 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
88 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
89 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui-1.7.1.custom.min.js"></script>
90 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
91 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
92 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
93 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
94 <script type="text/javascript">
95 $(document).ready(function(){
97 // fancy box
98 enable_modals();
100 tabbify();
102 // special size for
103 $(".iframe_small").fancybox( {
104 'overlayOpacity' : 0.0,
105 'showCloseButton' : true,
106 'frameHeight' : 170,
107 'frameWidth' : 380
109 $(".iframe_medium").fancybox( {
110 'overlayOpacity' : 0.0,
111 'showCloseButton' : true,
112 'frameHeight' : 250,
113 'frameWidth' : 450
115 $(".iframe_abvmedium").fancybox( {
116 'overlayOpacity' : 0.0,
117 'showCloseButton' : true,
118 'frameHeight' : 500,
119 'frameWidth' : 700
121 $(function(){
122 // add drag and drop functionality to fancybox
123 $("#fancy_outer").easydrag();
126 function check_user_category(form,selectFrom,selectedList){
127 top.restoreSession();
128 var total_selected= form.elements[selectedList].length -1;
129 var msg='';
130 for (total_selected; total_selected>= 0; total_selected--)
132 if (form.elements[selectedList].options[total_selected].selected)
133 { if(document.getElementById('filter_users').value){
134 $.ajax({
135 type: "POST",
136 url: "ajax_code.php",
137 dataType: "html",
138 data: {
139 item: form.elements[selectedList].options[total_selected].value,
140 list_id: document.getElementById('filter_users').value,
141 source: "check_item"
143 async: false,
144 success: function(thedata){
145 if(thedata=='OK'){
146 total_clients= form.elements[selectFrom].length;
147 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
148 form.elements[selectFrom].options[total_clients] = opt;
149 form.elements[selectedList].options[total_selected] = null;
151 else{
152 msg += form.elements[selectedList].options[total_selected].text+"\n";
155 error:function(){
156 alert("fail");
160 else{
161 total_clients= form.elements[selectFrom].length;
162 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
163 form.elements[selectFrom].options[total_clients] = opt;
164 form.elements[selectedList].options[total_selected] = null;
168 jsub_sortNow(form.elements[selectFrom]);
169 if(msg!=''){
170 if(confirm("<?php echo addslashes(xl('The following categories will be removed from your category List'));?> \n" +msg +"\n <?php echo addslashes(xl('Do you want to continue?'));?>")){
171 remove_selected(form,selectedList);
174 return;
176 function remove_selected(form,selectedList)
178 top.restoreSession();
179 var total_selected= form.elements[selectedList].length -1;
180 for (total_selected; total_selected>= 0; total_selected--)
182 if (form.elements[selectedList].options[total_selected].selected)
184 form.elements[selectedList].options[total_selected] = null;
187 jsub_sortNow(form.elements[selectFrom]);
188 return;
190 function all_selected(selectedList){
191 top.restoreSession();
192 var total_selected= document.getElementById(selectedList).length -1;
193 for (total_selected; total_selected>= 0; total_selected--)
195 document.getElementById(selectedList).options[total_selected].selected=true;
198 function all_deselected(selectedList){
199 top.restoreSession();
200 var total_selected= document.getElementById(selectedList).length -1;
201 for (total_selected; total_selected>= 0; total_selected--)
203 document.getElementById(selectedList).options[total_selected].selected=false;
206 function jsub_selected(form,selectFrom,selectedList)
208 top.restoreSession();
209 var total_selected= form.elements[selectedList].length -1;
210 for (total_selected; total_selected>= 0; total_selected--)
212 if (form.elements[selectedList].options[total_selected].selected)
214 total_clients= form.elements[selectFrom].length;
215 opt = new Option(form.elements[selectedList].options[total_selected].text, form.elements[selectedList].options[total_selected].value);
216 form.elements[selectFrom].options[total_clients] = opt;
217 form.elements[selectedList].options[total_selected] = null;
220 jsub_sortNow(form.elements[selectFrom]);
221 return;
223 function display_category_item(form,selectedList){
224 top.restoreSession();
225 var len=0;
226 var selectedval='';
227 var total_selected= form.elements[selectedList].length -1;
228 for (total_selected; total_selected>= 0; total_selected--)
230 if(form.elements[selectedList].options[total_selected].selected)
232 selectedval=form.elements[selectedList].options[total_selected].value;
233 len++;
236 if(len>1){
237 document.getElementById('itemdiv').style.display='none';
239 else if(len==1){
240 document.getElementById('itemdiv').style.display='';
241 $.ajax({
242 type: "POST",
243 url: "ajax_code.php",
244 dataType: "html",
245 data: {
246 list_id: selectedval,
247 source: "item_show"
249 async: false,
250 success: function(thedata){
251 document.getElementById('itemdiv').innerHTML=thedata;
253 error:function(){
254 alert("fail");
257 return;
260 function jsub_sortNow(obj)
262 top.restoreSession();
263 var len = obj.length-1;
264 var text = new Array();
265 var values = new Array();
266 var sortarr = new Array();
267 for(var i=len; i>=0; i--)
269 text[i] = obj.options[i].text;
270 values[i]=obj.options[i].value;
271 sortarr[i]=obj.options[i].text;
273 sortarr.sort();
274 obj.length=0;
275 for(i=0; i<=len; i++)
277 for(j=0; j<=len; j++)
279 if(sortarr[i] == text[j])
281 break;
284 opt = new Option(text[j],values[j]);
285 obj.options[i] = opt;
288 function personalize_save(){
289 top.restoreSession();
290 document.getElementById('submitform').value='save';
291 all_selected('topersonalized');
292 all_selected('personalized');
293 document.myform.submit();
295 </script>
296 </head>
297 <body class="body_top">
298 <form name="myform" method="post" onsubmit="top.restoreSession();">
299 <fieldset>
300 <legend><span class="text"><?php echo htmlspecialchars(xl('Filter'),ENT_QUOTES);?></span></legend>
301 <table>
302 <tr class="text">
303 <td><?php echo htmlspecialchars(xl('Context'),ENT_QUOTES);?></td>
304 <td>
305 <select name='filter_context' id='filter_context' onchange='javascript:document.myform.submit();'>
306 <option value=''><?php echo htmlspecialchars(xl('Select a Context'),ENT_QUOTES);?></option>
307 <?php
308 $context_sql="SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0";
309 $context_res=sqlStatement($context_sql);
310 while($context_row=sqlFetchArray($context_res)){
311 echo "<option value='".htmlspecialchars($context_row['cl_list_slno'],ENT_QUOTES)."' ";
312 echo ($_REQUEST['filter_context']==$context_row['cl_list_slno']) ? 'selected' : '' ;
313 echo ">".htmlspecialchars($context_row['cl_list_item_long'],ENT_QUOTES)."</option>";
316 </select>
317 </td>
318 <td><?php echo htmlspecialchars(xl('Users'),ENT_QUOTES);?></td>
319 <td>
320 <select name='filter_users' id='filter_users' onchange='javascript:document.myform.submit();'>
321 <option value=''><?php echo htmlspecialchars(xl('Select a User'),ENT_QUOTES);?></option>
322 <?php
323 $user_sql="SELECT DISTINCT(tu.tu_user_id),u.fname,u.lname FROM template_users AS tu LEFT OUTER JOIN users AS u ON tu.tu_user_id=u.id WHERE tu.tu_user_id!=?";
324 $user_res=sqlStatement($user_sql,array($_SESSION['authId']));
325 while($user_row=sqlFetchArray($user_res)){
326 echo "<option value='".htmlspecialchars($user_row['tu_user_id'],ENT_QUOTES)."' ";
327 echo ($_REQUEST['filter_users']==$user_row['tu_user_id']) ? 'selected' : '' ;
328 echo ">".htmlspecialchars($user_row['fname']." ".$user_row['lname'],ENT_QUOTES)."</option>";
331 </select>
332 </td>
333 </tr>
334 </table>
335 </fieldset>
336 <table align="center" width="100%">
337 <tr class="text">
338 <td colspan="3">
339 <a href=# class="css_button" onclick="top.restoreSession();personalize_save()"><span><?php echo htmlspecialchars(xl('Save'),ENT_QUOTES);?></span></a>
340 <?php
341 if(acl_check('nationnotes', 'nn_configure')){
343 <a href="delete_category.php" id="share_link" class="iframe_medium css_button" onclick="top.restoreSession();"><span><?php echo htmlspecialchars(xl('Delete Category'),ENT_QUOTES);?></span></a>
344 <?php
347 <?php
348 if(acl_check('nationnotes', 'nn_configure')){
350 <a href="add_template.php?list_id=<?php echo $_REQUEST['list_id'];?>" onclick="top.restoreSession();" class="iframe_small css_button" title="<?php echo htmlspecialchars(xl('Add Category'),ENT_QUOTES);?>"><span><?php echo htmlspecialchars(xl('Add Category'),ENT_QUOTES);?></span></a>
351 <?php
354 <?php
355 if(acl_check('nationnotes', 'nn_configure')){
357 <a href="add_context.php" class="iframe_medium css_button" onclick="top.restoreSession();" title="<?php echo htmlspecialchars(xl('Add Context'),ENT_QUOTES);?>"><span><?php echo htmlspecialchars(xl('Add Context'),ENT_QUOTES);?></span></a>
358 <?php
361 <tr class="text">
362 <th><?php echo htmlspecialchars(xl('Available categories'),ENT_QUOTES);?></th>
363 <th>&nbsp;</th>
364 <?php
365 $user = sqlQuery("SELECT * FROM users WHERE id=?",array($_SESSION['authId']));
367 <th><?php echo htmlspecialchars(xl('Categories for')." ".$user['fname']." ".$user['lname'],ENT_QUOTES);?></th>
368 </tr>
369 <tr class="text">
370 <td align=right>
371 <select multiple name="topersonalized[]" id="topersonalized" size="6" style="width:220px" onchange="display_category_item(document.myform,'topersonalized');">
372 <?php
373 $where ='';
374 $join = '';
375 $arval = array($_SESSION['authId']);
376 $arval1 = array($_REQUEST['filter_users'],$_SESSION['authId']);
377 if($_REQUEST['filter_context']){
378 $where .=" AND cl_list_id=?";
379 array_push($arval,$_REQUEST['filter_context']);
380 array_push($arval1,$_REQUEST['filter_context']);
382 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno
383 WHERE cl_list_type=3 AND cl_deleted=0 AND tu.tu_template_id NOT IN (SELECT tu_template_id FROM template_users AS tuser WHERE
384 tu_user_id=?) ".
385 $where.
386 " ORDER BY cl_list_id,tu_user_id,cl_list_item_long";
387 $resTemplates = sqlStatement($sql,$arval);
388 if($_REQUEST['filter_users']){
389 $sql = " SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
390 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 AND tu.tu_template_id NOT IN
391 (SELECT tu_template_id FROM template_users AS tuser WHERE tu_user_id=?)".
392 $where .
393 "ORDER BY cl_list_id,tu_user_id,c.cl_list_item_long";
394 $resTemplates = sqlStatement($sql,$arval1);
396 while($rowTemplates = sqlFetchArray($resTemplates)){
397 $cntxt='';
398 if(!$_REQUEST['filter_context']){
399 $context=sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?",array($rowTemplates['cl_list_id']));
400 $cntxt.=$context['cl_list_item_long']."->";
402 if(!$_REQUEST['filter_users']){
403 $context=sqlQuery("SELECT * FROM users WHERE id=?",array($rowTemplates['tu_user_id']));
404 $cntxt.=$context['username']."->";
406 echo "<option value='".htmlspecialchars($rowTemplates['cl_list_slno']."|".$rowTemplates['tu_user_id'],ENT_QUOTES)."'>".htmlspecialchars($cntxt.$rowTemplates['cl_list_item_long'],ENT_QUOTES)."</option>";
408 $sqlorphan = "SELECT * FROM customlists WHERE cl_list_type=3 AND cl_deleted=0 AND cl_list_slno ".
409 " NOT IN (SELECT DISTINCT tu_template_id FROM template_users) ".
410 $where.
411 " ORDER BY cl_list_id,cl_list_item_long";
412 $resorphan = sqlStatement($sqlorphan);
413 while($roworphan = sqlFetchArray($resorphan)){
414 $cntxt='';
415 if(!$_REQUEST['filter_context']){
416 $context=sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?",array($roworphan['cl_list_id']));
417 $cntxt.=$context['cl_list_item_long']."->";
419 echo "<option value='".htmlspecialchars($roworphan['cl_list_slno']."|",ENT_QUOTES)."'>".htmlspecialchars($cntxt.$roworphan['cl_list_item_long'],ENT_QUOTES)."</option>";
422 </select>
423 </td>
424 <td align="center">
425 <input type="button" name="remove" value=&raquo; onclick="jsub_selected(document.myform,'personalized','topersonalized')"></br>
426 <input type="button" name="remove" value=&laquo; onclick="check_user_category(document.myform,'topersonalized','personalized')">
427 </td>
428 <td align=left>
429 <select multiple name="personalized[]" id="personalized" size="6" style="width:220px">
430 <?php
431 $where ='';
432 if($_REQUEST['filter_context']){
433 $where .=" AND cl_list_id='".$_REQUEST['filter_context']."'";
435 $sql = "SELECT * FROM template_users AS tu LEFT OUTER JOIN customlists AS c ON tu.tu_template_id=c.cl_list_slno WHERE
436 tu.tu_user_id=? AND c.cl_list_type=3 AND cl_deleted=0 ".
437 $where .
438 "ORDER BY c.cl_list_item_long";
439 $resTemplates = sqlStatement($sql,array($_SESSION['authId']));
440 while($rowTemplates = sqlFetchArray($resTemplates)){
441 $cntxt='';
442 if(!$_REQUEST['filter_context']){
443 $context=sqlQuery("SELECT * FROM customlists WHERE cl_list_slno=?",array($rowTemplates['cl_list_id']));
444 $cntxt.=$context['cl_list_item_long']."->";
446 echo "<option value='".htmlspecialchars($rowTemplates['cl_list_slno']."|".$rowTemplates['tu_user_id'],ENT_QUOTES)."'>".htmlspecialchars($cntxt.$rowTemplates['cl_list_item_long'],ENT_QUOTES)."</option>";
449 </select>
450 </td>
451 </tr>
452 <tr class="text">
453 <td>&nbsp;</td>
454 <td>&nbsp;</td>
455 <td><input type="hidden" name="submitform" id="submitform" value=""></td>
456 </tr>
457 <tr class="text">
458 <td colspan="3">
459 <div style="width:100%;overflow:auto;height:150px" id="itemdiv"></div>
460 </td>
461 </tr>
462 </table>
463 </form>
464 </body>
465 </html>