Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / main / finder / dynamic_finder.php
blob7f6f9b2894fede20edf04c22c19dd58144ea55ee
1 <?php
2 /**
3 * dynamic_finder.php
5 * Sponsored by David Eschelbacher, MD
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @author Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2012-2016 Rod Roark <rod@sunsetsystems.com>
13 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
14 * @copyright Copyright (c) 2019 Jerry Padgett <sjpadgett@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
19 require_once(dirname(__FILE__) . "/../../globals.php");
20 require_once "$srcdir/user.inc";
21 require_once "$srcdir/options.inc.php";
22 use OpenEMR\Core\Header;
24 $uspfx = 'patient_finder.'; //substr(__FILE__, strlen($webserver_root)) . '.';
25 $patient_finder_exact_search = prevSetting($uspfx, 'patient_finder_exact_search', 'patient_finder_exact_search', ' ');
27 $popup = empty($_REQUEST['popup']) ? 0 : 1;
28 $searchAny = empty($_GET['search_any']) ? "" : $_GET['search_any'];
29 unset($_GET['search_any']);
30 // Generate some code based on the list of columns.
32 $colcount = 0;
33 $header0 = "";
34 $header = "";
35 $coljson = "";
36 $res = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
37 "list_id = 'ptlistcols' AND activity = 1 ORDER BY seq, title");
38 while ($row = sqlFetchArray($res)) {
39 $colname = $row['option_id'];
40 $title = xl_list_label($row['title']);
41 $title1 = ($title == xl('Full Name'))? xl('Name'): $title;
42 $header .= " <th>";
43 $header .= text($title);
44 $header .= "</th>\n";
45 $header0 .= " <td ><input type='text' size='20' ";
46 $header0 .= "value='' class='search_init' placeholder='".xla("Search by"). " " . $title1 ."'/></td>\n";
47 if ($coljson) {
48 $coljson .= ", ";
50 $coljson .= "{\"sName\": \"" . addcslashes($colname, "\t\r\n\"\\") . "\"}";
51 ++$colcount;
53 $loading = "<i class='fa fa-refresh fa-2x fa-spin'></i>";
55 <html>
56 <head>
57 <?php Header::setupHeader();?>
58 <title><?php echo xlt("Patient Finder"); ?></title>
59 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-dt/css/jquery.dataTables.css" type="text/css">
60 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-colreorder-dt/css/colReorder.dataTables.css" type="text/css">
61 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net/js/jquery.dataTables.js"></script>
62 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-colreorder/js/dataTables.colReorder.js"></script>
63 <style>
64 /* Finder Processing style */
65 div.dataTables_wrapper div.dataTables_processing {
66 top: -20px;
67 width: auto;
68 margin: 0;
69 color: red;
70 transform: translateX(-50%);
72 </style>
73 <script language="JavaScript">
75 var uspfx = '<?php echo attr($uspfx); ?>';
77 $(function () {
78 // Initializing the DataTable.
80 let serverUrl = "dynamic_finder_ajax.php?csrf_token_form=" + <?php echo js_url(collectCsrfToken()); ?>;
81 let srcAny = <?php echo js_url($searchAny); ?>;
82 if (srcAny) {
83 serverUrl += "&search_any=" + srcAny;
85 var oTable = $('#pt_table').dataTable({
86 "processing": true,
87 // next 2 lines invoke server side processing
88 "serverSide": true,
89 // NOTE kept the legacy command 'sAjaxSource' here for now since was unable to get
90 // the new 'ajax' command to work.
91 "sAjaxSource": serverUrl,
92 "fnServerParams": function (aoData) {
93 var searchType = $("#setting_search_type:checked").length > 0;
94 aoData.push({"name": "searchType", "value": searchType});
96 // dom invokes ColReorderWithResize and allows inclusion of a custom div
97 "dom": 'Rlfrt<"mytopdiv">ip',
98 // These column names come over as $_GET['sColumns'], a comma-separated list of the names.
99 // See: http://datatables.net/usage/columns and
100 // http://datatables.net/release-datatables/extras/ColReorder/server_side.html
101 "columns": [ <?php echo $coljson; ?> ],
102 "lengthMenu": [10, 25, 50, 100],
103 "pageLength": <?php echo empty($GLOBALS['gbl_pt_list_page_size']) ? '10' : $GLOBALS['gbl_pt_list_page_size']; ?>,
104 <?php // Bring in the translations ?>
105 <?php $translationsDatatablesOverride = array('search' => (xla('Search all columns') . ':')); ?>
106 <?php $translationsDatatablesOverride = array('processing' => $loading); ?>
107 <?php require($GLOBALS['srcdir'] . '/js/xl/datatables-net.js.php'); ?>
111 $("div.mytopdiv").html("<form name='myform'><label for='form_new_window' id='form_new_window_label'><input type='checkbox' id='form_new_window' name='form_new_window' value='1'<?php
112 if (!empty($GLOBALS['gbl_pt_list_new_window'])) {
113 echo ' checked';
115 ?> /><?php echo xlt('Open in New Window'); ?></label><label for='setting_search_type' id='setting_search_type_label'><input type='checkbox' name='setting_search_type' id='setting_search_type' onchange='persistCriteria(this, event)' value='<?php echo attr($patient_finder_exact_search); ?>'<?php echo text($patient_finder_exact_search); ?>/><?php echo xlt('Search with exact method'); ?></label></form>");
117 // This is to support column-specific search fields.
118 // Borrowed from the multi_filter.html example.
119 $("thead input").keyup(function () {
120 // Filter on the column (the index) of this element
121 oTable.fnFilter(this.value, $("thead input").index(this));
123 // OnClick handler for the rows
124 $('#pt_table').on('click', 'tbody tr', function () {
125 // ID of a row element is pid_{value}
126 var newpid = this.id.substring(4);
127 // If the pid is invalid, then don't attempt to set
128 // The row display for "No matching records found" has no valid ID, but is
129 // otherwise clickable. (Matches this CSS selector). This prevents an invalid
130 // state for the PID to be set.
131 if (newpid.length === 0) {
132 return;
134 if (document.myform.form_new_window.checked) {
135 openNewTopWindow(newpid);
137 else {
138 top.restoreSession();
139 top.RTop.location = "../../patient_file/summary/demographics.php?set_pid=" + encodeURIComponent(newpid);
144 function openNewTopWindow(pid) {
145 document.fnew.patientID.value = pid;
146 top.restoreSession();
147 document.fnew.submit();
150 function persistCriteria(el, e) {
151 e.preventDefault();
152 let target = uspfx + "patient_finder_exact_search";
153 let val = el.checked ? ' checked' : ' ';
154 $.post("../../../library/ajax/user_settings.php",
156 target: target,
157 setting: val,
158 csrf_token_form: "<?php echo attr(collectCsrfToken()); ?>"
163 </script>
164 <?php
165 //to determine and set the page to open in the desired state - expanded or centered, any selection the user makes will
166 //become the user-specific default for that page. collectAndOrganizeExpandSetting() takes a single indexed array as an
167 //argument, containing one or more elements, the name of the current file is the first element, if there are linked
168 //files they should be listed thereafter, please add _xpd suffix to the file name
169 $arr_files_php = array("dynamic_finder_xpd");
170 $current_state = collectAndOrganizeExpandSetting($arr_files_php);
171 require_once("$srcdir/expand_contract_inc.php");
173 <script>
174 <?php require_once("$include_root/expand_contract_js.php");//jQuery to provide expand/contract icon toggle if page is expandable ?>
175 </script>
177 </head>
178 <body class="body_top">
179 <div class="<?php echo $container;?> expandable">
180 <div class="row">
181 <div class="col-sm-10">
182 <h2>
183 <?php echo xlt('Patient Finder') ?> <i id="exp_cont_icon" class="fa <?php echo attr($expand_icon_class);?> oe-superscript-small expand_contract"
184 title="<?php echo attr($expand_title); ?>" aria-hidden="true"></i> <i id="show_hide" class="fa fa-search-plus fa-2x small" title="<?php echo xla('Click to show advanced search'); ?>"></i>
185 </h2>
186 </div>
187 <div class="col-sm-2">
188 <?php if (acl_check('patients', 'demo', '', array('write','addonly'))) { ?>
189 <button id="create_patient_btn" onclick="top.restoreSession();top.RTop.location = '<?php echo $web_root ?>/interface/new/new.php'"><?php echo xlt('Create Patient'); ?></button>
190 <?php } ?>
191 </div>
192 </div>
193 <br>
194 <div class="row">
195 <div class="col-sm-12">
196 <div id="dynamic"><!-- TBD: id seems unused, is this div required? -->
197 <!-- Class "display" is defined in demo_table.css -->
198 <table border="0" cellpadding="0" cellspacing="0" class="display" id="pt_table">
199 <thead>
200 <tr id="advanced_search" class="hideaway" style="display: none;">
201 <?php echo $header0; ?>
202 </tr>
203 <tr class="head">
204 <?php echo $header; ?>
205 </tr>
206 </thead>
207 <tbody>
208 <tr>
209 <!-- Class "dataTables_empty" is defined in jquery.dataTables.css -->
210 <td class="dataTables_empty" colspan="<?php echo attr($colcount); ?>">...</td>
211 </tr>
212 </tbody>
213 </table>
214 </div>
215 </div>
216 </div>
217 <div class="row">
218 <div class="col-sm-12">
219 <!-- form used to open a new top level window when a patient row is clicked -->
220 <form name='fnew' method='post' target='_blank' action='../main_screen.php?auth=login&site=<?php echo attr_url($_SESSION['site_id']); ?>'>
221 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
222 <input type='hidden' name='patientID' value='0'/>
223 </form>
224 </div>
225 </div>
226 </div><!--end of container div-->
227 <script>
228 $(function () {
229 $("#pt_table").removeAttr("style");
230 $("#exp_cont_icon").click(function () {
231 $("#pt_table").removeAttr("style");
234 </script>
235 <script>
236 $('#show_hide').click(function () {
237 var elementTitle = $('#show_hide').prop('title');
238 var hideTitle = '<?php echo xla('Click to hide advanced search'); ?>';
239 var showTitle = '<?php echo xla('Click to show advanced search'); ?>';
240 $('.hideaway').toggle();
241 $(this).toggleClass('fa-search-plus fa-search-minus');
242 if (elementTitle == hideTitle) {
243 elementTitle = showTitle;
244 } else if (elementTitle == showTitle) {
245 elementTitle = hideTitle;
247 $('#show_hide').prop('title', elementTitle);
249 </script>
250 </body>
251 </html>