Add new modules loaded event (#7463)
[openemr.git] / interface / de_identification_forms / find_drug_popup.php
blob566ca88280ec8fa45b84b478f1b61fd3f193cf04
1 <?php
3 /**
4 * find_drug_popup.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Visolve <vicareplus_engg@visolve.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2010 ViCarePlus, Visolve <vicareplus_engg@visolve.com>
11 * @copyright Copyright (c) 2018-2019 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc.php");
17 require_once("../../custom/code_types.inc.php");
19 use OpenEMR\Common\Csrf\CsrfUtils;
20 use OpenEMR\Core\Header;
22 $info_msg = "";
23 $codetype = $_REQUEST['codetype'];
24 $form_code_type = $_POST['form_code_type'];
26 <html>
27 <head>
28 <title><?php echo xlt('Drug Finder'); ?></title>
29 <?php Header::setupHeader(); ?>
31 <style>
32 td { font-size:10pt; }
33 </style>
35 <script>
36 //pass value selected to the parent window
37 function window_submit(chk)
39 var str;
40 var len=chk.length;
41 if (len==undefined && chk.checked==1)
43 if(!str)
44 str = chk.value;
45 else
46 str = "#"+chk.value;
48 else
50 for (pr = 0; pr < chk.length; pr++)
52 if(chk[pr].checked == 1)
54 if(!str)
55 str = chk[pr].value;
56 else
57 str = str+"#"+chk[pr].value;
61 if(!str)
62 alert(<?php echo xlj("Select Drug");?>);
63 if (opener.closed || ! opener.set_related)
64 alert(<?php echo xlj('The destination form was closed')?>);
65 else
66 opener.set_related(str,"drugs");
68 window.close();
72 function window_close(chk)
74 window.close();
77 function chkbox_select_none(chk)
79 var len=chk.length;
80 if (len==undefined) {chk.checked=false;}
81 else
83 for (pr = 0; pr < chk.length; pr++)
85 chk[pr].checked=false;
90 function chkbox_select_all(chk)
92 var len=chk.length;
93 if (len==undefined) {chk.checked=true;}
94 else
96 for (pr = 0; pr < chk.length; pr++)
98 chk[pr].checked=true;
103 function check_search_str()
105 var search_str = document.getElementById('search_term').value;
106 if(search_str.length < 3)
108 alert(<?php echo xlj("Search string should have at least three characters");?>);
109 return false;
111 top.restoreSession();
112 return true;
115 </script>
116 </head>
117 <body class="body_top">
118 <form method='post' name='theform' action='find_drug_popup.php' onsubmit="return check_search_str();">
119 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
120 <center>
121 <input type="hidden" name="search_status" id="search_status" value=1;>
122 <table border='0' cellpadding='5' cellspacing='0'>
123 <tr>
124 <td height="1">
125 </td>
126 </tr>
127 <tr>
128 <td>
130 <?php echo xlt('Search for'); ?>
131 <input type='text' name='search_term' id='search_term' size='12' value='<?php echo attr($_REQUEST['search_term']); ?>'
132 title='<?php echo xla('Any part of the drug id or drug name'); ?>' />
133 &nbsp;
134 <input type='submit' name='bn_search' id='bn_search' value='<?php echo xla('Search'); ?>' />
135 </b>
136 </td>
137 </tr>
138 <tr>
139 <td height="1">
140 </td>
141 </tr>
142 </table>
143 </center>
144 </form>
145 <form method='post' name='select_drug'>
146 <table>
147 <tr>
148 <td colspan="4">
149 <?php if ($_REQUEST['bn_search']) {
150 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
151 CsrfUtils::csrfNotVerified();
154 $search_term = $_REQUEST['search_term'];
156 $query = "SELECT count(*) as count FROM drugs " .
157 "WHERE (drug_id LIKE ? OR " .
158 "name LIKE ?) ";
159 $res = sqlStatement($query, array('%' . $search_term . '%', '%' . $search_term . '%'));
160 if ($row = sqlFetchArray($res)) {
161 $no_of_items = $row['count'];
162 if ($no_of_items < 1) {
164 <script>
165 alert(<?php echo xlj('Search string does not match with list in database'); ?> + '\n' + <?php echo xlj('Please enter new search string'); ?>);
166 document.theform.search_term.value=" ";
167 document.theform.search_term.focus();
168 </script>
169 <?php
172 $query = "SELECT drug_id, name FROM drugs " .
173 "WHERE (drug_id LIKE ? OR " .
174 "name LIKE ?) " .
175 "ORDER BY drug_id";
176 $res = sqlStatement($query, array('%' . $search_term . '%', '%' . $search_term . '%'));
177 $row_count = 0;
178 while ($row = sqlFetchArray($res)) {
179 $row_count = $row_count + 1;
180 $itercode = $row['drug_id'];
181 $itertext = ucfirst(strtolower(trim($row['name'])));
183 <input type="checkbox" id="chkbox" name ="chkbox" value= "<?php echo attr($itercode) . "-" . attr($itertext); ?>" > <?php echo text($itercode) . " " . text($itertext) . "<br />";
189 </td>
190 </tr>
191 </table>
192 <center>
193 <input type='button' name='select_all' value='<?php echo xla('Select All'); ?>' onclick="chkbox_select_all(document.select_drug.chkbox);"/>
195 <input type='button' name='unselect_all' value='<?php echo xla('Unselect All'); ?>' onclick="chkbox_select_none(document.select_drug.chkbox);"/>
197 <input type='button' name='submit' value='<?php echo xla('Submit'); ?>' onclick="window_submit(document.select_drug.chkbox);"/>
199 <input type='button' name='cancel' value='<?php echo xla('Cancel'); ?>' onclick="window_close();"/>
200 </center>
201 <?php } ?>
202 </form>
203 </body>
204 </html>