| Current Path : /var/www/html/mmishra/irp/operator/ |
| Current File : /var/www/html/mmishra/irp/operator/indentform.php |
<?php
//operator/index.php
require("../init.inc.php");
if ($role != 'operator') {
header("Location: /");
}
echo $header;
$tbl = 'indents';
$indent_no = $_POST["indent_no"];
if ($_POST["submit"] == 'SAVE') {
$indent_head = $_POST['indent_head'];
$indent_date = date_create($_POST['indent_date']);
$indent_date = date_format($indent_date,"Y-m-d");
$purpose = $_POST['purpose'];
$indent_by = $_POST['indent_by'];
$recommended_by = $_POST['recommended_by'];
$rs = mysql_query("select * from $tbl where indent_no=$indent_no");
if (mysql_num_rows($rs)) {
mysql_query("update $tbl set indent_head='$indent_head',indent_date='$indent_date',purpose='$purpose',
indent_by='$indent_by',recommended_by='$recommended_by' where indent_no=$indent_no");
} else {
mysql_query("insert into $tbl(indent_no,indent_head,indent_date,purpose,indent_by,recommended_by)
values($indent_no,'$indent_head','$indent_date','$purpose','$indent_by','$recommended_by')");
}
$item_name = $_POST['item_name'];
$specification = $_POST['specification'];
$qty_demanded = $_POST['qty_demanded'];
$approx_cost = $_POST['approx_cost'];
mysql_query("delete from indent_items where indent_no=$indent_no");
for ($i=0; $i < count($item_name); $i++) {
if ($item_name[$i]) {
mysql_query("insert into indent_items(indent_no,item_name,specification,qty_demanded,approx_cost)
values($indent_no,'$item_name[$i]','$specification[$i]',$qty_demanded[$i],$approx_cost[$i])");
}
}
}
?>
<h2>Indent Form</h2>
<center>
<?php
$item_name = array('');
$specification = array('');
$qty_demanded = array('');
$approx_cost = array('');
$dept_code = array('');
$dept_name = array('');
$employees = array('');
$heads = array('Individual', 'Project', 'Department', 'Institute');
if ($indent_no) {
//$rs = mysql_query("select indent_no,indent_head,date_format(indent_date,'%d/%m/%Y') as dated,purpose,indent_by,recommended_by from $tbl where indent_no=$indent_no");
$rs = mysql_query("select indent_no,indent_head,indent_date,purpose,indent_by,recommended_by from $tbl where indent_no=$indent_no");
/* fetch values */
while ($o = mysql_fetch_object($rs)) {
$indent_head = $o->indent_head;
$indent_date = $o->indent_date;
$purpose = $o->purpose;
$indent_by = $o->indent_by;
$recommended_by = $o->recommended_by;
}
$rs = mysql_query("select * from indent_items where indent_no=$indent_no");
/* fetch values */
while ($o = mysql_fetch_object($rs)) {
array_push($item_name, $o->item_name);
array_push($specification, $o->specification);
array_push($qty_demanded, $o->qty_demanded);
array_push($approx_cost, $o->approx_cost);
}
}
$rs = mysql_query("select * from departments order by dept_code");
/* fetch values */
while ($o = mysql_fetch_object($rs)) {
array_push($dept_code, $o->dept_code);
array_push($dept_name, $o->dept_name);
}
$rs = mysql_query("select * from employees order by emp_code");
/* fetch values */
while ($o = mysql_fetch_object($rs)) {
array_push($employees, $o->emp_code);
//array_push($emp_name, $o->emp_name);
}
echo "<table width='95%' border='1' style='border-collapse: collapse'><tr><td align='center'>
Indent No. <input type='text' name='indent_no' size='10' value='$indent_no'>
<input type='submit' name='submit' value='FIND'><br><br>
Fund Head <select name='indent_head'>";
foreach ($heads as $h) {
echo "<option value='$h'";
if ($h == $indent_head) echo " selected";
echo ">$h</option>";
}
echo "</select>
Indent Date <input type='text' name='indent_date' size='13' value='$indent_date' id='datepicker'>
<br>Purpose <input type='text' name='purpose' size='70' value='$purpose'>
<br>Indent By <select name='indent_by'>";
foreach ($employees as $e) {
echo "<option value='$e'";
if ($e == $indent_by) echo " selected";
echo ">$e</option>";
}
echo "</select>
Recommended By <input type='text' name='recommended_by' size='30' value='$recommended_by'>
</td></tr></table>
<br>";
//item list
echo "<table width='95%' border='1' style='border-collapse: collapse'>
<tr><th>Sr.</th><th>Item Name</th><th>Specification</th><th>Qty</th><th>Approx Cost</th></tr>
";
for ($i=0; $i < count($item_name); $i++) {
echo "<tr><td>". (!$i?'new':$i) ."</td>
<td><input type='text' name='item_name[]' size='20' value='".$item_name[$i]."'></td>
<td><input type='text' name='specification[]' size='40' value='".$specification[$i]."'></td>
<td><input type='text' name='qty_demanded[]' size='5' value='".$qty_demanded[$i]."'></td>
<td><input type='text' name='approx_cost[]' size='10' value='".$approx_cost[$i]."'</td>
";
}
echo "</table>";
?>
<input type='submit' name='submit' value='SAVE'>
</center>
<?php
echo $footer;
?>