public static function load($curPage, $status)
 {
     $totalItems = null;
     $advertisement = null;
     $maxItems = 5;
     $maxPages = 25;
     $offset = ($curPage - 1) * $maxItems;
     if ($status == -1) {
         $advertisement = QuangCaoBUS::getBySQL("select * from quangcao limit {$offset},{$maxItems}");
         $totalItems = QuangCaoBUS::countBySQL("select count(*) from quangcao");
     } else {
         $advertisement = QuangCaoBUS::getBySQL("select * from quangcao where status={$status} limit {$offset},{$maxItems}");
         $totalItems = QuangCaoBUS::countBySQL("select count(*) from quangcao where status={$status}");
     }
     $display = AdvertisementProcessor::displayHeader($totalItems);
     $display .= AdvertisementProcessor::display($advertisement);
     $display .= AdvertisementProcessor::displayFooter();
     $strPaging = Utils::paging('', $totalItems, $curPage, $maxPages, $maxItems);
     return $display . $strPaging;
 }
    $flag = 1;
}
if ($_SESSION["curUser"][8] == 3) {
    $flag = 1;
}
if ($flag == 0) {
    // Khong duoc phep di tiep
    header("Location: index.php");
}
$id = (int) $_GET["id"];
if (empty($id)) {
    return;
}
$PATH = str_replace('//', '/', dirname(__FILE__) . '/');
include_once $PATH . "../../../BUS/QuangCaoBUS.php";
$qc = QuangCaoBUS::GetAdvByID($id);
?>
<script>
	function saveNewQuangCao()
	{
		if (document.getElementById("txtChuSoHuu").value == "")
		{
			alert("Tên chủ sở hữu không được rỗng. Vui lòng kiểm tra lại.");
			document.getElementById("txtChuSoHuu").focus();
			return false;
		}
		if (document.getElementById("txtSDT").value == "")
		{
			alert("Số điện thoại không được rỗng. Vui lòng kiểm tra lại.");
			document.getElementById("txtSDT").focus();
			return false;
            $path = "{$path}/quangcao/";
            $filename;
            if ($_FILES["fileUpQuangCao"]["name"] != "") {
                $filename = $random . $_FILES["fileUpQuangCao"]["name"];
                move_uploaded_file($_FILES["fileUpQuangCao"]["tmp_name"], $path . $random . $_FILES["fileUpQuangCao"]["name"]);
            } else {
                $filename = null;
            }
            $kq = QuangCaoBUS::Update($id, $chusohuu, $sdt, $email, $diachi, $sothang, $filename, $link);
            // if($kq == false)
            // {
            // $flagInsert = false;
            // echo "<br>Insert image = false";
            // }
            // else
            // echo "upload picture finish!";
            break;
    }
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete") {
    $advid = explode(',', $_GET["advid"]);
    for ($i = 0; $i < count($advid); $i++) {
        QuangCaoBUS::delete($advid[$i]);
    }
}
$status = isset($_REQUEST["status"]) ? (int) $_REQUEST["status"] : -2;
$url = "index.php?view=advertisement";
if ($status != -2) {
    $url .= "&status=" . $status;
}
header("Location:../../" . $url);
		</tr>
	</table>
</div>
<div class="box_left">
	<table width="100%">
		<tr>
			<td width="30px">
				<img src="../images/megaphone.png">
			</td>
			<td>
				<p style="font-size:20pt;"><b>THÔNG TIN QUẢNG CÁO</b></p>
			</td>
		</tr>
		<?php 
include_once "../BUS/QuangCaoBUS.php";
$listAdv = QuangCaoBUS::GetAdvByType(1);
for ($i = 0; $i < count($listAdv); $i++) {
    $ext = substr($listAdv[$i]["hinhanh"], -3);
    echo "<tr><td colspan='2' align='center'>";
    if ($ext == "swf") {
        echo "<a href='" . $listAdv[$i]["link"] . "'><embed type='application/x-shockwave-flash' src='../admin/upload/quangcao/" . $listAdv[$i]["hinhanh"] . "' id='mymovie'\r\n\t\t\t\t\t\tname='mymovie' bgcolor='#000000' quality='high' loop='true' wmode='transparent' width='180px' height='160px'></a>";
    } else {
        echo "<a href='" . $listAdv[$i]["link"] . "'><img src='../admin/upload/quangcao/" . $listAdv[$i]["hinhanh"] . "' width='180' height='160' /></a>";
    }
    echo "</td></tr>";
}
?>
		<tr>
			<td colspan="2" align="center">
				<img src="../admin/upload/quangcao/ad_noimage.jpg" />
			</td>
// Cap nhat status quang cao
include_once "../BUS/QuangCaoBUS.php";
include_once "../module/Utils/Utils.php";
$listAdv = QuangCaoBUS::GetAdvByType(-2);
for ($i = 0; $i < count($listAdv); $i++) {
    $date1 = $listAdv[$i]["ngaydang"];
    $sothang = $listAdv[$i]["sothang"];
    $arr = explode("-", $date1);
    $month = $arr[1] + $sothang;
    $date2 = $arr[2] . "-" . $month . "-" . $arr[0];
    $rs = Utils::compareDate($date2, date('d-m-Y'));
    if ($rs == 1) {
        // Đã hết hạn: cap nhat bien status trong table QuangCao
        QuangCaoBUS::setStatusQuangCao($listAdv[$i]["id"], 0);
    } else {
        QuangCaoBUS::setStatusQuangCao($listAdv[$i]["id"], 1);
    }
}
// THINH: end
// $ip = $_SERVER['REMOTE_ADDR'];
// echo "<br>AAAAAAAA".$ip;
// $seft = $_SERVER['PHP_SELF'];
// echo "<br>BBBBBB".$seft;
?>
<body style="margin: 0pt; padding: 0pt;" bgcolor="#000c1c">
	<div style="width: 100%; background-image: url(&quot;../images/bg_top.gif&quot;); background-repeat: repeat-x; text-align: center;">
		<center>
            <div style="clear: both; width: 1100px; text-align: center; background-image: url(&quot;../images/logo_top.gif&quot;);
                background-repeat: no-repeat;">
                <div style="padding-left: 140px;">
                    <center>
				}
				else //else if this is a session only cookie
					document.cookie = name+"="+value;
			}
			function loadAdvByStatus()
			{
				var status = document.getElementById("status");
				window.location = "index.php?view=advertisement&status=" + status.value;
			}
		</script>
		<form method="post" name="frmListItem" id="frmListItem">
			<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td width="69%">
						<?php 
$listAdv = QuangCaoBUS::GetAdvByType($status);
echo "<b>Có " . count($listAdv) . " mẫu tin.</b>";
?>
					</td>
					<td width="31%">
						<div align="right">
							<select id="status" onchange="return loadAdvByStatus();">
								<option value="-2" <?php 
echo $status == -1 ? "selected" : "";
?>
> - Chọn hiệu lực - </option>
								<option value="1"  <?php 
echo $status == 1 ? "selected" : "";
?>
>Còn hạn</option>
								<option value="0"  <?php