// move file & đổi tên ...
     $dir = "users/" . $nguoi_dung->UserName . "/" . $file['name'];
     if (!move_uploaded_file($file['tmp_name'], $dir)) {
         $mess .= "<br><span class='error'>Up ảnh bị lỗi, bạn có thể vào <a href='trang_ca_nhan.php'>trang cá nhân </a> để up lại.</span><br/><br/>";
     }
     //upfile thành công
     $nguoi_dung->AnhDaiDien = $dir;
 }
 // insert vào CSDL
 mysql_connect("localhost", "root", "") or die("Not connect host");
 mysql_select_db("shopping_here") or die("Not connect database");
 // insert đối tượng
 $result_doituong = DoiTuongDAO::ThemDoiTuong('Nguoi mua');
 if ($result_doituong) {
     $nguoi_dung->MaNguoiDung = $result_doituong;
     $result = NguoiDungDAO::ThemNguoiDung($nguoi_dung);
     if ($result) {
         $_SESSION['IsLogin'] = 1;
         $_SESSION['IdUser'] = $nguoi_dung->MaNguoiDung;
         $_SESSION['UserName'] = $nguoi_dung->UserName;
         $_SESSION['Authentication'] = 'Nguoi mua';
         $mess .= "<p>\r\n\t\t\t\t\t Bạn đã đăng ký thành công, \r\n\t\t\t\t\t click vào đây để về <span class='text-color-bold-1'><a href='trang_ca_nhan.php'>trang cá nhân</a></span> \r\n\t\t\t\t\t hoặc về <span class='text-color-bold-1'><a href='index.php'>trang chủ.</a></span>                 </p>";
         // tạo folder người dùng
         $structure = "./users/" . $nguoi_dung->UserName . "/theme/";
         if (!mkdir($structure, 0, true)) {
             die('Failed to create folders...');
             return;
         }
         $structure = "./users/" . $nguoi_dung->UserName . "/product/";
         if (!mkdir($structure, 0, true)) {
             die('Failed to create folders...');
              </div>
            </div>
            <!--end .login-wrapper-->
            <div class="account-wrapper">
           	  <div class="account-content">
              	<div class="account-content-line">
               	  <div class="profile-page"><a href="trang_ca_nhan.php?id=tcn">Trang cá nhân</a></div>
                </div>
              	<div class="account-content-line">
                	<div class="my-orders"><a href="trang_ca_nhan.php?id=ddh">Đơn hàng của tôi</a></div>
                </div>
                <div class="account-content-line">
                	<?php 
//kiểm tra người dùng có gian hàng hay chưa
require_once 'class/NguoiDungDAO.php';
$chkCoGianHang = NguoiDungDAO::LayThongTinNguoiDungTheoMa($_SESSION['IdUser']);
if (!is_null($chkCoGianHang)) {
    if (is_null($chkCoGianHang->MaGianHang) || $chkCoGianHang->MaGianHang <= 0) {
        // chưa có gian hàng
        echo '<div class="my-shop">
								<a href="tao_gian_hang.php">Tạo gian hàng</a>
								</div>';
    } else {
        // đã có gian hàng
        echo '<div class="my-shop">
								<a href="gian_hang.php?maGianHang=' . $chkCoGianHang->MaGianHang . '">Gian hàng của tôi</a>
								</div>';
    }
} else {
    echo '<div class="my-shop">
								<a href="tao_gian_hang.php">Tạo gian hàng</a>
 $gAddCart = "\r\n\t\t<div class='add-cart'>\t\r\n\t\t\t<h2>Đặt mua</h2>\r\n\t\t\t\t<div class='line'>\r\n\t\t\t\t\t<label for='txtSoLuongSPThemVaoSoGio'>Số lượng:</label><input name='txtSoLuongSPThemVaoSoGio' id='txtSoLuongSPThemVaoSoGio' type='text' size='10' style='text-align:right;' onchange='updateThanhTien(this.id)' />                    \r\n\t\t\t\t\t<input type='hidden' id='hidMaSanPham' name= 'hidMaSanPham' value='{$maSanPham}'/>\r\n\t\t\t\t</div>\r\n\t\t\t\t<div class='line'>\r\n\t\t\t\t\t<label>Thành tiền: <span class='new-price'><span id='idThanhTien'>0</span> VND </span></label>\r\n\t\t\t\t</div>\r\n\t\t\t\t<div class='line'>\r\n\t\t\t\t\t<input name='btnThemVaoGioHang' type='submit' class='button ui-state-default ui-button-text-icon-primary' value='Thêm vào giỏ hàng' onclick='funcThemVaoGioHang()' />                                   \r\n\t\t\t\t</div>\t\t\t\r\n        </div>\r\n        <!--end .add-cart-->";
 /***************************************************/
 //thông tin chi tiết
 $gInfoDetail = "<div class='content'>{$sanPham->DacDiemSP}</div>\r\n        <!--end .content-->";
 /***************************************************/
 // BÌNH LUẬN SẢN PHẨM
 $lstBinhLuan = BinhLuanDAO::LayDSBL_TheoMaDoiTuong($maSanPham, 0);
 $gSoBinhLuan = count($lstBinhLuan);
 if ($_SESSION['IsLogin'] == 0) {
     $gBinhLuan = "Bạn phải đăng nhập mới được quyền xem bình luận";
 } else {
     $nguoiDung = NguoiDungDAO::LayThongTinNguoiDungTheoMa($_SESSION['IdUser']);
     // ds các bình luận
     if ($gSoBinhLuan > 0) {
         foreach ($lstBinhLuan as $binhLuanDto) {
             $nguoiDungBL = NguoiDungDAO::LayThongTinNguoiDungTheoMa($binhLuanDto->NguoiBL);
             $thoiGianBL = date_create($binhLuanDto->NgayBL);
             $gioBL = $thoiGianBL->format('H:i');
             $ngayBL = $thoiGianBL->format('d-m-Y');
             $dsLikes = LikesDAO::LayDanhSachLikesTheoMaDoiTuong($binhLuanDto->MaBL);
             $soNguoiLike = count($dsLikes);
             $nguoiDungLikeBL = LikesDAO::LayDanhSachLikesTheoMaDT_MaNguoiDung($binhLuanDto->MaBL, $nguoiDung->MaNguoiDung);
             $idKQ_Like_BL = "kq_like_binhluan_sp_" . $binhLuanDto->MaBL;
             $funcLikeBL = "funcLike('" . $binhLuanDto->MaBL . "','" . $nguoiDung->MaNguoiDung . "','" . $idKQ_Like_BL . "','BinhLuanSP')";
             if (is_null($nguoiDungLikeBL)) {
                 $txtLikeBL = "Like";
             } else {
                 $txtLikeBL = "Unlike";
             }
             $gBinhLuan .= "\r\n\t\t\t\t<div class='comment-wrapper'>                       \t  \t\r\n\t\t\t\t\t<div class='avatar'><img src='{$nguoiDungBL->AnhDaiDien}' width='1280' height='1024' /></div>\r\n\t\t\t\t\t<div class='content'>\r\n\t\t\t\t\t\t <div class='title-comment'>\r\n\t\t\t\t\t\t\t<span class='text-color-normal-1'>\r\n\t\t\t\t\t\t\t\t<a href='trang_ca_nhan.php?id={$nguoiDungBL->MaNguoiDung}'>" . $nguoiDungBL->UserName . "</a>\r\n\t\t\t\t\t\t\t</span> bình luận lúc {$gioBL} ngày {$ngayBL}.\r\n\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t <div class='primary-comment'>\r\n\t\t\t\t\t\t\t\t{$binhLuanDto->NoiDungBL}\r\n\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t <div class='action' id='kq_like_binhluan_sp_{$binhLuanDto->MaBL}'>\r\n\t\t\t\t\t\t\t{$soNguoiLike} người thích <span class='text-color-normal-1 likes' onclick={$funcLikeBL} >{$txtLikeBL}</span>\r\n\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t</div>                            \r\n\t\t\t\t\t<!--end .content-->\r\n\t\t\t\t\t<div class='button'>\r\n\t\t\t\t\t\t<span class='remove ui-icon ui-icon-close' title='Xóa'>&nbsp;</span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t<!--end .comment-wrapper-->";
         }
require_once 'class/NguoiDungDAO.php';
$username = $_POST["txtUserName"];
$password = $_POST["txtPassword"];
if (isset($_POST["btnLogin"])) {
    mysql_connect("localhost", "root", "") or die("Not connect host");
    mysql_select_db("shopping_here") or die("Not connect database");
    // mã hóa password = md5
    $password = md5($password);
    $check_user_name = NguoiDungDAO::LayThongTinNguoiDungTheoTenTaiKhoan($username);
    if (is_null($check_user_name)) {
        echo "<script>alert('Tên đăng nhập này chưa tồn tại!');</script>";
        echo "<meta http-equiv='refresh' content='1;url=index.php'/>";
    } else {
        $result = NguoiDungDAO::KiemTraDangNhap($username, $password);
        if ($result) {
            $nguoiDungDto = NguoiDungDAO::LayThongTinNguoiDungTheoTenTaiKhoan($username);
            // set session:
            $_SESSION['IsLogin'] = true;
            $_SESSION['IdUser'] = $nguoiDungDto->MaNguoiDung;
            $_SESSION['UserName'] = $nguoiDungDto->UserName;
            $_SESSION['Authentication'] = $nguoiDungDto->MaLoaiND;
            $response = "\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t<div class='standard_error'>\r\n\t\t\t\t\t\t<form class='block vbform' method='post' action='#' name='postvarform'>\r\n\t\t\t\t\t\t\t<h2 class='blockhead'>Ðang chuyển tới ...</h2>\r\n\t\t\t\t\t\t\t<div class='blockbody formcontrols'>\r\n\t\t\t\t\t\t\t\t<p class='blockrow restore'>Cảm ơn, <strong>{$username}</strong> đã đăng nhập thành công<br><br> </p>\r\n\t\t\t\t\t\t\t\t<center>Shopping-Here website mua bán hàng đầu Việt Nam</center>\r\n\t\t\t\t\t\t\t\t<p></p>\r\n\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t<div class='blockfoot actionbuttons redirect_button'>\r\n\t\t\t\t\t\t\t\t<div class='group' id='redirect_button'>\r\n\t\t\t\t\t\t\t\t\t<a href='index.php' class='textcontrol'>[ Click vào đây nếu trình duyệt không tự chuyển ]</a>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t</form>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t";
            //echo "<p align='center'  style='font:arial; color:#000; font-size:14px;'>Đăng nhập thành công! Đang chuyển hướng về trang chủ</p>";
            if ($nguoiDungDto->MaLoaiND == 3) {
                echo $response;
                echo "<meta http-equiv='refresh' content='3;url=admin.php'/>";
            } else {
                echo $response;
                echo "<meta http-equiv='refresh' content='3;url=index.php'/>";
            }
        } else {
<?php

require_once '../class/BinhLuanDAO.php';
require_once '../class/DoiTuongDAO.php';
require_once '../class/NguoiDungDAO.php';
if (isset($_REQUEST['noiDungBL']) && isset($_REQUEST['id']) && isset($_REQUEST['user']) && isset($_REQUEST['kq']) && isset($_REQUEST['page']) && isset($_REQUEST['t'])) {
    $maDoiTuong = $_REQUEST['id'];
    $noiDungBL = $_REQUEST['noiDungBL'];
    $nguoiBL = NguoiDungDAO::LayThongTinNguoiDungTheoMa($_REQUEST['user']);
    // tạo đối tượng
    $maBL = DoiTuongDAO::ThemDoiTuong('Binh luan');
    if ($maBL > 0) {
        // nếu tạo tối tượng thành công --> thêm bình luận
        $binhLuan = new BinhLuanDTO();
        $binhLuan->MaBL = $maBL;
        $binhLuan->NoiDungBL = $noiDungBL;
        $binhLuan->NguoiBL = $nguoiBL->MaNguoiDung;
        $binhLuan->DaXoa = 0;
        $binhLuan->DoiTuongBL = $maDoiTuong;
        $binhLuan->NgayBL = date('Y-m-d');
        if (BinhLuanDAO::ThemBL($binhLuan)) {
            // nếu thêm thành công
            $binhLuanDto = BinhLuanDAO::LayBinhLuanTheoMaBL($maBL);
            $thoiGianBL = date_create($binhLuanDto->NgayBL);
            $gioBL = $thoiGianBL->format('H:i');
            $ngayBL = $thoiGianBL->format('d-m-Y');
            $soNguoiLike = 0;
            if ($_REQUEST['page'] == "BinhLuan_SP") {
                $idKQ_Like_BL = "kq_like_binhluan_sp_" . $binhLuanDto->MaBL;
                $funcLikeBL = "funcLike('" . $binhLuanDto->MaBL . "','" . $nguoiBL->MaNguoiDung . "','" . $idKQ_Like_BL . "','BinhLuanSP')";
            }
        } else {
            if (!is_null($dsBinhLuan)) {
                foreach ($dsBinhLuan as $binhLuanDto) {
                    $nguoiDungBL = NguoiDungDAO::LayThongTinNguoiDungTheoMa($binhLuanDto->NguoiBL);
                    $thoiGianBL = date_create($binhLuanDto->NgayBL);
                    $gioBL = $thoiGianBL->format('H:i');
                    $ngayBL = $thoiGianBL->format('d-m-Y');
                    $dsLikes = LikesDAO::LayDanhSachLikesTheoMaDoiTuong($binhLuanDto->MaBL);
                    $soNguoiLike = count($dsLikes);
                    $nguoiDungLikeBL = LikesDAO::LayDanhSachLikesTheoMaDT_MaNguoiDung($binhLuanDto->MaBL, $_SESSION['IdUser']);
                    $idKQ_Like_BL = "kq_like_binhluan_sk_" . $binhLuanDto->MaBL;
                    $funcLikeBL = "funcLike('" . $binhLuanDto->MaBL . "','" . $_SESSION['IdUser'] . "','" . $idKQ_Like_BL . "','BinhLuan_SK')";
                    if (is_null($nguoiDungLikeBL)) {
                        $txtLikeBL = "Like";
                    } else {
                        $txtLikeBL = "Unlike";
                    }
                    $gBinhLuanSK .= "\r\n\t\t\t\t\t\t\t\t\t<div class='comment-wrapper'>                       \t  \t\r\n\t\t\t\t\t\t\t\t\t\t<div class='avatar'><img src='{$nguoiDungBL->AnhDaiDien}' width='1280' height='1024' /></div>\r\n\t\t\t\t\t\t\t\t\t\t<div class='content'>\r\n\t\t\t\t\t\t\t\t\t\t\t <div class='title-comment'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<span class='text-color-normal-1'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='trang_ca_nhan.php?id={$nguoiDungBL->MaNguoiDung}'>" . $nguoiDungBL->UserName . "</a>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</span> bình luận lúc {$gioBL} ngày {$ngayBL}.\r\n\t\t\t\t\t\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t\t\t\t\t\t <div class='primary-comment'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{$binhLuanDto->NoiDungBL}\r\n\t\t\t\t\t\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t\t\t\t\t\t <div class='action' id='kq_like_binhluan_sk_{$binhLuanDto->MaBL}'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t{$soNguoiLike} người thích <span class='text-color-normal-1 likes' onclick={$funcLikeBL} >{$txtLikeBL}</span>\r\n\t\t\t\t\t\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t\t\t\t\t\t \r\n\t\t\t\t\t\t\t\t\t\t</div>                            \r\n\t\t\t\t\t\t\t\t\t\t<!--end .content-->\r\n\t\t\t\t\t\t\t\t\t\t<div class='button'>\r\n\t\t\t\t\t\t\t\t\t\t\t<span class='remove ui-icon ui-icon-close' title='Xóa'>&nbsp;</span>\r\n\t\t\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t\t<!--end .comment-wrapper-->";
                }
            } else {
                $gBinhLuanSK .= "Không có bình luận nào.";
            }
            /**********************************************************/
            // bình luận mới
            $curUser = NguoiDungDAO::LayThongTinNguoiDungTheoMa($_SESSION['IdUser']);
            $funcThemBinhLuan = 'funcThemBinhLuan("txtNoiDungBinhLuan_SK", "' . $suKienDto->MaSuKien . '", "' . $_SESSION['IdUser'] . '","kq_binhluan_sk", "BinhLuan_SK")';
            $gBinhLuanMoi .= "\r\n\t\t\t\t\t\t\t\t <div id='kq_binhluan_sk'>\r\n\t\t\t\t\t\t\t\t </div>\r\n\t\t\t\t\t\t\t\t <div class='comment-wrapper'>                       \t  \t\r\n\t\t\t\t\t\t\t\t\t<div class='avatar'><img src='{$curUser->AnhDaiDien}' width='1280' height='1024' /></div>\r\n\t\t\t\t\t\t\t\t\t<div class='content'>\r\n\t\t\t\t\t\t\t\t\t\t<div class='title-comment'>\r\n\t\t\t\t\t\t\t\t\t\t\t<span class='text-color-normal-1'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<a href='trang_ca_nhan.php?id={$curUser->MaNguoiDung}'>" . $curUser->UserName . "</a>\r\n\t\t\t\t\t\t\t\t\t\t\t</span>\r\n\t\t\t\t\t\t\t\t\t\t</div>\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t<textarea id='txtNoiDungBinhLuan_SK' name='txtNoiDungBinhLuan_SK' cols='80' rows='5'></textarea><br />                       \t\t\t\t<input name='btnBinhLuan' type='button' value='Bình luận' class='ui-state-default ui-state-hover ui-button-text-only' onclick='" . $funcThemBinhLuan . "'  />\r\n\t\t\t\t\t\t\t\t\t</div>                            \r\n\t\t\t\t\t\t\t\t\t<!--end .content-->                           \r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t<!--end .comment-wrapper || đăng bình luận-->\r\n\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t<!--end .comment-->\r\n\t\t\t\t\t\t\t<div class='paging'>\r\n\t\t\t\t\t\t\t\t<div class='item'>                \r\n\t\t\t\t\t\t\t\t  <a href='#' class='item current'>1</a> \r\n\t\t\t\t\t\t\t\t  <a href='#' class='item'>2</a>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t<!--end .paging -->\r\n\t\t\t\t\t  </div>\r\n\t\t\t\t\t  <!--end row bình luận -->\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<!--end .event-detail-->\r\n\t\t\t\t</div>\r\n\t\t\t\t<!--end #kq_xuly-->";
        }
        echo $gChiTietSK . $gBinhLuanSK . $gBinhLuanMoi;
    }
}