示例#1
0
function cart_list()
{
    $data = array();
    if (!isset($_SESSION['cart'])) {
        $data['error'] = 'Giỏ trống trơn!';
    } else {
        $data['cart'] = $_SESSION['cart'];
        $fromDB = model('book')->getCartList($data['cart']);
        $merge = array();
        foreach ($data['cart'] as $cart) {
            foreach ($fromDB as $value) {
                if (intval($value['id']) == $cart['book_id']) {
                    $merge[] = array_merge($cart, $value);
                }
            }
        }
        //var_dump($merge);
        $data['merge'] = $merge;
    }
    //Submit cart
    if (isPostRequest()) {
        $postData = postData();
        for ($i = 1; $i <= count($_SESSION['cart']); $i++) {
            foreach ($_SESSION['cart'] as $key => $cart) {
                if ($postData['bookid' . $i] == $cart['book_id']) {
                    $_SESSION['cart'][$key]['quantity'] = $postData['quantity' . $i];
                }
            }
        }
        redirect('index.php?c=bill&m=view');
    }
    $data['template_file'] = 'cart/list.php';
    render('layout.php', $data);
}
示例#2
0
function bill_detail()
{
    $data = array();
    $user = adminLogged();
    if (!adminLogged()) {
        redirect('/index.php?c=admin&m=login');
    } else {
        $bill_detail = model('bill')->getBillDetails($_GET['id']);
        $data['total'] = 0;
        foreach ($bill_detail as $key => $b) {
            $book = model('book')->getSingle($b['book_id']);
            $bill_detail[$key]['name'] = $book['name'];
            $bill_detail[$key]['price'] = intval($book['price']);
            $bill_detail[$key]['total'] = $book['price'] * $b['quantity'];
            $bill_detail[$key]['image'] = $book['image'];
            $data['total'] += $book['price'] * $b['quantity'];
        }
        $data['bill_detail'] = $bill_detail;
    }
    $data['statuses'] = array('Chờ duyệt', 'Đang giao hàng', 'Đã giao hàng', 'Hủy');
    $data['stt'] = model('bill')->getOneBy($_GET['id'], null)['status'];
    if (isPostRequest()) {
        $postData = postData();
        db_update('bills', $postData, 'id=' . $_GET['id']);
        $data['stt'] = $postData['status'];
        $data['error'] = 'Tình trạng đơn hàng update thành công.';
    }
    $data['user'] = model('user')->getOneBy(model('bill')->getOneBy($_GET['id'], null)['user_id'], null);
    $data['template_file'] = 'bill/detail.php';
    render('layout.php', $data);
}
示例#3
0
function user_signup()
{
    if (isPostRequest()) {
        $arr_user = array('user_name' => $_POST['user_name'], 'name' => $_POST['name'], 'password' => md5($_POST['password']));
        model('user')->signup($arr_user);
        redirect('index.php');
    }
    $data['template_file'] = 'user/signup.php';
    render('layout.php', $data);
}
示例#4
0
function news_add()
{
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        $currentUser = isLogged();
        if (model('news')->addToUser($postData, $currentUser['id'])) {
            redirect('index.php?c=news&m=list.php');
        }
    }
    $data['template_file'] = 'news/add.php';
    render('layout.php', $data);
}
示例#5
0
function test_feedback()
{
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        $currentUser = isLogged();
        // echo "<pre>";;var_dump($postData);die();
        if (model('question')->addToUser($postData, $currentUser['id'])) {
            redirect('index.php?c=test&m=list');
        }
    }
    $data['template_file'] = 'test/feedback.php';
    render('test.php', $data);
}
示例#6
0
function admin_login()
{
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        if (model('admin')->adminLogin($postData)) {
            redirect('/admin/index.php?c=bill&m=list');
        } else {
            $data['error'] = 'Login failed! Please try again!';
        }
    }
    $data['template_file'] = 'admin/login.php';
    render('layout.php', $data);
}
示例#7
0
function auth_register()
{
    $data = array();
    $data['template_file'] = 'auth/register.php';
    if (isPostRequest()) {
        $postData = postData();
        if (model('user')->authRegister($postData)) {
            redirect('index.php?c=payment&m=list');
        } else {
            $data['error'] = 'Register failed ! Email exists ! Please try again !';
            $data['postData'] = $postData;
        }
    }
    render('layout.php', $data);
}
示例#8
0
function auth_register()
{
    sleep(1);
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        if (model('user')->aut_register($postData)) {
            redirect('/blogtaolao_MVC_/index.php');
        } else {
            $data['error'] = 'Email đã tồn tại ';
        }
    }
    $data['template_file'] = 'auth/register.php';
    render('layout.php', $data);
}
示例#9
0
function blog_detail()
{
    $id = $_GET['id'];
    if (isPostRequest()) {
        $postData = postData();
        $currentUser = isLogged();
        if (model('blog')->addComment($postData, $id)) {
            redirect('/index.php?c=blog&m=detail&id=' . $id);
        }
    }
    $data['blog_content'] = model('blog')->getOneBlog($id);
    $data['blog_comment'] = model('blog')->getAllComment($id);
    //var_dump($data);die;
    $data['template_file'] = 'blog/viewBlog.php';
    render('layout.php', $data);
}
示例#10
0
function blog_update()
{
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        $currentUser = isLogged();
        if ($currentUser && model('entry')->update($postData, $_GET['entry'])) {
            redirect('/index.php?c=blog&m=list');
        }
    } else {
        $data['single'] = model('entry')->getSingle($_GET['entry']);
    }
    $data['title'] = 'Chỉnh sửa bài viết';
    $data['template_file'] = 'entry/add.php';
    render('layout.php', $data);
}
示例#11
0
function auth_change_info()
{
    $logged = isLogged();
    $email = $logged['email'];
    $role = $logged['role'];
    if (isPostRequest()) {
        $postData = postData();
        //var_dump($postData);die;
        if (model('user')->authChangeInfo($postData, $email, $role)) {
            redirect('/index.php?c=blog&m=list');
        }
    }
    $data['user_info'] = model('user')->authGetInfo($email);
    //var_dump($data);die;
    $data['template_file'] = 'auth/change_info.php';
    render('layout.php', $data);
}
示例#12
0
function book_list()
{
    $data = array();
    if (isset($_GET['pagenum'])) {
        $pagenum = $_GET['pagenum'];
    } else {
        $pagenum = 0;
    }
    $data['books'] = model('book')->get12($pagenum);
    if (model('book')->getCount() % 12 === 0) {
        $data['pages'] = intval(model('book')->getCount()) / 12;
    } else {
        $data['pages'] = intval(model('book')->getCount() / 12) + 1;
    }
    $data['pagenum'] = $pagenum;
    //Thêm vào giỏ hàng:
    if (isPostRequest()) {
        $postData = postData();
        $id = intval($postData['aidi']);
        $quantity = intval($postData['quantity']);
        if ($quantity <= 0) {
            $data['info'] = 'Số lượng không đúng!';
        } else {
            if (!isset($_SESSION['cart'])) {
                $_SESSION['cart'][0] = array('book_id' => $id, 'quantity' => $quantity);
            } else {
                $flag = false;
                foreach ($_SESSION['cart'] as $cart) {
                    if ($cart['book_id'] === $id) {
                        //$cart['quantity'] += $quantity;
                        $flag = true;
                        $data['info'] = 'Sách này đã có trong giỏ hàng!';
                        break;
                    }
                }
                if ($flag == false) {
                    $_SESSION['cart'][] = array('book_id' => $id, 'quantity' => $quantity);
                    $data['info'] = 'Thêm sách vào giỏ hàng thành công!';
                }
            }
        }
    }
    //var_dump($_SESSION['cart']);
    $data['template_file'] = 'book/list.php';
    render('layout.php', $data);
}
示例#13
0
function book_update()
{
    $data = array();
    if (isPostRequest()) {
        $postData = postData();
        $currentUser = adminLogged();
        if ($currentUser && model('book')->update($postData, $_GET['bookid'], $_SERVER['DOCUMENT_ROOT'] . '/images/') === 'success') {
            redirect('/admin/index.php?c=book&m=list');
        } else {
            $data['error'] = model('book')->update($postData, $_GET['bookid'], $_SERVER['DOCUMENT_ROOT'] . '/images/');
            $data['single'] = model('book')->getSingle($_GET['bookid']);
        }
    } else {
        $data['single'] = model('book')->getSingle($_GET['bookid']);
        $_SESSION['oldImage'] = $data['single']['image'];
    }
    $data['title'] = 'Chỉnh sửa sách';
    $data['template_file'] = 'book/add.php';
    render('layout.php', $data);
}
示例#14
0
function product_add()
{
    if (isPostRequest()) {
        $postData = postData();
        $postData['image'] = uploadImage();
        $currentUser = isLogged();
        //var_dump($postData);die;
        if ($postData['image'] == 0) {
            echo "Không upload được hình ảnh";
        } else {
            if (model('product')->addProduct($postData)) {
                redirect('/index.php?c=product&m=list');
            } else {
                echo "<script>alert('" . "Không thêm vào được CSDL!" . "')</script>";
            }
        }
    }
    $data['template_file'] = 'product/add.php';
    render('layout.php', $data);
}
示例#15
0
function bill_view()
{
    $data = array();
    if (!isset($_SESSION['cart'])) {
        redirect('index.php?c=cart&m=list');
    } else {
        $data['cart'] = $_SESSION['cart'];
        $fromDB = model('book')->getCartList($data['cart']);
        $merge = array();
        foreach ($data['cart'] as $cart) {
            foreach ($fromDB as $value) {
                if (intval($value['id']) == $cart['book_id']) {
                    $merge[] = array_merge($cart, $value);
                }
            }
        }
        $total = 0;
        foreach ($merge as $m) {
            $total += $m['quantity'] * $m['price'];
        }
        $data['total'] = $total;
    }
    if (isLogged()) {
        $data['user'] = $_SESSION['logged'];
    }
    if (isset($_GET['update'])) {
        $data['update'] = 1;
    }
    if (isPostRequest()) {
        $postData = postData();
        if (model('user')->update($postData, $postData['email'])) {
            $data['user'] = model('user')->getOneBy($postData['email'], 'email');
            unset($data['user']['password']);
            $_SESSION['logged'] = $data['user'];
            unset($_GET['update']);
            redirect('index.php?c=bill&m=view');
        }
    }
    $data['template_file'] = 'bill/view.php';
    render('layout.php', $data);
}
示例#16
0
function auth_register()
{
    $data = array();
    $data['template_file'] = 'auth/register.php';
    if (isPostRequest()) {
        $postData = postData();
        if ($postData['status'] == 'on') {
            $postData['status'] = 1;
        } else {
            $postData['status'] = 0;
            exit;
        }
        if (model('user')->authRegister($postData)) {
            redirect('index.php?c=post&m=list');
        } else {
            $data['error'] = 'Register failed ! Email exists ! Please try again !';
            $data['postData'] = $postData;
        }
    }
    $data['category'] = model('category')->getAllBycategory();
    render('layout.php', $data);
}
示例#17
0
        <title>Address Box</title>
        

    </head>
    <body>
        <center>
        <?php 
require_once '/includes/session-start.req-inc';
include_once '/functions/dbconnect.php';
include_once '/functions/login-function.php';
include_once '/functions/signupFunction.php';
include_once '/functions/newContact-function.php';
include_once '/functions/update.php';
include_once '/functions/until.php';
$view = filter_input(INPUT_GET, 'view');
if (isPostRequest()) {
    $email = filter_input(INPUT_POST, 'email');
    $password = filter_input(INPUT_POST, 'pass');
    if (isValidUser($email, $password)) {
        $_SESSION['isValidUser'] = true;
        header('Location: index.php?view=userdefault');
    } else {
        if (!isset($_SESSION['isValidUser']) || $_SESSION['isValidUser'] !== true) {
            $results = 'Invalid Login. Sorry, please try again';
        }
    }
}
?>
        
    <nav>
        <ul>
示例#18
0
include './functions/utils.php';
$results = '';
$link = filter_input(INPUT_POST, 'link');
$errors = '';
$output = '';
/*
 * easy validation
 */
if (isPostRequest()) {
    if (filter_var($link, FILTER_VALIDATE_URL) == false) {
        $errors = 'Not a valid URL.';
    } else {
        $output = getLinks($link);
    }
}
if (isPostRequest() && empty($errors) && count($output) > 0) {
    if (saveSite($link, $output)) {
        $results = 'Data Added';
    } else {
        $errors = "Error. Data not added.";
    }
}
?>


        <h1><?php 
echo $results;
?>
</h1>
        <h1><?php 
echo $errors;
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
include './functions/until.php';
$email = filter_input(INPUT_POST, 'email');
$isValid = true;
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
    $isValid = false;
}
?>
        
        <?php 
if (isPostRequest() && !$isValid) {
    ?>
        <h1>Email is invalid</h1>
        <?php 
}
?>
        
        <form method="post" action="#">
 
            Email<input type="text" name="email" value="" />
            <input type="submit" value="submit" />
           

            <input type="submit" value="Submit" />
        </form>
        
示例#20
0
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
require './functions/until.php';
$email = filter_input(INPUT_POST, 'email');
$isValid = true;
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false && isPostRequest()) {
    $isValid = false;
}
?>
        
        <?php 
if (!$isValid) {
    ?>
            <h1>Email is invalid</h1>
        <?php 
}
?>
         <form method="post" action="#">
            Email<input type="text" name="email" value="" />
            <input type="submit" value="Submit" />
            </form>
    </body>
</html>
示例#21
0
function admin_addnews()
{
    if (isAdmin()) {
        if (isPostRequest()) {
            $edit = array();
            $edit['ID'] = $_POST['ID'];
            $edit['title'] = $_POST['title'];
            $edit['author'] = $_POST['author'];
            $edit['content'] = $_POST['content_'];
            $edit['time'] = date('yy-mm-dd h:i:s');
            $edit['slogan'] = $_POST['slogan'];
            $edit['tag'] = $_POST['tag'];
            //goi ham xu li tag
            $t = model('news')->add_tag($_POST['ID'], $_POST['tag']);
            //upload image
            $path = 'styles/img/news/' . $_FILES['image']['name'];
            // Đường dẫn chưa file upload
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            $edit['figimage'] = "styles/img/news/" . $_FILES['image']['name'];
            db_insert('news', $edit);
            redirect('index.php?c=news&m=mainpage');
        }
        $data['template_file'] = 'news/addNews.php';
        render('layout.php', $data);
    }
}
示例#22
0
function news_addDb()
{
    $data = array();
    if (isLogged()) {
        if (isPostRequest()) {
            $postData = postData();
            $currentUser = isLogged();
            if (model('dichbenh')->addToUser($postData, $currentUser['id'])) {
                redirect('index.php?c=news&m=dichbenh');
            }
        }
    } else {
        $data['error'] = 'Vui lòng đăng nhập !!!';
    }
    $data['template_file'] = 'news/addDb.php';
    render('layout.php', $data);
}
示例#23
0
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"><!-- css style sheet -->
        <title></title>        
    </head>
    <body>
        <header><h1>Url Finder by Site Given</h1></header>
        <?php 
include_once './functions/dbconnect.php';
//includes
include_once './functions/until.php';
include './functions/validation.php';
include './functions/Curl.php';
if (isPostRequest() === TRUE) {
    //check if there was a post request to display correct information
    $isValidUrl = validateUrl();
    //if there is a post request validate url
    $isValidUrlInDB = doesExistInDB();
    //check if this url is already in the database
    if ($isValidUrl === TRUE && $isValidUrlInDB === FALSE) {
        $output = specialOPCurl();
        $htmlMatch = array();
        $urlRegEx = "/(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,6}[\\/\\w \\.-]+)/";
        //grab all urls on page and store in a string variable
        $ExtractedHtml = filter_input(INPUT_POST, 'ExtractedHtml');
        //extract urls and store in an array
        preg_match_all($urlRegEx, $output, $htmlMatch);
        //remove duplicates from array
        $finalMatches = array_unique($htmlMatch[0]);
        $url = filter_input(INPUT_POST, 'URL');
if ($stmt->execute() && $stmt->rowCount() > 0) {
    $states = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
if (isPostRequest()) {
    $stmt = $db->prepare("SELECT * FROM cities WHERE state_id = :state_id");
    $state_id = filter_input(INPUT_POST, 'state_id');
    $binds = array(":state_id" => $state_id);
    if ($stmt->execute($binds) && $stmt->rowCount() > 0) {
        $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
}
?>
        
<!-- if to error for no results -->
        <?php 
if (isPostRequest() && !isset($results)) {
    ?>
        
        <h1>No results found</h1>
        
        <?php 
}
?>

<!-- form to select state -->        
        <form method="post" action="#">
 
            <select name="state_id">
            <?php 
foreach ($states as $row) {
    ?>
示例#25
0
function product_edit()
{
    $data = array();
    // kiểm tra login
    checkaut();
    // bắt dữ id bài viết cần chỉnh sửa
    //
    $Currentproduct = empty($_GET['id']) ? null : strtolower($_GET['id']);
    if (!model('product')->check_true($Currentproduct, 'product_id')) {
        $msg = "sản phẩm không tồn tại!!";
        abort($msg);
    }
    $data['products'] = model('product')->getOneBy($Currentproduct, 'product_id');
    // lưu bài viết đã chỉnh sửa
    if (isPostRequest()) {
        $recheck = false;
        $postData = postData();
        if (is_uploaded_file($_FILES['product_image']['tmp_name'])) {
            // lấy id cao nhất của product rồi+1 -> đặt tên cho image k bị trùng
            $id = $Currentproduct;
            //
            $FileName = $_FILES['product_image']['name'];
            $pos = strrpos($FileName, ".");
            $FileExtension = substr($FileName, $pos);
            $images = "../BlogTaolao_MVC_/images/product_{$id}" . $FileExtension;
            if (move_uploaded_file($_FILES['product_image']['tmp_name'], $images)) {
                // tạo data image cho file hình
                $postData['product_image'] = $images;
                $recheck = true;
            } else {
                $msg = "Không thể up hình!!";
                abort($msg);
            }
        }
        if (model('product')->update($postData, $Currentproduct) >= 1) {
            redirect('/blogtaolao_MVC_/index.php?c=product&m=list');
        } elseif ($recheck == true) {
            redirect('/blogtaolao_MVC_/index.php?c=product&m=list');
        }
    }
    $data['template_file'] = 'product/edit.php';
    render('layout.php', $data);
}
示例#26
0
function post_edit()
{
    $data = array();
    // kiểm tra login
    checkaut();
    // bắt dữ id bài viết cần chỉnh sửa
    $CurrentPost = empty($_GET['id']) ? null : strtolower($_GET['id']);
    if (!model('post')->check_true($CurrentPost, 'Post_id')) {
        $msg = "Bài viết không tồn tại!!";
        abort($msg);
    }
    $data['posts'] = model('post')->getOneBy($CurrentPost, 'Post_id');
    //
    // lưu bài viết đã chỉnh sửa
    if (isPostRequest()) {
        $postData = postData();
        if (is_uploaded_file($_FILES['image']['tmp_name'])) {
            $id = $CurrentPost;
            $FileName = $_FILES['image']['name'];
            $pos = strrpos($FileName, ".");
            $FileExtension = substr($FileName, $pos);
            $images = "../BlogTaolao_MVC_/images/image_{$id}" . $FileExtension;
            if (move_uploaded_file($_FILES['image']['tmp_name'], $images)) {
                $postData['image'] = $images;
            } else {
                $postData['image'] = $postData['image1'];
            }
        }
        if (model('post')->update($postData, $CurrentPost) >= 1) {
            redirect('/blogtaolao_MVC_/index.php?c=post&m=list');
        }
    }
    $data['template_file'] = 'post/edit.php';
    render('layout.php', $data);
}