<? require_once("../includes/main.inc.php");

$headerTitleName = "zip List";



/**for  delete  groups **/

if($_REQUEST['action']=='alldelete'){



	 $sql6= "TRUNCATE TABLE `tbl_zip` ";



	 db_query($sql6);

	 set_session_msg("All zip and Related Data have been deleted successfully");

			

	header("Location: ".$_SERVER['HTTP_REFERER']);

	exit;

}

/**for  delete  groups **/

if($_REQUEST['action']=='delete'){

	 $sql6= "delete from `tbl_zip` where zip_id in ($page_id)";





	 db_query($sql6);

	 set_session_msg("Selected zip and Related Data  have been deleted successfully");

			

	header("Location: ".$_SERVER['HTTP_REFERER']);

	exit;

}

$start = intval($start);

$pagesize = intval($pagesize)==0?$pagesize=50:$pagesize;

$columns = "select `tbl_zip`.zip_code,`tbl_state`.state_name,`tbl_county`.county_name,`tbl_country`.country_name,`tbl_zip`.state_id ,`tbl_zip`.country_id ,`tbl_zip`.county_id ,`tbl_zip`.zip_status,`tbl_zip`.zip_id,`tbl_city`.city_name,`tbl_block`.block_name,`tbl_block`.block_id ";

$sql = " from `tbl_zip` ";

$sql .= " LEFT JOIN `tbl_country` ON `tbl_zip`.country_id = `tbl_country`.country_id ";

$sql .= " LEFT JOIN `tbl_state` ON `tbl_zip`.state_id = `tbl_state`.state_id ";

$sql .= " LEFT JOIN `tbl_county` ON `tbl_zip`.county_id = `tbl_county`.county_id ";

$sql .= " LEFT JOIN `tbl_city` ON `tbl_zip`.city_id = `tbl_city`.city_id ";

$sql .= " LEFT JOIN `tbl_block` ON `tbl_zip`.block_id = `tbl_block`.block_id ";

$sql .= " where 1 ";



$order_by == '' ? $order_by = '`zip_id`' : true;



$order_by2 == '' ? $order_by2 = 'ASC' : true;



$sql_count = "select count(*) ".$sql; 



$sql .= "order by $order_by $order_by2 ";



$sql .= "limit $start, $pagesize ";



$sql = $columns.$sql;



$result = db_query($sql);



$reccnt = db_scalar($sql_count);

?><link href="styles.css" rel="stylesheet" type="text/css">

<? include("top.inc.php");?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td id="pageHead"><div id="txtPageHead">

    Manage Zip</div></td>

  </tr>

</table>

		<table width="100%" border="0" cellspacing="0" cellpadding="0">



  <tr>



    <td id="content">



        <div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br />

        





        <a href="zip_add.php?page_id=&start=0" class="redcolor">Add New zip</a>  <a style="margin-left:20px;" href="import_zip.php" class="redcolor">Import zip Record in excel</a><a style="margin-left:20px;" href="zip_detail.php?action=alldelete" onclick="return confirm('Are you sure?')" class="redcolor">Delete All zip</a>



      <? if(mysql_num_rows($result)==0){?>

      

      <div class="msg">Sorry, no records found.</div>

      

      <? } else{ ?>

      <div align="right"> Showing Records: <?= $start+1?> to   <?=($reccnt<$start+$pagesize)?($reccnt-$start):($start+$pagesize)?>    of   <?=$reccnt?> </div>

      <form method="post" name="form1" id="form1" onSubmit="confirm_submit(this)">



        <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="tableList">

          <tr>

          <th  align="center" width="3%">SL</th>

          <th  align="left" width="9%" style="padding-left:10px;">Zip Code</th>

          <th  align="left" width="17%" style="padding-left:10px;"> Block Name</th>

          <th  align="left" width="17%" style="padding-left:10px;"> Area/ Post Office Name</th>

          <th  align="left" width="18%" style="padding-left:10px;">Taluk / Tehsil / City Name</th>

          <th  align="left" width="16%" style="padding-left:10px;">District Name</th>

          <th  align="left" width="15%" style="padding-left:10px;">State Name</th>

          <th  align="center" width="9%">Status</th>

          <th align="center" width="7%">Edit</th>

          <th align="center" width="6%">Delete</th>

          </tr>

      <? 

if($start==0){

	$cnt=0;

}

else{

	$cnt=$start;

}

while ($line_raw = mysql_fetch_array($result)) {

	$cnt++;

$line = ms_display_value($line_raw);

@extract($line);

$css = ($css=='trOdd')?'trEven':'trOdd';

?><tr class="<?=$css?>">

<td  valign="top" align="center"><?=$cnt;?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($zip_code)?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($block_name)?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($city_name)?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($county_name)?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($state_name)?></td>

<td align="left" valign="middle" style="padding-left:10px;"><?=stripslashes($country_name)?></td>



<td align="center" valign="middle"><?php if($zip_status=='1'){ echo 'Active'; }else{ echo '<span style="color:red;">InActive</span>'; } ?></td>

<td align="center" valign="top"><a href="zip_add.php?page_id=<?=$zip_id?>&start=<?=$start?>"><img src="images/icons/edit.png" alt="Edit" width="16" height="16" border="0" /></a></td>



<td align="center" valign="top"><a href="zip_detail.php?page_id=<?=$zip_id?>&start=<?=$start?>&action=delete" onclick="return stdel_confirm();"><img src="images/icons/trash-20.png" alt="Edit" width="16" height="16" border="0" /></a></td>

</tr>

<? }?>        </table>

 </form>

<? }?>

 <? include("paging.inc.php");?>    </td>



  </tr>



</table>

<script>

function stdel_confirm(){  return confirm("Are you sure want to delete?"); }

</script>

<? include("bottom.inc.php");?>