<?php
require_once "class_db.php";
class qly_pages extends db{

    public function LayTieuDeKD($idPa){
		$sql="SELECT TieuDeKD  FROM mk_pages WHERE idPa = '$idPa'";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['TieuDeKD'];
	}
	public function LayTieuDe($idPa){
		$sql="SELECT TieuDe  FROM mk_pages WHERE idPa = '$idPa'";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['TieuDe'];
	}
	public function LayID($TieuDeKD){
		$sql="SELECT idPa  FROM mk_pages WHERE TieuDeKD = '$TieuDeKD'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['idPa'];
	}
	public function LayIDGroup($idPa){
		$sql="SELECT idGroup  FROM mk_pages WHERE idPa = '$idPa'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['idGroup'];
	}
	public function LayParent($idPa){
		$sql="SELECT Parent  FROM mk_pages WHERE idPa = '$idPa'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['Parent'];
	}
	public function LayNoiDung($idPa){
		$sql="SELECT NoiDung  FROM mk_pages WHERE idPa = '$idPa'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['NoiDung'];
	}
	public function Pages($idPa){
		$sql="SELECT *
            FROM mk_pages
            WHERE  idPa = $idPa";
		$kq = mysql_query($sql,$this->conn);
		return $kq;
	}
	public function ListCauHoi(){
		$sql="SELECT TomTat, NoiDung
            FROM mk_pages
            WHERE  AnHien = 1 and idGroup = 2
			ORDER BY idPa
			";
		$kq = mysql_query($sql,$this->conn) or die(mysql_error());
		return $kq;
	}
	public function DanhChoKhachHang($parent){
		$sql="SELECT *
            FROM mk_pages
            WHERE  Parent = $parent and AnHien = 1 
            Order By ThuTu ASC, idLoai DESC
            ";
		$kq = mysql_query($sql,$this->conn);
		return $sql;
	}
	
    
	public function ListPagesParent($idGroup, &$totalRows, $pageNum=1, $pageSize = 10, $Parent){
        $startRow = ($pageNum-1)*$pageSize;
		$sql="SELECT TieuDe, TieuDeKD, TomTat, NoiDung, UrlHinh
            FROM mk_pages
            WHERE  AnHien = 1 and idGroup = $idGroup and Parent = '$Parent'
			ORDER BY idPa desc
			LIMIT $startRow , $pageSize
			";
		$kq = mysql_query($sql,$this->conn) or die(mysql_error());
		$sql="SELECT count(*) FROM mk_pages WHERE AnHien = 1 and idGroup = $idGroup and Parent = '$Parent'
			";
		$rs= mysql_query($sql) or die(mysql_error());;
		$row_rs = mysql_fetch_row($rs);
		$totalRows = $row_rs[0];
		return $kq;
	}
	public function ListPages($idGroup, &$totalRows, $pageNum=1, $pageSize = 10, $lang = 'vi'){
        $startRow = ($pageNum-1)*$pageSize;
		$sql="SELECT TieuDe, TomTat, TieuDeKD, UrlHinh, NgayDang, NoiDung
            FROM mk_pages
            WHERE  AnHien = 1 and idGroup = $idGroup and Lang = '$lang'
			ORDER BY idPa desc
			LIMIT $startRow , $pageSize
			";
		$kq = mysql_query($sql,$this->conn) or die(mysql_error());
		$sql="SELECT count(*) FROM mk_pages WHERE AnHien = 1 and idGroup = $idGroup and Lang = '$lang'
			";
		$rs= mysql_query($sql) or die(mysql_error());;
		$row_rs = mysql_fetch_row($rs);
		$totalRows = $row_rs[0];
		return $kq;
	}
	public function ListTinTuc($sotin, $idGroup){
		if($idGroup == -1){
			$sql="SELECT TieuDe, TomTat, TieuDeKD, UrlHinh, NgayDang
            FROM mk_pages
            WHERE  AnHien = 1 and idGroup in (1, 2)
			ORDER BY idPa desc
			LIMIT 0 , $sotin
			";
		}else{
			$sql="SELECT TieuDe, TomTat, TieuDeKD, UrlHinh, NgayDang
            FROM mk_pages
            WHERE  AnHien = 1 and idGroup = $idGroup
			ORDER BY idPa desc
			LIMIT 0 , $sotin
			";
		}
		$kq = mysql_query($sql,$this->conn) or die(mysql_error());
		return $kq;
	}
	public function ListMenu($idGroup){
		$sql="SELECT TieuDe, TieuDeKD, idPa
        FROM mk_pages
        WHERE  AnHien = 1 and idGroup = $idGroup and idPa <> 2 and idPa <> 109
		ORDER BY ThuTu ASC";
		$kq = mysql_query($sql,$this->conn) or die(mysql_error());
		return $kq;
	}
	public function LayTitle($idPa){
		$sql="SELECT Title  FROM mk_pages WHERE idPa = '$idPa'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['Title'];
	}
	public function LayDes($idPa){
		$sql="SELECT Des  FROM mk_pages WHERE idPa = '$idPa'
			";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['Des'];
	}
	public function LayKeyword($idPa){
		$sql="SELECT Keyword  FROM mk_pages WHERE idPa = '$idPa'";
		$kq = mysql_query($sql,$this->conn);
		$row_trang = mysql_fetch_assoc($kq);
        return $row_trang['Keyword'];
	}
}
?>