Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / interface / main / finder / dynamic_finder.php
blob8447f58df0ed5b1737bfa83c6a740898007c88c3
1 <?php
2 // Copyright (C) 2012 Rod Roark <rod@sunsetsystems.com>
3 // Sponsored by David Eschelbacher, MD
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // Sanitize escapes and stop fake register globals.
12 $sanitize_all_escapes = true;
13 $fake_register_globals = false;
15 require_once("../../globals.php");
16 require_once("$srcdir/formdata.inc.php");
18 $popup = empty($_REQUEST['popup']) ? 0 : 1;
20 // Generate some code based on the list of columns.
22 $colcount = 0;
23 $header0 = "";
24 $header = "";
25 $coljson = "";
26 $res = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
27 "list_id = 'ptlistcols' ORDER BY seq, title");
28 while ($row = sqlFetchArray($res)) {
29 $colname = $row['option_id'];
30 $title = xl_list_label($row['title']);
31 $header .= " <th>";
32 $header .= text($title);
33 $header .= "</th>\n";
34 $header0 .= " <td align='center'><input type='text' size='10' ";
35 $header0 .= "value='' class='search_init' /></td>\n";
36 if ($coljson) $coljson .= ", ";
37 $coljson .= "{\"sName\": \"" . addcslashes($colname, "\t\r\n\"\\") . "\"}";
38 ++$colcount;
41 <html>
42 <head>
43 <?php html_header_show(); ?>
45 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
47 <style type="text/css">
48 @import "../../../library/js/datatables/media/css/demo_page.css";
49 @import "../../../library/js/datatables/media/css/demo_table.css";
50 .mytopdiv { float: left; margin-right: 1em; }
51 </style>
53 <script type="text/javascript" src="../../../library/js/datatables/media/js/jquery.js"></script>
54 <script type="text/javascript" src="../../../library/js/datatables/media/js/jquery.dataTables.min.js"></script>
55 <!-- this is a 3rd party script -->
56 <script type="text/javascript" src="../../../library/js/datatables/extras/ColReorder/media/js/ColReorderWithResize.js"></script>
58 <script language="JavaScript">
60 $(document).ready(function() {
62 // Initializing the DataTable.
64 var oTable = $('#pt_table').dataTable( {
65 "bProcessing": true,
66 // next 2 lines invoke server side processing
67 "bServerSide": true,
68 "sAjaxSource": "dynamic_finder_ajax.php",
69 // sDom invokes ColReorderWithResize and allows inclusion of a custom div
70 "sDom" : 'Rlfrt<"mytopdiv">ip',
71 // These column names come over as $_GET['sColumns'], a comma-separated list of the names.
72 // See: http://datatables.net/usage/columns and
73 // http://datatables.net/release-datatables/extras/ColReorder/server_side.html
74 "aoColumns": [ <?php echo $coljson; ?> ],
75 "aLengthMenu": [ 10, 25, 50, 100 ],
76 "iDisplayLength": <?php echo empty($GLOBALS['gbl_pt_list_page_size']) ? '10' : $GLOBALS['gbl_pt_list_page_size']; ?>,
77 // language strings are included so we can translate them
78 "oLanguage": {
79 "sSearch" : "<?php echo xla('Search all columns'); ?>:",
80 "sLengthMenu" : "<?php echo xla('Show') . ' _MENU_ ' . xla('entries'); ?>",
81 "sZeroRecords" : "<?php echo xla('No matching records found'); ?>",
82 "sInfo" : "<?php echo xla('Showing') . ' _START_ ' . xla('to{{range}}') . ' _END_ ' . xla('of') . ' _TOTAL_ ' . xla('entries'); ?>",
83 "sInfoEmpty" : "<?php echo xla('Nothing to show'); ?>",
84 "sInfoFiltered": "(<?php echo xla('filtered from') . ' _MAX_ ' . xla('total entries'); ?>)",
85 "oPaginate": {
86 "sFirst" : "<?php echo xla('First'); ?>",
87 "sPrevious": "<?php echo xla('Previous'); ?>",
88 "sNext" : "<?php echo xla('Next'); ?>",
89 "sLast" : "<?php echo xla('Last'); ?>"
92 } );
94 // This puts our custom HTML into the table header.
95 $("div.mytopdiv").html("<form name='myform'><input type='checkbox' name='form_new_window' value='1'<?php
96 if (!empty($GLOBALS['gbl_pt_list_new_window'])) echo ' checked'; ?> /><?php
97 echo xlt('Open in New Window'); ?></form>");
99 // This is to support column-specific search fields.
100 // Borrowed from the multi_filter.html example.
101 $("thead input").keyup(function () {
102 // Filter on the column (the index) of this element
103 oTable.fnFilter( this.value, $("thead input").index(this) );
106 // OnClick handler for the rows
107 $('#pt_table tbody tr').live('click', function () {
108 var newpid = this.id.substring(4);
109 if (document.myform.form_new_window.checked) {
110 openNewTopWindow(newpid);
112 else {
113 <?php if ($GLOBALS['concurrent_layout']) { ?>
114 document.location.href = "../../patient_file/summary/demographics.php?set_pid=" + newpid;
115 <?php } else { ?>
116 top.location.href = "../../patient_file/patient_file.php?set_pid=" + newpid;
117 <?php } ?>
119 } );
123 function openNewTopWindow(pid) {
124 document.fnew.patientID.value = pid;
125 top.restoreSession();
126 document.fnew.submit();
129 </script>
131 </head>
132 <body class="body_top">
134 <div id="dynamic"><!-- TBD: id seems unused, is this div required? -->
136 <!-- Class "display" is defined in demo_table.css -->
137 <table cellpadding="0" cellspacing="0" border="0" class="display" id="pt_table">
138 <thead>
139 <tr>
140 <?php echo $header0; ?>
141 </tr>
142 <tr>
143 <?php echo $header; ?>
144 </tr>
145 </thead>
146 <tbody>
147 <tr>
148 <!-- Class "dataTables_empty" is defined in jquery.dataTables.css -->
149 <td colspan="<?php echo $colcount; ?>" class="dataTables_empty">...</td>
150 </tr>
151 </tbody>
152 </table>
154 </div>
156 <!-- form used to open a new top level window when a patient row is clicked -->
157 <form name='fnew' method='post' target='_blank' action='../main_screen.php?auth=login&site=<?php echo attr($_SESSION['site_id']); ?>'>
158 <input type='hidden' name='patientID' value='0' />
159 </form>
161 </body>
162 </html>