<?php
    session_start();
    if(empty($_SESSION['p0B_c0ff33'])) header('location:login.php?goto=index');
?>
<?php include('templates/header.php'); ?>
<body>
<!-- Start: page-top-outer -->

<?php include('templates/menu.php'); ?>
<?php
	include "../db_function.php";
	if(empty ($_GET['page'])){
		$_GET['page']=1;
	}

$table="tbl_cate_clothes";
if(!empty($_GET['sid'])){
    $sid = $_GET['sid'];
}
$show_title = mysql_fetch_array(mysql_query("Select * From tbl_shop WHERE id='".mysql_real_escape_string($sid)."'"));
if(isset($_POST['save'])){
	$id=$_POST['txtID'];
	$cate=$_POST['cate'];
	$name=$_POST['name'];
	$name1=$_POST['name1'];
	
		$str="UPDATE $table SET  par_id='$cate', name='$name', name_kh='$name1' WHERE id=$id";
		$suse=mysql_query($str);
		if($suse){
			$masg=0;
			}else{
			$masg=1;
		}
}
//Delete here/////////////////////////////////////////////////////////////
else if(isset($_POST['subdelete'])){
		$id=$_POST['txtID'];

		$delete = "DELETE FROM $table WHERE id=$id";
		mysql_query($delete);

		$masg=3;

}



?>

<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->
<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
	    <div style="font-size: 20px; border: 0px solid #ff0000; text-align: center;"><?php echo $show_title['name']; ?></div>
		<h1>View Sub Category</h1>
           <!--  start top-search -->
	<div id="top-search">
    <form action="" method="post" enctype="multipart/form-data">
		<table border="0" cellpadding="0" cellspacing="0">
		<tr>
		<td><input type="text" name="kernh" value="Search" onBlur="if (this.value=='') { this.value='Search'; }" onFocus="if (this.value=='Search') { this.value=''; }" class="top-search-inp" /></td>
		<td>
		</td>
		<td>
		<input type="submit" name="search" value="Search" class="search" style="width: 70px; height: 31px;"  />
		</td>
		</tr>
		</table>
    </form>
	</div>
 	<!--  end top-search -->
 	<div class="clear"></div>
	</div>
	<!-- end page-heading -->



	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
		<?php
	if(isset($masg) && $masg==0 ){
	echo'
	<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Your update sucess.</td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==1){
	echo'
	<div id="message-red">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr>
					<td class="red-left">Your update is Fail. Please try again!</td>
				<td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif"   alt="" /></a></td>
			</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==2){
	echo'
	<div id="message-yellow">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr>
					<td class="yellow-left">'.$change.'</td>
				<td class="yellow-right"><a class="close-yellow"><img src="images/table/icon_close_yellow.gif"   alt="" /></a></td>
			</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==3 ){
	echo'
	<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Your delete suces.   </td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
	}
	?>
			<!--  start table-content  -->
			<div id="table-content">

				<!--  start Update Succes -->


				<!--  end message-green -->


				<!--  start product-table ..................................................................................... -->
           <?php
	if(isset($_POST['search']))
	{
		$kernh=$_POST['kernh'];

			$query2 = "SELECT * FROM $table WHERE s_id='$sid' AND par_id !='0' AND name LIKE '%$kernh%' ORDER BY id ASC";

		include("include/paginator.php");
		//include the extension that makes the pre-made links
		include("include/paginator_html.php");
		//Makes the array used in this example.


		$result2=mysql_query($query2);
		echo mysql_error();
		$num_rows=mysql_num_rows($result2);

		$vlimit=500;
		//gets the total number of items
		//========================================================================
		//Parts used to make a new paginator
		//========================================================================
		//Makes new Paginator_html.  Current page here is sent by the get method.
		//$num_rows is the total items in the source.
		$a =new Paginator_html($_GET['page'],$num_rows);
		//sets the number of records displayed
		//defaults to five
		$a->set_Limit($vlimit);
		// if using numbered links this will set the number before and behind
		//the current page.
		//defaults to five
		$a->set_Links(3);
		//gets starting point.
		$limit1 = $a->getRange1();
		//gets number of items displayed on page.
		$limit2 = $a->getRange2();
		//=========================================================================
		//Printing out the items in the array

		$query = "SELECT * FROM $table WHERE s_id='$sid' AND par_id !='0' AND  name LIKE '%$kernh%' limit $limit1, $limit2 ";
	}
	else
	{
		$query2 = "SELECT * FROM $table WHERE s_id='$sid' AND par_id !='0' ORDER BY id ASC";


		include("include/paginator.php");
		//include the extension that makes the pre-made links
		include("include/paginator_html.php");
		//Makes the array used in this example.


		$result2=mysql_query($query2);
		echo mysql_error();
		$num_rows=mysql_num_rows($result2);

		$vlimit=15;
		//gets the total number of items
		//========================================================================
		//Parts used to make a new paginator
		//========================================================================
		//Makes new Paginator_html.  Current page here is sent by the get method.
		//$num_rows is the total items in the source.
		$a =new Paginator_html($_GET['page'],$num_rows);
		//sets the number of records displayed
		//defaults to five
		$a->set_Limit($vlimit);
		// if using numbered links this will set the number before and behind
		//the current page.
		//defaults to five
		$a->set_Links(3);
		//gets starting point.
		$limit1 = $a->getRange1();
		//gets number of items displayed on page.
		$limit2 = $a->getRange2();
		//=========================================================================
		//Printing out the items in the array

		$query = "SELECT * FROM $table WHERE s_id='$sid' AND par_id !='0' limit $limit1, $limit2";
	}

	?>

    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <tr>
            <th class="table-header-check"><a id="toggle-all"></a></th>
            <th class="table-header-repeat line-left minwidth-1"><a href="">Category</a></th>
            <th class="table-header-repeat line-left minwidth-1"><a href="">Name (English)</a></th>
            <th class="table-header-repeat line-left minwidth-1"><a href="">Name (Khmer)</a></th>
            <th class="table-header-options line-left"><a href="">Option</a></th>
        </tr>

	<?php
    $result =mysql_query($query);
    echo mysql_error();
	$bgcolor="#d8d8d8";
	$i=1;

	while ($row = mysql_fetch_array($result))
	{
		echo'<form name="editservices" method="POST" action="" enctype="multipart/form-data">';
		echo'
		<tr>
			<td><input name="checkbox" id="checkbox" type="checkbox"/><input type="hidden" name="txtID" value="'.$row['id'].'" size="2" >
			<input type="hidden" name="txtID" value="'.$row['id'].'" size="2" >
			</td>
			<td align="center">'; ?>
			<select name="cate" id="cate" class="validate[required] styledselect-month" style="width:200px;">
				<?php
                    $cate=mysql_query("SELECT * FROM tbl_cate_clothes WHERE s_id='$sid' AND  par_id ='0'");
                    while($rowcate=mysql_fetch_array($cate)){
                    if($rowcate['id']==$row['par_id'])
					{
						echo '<option value="'.$rowcate['id'].'" selected="selected">'.$rowcate['name'].'</option>';
					}
					else
					{
						echo '<option value="'.$rowcate['id'].'">'.$rowcate['name'].'</option>';
					}
                    }
					?>
            </select>
            <?php
            echo '
			</td>
			<td align="center">
				<input type="text" class="inp-form" id="name" value="'.$row['name'].'" name="name" style="width: 300px;" /><br/>
			</td>
			<td align="center">
				<input type="text" class="inp-form" id="name1" value="'.$row['name_kh'].'" name="name1" style="width: 300px;" /><br/>
			</td>

			<td class="options-width">
			<input type="submit" name="subdelete" value="&nbsp;" title="Delete" class="icon-2 info-tooltip" '; ?> onclick="return confirm('Are you sure want to delete this Item?')" <?php echo ' >
			<input type="submit" name="save" value="&nbsp;" title="Save" class="icon-5 info-tooltip">
			</td>
		</tr>';

		$i++;
		echo'</form>';
	}
	?>

		</table>		<!--  end product-table................................... -->
	</form>

			</div>
			<!--  end content-table  -->

			<!--  start actions-box ............................................... -->

			<!-- end actions-box........... -->

			<!--  start paging..................................................... -->
			<table border="0" cellpadding="0" cellspacing="0" id="paging-table">
			<tr>
			<td valign="top" class="paging">
			<?php
			$a->previousNext();
			echo '<br /><br /><br />';
			echo'<font size=2><b>Total: </b>';
			echo ceil($num_rows/$vlimit);
			echo' pages';
			echo ' ('.$num_rows.' Items) </font>';			
			?>
				
			</td>
			</tr>
			</table>
			<!--  end paging................ -->

			<div class="clear"></div>

		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->

<div class="clear">&nbsp;</div>

 <?php include('templates/footer.php'); ?>
