Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/ilight/mybp/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/ilight/mybp/elflats.inc

<h1><img src='images/bulb7.jpg' height='12'> Buildings / Flats</h1>
<?php
$tbl = "el_flats";

$id = $_REQUEST["id"];
$flatno = $_POST["flatno"];
$flattype = $_POST["flattype"];
$meterno = $_POST["meterno"];
$reading = $_POST["reading"];
if (!$reading) $reading = 0.00;
$meterno_new = $_POST["meterno_new"];
$reading_new = $_POST["reading_new"];
if (!$reading_new) $reading_new = 0.00;
$status = $_POST["status"];
$dated = date("Y-m-d");

if ($_POST["submit"] == 'SAVE') {
	if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
		mysql_query("update $tbl set flatno='$flatno',flattype='$flattype',meterno='$meterno',reading=$reading,
		meterno_new='$meterno_new',reading_new=$reading_new,status='$status' 
		where id=$id");
	} else {
                mysql_query("insert into $tbl(flatno,flattype,meterno,reading,meterno_new,reading_new,status,dated) 
		values('$flatno','$flattype','$meterno',$reading,'$meterno_new',$reading_new,'$status',now())");
	}
}

echo "
<table width='100%' border='1' style='border-collapse: collapse'>
<tr><th>No</th><th>FlatNo</th><th>FlatType</th><th>MeterNo</th><th>Reading</th><th>MeterNo+</th><th>Reading+</th><th>Status</th></tr>";

echo "<tr><td><a name='new'>New</a></td>";
if (!$id) {
        echo "
        <td><input type='text' name='flatno' size='10' value=''></td>
        <td><input type='text' name='flattype' size='10' value=''></td>
        <td><input type='text' name='meterno' size='10' value=''></td>
        <td><input type='text' name='reading' size='10' value='0.00'></td>
        <td><input type='text' name='meterno_new' size='10' value=''></td>
        <td><input type='text' name='reading_new' size='10' value='0.00'></td>
        <td><select name='status'>";
        foreach ($statuss as $s) {
                echo "<option value='$s'";
                if ($s == $status) echo " selected";
                echo ">$s</option>";
        }
        echo "</select><input type='hidden' name='id' value='0'></td></tr>
        <tr><td align='center' colspan='8'><input type='submit' name='submit' value='SAVE'></td>";
} else {
        echo "<td colspan='5'><a href='?pg=$pg&id=#new'>Flat</a></td>";
}
echo "</tr>";

//existing records
//$rs = mysql_query("select * from $tbl order by flatno");

$rs = mysql_query("select *,
    least(
      case when locate('0', flatno)>0 then locate('0', flatno) else length(flatno)+1 end,
      case when locate('1', flatno)>0 then locate('1', flatno) else length(flatno)+1 end,
      case when locate('2', flatno)>0 then locate('2', flatno) else length(flatno)+1 end,
      case when locate('3', flatno)>0 then locate('3', flatno) else length(flatno)+1 end,
      case when locate('4', flatno)>0 then locate('4', flatno) else length(flatno)+1 end,
      case when locate('5', flatno)>0 then locate('5', flatno) else length(flatno)+1 end,
      case when locate('6', flatno)>0 then locate('6', flatno) else length(flatno)+1 end,
      case when locate('7', flatno)>0 then locate('7', flatno) else length(flatno)+1 end,
      case when locate('8', flatno)>0 then locate('8', flatno) else length(flatno)+1 end,
      case when locate('9', flatno)>0 then locate('9', flatno) else length(flatno)+1 end) pos
  from $tbl order by left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0");

while ($o = mysql_fetch_object($rs)) {
	$i++;
	echo "<tr><td><a name='f$i'>$i</a></td>";
	if ($o->id == $id) {
		echo "
		<td><input type='text' name='flatno' size='10' value='$o->flatno'></td>
		<td><input type='text' name='flattype' size='10' value='$o->flattype'></td>
		<td><input type='text' name='meterno' size='10' value='$o->meterno'></td>
		<td><input type='text' name='reading' size='10' value='$o->reading'></td>
		<td><input type='text' name='meterno_new' size='10' value='$o->meterno_new'></td>
		<td><input type='text' name='reading_new' size='10' value='$o->reading_new'></td>
		<td><select name='status'>";
		foreach ($statuss as $s) {
			echo "<option value='$s'";
			if ($s == $o->status) echo " selected";
			echo ">$s</option>";
		}
		echo "</select><input type='hidden' name='id' value='$o->id'></td></tr>
		<tr><td align='center' colspan='8'><input type='submit' name='submit' value='SAVE'></td>";
	} else {
		echo "
		<td><a href='?pg=$pg&id=$o->id#f$i'>$o->flatno</a></td><td>$o->flattype</td>
		<td>$o->meterno</td><td>$o->reading</td><td>$o->meterno_new</td><td>$o->reading_new</td>
		<td>$o->status</td>";
	}
	echo "</tr>";

}
echo "</table>";
?>