<?php
	include_once("includes/paginator.php");
	include_once("includes/paginator_html.php");   
?>
<div class="cover_con" style="border: 0px solid #ff0000; width: 930px;">
<?php
  if($action == '0'){
?>
			<!--Beauty women-->
			<div id="hot_news" style="background: url(images/current.png) no-repeat bottom center; text-align: center; float: left; width: 214px;">ព័ត៌មានតារា</div>
			<div id="box_search">
				 <div class="search">
					<script type="text/javascript" >
						function isValid() {          
						 var search=document.getElementById("txtSearch");           
						 if(search.value==''){
							alert ('Please Input Text!');
							document.getElementById('txtSearch').focus();
							return false;
						 }
						}
					</script>
					<form name="fn" id="imageform" method="POST" enctype="multipart/form-data" action="?p=news&search=search_srv#txt" onSubmit="return isValid();">
						<input type="hidden" name="p" value="news">
						<input type="text" name="txtSearch"  id="txtSearch" class="formText required" placeholder="Enter news ..." />
						<input type="submit" name="search"  id="s_btn" value="&nbsp;"/>
					</form>
				</div>
			</div>
			<div class="clear" style="height: 18px;"></div>

			<?php
			     if($search == '0'){
						  $achs=mysql_query("SELECT * FROM tbl_news");
						  $num_rows = mysql_num_rows($achs);
							if(isset($_GET['page']))
								$s= $_GET['page'];
							else
						  $s="1";
						  $param ="p=news";
						  $a = new Paginator_html($s,$num_rows, $param);
						  $a->set_Limit(6);
						  $a->set_Links(2);
						  $limit1 = $a->getRange1();
						  $limit2 = $a->getRange2();
						  //End Select Paging 
						  
						  $sql_bea = mysql_query("Select * From tbl_news ORDER BY id DESC LIMIT $limit1, $limit2");
				  }else{
				          if(isset($_POST['txtSearch'])){
							   $txtSearch = $_POST['txtSearch'];		   
							}
							if(isset($_GET['s'])){
							   $txtSearch = $_GET['s'];	
							}
							if(isset($_GET['page'])){
							   $page = '&page='.$_GET['page'];	
							}
							$serverPath = getBaseUrl();
							//echo '<script>alert("'.$serverPath.'");</script>';
							$proUrl = str_replace("/Site/", "/Site/?p=news&search=search_srv&s=".$txtSearch.$page."#txt", $serverPath);
					?>
					<script type="text/javascript">		
						var url = '<?php echo $proUrl; ?>';	
						//alert(url);									
						window.history.pushState({path:url},'',url);                               								
					</script>
					
				  
					<?php 
						  $achs=mysql_query("SELECT * FROM tbl_news WHERE title LIKE '%".trim($txtSearch)."%' OR detail Like '%".trim($txtSearch)."%'");
						  $num_rows = mysql_num_rows($achs);
							if(isset($_GET['page']))
								$s= $_GET['page'];
							else
						  $s="1";
						  $param ="p=news&search=search_srv&s=".$txtSearch."";
						  $a = new Paginator_html($s,$num_rows, $param);
						  $a->set_Limit(6);
						  $a->set_Links(2);
						  $limit1 = $a->getRange1();
						  $limit2 = $a->getRange2();
						  //End Select Paging 
						  $sql_bea = mysql_query("Select * From tbl_news WHERE title LIKE '%".trim($txtSearch)."%' OR detail Like '%".trim($txtSearch)."%' ORDER BY id DESC LIMIT $limit1, $limit2");
					}
				  
						  while($row_bea = mysql_fetch_array($sql_bea)){
						  $pos = strpos($row_bea['detail'], "~");
					?>
			<div id="box_beaty">
			    
			   <?php echo'<a href="?p=news&n_id='.$row_bea['id'].'&action=b_show#txt" title="'.$row_bea['title'].'" style="text-decoration: none;"><div id="box_beauty_img" style="background: url(\'images/news/'.$row_bea['image'].'\') no-repeat center center;"></div></a>'; ?>
			   <div id="box_beaty_desc">
			   <div id="box_beaty_title"><?php echo $row_bea['title']; ?></div>
			   <?php //echo $row_bea['detail']; 
				   if($pos){
				   $sp=substr($row_bea['detail'],0,$pos);
				   echo $sp.'...';
				   }else{
				   $sp=substr($row_bea['detail'],0,460);
					 echo $sp.'...'; 
				   }
				 
			   ?></div>
			   <div class="clear" style="height: 15px;"></div>
			   <a href="?p=news&n_id=<?php echo $row_bea['id']; ?>&action=b_show#txt" style="text-decoration: none;"><div id="read_more" style="bottom: 5px;"​​>អានលំអិត...&nbsp;&nbsp;&nbsp;</div></a>
			</div>
			<?php } ?>
			<?php if($num_rows > 6){?>  
				<div class="clear" style="height: 25px;"></div> 							
					<table><tr><td>
					  <span class="as" style="color: #ff0000; font-weight: bold; font-family: Arial; font-size: 12px;"><?php $a->first(); ?><?php $a->previousNext(); ?><?php $a->Last(); ?></span>                         
				   </td></tr></table>
				<div class="clear" style="height: 15px;"></div>
		<?php } ?>

<?php }else{ 
      if(isset($_GET['n_id'])){
	     $n_id = $_GET['n_id'];
	  }
	  $bea_detail = mysql_fetch_array(mysql_query("Select * From tbl_news WHERE id='".mysql_real_escape_string($n_id)."'"));
	  $bea_other = mysql_query("Select * From tbl_news WHERE id!='".mysql_real_escape_string($n_id)."' ORDER BY RAND(), id DESC LIMIT 0,5");
	  $count = mysql_num_rows(mysql_query("Select * From tbl_news"));
	  
?>			
			<div id="box_beaty_detail">
				<div id="box_beaty_title" style="text-align: left; width: 914px; float: left; font-size: 16px;"><!--សម្ផស្ស និងសុខភាពស្រ្តី--><?php echo $bea_detail['title']; ?></div>
				<div class="clear" style="height: 10px;"></div>
				<img src="images/news/b/<?php echo $bea_detail['image']; ?>" />
				<div class="clear" style="height: 14px;"></div>
					<?php echo str_replace('~', '', $bea_detail['detail']); ?>
					
					
				<?php if($count >= 2){ ?>	
					<div class="clear" style="height: 30px;"></div>
					<div id="box_beaty_title" style="text-align: left; color: #000; width: 914px; float: left; font-size: 14px;">
					    អត្ថបទផ្សេងៗទៀត៖ 
					</div>
					<div class="clear" style=""></div>
					<ul>
						<?php
						   while($other = mysql_fetch_array($bea_other)){
						?>
							   <a href="?p=news&n_id=<?php echo $other['id']; ?>&action=b_show#txt" style="text-decoration: none;"><li><?php echo $other['title']; ?></li></a>
						  
						<?php } ?>
					 </ul>
					 <div class="clear" style="height: 20px;"></div>
			<?php } ?>		 
					
			</div>

<?php } ?>				
	
	<div class="clear" style="height: 20px;"></div> 
</div>