consolidate attr_url function (#2143)
[openemr.git] / interface / main / finder / dynamic_finder.php
blobff1d9611fd979c16b9b3f2131b9d129b265bd7e7
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 * @copyright Copyright (c) 2012-2016 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../../globals.php");
18 require_once "$srcdir/user.inc";
19 require_once "$srcdir/options.inc.php";
20 use OpenEMR\Core\Header;
22 $uspfx = 'patient_finder.'; //substr(__FILE__, strlen($webserver_root)) . '.';
23 $patient_finder_exact_search = prevSetting($uspfx, 'patient_finder_exact_search', 'patient_finder_exact_search', ' ');
25 $popup = empty($_REQUEST['popup']) ? 0 : 1;
27 // Generate some code based on the list of columns.
29 $colcount = 0;
30 $header0 = "";
31 $header = "";
32 $coljson = "";
33 $res = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
34 "list_id = 'ptlistcols' AND activity = 1 ORDER BY seq, title");
35 while ($row = sqlFetchArray($res)) {
36 $colname = $row['option_id'];
37 $title = xl_list_label($row['title']);
38 $title1 = ($title == xl('Full Name'))? xl('Name'): $title;
39 $header .= " <th>";
40 $header .= text($title);
41 $header .= "</th>\n";
42 $header0 .= " <td ><input type='text' size='20' ";
43 $header0 .= "value='' class='search_init' placeholder='".xla("Search by"). " " . $title1 ."'/></td>\n";
44 if ($coljson) {
45 $coljson .= ", ";
47 $coljson .= "{\"sName\": \"" . addcslashes($colname, "\t\r\n\"\\") . "\"}";
48 ++$colcount;
51 <html>
52 <head>
53 <?php Header::setupHeader();?>
54 <title><?php echo xlt("Patient Finder"); ?></title>
55 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-dt/css/jquery.dataTables.css" type="text/css">
56 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-colreorder-dt/css/colReorder.dataTables.css" type="text/css">
57 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net/js/jquery.dataTables.js"></script>
58 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/datatables.net-colreorder/js/dataTables.colReorder.js"></script>
60 <script language="JavaScript">
62 var uspfx = '<?php echo attr($uspfx); ?>';
64 $(document).ready(function () {
66 // Initializing the DataTable.
68 var oTable = $('#pt_table').dataTable({
69 "processing": true,
70 // next 2 lines invoke server side processing
71 "serverSide": true,
72 // NOTE kept the legacy command 'sAjaxSource' here for now since was unable to get
73 // the new 'ajax' command to work.
74 "sAjaxSource": "dynamic_finder_ajax.php?csrf_token_form=" + <?php echo js_escape(urlencode(collectCsrfToken())); ?>,
75 "fnServerParams": function (aoData) {
76 var searchType = $("#setting_search_type:checked").length > 0;
77 aoData.push({"name": "searchType", "value": searchType});
79 // dom invokes ColReorderWithResize and allows inclusion of a custom div
80 "dom": 'Rlfrt<"mytopdiv">ip',
81 // These column names come over as $_GET['sColumns'], a comma-separated list of the names.
82 // See: http://datatables.net/usage/columns and
83 // http://datatables.net/release-datatables/extras/ColReorder/server_side.html
84 "columns": [ <?php echo $coljson; ?> ],
85 "lengthMenu": [10, 25, 50, 100],
86 "pageLength": <?php echo empty($GLOBALS['gbl_pt_list_page_size']) ? '10' : $GLOBALS['gbl_pt_list_page_size']; ?>,
87 <?php // Bring in the translations ?>
88 <?php $translationsDatatablesOverride = array('search' => (xla('Search all columns') . ':')); ?>
89 <?php require($GLOBALS['srcdir'] . '/js/xl/datatables-net.js.php'); ?>
90 });
93 $("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
94 if (!empty($GLOBALS['gbl_pt_list_new_window'])) {
95 echo ' checked';
97 ?> /><?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>");
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));
105 // OnClick handler for the rows
106 $('#pt_table').on('click', 'tbody tr', function () {
107 // ID of a row element is pid_{value}
108 var newpid = this.id.substring(4);
109 // If the pid is invalid, then don't attempt to set
110 // The row display for "No matching records found" has no valid ID, but is
111 // otherwise clickable. (Matches this CSS selector). This prevents an invalid
112 // state for the PID to be set.
113 if (newpid.length === 0) {
114 return;
116 if (document.myform.form_new_window.checked) {
117 openNewTopWindow(newpid);
119 else {
120 top.restoreSession();
121 top.RTop.location = "../../patient_file/summary/demographics.php?set_pid=" + encodeURIComponent(newpid);
126 function openNewTopWindow(pid) {
127 document.fnew.patientID.value = pid;
128 top.restoreSession();
129 document.fnew.submit();
132 function persistCriteria(el, e){
133 e.preventDefault();
134 let target = uspfx + "patient_finder_exact_search";
135 let val = el.checked ? ' checked' : ' ';
136 $.post( "../../../library/ajax/user_settings.php",
138 target: target,
139 setting: val,
140 csrf_token_form: "<?php echo attr(collectCsrfToken()); ?>"
145 </script>
146 <?php
147 //to determine and set the page to open in the desired state - expanded or centered, any selection the user makes will
148 //become the user-specific default for that page. collectAndOrganizeExpandSetting() takes a single indexed array as an
149 //argument, containing one or more elements, the name of the current file is the first element, if there are linked
150 //files they should be listed thereafter, please add _xpd suffix to the file name
151 $arr_files_php = array("dynamic_finder_xpd");
152 $current_state = collectAndOrganizeExpandSetting($arr_files_php);
153 require_once("$srcdir/expand_contract_inc.php");
155 <script>
156 <?php require_once("$include_root/expand_contract_js.php");//jQuery to provide expand/contract icon toggle if page is expandable ?>
157 </script>
159 </head>
160 <body class="body_top">
161 <div class="<?php echo $container;?> expandable">
162 <div class="row">
163 <div class="col-sm-12">
164 <h2>
165 <?php echo xlt('Patient Finder') ?> <i id="exp_cont_icon" class="fa <?php echo attr($expand_icon_class);?> oe-superscript-small expand_contract"
166 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>
167 </h2>
168 </div>
169 </div>
170 <br>
171 <div class="row">
172 <div class="col-sm-12">
173 <div id="dynamic"><!-- TBD: id seems unused, is this div required? -->
174 <!-- Class "display" is defined in demo_table.css -->
175 <table border="0" cellpadding="0" cellspacing="0" class="display" id="pt_table">
176 <thead>
177 <tr id="advanced_search" class="hideaway" style="display: none;">
178 <?php echo $header0; ?>
179 </tr>
180 <tr class="head">
181 <?php echo $header; ?>
182 </tr>
183 </thead>
184 <tbody>
185 <tr>
186 <!-- Class "dataTables_empty" is defined in jquery.dataTables.css -->
187 <td class="dataTables_empty" colspan="<?php echo attr($colcount); ?>">...</td>
188 </tr>
189 </tbody>
190 </table>
191 </div>
192 </div>
193 </div>
194 <div class="row">
195 <div class="col-sm-12">
196 <!-- form used to open a new top level window when a patient row is clicked -->
197 <form name='fnew' method='post' target='_blank' action='../main_screen.php?auth=login&site=<?php echo attr_url($_SESSION['site_id']); ?>'>
198 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
199 <input type='hidden' name='patientID' value='0'/>
200 </form>
201 </div>
202 </div>
203 </div><!--end of container div-->
204 <script>
205 $(document).ready(function(){
206 $("#pt_table").removeAttr("style");
207 $("#exp_cont_icon").click(function(){
208 $("#pt_table").removeAttr("style");
211 </script>
212 <script>
213 $('#show_hide').click(function () {
214 var elementTitle = $('#show_hide').prop('title');
215 var hideTitle = '<?php echo xla('Click to hide advanced search'); ?>';
216 var showTitle = '<?php echo xla('Click to show advanced search'); ?>';
217 $('.hideaway').toggle();
218 $(this).toggleClass('fa-search-plus fa-search-minus');
219 if (elementTitle == hideTitle) {
220 elementTitle = showTitle;
221 } else if (elementTitle == showTitle) {
222 elementTitle = hideTitle;
224 $('#show_hide').prop('title', elementTitle);
226 </script>
227 </body>
228 </html>