<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
	session_start();
	if(isset($_SESSION['dem'])){
		$_SESSION['dem']++;
	} else{
		$_SESSION['dem']=1;
	}
	$dem1 = 0;
	$url = isset($_SESSION['url']) ? $_SESSION['url'] : array();
	foreach ($url as $url1) {
		if($_SERVER['REQUEST_URI'] == $url1) {
			$dem1 = 1;
		}
	}
	if($dem1 != 1 ) {
			
			array_push($url, $_SERVER['REQUEST_URI']);
		}
	//echo "<pre>"; print_r($url); echo "</pre>"; exit();
	$_SESSION['url'] = $url;
	//echo "<pre>"; print_r($_SESSION['url']); echo "</pre>"; exit();
	include('lib_db.php');

	$page = isset($_GET["page"]) ? $_GET["page"] : 1;

	$menu_sql = "select * from category";
	$menu_data = select_list($menu_sql);
	//echo "<pre>"; print_r($menu_data); echo "</pre>"; exit();

	$content_sql = "select * from content limit ".(($page-1)*5) .",5";
	//echo $content_sql; exit();
	//$content_sql = "select * from content limit 24,5";
	$content_data = select_list($content_sql);
	//echo "<pre>"; print_r($content_data); echo "</pre>"; exit();

	
		$tong_sql = "select t_cid,COUNT(*) from content";
		//$tong_sql .= " where t_cid =" .$id;
		$tong_data = select_one($tong_sql);
		//echo "<pre>" ;print_r($tong_data);echo "</pre>"; exit();

	
	$tong_page = ceil($tong_data['COUNT(*)']/5);

	include("checklogin.php");
	$user = checkLoggedUser();
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>ASU/admin</title>
	<META content="IE=5.0000" http-equiv="X-UA-Compatible">
	<meta http-equiv="Content-Type" content="text/shtml; charset=utf-8" />
	<link type="text/css" href="css/style.css" rel="stylesheet" media="screen"/>
	<link rel="icon" href="images/asus.png" type="image/png" />
	<link type="text/css" href="css/style-search.css" rel="stylesheet" media="screen"/>
	<link type="text/css" href="css/style-list.css" rel="stylesheet" media="screen"?>	
</head>	
<!--------------------------------------body-------------------------------->
<body>
	<div id="Header-top">
		<div class="header-top-warpper">
			<div class="Header-top1">
			<ul>
				<li>
					<a href="#">Những trang đã xem
						<span class="info-number"><?php echo $_SESSION['dem'] ?></span>
					</a>
				</li>
				<li class="divider-vertical"></li>
				
				<li>
					<?php
					if(isset($_SESSION['account'])){ ?>
						<a href="logout.php">Đăng xuất
						</a>
					<?php } else{?>
						<a href="login.php">Đăng nhập
						</a>
						<?php }?>
				</li>
				<li class="divider-vertical"></li>
	
				<li>
					<a href="#">Đăng ký
					</a>
				</li>
			</ul>
		</div><!--EndHeader-top1-->
		</div>
		<div class="clear-both"></div>
	</div>
	<div class="clear-both"></div>
	<div id="Warpper">
		<!-------------------------------------Header------------------------------>
		<div id="Warpper-one">
			<div id="Header">
				<div class="Header-top2">
					<div id="asus-logo" class="span2">
						<a title="ASUS" href="index.php"></a>
					</div><!--EndLogo-->
					<div id="Header-top2-menu">
						<ul id="nav" class="nav">
							<li id="products_memu">
								<a class="menu1" href="list.php?id=0&page=1">Sản phẩm</a>
								<div  class="product-sub-nav">
									<ul class="row-fluid">
										<?php if($menu_data) foreach ($menu_data as $key) { ?>
												<li class="span-5col">
													<?php echo $key['c_name'] ?>
													<ul>
														<?php $menu_sql = 'select DISTINCT  t_type,t_cid from content where t_cid = '.$key["c_id"];
														$menu2_data = select_list($menu_sql); ?>
														<?php if($menu2_data) foreach ($menu2_data as $key1) { ?>
															<li>
																<a href="list.php?id=<?php echo $key1['t_cid']  ?>&type=<?php echo $key1['t_type'] ?>&page=1" ><?php echo $key1['t_type']?></a>
															</li>
														<?php } ?>
													</ul>
												</li>
										<?php } ?>
									</ul>
								</div>
							</li>
							<li id="commercial_memu">
								<a class="menu1" href="/vn/index.aspx">Doanh nghiệp</a>
							</li>
							<li id="support_memu">
								<a title="" href="http://www.asus.com/vn/support/">Hỗ trợ</a>
							</li>
						</ul>	
					</div><!--EndMenu1-->
					<div class="Header-top2-menu2">
						<li class="icon">
							<a rel="YouTube" title="YouTube" target="_blank" href="http://www.youtube.com/user/asus">
								<img src="images/icon_youtube.png">
							</a>
						</li>
						<li class="icon" >
							<a rel="Facebook" title="Facebook" target="_blank" href="http://www.facebook.com/asus.vn">
									<img src="images/icon_facebook.png">
							</a>
						</li>
						<li class="icon">
							<a rel="FacebookORG" title="ORG Facebook" target="_blank" href="https://www.facebook.com/vn.asus.rog">
								<img src="images/icon_facebookasus.png">
							</a>
						</li>
						<div class="search">
							<div class="form-search">
								<form action="search.php?q=$q" method='get'>
								<input type="text" class="inputtext" value="Tìm kiếm" onFocus="if (this.value=='Tìm kiếm') this.value='';" onBlur="if (this.value=='') this.value='Tìm kiếm';" name="q">
								<button id="search-btn" value="Tim kiếm"><span></span></button>
								</form>
							</div>	
						</div>
					</div><!--EndMenu2-->
				</div><!--EndHeader-top2-->
			</div><!--EndHeader-->			
		</div><!--EndWarpper-one-->
		<!-------------------------------Content--Fooder------------------------------>
		<div id="Warpper-tow">
			<div id="Content">
				<div class="Content-center">
					<div class="Content-left">
						<span>
						Thông tin mới về ASUS
					</span>
						<li>
							<a href="list.php?id=0&page=1">
								Tất cả các tin
							</a>
						</li>
						<?php foreach ($menu_data as $key) { ?>
							<li>
								<a href="list.php?id=<?php echo $key['c_id'] ?>&page=1">
									<?php echo $key['c_name']  ?>
								</a>
							</li>
						<?php } ?>
						<span>
							Doanh nghiệp
						</span>
					</div><!--EndConten-left-->
					<div class="Content-right">
						<div class="right1">
							<span class="tintuc">Trang quản lý</span>

							<span class="tongcong">
								<?php if($tong_data['COUNT(*)']>($page*5)) {?>
									<?php echo ($page-1)*5+1 ?> đến <?php echo ($page*5) ?> trên Tổng cộng:
								<?php } else { ?>
									<?php echo ($page-1)*5+1 ?> đến <?php echo $tong_data['COUNT(*)'] ?> trên Tổng cộng:
								<?php } ?>
								<span class="blueword"><?php echo $tong_data['COUNT(*)'] ?></span>
							</span>
						</div>
						<div class="right2">
							<a class="add" href="add_form.php">Thêm tin tức</a>
						</div>
						<!-- <div class="right2">
							<a href="/">
								<img src="images/img_search.png.jpg" />
							</a>
							<div class="tit">
								<a href="/" class="a2">
										Z97I-PLUS
										<label class="checkbox">
											<input type="checkbox">
											Thêm vào danh sách so sánh
										</label>
										<div class="clear-both"></div>
								</a>
								<div>
								High-performance Z97 mini-ITX boasts exceptionally-smart layout for ATX capability, with 802.11ac Wi-Fi, speedy M.2 and enduring 5X Protection
								</div>
							</div>
							<div class="clear-both"></div>
							<div class="right2-buttom">
								<a href="/" class="sub-btn">Miêu tả chung</a>
								<a href="/" class="sub-btn">Thông số kỹ thuật</a>
								<a href="/" class="sub-btn">Hỗ trợ</a>
								<div class="clear-both"></div>
							</div>
							<div class="clear-both"></div>
						</div> -->
						
							<?php foreach ($content_data as $key2) { ?>
								<div class="right3">
									<a href="detail.php?id=<?php echo $key2['t_id'] ?>">
										<h2>
											<?php echo $key2['t_title'] ?>	
										</h2>
									</a>
									<span class="list-date"><?php echo $key2['t_date'] ?></span>
									<div class="clear-both"></div>
									<div class="right-content"><?php echo $key2['t_info'] ?></div>
									<br />
									<a class="more_button" href="detail.php?id=<?php echo $key2['t_id'] ?>">chi tiết</a>
									<li>
										<a class="edit_button" href="edit_form.php?id=<?php echo $key2['t_id'] ?>">Sửa</a>
										<a class="delete_button" href="delete_form.php?id=<?php echo $key2['t_id'] ?>">Xóa</a>
									</li>
								</div>
							<?php } ?>
						<?php for ($i=1; $i <= $tong_page  ; $i++) { ?> 
							<a href="account.php?page=<?php echo $i ?>"><?php echo $i ?></a>
						<?php } ?>
					</div><!--EndContent-right-->
					<div class="clear-both"></div>
				</div><!--EndConten-center-->
			</div><!--EndContent-->
			<div class="clear-both"></div>
		</div><!--EndWarpper-tow-->
		<!---------------------------------Fooder------------------------------>
		<div id="Warpper-three">
			<div id="foodter">
				<div id="foodter-one">
					<div class="foodter-container">
						<a href="http://www.asus.com/entry.htm" >
						Vietnam /<span style="color:#fff"> Việt Nam</span></a>
					</div>
					<div class="clear-both"></div>
				</div><!--EndFoodterOne-->
				<div id="foodter-tow">
					<div class="container">
						<div class="container1">
							<div class="row">
								<h4>Cần thêm?</h4>
								<li>
									<a href="#">Text In Style</a>
								</li>
								<li>
									<a href="#">ROG</a>
								</li>
								<li>
									<a href="#">SonicMaster</a>
								</li>
								<li>
									<a href="#">Eee is Me</a>
								</li>
								<li>
									<a href="#">ZENBOOK</a>
								</li>
							</div>
							<div class="row">
								<h4>Về chúng tôi</h4>
								<li>
									<a href="#">Các quan hệ đầu tư</a>
								</li>
								<li>
									<a href="#">Nhân sự</a>
								</li>
								<li>
									<a href="#">GreenASUS & SERASUS</a>
								</li>
								<li>
									<a href="#">Press Room</a>
								</li>
							</div>
							<div class="row">
								<h4>Cần trợ giúp?</h4>
								<li>
									<a href="#">Liên hệ</a>
								</li>
								<li>
									<a href="#">Đăng ký sản phẩm</a>
								</li>
								<li>
									<a href="#">Tải driver</a>
								</li>
								<li>
									<a href="#">Tiến độ sửa chữa</a>
								</li>
							</div>
							<div class="row"  id="last">
								<li>
									<a href="#">Giải thưởng</a>
								</li>
								<li>
									<a href="#">Tin tức</a>
								</li>
								<li>
									<a href="#">Về ASUS</a>
								</li>
							</div>
						<div class="clear-both"></div>
						</div><!--EndContainer1-->
						<div class="container2">
							<div id="bottom-menu">
								<a href="#">Thông tin hợp pháp</a>
								<a href="#">Qui chế pháp lý</a>
								<div id="copyright">©ASUSTeK Computer Inc. All rights reserved. </div>
							</div>
						</div><!--EndContainer2-->
					</div>
				</div><!--EndFoodterTow-->
			</div><!--EndFooder-->
			<div class="clear-both"></div>
		</div><!--EndWarpperThree-->
	</div><!--EndWarpper-->
</body>

</html>