2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("drugs.inc.php");
13 $drug_id = $_REQUEST['drug'];
17 if (!acl_check('admin', 'drugs')) die("Not authorized!");
19 // Write a line of data for one template to the form.
21 function writeTemplateLine($selector, $dosage, $period, $quantity, $refills) {
22 global $tmpl_line_no, $interval_array;
26 echo " <td class='tmplcell'>";
27 echo "<input type='text' name='tmpl[$tmpl_line_no][selector]' value='$selector' size='10' maxlength='100'>";
29 echo " <td class='tmplcell'>";
30 echo "<input type='text' name='tmpl[$tmpl_line_no][dosage]' value='$dosage' size='10' maxlength='10'>";
32 echo " <td class='tmplcell'>";
33 echo "<select name='tmpl[$tmpl_line_no][period]'>";
34 foreach ($interval_array as $key => $value) {
35 echo "<option value='$key'";
36 if ($key == $period) echo " selected";
37 echo ">$value</option>";
40 echo " <td class='tmplcell'>";
41 echo "<input type='text' name='tmpl[$tmpl_line_no][quantity]' value='$quantity' size='5' maxlength='7'>";
43 echo " <td class='tmplcell'>";
44 echo "<input type='text' name='tmpl[$tmpl_line_no][refills]' value='$refills' size='3' maxlength='5'>";
51 <title
><?php
echo $drug_id ?
xl("Edit") : xl("Add New"); xl (' Drug','e'); ?
></title
>
52 <link rel
=stylesheet href
='<?php echo $css_header ?>' type
='text/css'>
55 td
{ font
-size
:10pt
; }
58 <script language
="JavaScript">
63 <body
<?php
echo $top_bg_line;?
>>
65 // If we are saving, then save and close the window.
67 if ($_POST['form_save'] ||
$_POST['form_delete']) {
70 if ($_POST['form_save']) {
71 sqlStatement("UPDATE drugs SET " .
72 "name = '" . $_POST['form_name'] . "', " .
73 "ndc_number = '" . $_POST['form_ndc_number'] . "', " .
74 "on_order = '" . $_POST['form_on_order'] . "', " .
75 "reorder_point = '" . $_POST['form_reorder_point'] . "', " .
76 "form = '" . $_POST['form_form'] . "', " .
77 "size = '" . $_POST['form_size'] . "', " .
78 "unit = '" . $_POST['form_unit'] . "', " .
79 "route = '" . $_POST['form_route'] . "' " .
80 "WHERE drug_id = '$drug_id'");
81 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
84 if (acl_check('admin', 'super')) {
85 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = '$drug_id'");
86 sqlStatement("DELETE FROM drug_templates WHERE drug_id = '$drug_id'");
87 sqlStatement("DELETE FROM drugs WHERE drug_id = '$drug_id'");
90 } else if ($_POST['form_save']) {
92 $drug_id = sqlInsert("INSERT INTO drugs ( " .
93 "name, ndc_number, on_order, reorder_point, form, " .
94 "size, unit, route " .
96 "'" . $_POST['form_name'] . "', " .
97 "'" . $_POST['form_ndc_number'] . "', " .
98 "'" . $_POST['form_on_order'] . "', " .
99 "'" . $_POST['form_reorder_point'] . "', " .
100 "'" . $_POST['form_form'] . "', " .
101 "'" . $_POST['form_size'] . "', " .
102 "'" . $_POST['form_unit'] . "', " .
103 "'" . $_POST['form_route'] . "' " .
107 if ($_POST['form_save'] && $drug_id) {
108 $tmpl = $_POST['tmpl'];
109 for ($lino = 1; isset($tmpl["$lino"]['selector']); ++
$lino) {
110 $iter = $tmpl["$lino"];
111 if (trim($iter['selector'])) {
112 sqlInsert("INSERT INTO drug_templates ( " .
113 "drug_id, selector, dosage, period, quantity, refills " .
116 "'" . trim($iter['selector']) . "', " .
117 "'" . trim($iter['dosage']) . "', " .
118 "'" . trim($iter['period']) . "', " .
119 "'" . trim($iter['quantity']) . "', " .
120 "'" . trim($iter['refills']) . "' " .
126 // Close this window and redisplay the updated list of drugs.
128 echo "<script language='JavaScript'>\n";
129 if ($info_msg) echo " alert('$info_msg');\n";
130 echo " if (opener.refreshme) opener.refreshme();\n";
132 echo " window.location.href='add_edit_lot.php?drug=$drug_id&lot=0'\n";
134 echo " window.close();\n";
136 echo "</script></body></html>\n";
141 $row = sqlQuery("SELECT * FROM drugs WHERE drug_id = '$drug_id'");
142 $tres = sqlStatement("SELECT * FROM drug_templates WHERE " .
143 "drug_id = '$drug_id' ORDER BY selector");
147 <form method
='post' name
='theform' action
='add_edit_drug.php?drug=<?php echo $drug_id; ?>'>
150 <table border
='0' width
='100%'>
153 <td valign
='top' nowrap
><b
><?php
xl('Name','e'); ?
>:</b
></td
>
155 <input type
='text' size
='40' name
='form_name' maxlength
='80' value
='<?php echo $row['name
'] ?>' style
='width:100%' />
160 <td valign
='top' nowrap
><b
><?php
xl('NDC Number','e'); ?
>:</b
></td
>
162 <input type
='text' size
='40' name
='form_ndc_number' maxlength
='20' value
='<?php echo $row['ndc_number
'] ?>' style
='width:100%' />
167 <td valign
='top' nowrap
><b
><?php
xl('On Order','e'); ?
>:</b
></td
>
169 <input type
='text' size
='5' name
='form_on_order' maxlength
='7' value
='<?php echo $row['on_order
'] ?>' />
174 <td valign
='top' nowrap
><b
><?php
xl('Reorder At','e'); ?
>:</b
></td
>
176 <input type
='text' size
='5' name
='form_reorder_point' maxlength
='7' value
='<?php echo $row['reorder_point
'] ?>' />
181 <td valign
='top' nowrap
><b
><?php
xl('Form','e'); ?
>:</b
></td
>
183 <select name
='form_form'>
185 foreach ($form_array as $key => $value) {
186 echo " <option value='$key'";
187 if ($key == $row['form']) echo " selected";
196 <td valign
='top' nowrap
><b
><?php
xl('Pill Size','e'); ?
>:</b
></td
>
198 <input type
='text' size
='5' name
='form_size' maxlength
='7' value
='<?php echo $row['size
'] ?>' />
203 <td valign
='top' nowrap
><b
><?php
xl('Units','e'); ?
>:</b
></td
>
205 <select name
='form_unit'>
207 foreach ($unit_array as $key => $value) {
208 echo " <option value='$key'";
209 if ($key == $row['unit']) echo " selected";
218 <td valign
='top' nowrap
><b
><?php
xl('Route','e'); ?
>:</b
></td
>
220 <select name
='form_route'>
222 foreach ($route_array as $key => $value) {
223 echo " <option value='$key'";
224 if ($key == $row['route']) echo " selected";
233 <td valign
='top' nowrap
><b
><?php
xl('Templates','e'); ?
>:</b
></td
>
235 <table border
='0' width
='100%'>
237 <td
><b
><?php
xl('Name' ,'e'); ?
></b
></td
>
238 <td
><b
><?php
xl('Schedule','e'); ?
></b
></td
>
239 <td
><b
><?php
xl('Interval','e'); ?
></b
></td
>
240 <td
><b
><?php
xl('Qty' ,'e'); ?
></b
></td
>
241 <td
><b
><?php
xl('Refills' ,'e'); ?
></b
></td
>
247 while ($trow = sqlFetchArray($tres)) {
248 writeTemplateLine($trow['selector'], $trow['dosage'], $trow['period'],
249 $trow['quantity'], $trow['refills']);
252 for ($i = 0; $i < $blank_lines; ++
$i) {
253 writeTemplateLine('', '', '', '', '');
263 <input type
='submit' name
='form_save' value
='<?php xl('Save
','e
'); ?>' />
265 <?php
if (acl_check('admin', 'super')) { ?
>
267 <input type
='submit' name
='form_delete' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' />
271 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />