<?php 
class quantri extends DB
{
public function timkiem($tukhoa)
	{
		$qr = "SELECT bangtin.*,TenTL FROM bangtin,theloai WHERE bangtin.idTL = theloai.idTL AND TieuDe LIKE '%$tukhoa%' ORDER BY Ngay DESC LIMIT 0,50";
		return mysqli_query($this -> con,$qr);
	}
public function timkiemtl($idtl)
	{
		$qr = "SELECT bangtin.*,TenTL FROM bangtin,theloai WHERE bangtin.idTL = theloai.idTL AND bangtin.idTL= $idtl ORDER BY Ngay DESC LIMIT 0,50";
		return mysqli_query($this -> con,$qr);
	}
public function baiviet()
{
	$qr = "SELECT * FROM bangtin ";
	return mysqli_query($this -> con,$qr);
}
public function thembaiviet($tieude,$tenkhongdau,$urlhinh,$ngay,$iduser,$noidung,$theloai,$theloai2,$solanxem)
{
	 $qr = "INSERT INTO bangtin VALUES(null,'$tieude','$tenkhongdau','','$urlhinh','$ngay','$iduser','$noidung','$theloai','$theloai2','$solanxem','1','1','8') ";
	
	mysqli_query($this -> con,$qr);
}
public function xoabai($idtin)
{
	$qr = "DELETE FROM bangtin WHERE idTin= $idtin";
	mysqli_query($this -> con,$qr);
}
public function idbaiviet($idtin)
{
	$qr = "SELECT * FROM bangtin WHERE idTin = $idtin";
	return mysqli_query($this -> con,$qr);
}
public function suabaiviet($idtin,$tieude,$tenkhongdau,$urlhinh,$ngay,$noidung,$theloai,$theloai2)
{
	 $qr = "UPDATE bangtin SET 
	 TieuDe ='$tieude',
	 TieuDe_KhongDau ='$tenkhongdau',
	 urlHinh='$urlhinh',
	 Ngay='$ngay',
	 Content = '$noidung',
	 idTL='$theloai',
	 idTL2='$theloai2'
	 WHERE idTin = '$idtin' ";
	 mysqli_query($this -> con,$qr);
}
public function phantrang($from,$sotin)
{
		$qr = "SELECT bangtin.*,TenTL FROM bangtin,theloai WHERE bangtin.idTL = theloai.idTL ORDER BY Ngay DESC LIMIT $from,$sotin";
		return mysqli_query($this -> con,$qr);
}

// -------------START THỂ LOẠI------------
public function theloai()
{
	$qr = "SELECT * FROM theloai ORDER BY idTL ASC ";
	return mysqli_query($this -> con,$qr);
}
public function themtheloai($tentl,$tentlkd,$thutu,$anhien)
{
	$qr = "INSERT INTO theloai VALUES(null,'$tentl','$tentlkd','$thutu','$anhien') ";
	mysqli_query($this -> con,$qr);
}
public function idtheloai($idtl)
{
	$qr = "SELECT * FROM theloai WHERE idTL = $idtl ";
	return mysqli_query($this -> con,$qr);
}
public function suatheloai($idtl,$tentl,$tentlkd,$thutu,$anhien)
{
	$qr = "UPDATE theloai SET TenTL= '$tentl',TenTL_KhongDau = '$tentlkd',ThuTu = '$thutu',AnHien ='$anhien' WHERE idTL = '$idtl' ";
    mysqli_query($this -> con,$qr);
}
public function xoatheloai($idtl)
{
	$qr = "DELETE FROM theloai WHERE idTL= $idtl";
	mysqli_query($this -> con,$qr);
}
// -------------finish thể loại------------
// ------------slide----------
public function slide()
	{
		$qr = "SELECT * FROM bangslide ";
		return mysqli_query($this-> con,$qr);
	}
public function idslide($idslide)
{
	$qr = "SELECT * FROM bangslide WHERE idslide = $idslide";
	return mysqli_query($this -> con,$qr);
}
public function editslide($idslide,$urlhinh,$lienket)
{
	$qr = "UPDATE bangslide SET urlhinh = '$urlhinh', lienket = '$lienket' WHERE idslide = '$idslide' ";
	return mysqli_query($this -> con,$qr);
}		
// ---------------kết thúc slide----------
// --------ảnh thông báo----------
public function anhthongbao()
	{
		$qr = "SELECT * FROM thongbao ";
		return mysqli_query($this-> con,$qr);
	}
public function idanh($idanh)
{
	$qr = "SELECT * FROM thongbao WHERE idQC = $idanh";
	return mysqli_query($this -> con,$qr);
}
public function editanhthongbao($idanh,$vitri,$urlhinh,$lienket)
{
	$qr = "UPDATE thongbao SET vitri= '$vitri',urlHinh = '$urlhinh', Url = '$lienket' WHERE idQC = '$idanh' ";
	return mysqli_query($this -> con,$qr);
}		
// -------------Kết thúc ảnh thông báo-----------
// --------lieenket------
public function lienket()
	{
		$qr = "SELECT * FROM lienket ORDER BY vitri ASC  ";
		return mysqli_query($this-> con,$qr);
	}
public function idlk($idlk)
{
	$qr = "SELECT * FROM lienket WHERE idlk = $idlk";
	return mysqli_query($this -> con,$qr);
}	
public function editlienket($idlk,$vitri,$tieude,$urlhinh,$lienket)
{
	$qr = "UPDATE lienket SET vitri= '$vitri',Tieude= '$tieude',urlHinh = '$urlhinh', Url = '$lienket' WHERE idlk = '$idlk' ";
	return mysqli_query($this -> con,$qr);
}	
// --------Quản lý user----------
public function iduser($iduser)
{
	$qr = "SELECT * FROM tueba_users WHERE iduser = $iduser";
	return mysqli_query($this -> con,$qr);
}
public function edituser($iduser,$lmhpass)
{
	$qr = "UPDATE tueba_users SET lmhpass = '$lmhpass' WHERE iduser = '$iduser' ";
	return mysqli_query($this -> con,$qr);
}	
// ------------- Kết thúc quản lý user----------
public function stripUnicode($str)
{
  if(!$str) return false;
   $unicode = array(
     'a'=>'á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ',
     'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ằ|Ẳ|Ẵ|Ặ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
     'd'=>'đ',
     'D'=>'Đ',
	  'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
	  'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
	  'i'=>'í|ì|ỉ|ĩ|ị',	  
	  'I'=>'Í|Ì|Ỉ|Ĩ|Ị',
     'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
	  'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
     'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
	  'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
     'y'=>'ý|ỳ|ỷ|ỹ|ỵ',
     'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ'
   );
foreach($unicode as $khongdau=>$codau) {
	$arr=explode("|",$codau);
	$str = str_replace($arr,$khongdau,$str);
}
return $str;
}
public function changeTitle($str){
	$str=trim($str);
	if ($str=="") return "";
	$str =str_replace('"','',$str);
	$str =str_replace("'",'',$str);
	$str = $this -> stripUnicode($str);
	$str = mb_convert_case($str,MB_CASE_TITLE,'utf-8');
	
	// MB_CASE_UPPER / MB_CASE_TITLE / MB_CASE_LOWER
	$str = str_replace(' ','-',$str);
	$str = str_replace('/','-',$str);
	$str = str_replace(':','-',$str);
	$str = str_replace(',','-',$str);
	$str = str_replace('%','-',$str);
	return $str;
}

public function mail_utf8($to, $from_user, $from_email, $subject = '(No subject)', $message = '')
{
	$from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
	$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
	$headers = "From: $from_user <$from_email>\r\n".
               "MIME-Version: 1.0" . "\r\n" .
               "Content-type: text/html; charset=UTF-8" . "\r\n";
	return mail($to, $subject, $message, $headers);
}

public function PhatSinhRandomKey()
{
	$s = "";
	
	$m = array(0,1,2,3,4,5,6,7,8,9,"a", "b", "c", "d", "e", "f", "g","h","i", "j");
	
	for($i=1; $i<=32; $i++){
		$r = rand(0, count($m)-1);
		$s = $s . $m[$r];
	}
	
	return $s;
}


}
 ?>
