made sl data authoritative and fixed some bugs and omissions
[openemr.git] / interface / drugs / add_edit_lot.php
blob5988dbf9a6709e37c3e3d9069650bd98f1ca1668
1 <?php
2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
3 //
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 function QuotedOrNull($fld) {
14 if ($fld) return "'$fld'";
15 return "NULL";
18 $drug_id = $_REQUEST['drug'];
19 $lot_id = $_REQUEST['lot'];
20 $info_msg = "";
22 if (!acl_check('admin', 'drugs')) die(xl('Not authorized'));
23 if (!$drug_id) die(xl('Drug ID missing!'));
25 <html>
26 <head>
27 <?php html_header_show();?>
28 <title><?php echo $lot_id ? xl("Edit") : xl("Add New"); xl('Lot','e',' '); ?></title>
29 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
31 <style>
32 td { font-size:10pt; }
33 </style>
35 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
36 <script type="text/javascript" src="../../library/textformat.js"></script>
37 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
38 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
39 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
41 <script language="JavaScript">
43 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
45 function validate() {
46 var f = document.forms[0];
47 if (f.form_lot_number.value.search(/\S/) < 0) {
48 alert('<?php xl('A lot number is required!','e'); ?>');
49 return false;
51 return true;
54 </script>
56 </head>
58 <body class="body_top">
59 <?php
60 // If we are saving, then save and close the window.
62 if ($_POST['form_save'] || $_POST['form_delete']) {
63 if ($lot_id) {
64 if ($_POST['form_save']) {
65 sqlStatement("UPDATE drug_inventory SET " .
66 "lot_number = '" . $_POST['form_lot_number'] . "', " .
67 "manufacturer = '" . $_POST['form_manufacturer'] . "', " .
68 "expiration = " . QuotedOrNull($form_expiration) . ", " .
69 "on_hand = '" . $_POST['form_on_hand'] . "' " .
70 "WHERE drug_id = '$drug_id' AND inventory_id = '$lot_id'");
71 } else {
72 sqlStatement("DELETE FROM drug_inventory WHERE drug_id = '$drug_id' AND inventory_id = '$lot_id'");
74 } else {
75 $lot_id = sqlInsert("INSERT INTO drug_inventory ( " .
76 "drug_id, lot_number, manufacturer, expiration, on_hand " .
77 ") VALUES ( " .
78 "'$drug_id', " .
79 "'" . $_POST['form_lot_number'] . "', " .
80 "'" . $_POST['form_manufacturer'] . "', " .
81 QuotedOrNull($form_expiration) . ", " .
82 "'" . $_POST['form_on_hand'] . "' " .
83 ")");
86 // Close this window and redisplay the updated list of drugs.
88 echo "<script language='JavaScript'>\n";
89 if ($info_msg) echo " alert('$info_msg');\n";
90 echo " window.close();\n";
91 echo " if (opener.refreshme) opener.refreshme();\n";
92 echo "</script></body></html>\n";
93 exit();
96 if ($lot_id) {
97 $row = sqlQuery("SELECT * FROM drug_inventory WHERE drug_id = '$drug_id' " .
98 "AND inventory_id = '$lot_id'");
102 <form method='post' name='theform' action='add_edit_lot.php?drug=<?php echo $drug_id ?>&lot=<?php echo $lot_id ?>'
103 onsubmit='return validate()'>
104 <center>
106 <table border='0' width='100%'>
108 <tr>
109 <td valign='top' width='1%' nowrap><b><?php xl('Lot Number','e'); ?>:</b></td>
110 <td>
111 <input type='text' size='40' name='form_lot_number' maxlength='40' value='<?php echo $row['lot_number'] ?>' style='width:100%' />
112 </td>
113 </tr>
115 <tr>
116 <td valign='top' nowrap><b><?php xl('Manufacturer','e'); ?>:</b></td>
117 <td>
118 <input type='text' size='40' name='form_manufacturer' maxlength='250' value='<?php echo $row['manufacturer'] ?>' style='width:100%' />
119 </td>
120 </tr>
122 <tr>
123 <td valign='top' nowrap><b><?php xl('Expiration','e'); ?>:</b></td>
124 <td>
125 <input type='text' size='10' name='form_expiration' id='form_expiration'
126 value='<?php echo $row['expiration'] ?>'
127 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
128 title=<?php xl('yyyy-mm-dd date of expiration','e','\'','\''); ?> />
129 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
130 id='img_expiration' border='0' alt='[?]' style='cursor:pointer'
131 title=<?php xl('Click here to choose a date','e','\'','\''); ?>>
132 </td>
133 </tr>
135 <tr>
136 <td valign='top' nowrap><b><?php xl('On Hand','e'); ?>:</b></td>
137 <td>
138 <input type='text' size='5' name='form_on_hand' maxlength='7' value='<?php echo $row['on_hand'] ?>' />
139 </td>
140 </tr>
142 </table>
145 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
147 &nbsp;
148 <input type='button' value='<?php xl('Destroy...','e'); ?>'
149 onclick="window.location.href='destroy_lot.php?drug=<?php echo $drug_id ?>&lot=<?php echo $lot_id ?>'" />
151 &nbsp;
152 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
153 </p>
155 </center>
156 </form>
157 <script language='JavaScript'>
158 Calendar.setup({inputField:"form_expiration", ifFormat:"%Y-%m-%d", button:"img_expiration"});
159 </script>
160 </body>
161 </html>