<repo_name>nghiatv/mvc-routes<file_sep>/resources/views/admin/edit_user.php
<?php include '_admin_template/header.php' ?>

    <body class="hold-transition skin-blue sidebar-mini">
<?php include '_admin_template/menu.php' ?>
<?php include '_admin_template/sidebar.php' ?>

    <div class="register-box">
        <div class="register-logo">
            <a href="<?php echo BASE_PATH; ?>">Chỉnh sửa thông tin của <b><?php echo $data['user_name']; ?></b></a>
        </div>

        <div class="register-box-body">

            <form action="<?php echo BASE_PATH ?>/admin/user/update/<?php echo $data['id']; ?>" method="post">

                <?php if (isset($_SESSION['error'])) : ?>

                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                        <ul>

                            <?php foreach ($_SESSION['error'] as $row) : ?>
                                <li> <?php echo $row; ?></li>
                            <?php endforeach; ?>
                        </ul>

                    </div>

                <?php endif; ?>


                <?php if (isset($_SESSION['mes'])) : ?>
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                        <ul>

                            <?php foreach ($_SESSION['mes'] as $row) : ?>
                                <li> <?php echo $row; ?></li>
                            <?php endforeach; ?>
                        </ul>

                    </div>
                <?php endif; ?>

                <div class="form-group has-feedback">
                    <input type="text" class="form-control" placeholder="Username" name="username"
                           value="<?php echo $data['user_name']; ?>">
                    <span class="glyphicon glyphicon-user form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="email" class="form-control" placeholder="Email"
                           name="email" value="<?php echo $data['user_email']; ?>"
                    >
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="Password"
                           name="password" value="<?php echo $data['user_pass']; ?>">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="Retype password" name="repassword"
                           value="<?php echo $data['user_pass']; ?>">
                    <span class="glyphicon glyphicon-log-in form-control-feedback"></span>
                </div>
                <div class="row">
                    <!-- /.col -->
                    <div class="col-xs-6">
                        <button type="submit" class="btn btn-success btn-block btn-flat">Cập nhật thông tin</button>
                    </div>
                    <!-- /.col -->
                </div>
            </form>

        </div>
        <!-- /.form-box -->
    </div>
    <!-- /.register-box -->


<?php unset($_SESSION['error']); ?>
<?php unset($_SESSION['mes']); ?>
<?php include '_admin_template/footer.php' ?><file_sep>/libs/Validation.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/8/16
 * Time: 10:25 AM
 */
class Validation
{
//    Kiem tra tinh hop le cua input
    static public function isValidUser($user) {
        $pattern = "/^[a-zA-Z0-9]{6,18}$/";
        if(preg_match($pattern, $user)) {
            return true;
        } else {
            return false;
        }
    }

//    kiem tra tinh hop le cua password
    static function isValidPass($pass) {
        $pattern = "/^[a-zA-Z0-9]{8,32}$/";
        if(preg_match($pattern, $pass)) {
            return true;
        } else {
            return false;
        }
    }

}<file_sep>/config.php
<?php
/**
 * Created by PhpStorm.
 * User: Nimo
 * Date: 07/08/2016
 * Time: 10:08 CH
 */

//Thong so ve database
//define("DB_TYPE",'mysql');
//define('DB_HOST', 'localhost');
//define('DB_USER', 'root');
//define('DB_PASS', '');
//define('DB_DBNAME', 'blog-v1');


define('PATH_APPLICATION', __DIR__ . "/app");

define('BASE_PATH',"http://localhost:8000");

define('ENVIRONMENT', 'development');

if (ENVIRONMENT == 'development' || ENVIRONMENT == 'dev') {
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
} else {
    error_reporting(0);
    ini_set("display_errors", 0);
}
<file_sep>/libs/application.php
<?php
namespace Libs;
/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/8/16
 * Time: 11:26 AM
 */
class Application
{
    private $controller;
    private $action = 'view';
    private $param;
    private $request_path = array();

    public function __construct()
    {

        $this->request_path = $this->request_path();
        $this->splitURL();


        $controller = empty($this->controller) ? 'index' : $this->controller;

        $controller = strtolower($controller)."_controller";

        //KIEM TRA FILE CO TON TAI HAY KHONG?
//        echo "<pre>";var_dump($this->param);echo "</pre>"; exit;

        if (!file_exists(PATH_APPLICATION . "/frontend/controller/".$controller.".php")){
//          header("Location:".BASE_PATH."/p404");
        }

        require PATH_APPLICATION."/frontend/controller/".$controller.".php";
        // KIEM TRA XEM CLASS CO TON TAI HAY KHONG?
        $controllerObj = new $controller();
        if(!class_exists($controller)){
            header("Location:".BASE_PATH."/p404");
        }


        //Kiem tra xem method co ton tai hay ko?
        if(method_exists($controller,$this->action)){
          if(!empty($this->param)){
              call_user_func_array(array($controllerObj,$this->action), $this->param);
          }else{
              $controllerObj->{$this->action}();
          }
        }else{
            header("Location:".BASE_PATH."/p404");
        }


    }
    private function request_path()
    {
        $request_uri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
        $script_name = explode('/', trim($_SERVER['SCRIPT_NAME'], '/'));
        $parts = array_diff_assoc($request_uri, $script_name);
        if (empty($parts) && empty($parts[0])) {
            return '/';
        }
        $path = implode('/', $parts);
        if (($position = strpos($path, '?')) !== FALSE) {
            $path = substr($path, 0, $position);
        }
        return $path;
    }


    private function splitURL()
    {
        if (empty($this->request_path)) {
            $this->controller = null;
            $this->param = null;
        } else {
            $url = $this->request_path; // truyen $url la doan url cat dc
            $url = filter_var($url, FILTER_SANITIZE_URL); // kiem tra voi filter
            $url = explode("/", $url); // cat theo dau / de lay gia tri
            $this->controller = isset($url[0]) ? $url[0] : null; // dau tien se la Controllers xu ly
//            $this->action = isset($url[1]) ? $url[0] : null; // tiep theo la action
            unset($url[0]); // cat Controllers ra khoi mang

            $this->param = array_values($url);
        }

    }
}<file_sep>/resources/views/admin/_admin_template/footer.php
<!-- jQuery 2.2.3 -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<!--<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>-->
<!-- Bootstrap 3.3.6 -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!--datatable-->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>

<!-- Slimscroll -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/dist/js/app.min.js"></script>
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/iCheck/icheck.min.js"></script>
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/select2/select2.min.js"></script>
<!-- CK Editor -->
<script src="<?php echo BASE_PATH; ?>/public/vendor/adminlte/plugins/ckeditor/ckeditor.js"></script>

<!--<script src="--><?php //echo BASE_PATH ; ?><!--/public/vendor/adminlte/dist/js/pages/dashboard.js"></script>-->
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });
</script>
<script>

    $(function () {
        $('#data-search').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": true
        });
    });

</script>



</body>
</html>








<file_sep>/app/frontend/controller/index_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: Nimo
 * Date: 08/08/2016
 * Time: 8:23 CH
 */
include "controller.php";

class index_controller extends controller
{
    public function view()
    {
        $limit = 5;
        //load view nao
        $this->loadModel('index');
        // $this->model la 1 object cua cai model dc load



        // truyen du lieu vao view

        $this->loadView('index', array(
            'result' => [],
            'title' => "luong's Blog",
            'description' => " Một sản phẩm của Nghĩa nhé!",
            'current_page' => isset($_GET['page']) ? $_GET['page'] : 1,
            'total_page' => 20
        ));


    }

}<file_sep>/app/frontend/controller/controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/8/16
 * Time: 2:53 PM
 */
//use Validation;
class controller
{
    public $model;
    public $view;

    public function loadView($view,$param = array())
    {
        if (!file_exists(dirname(PATH_APPLICATION) . "/resources/views/" . $view . ".php")) {
            header("Location:".BASE_PATH."/p404");
        }

        extract($param);
        require dirname(PATH_APPLICATION) . "/resources/views/__template/header.php";
        require dirname(PATH_APPLICATION) . "/resources/views/" . $view . ".php";
        require dirname(PATH_APPLICATION) . "/resources/views/__template/footer.php";

    }
    public function loadAdminView($view,$param = array()){
        if (!file_exists(dirname(PATH_APPLICATION) . "/resources/views/admin/" . $view . ".php")) {
            header("Location:".BASE_PATH."/p404");
        }
        extract($param);
        require dirname(PATH_APPLICATION) . "/resources/views/admin/" . $view . ".php";
    }

    public function loadModel($model)
    {
        $model = strtolower($model) . "_model";
        if (!file_exists(PATH_APPLICATION . "/model/" . $model . ".php")) {
            header("Location:".BASE_PATH."/p404");
        }

        include PATH_APPLICATION."/model/".$model.".php";
        $this->model = new $model();
    }

    public function load404()
    {
        if (!file_exists(dirname(PATH_APPLICATION) . "/resources/views/404/404.php")) {
            header("Location:".BASE_PATH."/p404");
        }

        include dirname(PATH_APPLICATION) . "/resources/views/404/404.php";
    }
}<file_sep>/app/backend/controller/register_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/10/16
 * Time: 3:14 PM
 */


include dirname(PATH_APPLICATION) . "/libs/Helper.php";
include dirname(PATH_APPLICATION) . "/libs/Validation.php";


class register_controller extends base_controller
{
    function view()
    {

        $this->loadAdminView('register');
    }

    public function check()
    {

//        echo "<pre>";var_dump($_POST);echo "</pre>"; exit;

        if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['repassword']) && isset($_POST['email']) && $_POST['agree'] == 'on') {
//            echo "<pre>";var_dump(1);echo "</pre>"; exit;
            $username = $_POST['username'];
            $password = $_POST['password'];
            $repassword = $_POST['repassword'];

            $email = $_POST['email'];

            Helper::oldInputResgister($username, $password, $repassword, $email);

            $flag = 0; // dat co cho no mau


            if (!Validation::isValidUser($username)) {
                Helper::setError('username', "Sai dinh dang username");
                $flag = 1;
            }
            if (!Validation::isValidPass($password)) {
                Helper::setError('password', "Sai dinh dang password");
                $flag = 1;
            }
            if (!Validation::isValidPass($repassword)) {
                Helper::setError('repassword', "Sai dinh dang repassword");
                $flag = 1;
            }
            if (!filter_var($email, FILTER_SANITIZE_EMAIL)) {
                Helper::setError('email', "Email khong hop le");
                $flag = 1;
            }

            if ($password != $repassword) {
                Helper::setError('repassword', "Hai mat khau khong trung nhau");
                $flag = 1;
            }


            if ($flag == 0) {

                $this->loadModel('register_admin');

                if ($this->model->checkExist($username, $email)) {
                    Helper::setError('sys', 'Tài khoản hoặc Email đã tồn tại nhé con chó');
                    header("Location:" . BASE_PATH . "/admin/register");
                } else {
                    $result = $this->model->add($username, $password, $email);

                    if ($result) {
                        $_SESSION['admin'] = $username;
                        header("Location:" . BASE_PATH . "/admin ");
                    } else {
                        Helper::setError('sys', 'Co gi do sai sai');
                        header("Location:" . BASE_PATH . "/admin/register");
                    }
                }


            } else {
                header("Location:" . BASE_PATH . "/admin/register");
            }


        }
    }
}<file_sep>/app/model/model.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/8/16
 * Time: 2:53 PM
 */
abstract class model
{
    protected $conn;
    protected $stmt;

    function __construct()
    {
        try {
            $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
            $this->conn = new PDO(getenv('DB_TYPE'). ":host=" . getenv('DB_HOST') . ";dbname=" . getenv('DB_DBNAME') . ";charset=utf8", getenv('DB_USER'), getenv('DB_PASS'), $options);

        } catch (PDOException $e) {
            die($e->getMessage());
        }

    }

    public function getAll($table)
    {
        $sql = "SELECT  * FROM " . $table;
        try {
            $this->stmt = $this->conn->prepare($sql);
            $this->stmt->execute();
        } catch (PDOException $e) {
            die($e->getMessage());
        }
        return $this->stmt->fetchAll();
    }

    public function getById($table, $id)
    {
        $sql = "SELECT * FROM " . $table . " WHERE id = ?";
        try {
            $this->stmt = $this->conn->prepare($sql);
            $this->stmt->bindParam(1, $id, PDO::PARAM_INT);
            $this->stmt->execute();

        } catch (PDOException $e) {
            die($e->getMessage());
        }
        return $this->stmt->fetch();

    }

    public function deleteById($table, $id)
    {
        $sql = "DELETE FROM " . $table . " WHERE id = ?";
        try {
            $this->stmt = $this->conn->prepare($sql);
            $this->stmt->bindValue(1, $id, PDO::PARAM_INT);
            $this->stmt->execute();
        } catch (PDOException $e) {
            echo "<pre>";
            var_dump($e->getMessage());
            echo "</pre>";
            exit;
        }
        if ($this->getById($table, $id) !== false) {
            return false;
        } else {
            return true;
        }
    }

    public function getByName($table, $name, $column)
    {
        $sql = "SELECT * FROM " . $table . " WHERE " . $column . " = ?";
        try {
            $this->stmt = $this->conn->prepare($sql);
            $this->stmt->bindValue(1, $name);
            $this->stmt->execute();
        } catch (PDOException $e) {
            echo "<pre>";
            var_dump($e->getMessage());
            echo "</pre>";
            exit;
        }
        $result = $this->stmt->fetch(PDO::FETCH_ASSOC);
        return $result;
    }

}<file_sep>/libs/helper.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/9/16
 * Time: 10:17 AM
 */
class Helper
{
    static function setError($name, $value)
    {
        $_SESSION['error'][$name] = $value;
    }

    static function setInput($name, $value)
    {
        $_SESSION['input'][$name] = $value;
    }


    static function setMes($name, $val)
    {
        $_SESSION['mes'][$name] = $val;
    }

    static function oldInputLogin($username, $password)
    {
        self::setInput('old_username', $username);
        self::setInput('old_password', $password);
    }

    static function oldInputResgister($username, $password, $repassword, $email)
    {
        self::setInput('old_username', $username);
        self::setInput('old_password', $password);
        self::setInput('old_repassword', $repassword);
        self::setInput('old_email', $email);
    }

}<file_sep>/resources/views/index.php
<?php //echo "<pre>";var_dump($result);echo "</pre>"; exit; ?>
<!-- Page Header -->
<!-- Set your background image for this header on the line below. -->
<header class="intro-header" style="background-image: url('public/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="site-heading">
                    <h1><?php echo $title ?></h1>
                    <hr class="small">
                    <span class="subheading"><?php echo $description ?></span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Main Content -->
<div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
            <?php foreach ($result as $row) : ?>
                <div class="post-preview">
                    <a href="post/<?php echo $row['id'] ?>">
                        <h2 class="post-title">
                            <?php echo $row['title'] ?>
                        </h2>
                    </a>
                    <h4 class="post-subtitle" style="font-weight: 300">
                        <span><?php echo strip_tags(substr($row['content'], 0, 200)); ?>
                            <a href="post/<?php echo $row['id'] ?>"> <span class="see-more"><h3> See more</h3></span>
                            </a>
                            </span>
                    </h4>


                    <p class="post-meta">Posted by <a href="#"><?php echo $row['user_name'] ?></a> on September 24, 2014
                    </p>
                </div>
                <hr>

            <?php endforeach; ?>
            <!-- Pager -->
            <ul class="pager">
                <?php if ($current_page > $total_page) : ?>
                    <li class="back_to_home">
                        <a style="float: left" href="<?php echo BASE_PATH ?>"> Back to homepage </a>
                    </li>
                <?php endif; ?>
                <?php if ($current_page > 1 && $current_page <= $total_page) : ?>
                    <li class="prev">
                        <a style="float: left" href="?page=<?php echo($current_page - 1) ?>">&#x2190; Newer Posts </a>
                    </li>
                <?php endif; ?>
                <?php if ($current_page < $total_page) : ?>
                    <li class="next">
                        <a href="?page=<?php echo($current_page + 1) ?>">Older Posts →</a>
                    </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</div>

<hr>

<file_sep>/resources/views/admin/dashboard.php
<?php include '_admin_template/header.php' ?>
<?php //echo "<pre>"; var_dump($newestPosts); echo "</pre>"; exit; ?>


    <body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<!--//cho nay de header nhe-->
<?php include '_admin_template/menu.php'?>
    <!-- Left side column. contains the logo and sidebar -->
<?php include '_admin_template/sidebar.php'?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Dashboard
                <small>Control panel</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
            <div class="row">
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-aqua">
                        <div class="inner">
                            <h3><?php echo $totalPosts; ?></h3>

                            <p>Tổng số bài đăng</p>
                        </div>
                        <div class="icon">
                            <i class="ion ion-bag"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-green">
                        <div class="inner">
                            <h3>53<sup style="font-size: 20px">%</sup></h3>

                            <p>Bounce Rate</p>
                        </div>
                        <div class="icon">
                            <i class="ion ion-stats-bars"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-yellow">
                        <div class="inner">
                            <h3><?php echo $totalUsers; ?></h3>

                            <p>Tổng số thành viên</p>
                        </div>
                        <div class="icon">
                            <i class="ion ion-person-add"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-red">
                        <div class="inner">
                            <h3>65</h3>

                            <p>Unique Visitors</p>
                        </div>
                        <div class="icon">
                            <i class="ion ion-pie-graph"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
                <!-- ./col -->
            </div>
            <!-- /.row -->
            <!-- Main row -->
            <div class="row">
                <!-- Left col -->
                <section class="col-sm-12 ">

                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">Responsive Hover Table</h3>

                            <div class="box-tools">
                                <form action="<?php echo BASE_PATH ; ?>/admin/search" method="get">
                                    <div class="input-group input-group-sm" style="width: 150px;">
                                        <input type="text" name="s" class="form-control pull-right"
                                               placeholder="Search">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <tbody>
                                <tr>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Date</th>
                                    <th>Category</th>
                                    <th>Author</th>
                                </tr>
                                <?php foreach ($newestPosts as $row) : ?>
                                    <tr>
                                        <td><?php echo $row['id']; ?></td>
                                        <td>
                                            <a href="<?php echo BASE_PATH; ?>/admin/post/edit/<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a>
                                        </td>
                                        <td><?php echo $row['created_time']; ?></td>
                                        <td>
                                            <a href="<?php echo BASE_PATH; ?>admin/category/edit/<?php echo $row['category_ID']; ?>">
                                                <span class="label label-success"><?php echo $row['category_name']; ?></span></a>
                                        </td>
                                        <td><?php echo $row['user_name']; ?></td>
                                    </tr>
                                <?php endforeach; ?>

                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->


                </section>
                <!-- /.Left col -->
                <!-- right col (We are only adding the ID to make the widgets sortable)-->
                <section class="col-sm-6">

                    <!-- quick email widget -->
                    <div class="box box-info">
                        <div class="box-header">
                            <i class="fa fa-envelope"></i>

                            <h3 class="box-title">Quick Email</h3>
                            <!-- tools box -->
                            <div class="pull-right box-tools">
                                <button type="button" class="btn btn-info btn-sm" data-widget="remove"
                                        data-toggle="tooltip" title="Remove">
                                    <i class="fa fa-times"></i></button>
                            </div>
                            <!-- /. tools -->
                        </div>
                        <div class="box-body">
                            <form action="#" method="post">
                                <div class="form-group">
                                    <input type="email" class="form-control" name="emailto" placeholder="Email to:">
                                </div>
                                <div class="form-group">
                                    <input type="text" class="form-control" name="subject" placeholder="Subject">
                                </div>
                                <div>
                                    <textarea class="textarea" placeholder="Message"
                                              style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                                </div>
                            </form>
                        </div>
                        <div class="box-footer clearfix">
                            <button type="button" class="pull-right btn btn-default" id="sendEmail">Send
                                <i class="fa fa-arrow-circle-right"></i></button>
                        </div>
                    </div>

                </section>
                <!-- right col -->
            </div>
            <!-- /.row (main row) -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.3.6
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="http://almsaeedstudio.com">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

</div>
<!-- ./wrapper -->
<?php include '_admin_template/footer.php' ?>





<file_sep>/app/backend/controller/post_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: Nimo
 * Date: 10/08/2016
 * Time: 9:41 CH
 */


include dirname(PATH_APPLICATION) . "/libs/Helper.php";


class post_controller extends base_controller
{
    function create()
    {
        if (isset($_SESSION['admin']) && isset($_SESSION['admin_id'])) {
            if (isset($_POST['title']) && isset($_POST['content']) && isset($_POST['category']) && isset($_POST['status'])) {
                $title = $_POST['title'];
                $content = $_POST['content'];
                $category = $_POST['category'];
                $status = $_POST['status'];
                $status = filter_var($status, FILTER_SANITIZE_NUMBER_INT);
                $category = filter_var($category, FILTER_SANITIZE_NUMBER_INT);

//            var_dump(empty($status));

                if (empty($title) || empty($content) || empty($status) || empty($category)) {
                    Helper::setError('edit', "Something wrong");
                } else {
                    $this->loadModel('post_admin');
                    $result = $this->model->insertPost($title, $content, $category, $status);
                    if ($result != false) {
                        header('location:' . BASE_PATH . '/admin/post/edit/' . $result);

                    } else {
                        Helper::setError('insert', "Không thể thêm bài viết");
                    }


                }


            } else {
                $this->loadModel('post_admin');

                $this->loadAdminView('create', array(
                    'listCategories' => $this->model->getListCategories()
                ));
            }
        } else {
            header('location:' . BASE_PATH . '/admin/login ');
        }
    }

    function edit($id)
    {
        if (isset($_SESSION['admin']) && isset($_SESSION['admin_id'])) {
            if (isset($_POST['title']) && isset($_POST['content']) && isset($_POST['category']) && isset($_POST['status'])) {
                $title = $_POST['title'];
                $content = $_POST['content'];
                $category = $_POST['category'];
                $status = $_POST['status'];
                $status = filter_var($status, FILTER_SANITIZE_NUMBER_INT);
                $category = filter_var($category, FILTER_SANITIZE_NUMBER_INT);


                if (empty($title) || empty($content) || empty($status) || empty($category)) {
                    Helper::setError('edit', "Something wrong");
                } else {
                    $this->loadModel('post_admin');

                    $result = $this->model->updatePost($id, $title, $content, $category, $status);

                    if ($result != false) {
                        Helper::setMes('success', "Update thành công rồi nhé cứng!");
                        header('location:' . BASE_PATH . '/admin/post/edit/' . $id);
                    } else {
                        Helper::setError('edit', "Không thể cập nhật bài viết");
                    }
                }


            } else {
                $this->loadModel('post_admin');

                $this->model->getPostById($id);

                $this->loadAdminView('edit', array(
                    'listCategories' => $this->model->getListCategories(),
                    'oldData' => $this->model->getPostById($id)
                ));

//        $this->loadModel()
            }
        } else {
            header('location:' . BASE_PATH . '/admin/login ');
        }

    }

    function view()
    {
//        echo "<pre>";var_dump("DCm sao the");echo "</pre>"; exit;
        if (isset($_SESSION['admin']) && isset($_SESSION['admin_id'])) {

            $this->loadModel('post_admin');
            $this->loadAdminView('list_posts', array(
                'data' => $this->model->getAllPost(),
            ));

//        $this->loadModel()

        } else {
            header('location:' . BASE_PATH . '/admin/login ');
        }
    }

    // xu ly load anh
//    public function ckeditor($a = 0){
//        include dirname(PATH_APPLICATION).'/public/vendor/AdminLTE/plugins/ckeditor/plugins/imageuploader/imgbrowser.php';
//    }
}<file_sep>/app/model/index_model.php
<?php

/**
 * Created by PhpStorm.
 * User: Nimo
 * Date: 08/08/2016
 * Time: 10:05 CH
 */

include 'model.php';

class index_model extends model
{
    public $table = "posts";

    public function getAll($table = null)
    {
        return parent::getAll($this->table); // TODO: Change the autogenerated stub
    }

    public function getTotalPost()
    {
        $sql = "SELECT count(*) as total_post FROM " . $this->table;
        $this->stmt = $this->conn->prepare($sql);
        $this->stmt->execute();
        return $this->stmt->fetch();
//        return $this->conn->

    }

    public function getData($limit = 5, $page = 1)
    {
        $sql = "SELECT p.*, u.user_name FROM posts p INNER JOIN users u ON p.user_ID = u.id  ORDER BY p.created_time DESC";
        if ($limit !== 'all') {
            $sql .= " LIMIT " . (($page - 1) * $limit) . "," . $limit;
        }

//        echo "<pre>";var_dump($sql);echo "</pre>"; exit;
        $this->stmt = $this->conn->prepare($sql);

        $this->stmt->execute();

        return $this->stmt->fetchAll();
    }
}<file_sep>/libs/config.php
<?php


class config{

    /**
     * con constructor.
     */


    public function __construct()
    {
    }
}<file_sep>/app/backend/controller/login_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/10/16
 * Time: 10:49 AM
 */

//include dirname(PATH_APPLICATION) . "/libs/Validation.php";
//include dirname(PATH_APPLICATION) . "/libs/Helper.php";

class login_controller extends base_controller
{
    public function view()
    {


        if (isset($_SESSION['admin'])) { // kiem tra xem session hay khong?
            header("Location:" . BASE_PATH . "/admin");
        } else {
            $this->loadAdminView('login');
        }
    }


    public function check()
    {
        if (isset($_POST['username']) && isset($_POST['password'])) {


            $username = $_POST['username'];
            $password = $_POST['password'];
            Helper::oldInputLogin($username, $password);
            $flag = 0;

            if (!Validation::isValidUser($username)) {
                Helper::setError('username', " Chỉ nhận 5->17 kí tự thôi");
                $flag = 1;
            }
            if (!Validation::isValidPass($password)) {
                Helper::setError('password', '<PASSWORD>');
                $flag = 1;
            }

            if ($flag != 0) {

                header("Location:" . BASE_PATH . "/admin/login");
            } else {
                $this->loadModel('login_admin');
//                echo "<pre>"; var_dump($this->model->checkLogin($username,$password)); echo "</pre>"; exit;
                if ($this->model->checkLogin($username, $password)) {
//                    Helper::setMes('success', "Đăng nhập thành công");
                    $_SESSION['admin'] = $username;
                    $_SESSION['admin_id'] = $this->model->getIdByName($username)['id'];
                    unset($_SESSION['input']);
//                    unset($_SESSION['admin_id']);
                    header("Location:" . BASE_PATH . "/admin ");
                } else {
                    Helper::setError('system', "Tài khoản mật khẩu không  đúng ");
                    header("Location:" . BASE_PATH . "/admin/login");
                }

            }


        } else {

            header("Location:" . BASE_PATH . "/admin/login");
        }
    }

    public function logout()
    {
        unset($_SESSION['admin']);
        unset($_SESSION['admin_id']);
        header('Location:' . BASE_PATH . '/admin/login');
    }

}<file_sep>/app/frontend/controller/about_controller.php
<?php
/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 11/24/16
 * Time: 12:05
 */
include 'controller.php';

class about_controller extends controller
{
    function view()
    {
        $this->loadView('about-coroi');
    }
}<file_sep>/resources/views/admin/edit.php
<?php include '_admin_template/header.php' ?>
<?php //echo "<pre>"; var_dump($newestPosts); echo "</pre>"; exit; ?>


<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--//cho nay de header nhe-->
    <?php include '_admin_template/menu.php' ?>
    <!-- Left side column. contains the logo and sidebar -->
    <?php include '_admin_template/sidebar.php' ?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Dashboard
                <small>Control panel</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="box box-info">
                <div class="box-body">
                    <form method="post" action="">
                        <div class="row" style="margin-bottom: 10px;">
                            <div class="col-sm-12">
                                <div class="toolbar">
                                    <?php if (isset($_SESSION['error'])) : ?>

                                        <div class="alert alert-danger alert-dismissible">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
                                                ×
                                            </button>
                                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                            <ul>
                                                <?php foreach ($_SESSION['error'] as $row): ?>
                                                    <li> <?php echo $row; ?></li>
                                                <?php endforeach; ?>

                                            </ul>
                                        </div>

                                    <?php endif; ?>


                                    <?php if (isset($_SESSION['mes'])) : ?>

                                        <div class="alert alert-success alert-dismissible">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
                                                ×
                                            </button>
                                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                                            <ul>
                                                <?php foreach ($_SESSION['mes'] as $row): ?>
                                                    <li> <?php echo $row; ?></li>
                                                <?php endforeach; ?>

                                            </ul>
                                        </div>

                                    <?php endif; ?>


                                    <a href="<?php echo BASE_PATH; ?>/admin/posts">
                                        <button type="button" class="btn btn-default">
                                            <i class="fa fa-angle-left"></i> Back
                                        </button>
                                    </a>
                                    <a href="#" class="pull-right">
                                        <button type="submit" class="btn btn-success">
                                            <i class="fa fa-check"></i> Chỉnh sửa hàng
                                        </button>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9 col-sm-9">
                                <div class="form-group">
                                    <label for="title">Tiêu đề <span class="required">*</span></label>
                                    <input type="text" class="form-control" required name="title" id="title"
                                           value="<?php echo $oldData['title']; ?>"
                                           autocomplete="off">
                                </div>

                                <div class="form-group">
                                    <label for="full_text">Nội dung*</label>
                                    <textarea id="editor1" class="form-control" required
                                              name="content"><?php echo $oldData['content']; ?></textarea>
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-3">
                                <div class="form-group">
                                    <label for="published">Trạng thái*</label>
                                    <select id="published" class="form-control" required name="status">
                                        <option value="1" <?php if ($oldData['status'] == 1) echo "selected" ?> >
                                            Bản nháp
                                        </option>
                                        <option value="2" <?php if ($oldData['status'] == 2) echo "selected" ?> >
                                            Hay là thật luôn đi
                                        </option>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label for="category">Danh mục*</label>
<?php //echo "<pre>";var_dump($listCategories);echo "</pre>"; exit; ?>
                                    <div id="category">
                                        <select class=" form-control" name="category" required>
                                            <option selected value="">Chọn một chủ đề</option>
                                            <?php foreach ($listCategories as $row) : ?>

                                                <option
                                                    value="<?php echo $row['id']; ?>" <?php if ($oldData['cate_id'] == $row['id']) echo "selected" ?> ><?php echo $row['category_name']; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <!-- ./row -->
        </section>
        <!-- /.content -->


    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.3.6
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="http://almsaeedstudio.com">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

</div>



<!-- ./wrapper -->
<?php unset($_SESSION['error'], $_SESSION['mes']) ?>
<?php include '_admin_template/footer.php' ?>
<script>
    var roxyFileman = '<?php echo BASE_PATH?>/public/fileman/index.html';
    $(function () {
        CKEDITOR.replace('editor1', {
            filebrowserBrowseUrl: roxyFileman,
            filebrowserImageBrowseUrl: roxyFileman + '?type=image',
            removeDialogTabs: 'link:upload;image:upload'
        });
    });
</script><file_sep>/resources/views/admin/search.php
<?php include '_admin_template/header.php'; ?>
<body class="hold-transition skin-blue sidebar-mini">
<!-- Automatic element centering -->

<?php include '_admin_template/menu.php'?>
<?php include '_admin_template/sidebar.php'?>

<div class="wrapper">
    <div class="content-wrapper">

        <section class="content-header">
            <h1>
                Users
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <section class="content">
            <div class="lockscreen-wrapper" style="margin-top: 0">
                <div class="lockscreen-logo">
                    <a href="../../index2.html"><b>Nghĩa's</b>Blog</a>
                </div>
                <!-- User name -->
                <div class="lockscreen-name"><NAME></div>

                <!-- START LOCK SCREEN ITEM -->
                <div class="lockscreen-item">
                    <!--         lockscreen image-->
                    <div class="lockscreen-image" style="top: -18px;">
                        <img src="<?php echo BASE_PATH ; ?>/public/vendor/AdminLTE/dist/img/user1-128x128.jpg" alt="User Image">
                    </div>
                    <!--         /.lockscreen-image -->

                    <!-- lockscreen credentials (contains the form) -->
                    <form class="lockscreen-credentials" action="<?php echo BASE_PATH ; ?>/admin/search">
                        <div class="input-group">
                            <input type="text" class="form-control input-lg" placeholder="Keyword" name="s">

                            <div class="input-group-btn">
                                <button type="submit" class="btn"><i class="fa fa-search text-muted"></i></button>
                            </div>
                        </div>
                    </form>
                    <!-- /.lockscreen credentials -->

                </div>




            </div>
            <div class="container">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <h3 class="box-title">Data Table With Full Features</h3>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body">
                                <table id="data-search" class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>Tít tờ le</th>
                                        <th>Ca te go ri </th>
                                        <th>Au tho</th>
                                        <th>x</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    <?php foreach($data as $row) : ?>
                                        <tr>
                                            <td><?php echo $row['id'] ; ?></td>
                                            <td><a href="<?php echo BASE_PATH ; ?>/admin/post/edit/<?php echo $row['id'] ; ?>"><?php echo $row['title'] ; ?></a>
                                            </td>
                                            <td><span class="label label-success"><?php echo $row['category_name']; ?></span></td>

                                            <td> <?php echo $row['author'] ; ?></td>
                                            <td>X</td>
                                        </tr>
                                    <?php endforeach; ?>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th>id</th>
                                        <th>Tít tờ le</th>
                                        <th>Ca te go ri </th>
                                        <th>Au tho</th>
                                        <th>x</th>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                            <!-- /.box-body -->
                        </div>


                    </div>
                </div>
            </div>
        </section>
    </div>
</div>

</body>



<!-- /.center -->

<?php include '_admin_template/footer.php'?>
<file_sep>/app/backend/controller/dashboard_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/10/16
 * Time: 10:08 AM
 */
class dashboard_controller extends base_controller
{
    function view(){
       if(isset($_SESSION['admin'])){
            $this->loadModel('dashboard_admin');
            $this->loadAdminView('dashboard',array(
                'totalPosts' => $this->model->getTotalPosts(),
                'totalUsers' => $this->model->getTotalUsers(),
                'newestPosts' => $this->model->getNewestPosts(),
            ));
//           unset($_SESSION['admin']);
       }else{
           header("Location:".BASE_PATH."/admin/login");
       }
    }
}<file_sep>/app/frontend/controller/p404_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/9/16
 * Time: 10:20 AM
 */
class p404_controller extends base_controller
{
    public function view(){
        $this->load404();
    }
}<file_sep>/resources/views/admin/list_users.php
<?php include '_admin_template/header.php' ?>
<?php //echo "<pre>"; var_dump($newestPosts); echo "</pre>"; exit; ?>


<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--//cho nay de header nhe-->
    <?php include '_admin_template/menu.php'?>
    <!-- Left side column. contains the logo and sidebar -->
    <?php include '_admin_template/sidebar.php'?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Users
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <!-- Main row -->
            <div class="row">
                <!-- Left col -->
                <section class="col-sm-12 ">


                    <?php if(isset($_SESSION['mes']['delete'])) : ?>
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-check"></i> Alert!</h4>
                           <?php echo $_SESSION['mes']['delete'] ; ?>
                        </div>
                    <?php endif; ?>


                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">Danh sách người dùng</h3>

                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" class="form-control pull-right"
                                           placeholder="Search">

                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <tbody>
                                <tr>
                                    <th>ID</th>
                                    <th>Tên Người dùng</th>
                                    <th>Email</th>
                                    <th>Ngày tham gia</th>
                                    <th>Cập nhật</th>
                                    <th>Xóa</th>
                                </tr>
<!--                               --><?php //var_dump($data) ?>
                                <?php foreach ($data as $row) : ?>
<!--                                    --><?php //echo "<pre>";var_dump($row);echo "</pre>"; exit; ?>
                                    <tr>
                                        <td><?php echo $row['id'] ; ?></td>
                                        <td><a href="<?php echo BASE_PATH ; ?>/admin/user/edit/<?php echo $row['id'] ; ?>"><?php echo $row['user_name'] ; ?></a></td>
                                        <td><?php echo $row['user_email'] ; ?></td>
                                        <td><?php echo $row['created_time'] ; ?></td>
                                        <td><a href="<?php echo BASE_PATH ; ?>/admin/user/edit/<?php echo $row['id'] ; ?>"><button class="btn btn-primary">Sửa</button></a> </td>
                                        <td><a href="<?php echo BASE_PATH ; ?>/admin/user/delete/<?php echo $row['id'] ; ?>"><button class="btn btn-danger">Xóa</button></a> </td>

                                    </tr>
                                <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->


                </section>
                <!-- /.Left col -->
            </div>
            <!-- /.row (main row) -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.3.6
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="http://almsaeedstudio.com">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

</div>
<!-- ./wrapper -->

<?php unset($_SESSION['mes']); ?>
<?php include '_admin_template/footer.php' ?>





<file_sep>/resources/views/admin/list_posts.php
<?php include '_admin_template/header.php' ?>
<?php //echo "<pre>"; var_dump($newestPosts); echo "</pre>"; exit; ?>


<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--//cho nay de header nhe-->
    <?php include '_admin_template/menu.php'?>
    <!-- Left side column. contains the logo and sidebar -->
    <?php include '_admin_template/sidebar.php'?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Dashboard
                <small>Control panel</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <!-- Main row -->
            <div class="row">
                <!-- Left col -->
                <section class="col-sm-12 ">

                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">Responsive Hover Table</h3>

                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" class="form-control pull-right"
                                           placeholder="Search">

                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <tbody>
                                <tr>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Date</th>
                                    <th>Category</th>
                                    <th>Author</th>
                                </tr>
                                <?php foreach ($data as $row) : ?>
                                    <tr>
                                        <td><?php echo $row['id']; ?></td>
                                        <td>
                                            <a href="<?php echo BASE_PATH; ?>/admin/post/edit/<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a>
                                        </td>
                                        <td><?php echo $row['created_time']; ?></td>
                                        <td>
                                            <a href="<?php echo BASE_PATH; ?>admin/category/edit/<?php echo $row['category_ID']; ?>">
                                                <span class="label label-success"><?php echo $row['category_name']; ?></span></a>
                                        </td>
                                        <td><?php echo $row['user_name']; ?></td>
                                    </tr>
                                <?php endforeach; ?>

                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->


                </section>
                <!-- /.Left col -->
            </div>
            <!-- /.row (main row) -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.3.6
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="http://almsaeedstudio.com">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

</div>
<!-- ./wrapper -->
<?php include '_admin_template/footer.php' ?>





<file_sep>/app/backend/controller/user_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/17/16
 * Time: 9:17 AM
 */
class user_controller extends base_controller
{   //De hien thi ra danh sach nguoi dung
    function view()
    {

        if (isset($_SESSION['admin'])) {

            //goi cai model day ra (user_admin_model)
            $this->loadModel('user_admin');

            $data = $this->model->getAllUser();

//            echo "<pre>";var_dump($data);echo "</pre>"; exit;


            $this->loadAdminView('list_users', array(
                'data' => $data
            ));// load view de xem co load dc view hay khong?


        }
    }

    function create()
    {

    }

    function edit($id) // load du lieu cua nguoi dung + form de chinh sua
    {
        if (isset($_SESSION['admin'])) {

            $this->loadModel('user_admin');

            $result = $this->model->getUserById($id);

//            echo "<pre>";var_dump($result);echo "</pre>"; exit;

            $this->loadAdminView('edit_user', array(
                'data' => $result
            ));
        } else {
            header('location:' . BASE_PATH . '/admin/login');
        }
    }


    function update($id)
    { // chinh sua thong tin cua nguoi dung vao database


        if (isset($_SESSION['admin'])) {

            if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//                echo "<pre>";var_dump($_POST);echo "</pre>"; exit;

                if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['password']) && isset($_POST['repassword'])) {
                    // dieu kien dung o day
                    $flag = 1; // Co` dung la 1 con khac 1 la sai

                    // Kiem tra dau vao cua username
                    if (Validation::isValidUser($_POST['username'])) {
                        $username = $_POST['username'];
                    } else {
                        $flag = 0;
                        Helper::setError('username', "Username deo dung chuan");
                    }

                    //Kiem tra dau vao cua email

                    if (filter_var($_POST['email'], FILTER_SANITIZE_EMAIL)) {
                        $email = $_POST['email'];
                    } else {
                        $flag = 0;
                        Helper::setError('email', "Email nhu cec");
                    }

                    // Kiem tra password

                    if (Validation::isValidPass($_POST['password'])) {
                        $password = $_POST['password'];
                    } else {
                        $flag = 0;
                        Helper::setError('password', '<PASSWORD>');
                    }

                    //Kiem tra repassword

                    if (Validation::isValidPass($_POST['repassword'])) {
                        $repassword = $_POST['repassword'];
                    } else {
                        $flag = 0;
                        Helper::setError('repassword', 'Repassword danh ngu nhu cho');
                    }

                    if ($_POST['password'] !== $_POST['repassword']) {
                        $flag = 0;
                        Helper::setError('repassword', "Khong biet danh mat khau giong nhau a");
                    }


                    if ($flag != 1) {
                        header('location:' . BASE_PATH . '/admin/user/edit/' . $id . '');
                    } else {
                        $this->loadModel('user_admin');

                        $data = $this->model->getUserById($id);

                        $check = 1;

                        // Kiem tra username ton tai
                        if ($username !== $data['user_name']) {
                            if ($this->model->checkUserExist($username)) {
                                $check = 0; // neu co thang nao day co username giong roi thi chuyen co
                                Helper::setError('username', "Trung roi username nhe!");
                            }
                        }
                        // Kiem tra email ton tai hay khong?
                        if ($email !== $data['user_email']) {
                            if ($this->model->checkEmailExist($email)) {
                                $check = 0;
                                Helper::setError('email', "Trung roi email nhe!");
                            }
                        }

                        if ($check != 1) {
                            header("location:" . BASE_PATH . "/admin/user/edit/" . $id);
                        } else {

                            $password = password_hash($password,PASSWORD_BCRYPT);

                            $result = $this->model->updateUser($username, $password, $email, $id);
                            if ($result) {
                                Helper::setMes('update', "Thanh cong gan la thanh roi nhe");
                            } else {
                                Helper::setError('update', "XIt roi, deo hieu vi sao");
                            }
                            header('location:' . BASE_PATH . '/admin/user/edit/' . $id);
                        }


//
                    }


                } else {
                    // dieu kien sai o day
                    die("Thieu input roi anh");
                }


            } else {
                die('Wrong request method');
            }

        } else {
            header("Location:" . BASE_PATH . "/admin/login");
        }
    }


    function delete($id) // xoa nguoi dung
    {
        if (isset($_SESSION['admin'])) {

            $this->loadModel('user_admin');
            $result = $this->model->deleteUserById($id);

            if ($result) {
//                echo "<pre>";var_dump("Xoa duoc roi nhe");echo "</pre>"; exit;

                Helper::setMes('delete', "Em đã xóa thành công thằng có ID là " . $id . " ");

                header('location:' . BASE_PATH . '/admin/user');

            } else {
                echo "<pre>";
                var_dump("Xoa xit roi nhe");
                echo "</pre>";
                exit;
            }


        } else {
            header('location:' . BASE_PATH . '/admin/login'); // Neu khong phai la admin thi day ra trang dang ki
        }
    }
}<file_sep>/app/backend/controller/search_controller.php
<?php

/**
 * Created by PhpStorm.
 * User: nghia
 * Date: 8/13/16
 * Time: 9:34 AM
 */
class search_controller extends base_controller
{
    function view()
    {
        if (!isset($_SESSION['admin'])) {
            header("location:" . BASE_PATH . "/admin/login");
        } else {

            if (!isset($_GET['s'])) {
                $this->loadAdminView('search');
            } else {
                $key = $_GET['s'];

                $this->loadModel('search_admin');

                $result = $this->model->getDataByKey($key);

                $this->loadAdminView('search',array(
                    'data' => $result
                ));


            }


        }


    }

}<file_sep>/resources/views/detail-post.php
<?php //echo "<pre>";var_dump($post);echo "</pre>"; exit; ?>

    <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <header class="intro-header" style="background-image: url('<?php echo BASE_PATH ?>/public/img/post-bg.jpg')">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <div class="post-heading">
                        <h1><?php echo $post['title'] ?></h1>
                        <h2 class="subheading"><?php echo substr($post['content'],0,50)?></h2>
                        <span class="meta">Đăng bởi <a href="#"><?php echo $post['user_name'] ?></a> vào hồi <?php echo $post['created_time']?> trong <?php echo $post['category_name'] ?></span>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Post Content -->
    <article>
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <?php echo $post['content'] ; ?>
                </div>
            </div>
        </div>
    </article>

    <hr>

<file_sep>/index.php
<?php


session_start();
//echo "<pre>";var_dump($_SESSION);echo "</pre>";
/*
 * Created by PhpStorm.
 * User: Nimo
 * Date: 07/08/2016
 * Time: 8:01 CH
 */

require __DIR__ . '/vendor/autoload.php';

require "config.php";




//$admin_pattern = "/(\/admin).*$/";

/*
 *  Cai dm tai thang  xammp no build nhu the nen phai chiu nhe.
 *  con de chay binh thuong thi no phai la
 *  $admin_pattern = "/^(\/admin).*$/";
 *  nhe
 */

//echo "<pre>";var_dump(Validation::isValidUser("ahihihihih"));echo "</pre>"; exit;
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv->load();


$app = new Libs\Application();

//if (preg_match($admin_pattern, $_SERVER['REQUEST_URI'])) {
//    $app = new application_admin();
//} else {
//
//    $app = new application();
//
//
//}

//
//
<file_sep>/resources/views/404/404.php
<!--
Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>404 NOT FOUND</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="<?php echo BASE_PATH ?>/public/vendor/404/css/style.css">
</head>
<body>
<div class="wrap">
	<h1>Nghia's Blog</h1>
	<div class="banner">
		<img src="<?php echo BASE_PATH ?>/public/vendor/404/images/banner.png" alt="" />
	</div>
	<div class="page">
		<h2>Không tìm thấy trang thì phải làm sao</h2>
	</div>
	<div class="footer">
		<p>Design by <a href="<?php echo BASE_PATH; ?>">Nghia's Blog</a></p>
	</div>
</div>
</body>
</html>

<file_sep>/resources/views/about.php
<!-- Page Header -->
<!-- Set your background image for this header on the line below. -->
<header class="intro-header" style="background-image: url('<?php echo BASE_PATH ?>/public/img/about-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="page-heading">
                    <h1>Giới thiệu về anh Nghĩa á!</h1>
                    <hr class="small">
                    <span class="subheading">Ngay dưới nhé.</span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Main Content -->
<div class="container">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
            <p>Nghĩa trang liệt sỹ Trường Sơn tọa lạc trên khu đồi Bến Tắt, cạnh đường quốc lộ 15, thuộc địa phận xã
                Vĩnh Trường, huyện Gio Linh; cách trung tâm tỉnh lỵ (thị xã Đông Hà) khoảng 38km về phía Tây bắc; cách
                quốc lộ 1A (ở đoạn thị trấn huyện lỵ Gio Linh) chừng hơn 20km về phía Tây bắc.
            </p>
            <p>Sau ngày đất nước thống nhất, Trung ương Đảng và Bộ Quốc phòng đã phê chuẩn dự án xây dựng nghĩa trang
                liệt sỹ Trường Sơn tại địa bàn tỉnh Quảng Trị làm nơi tưởng niệm, tôn vinh những người con thân yêu của
                tổ quốc đã anh dũng hy sinh xương máu của mình trên các nẻo đường Trường Sơn vì sự nghiệp giải phóng dân
                tộc. Nghĩa trang được khởi công xây dựng vào ngày 24/10/1975 và hoàn thành vào ngày 10/4/1977. Chỉ huy
                xây dựng là Bộ tư lệnh sư đoàn 559 với sự tham gia của hơn 40 đơn vị bộ đội chủ lực và bộ đội địa
                phương.
            </p>
            <p> Ngoài ra còn có tổ công nhân chuyên khắc chữ vào bia đá xã Hoà Hải, huyện Hòa Vang, tỉnh Quảng Nam.</p>
        </div>
    </div>
</div>

<hr>

