Skip to content

Commit 14c2f28

Browse files
committed
Add comment to code, chmod to 775 for all code.
1 parent 539ddfe commit 14c2f28

40 files changed

+725
-155
lines changed

.htaccess

100644100755
File mode changed.

README.md

100644100755
File mode changed.

admin-template.php

100644100755
File mode changed.

admin.php

100644100755
File mode changed.

admin_category.php

100644100755
+31-7
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,69 @@
11
<?php
2+
//Gọi cấu hình, thư viện được sử dụng
23
include 'libs/config.php';
34
include 'libs/functions.php';
45

6+
//Khai báo các class sử dụng
57
use libs\classes\DBAccess;
68
use libs\classes\FlashMessage;
79
use libs\classes\DBPagination;
810
use libs\classes\HttpException;
911

12+
//Tạo các đối tượng cần dùng
1013
$oFlashMessage = new FlashMessage();
1114
$oDBAccess = new DBAccess();
1215

16+
//Khai báo tiêu đề và module cho page
1317
$pageAliasName = 'category';
1418
$pageTitle = 'Quản lý Danh mục';
1519

20+
//Kiểm tra xem biến keyword có trên đường link hay không
1621
$keyword = '';
1722
if(isset($_GET['keyword'])) {
1823
$keyword = $_GET['keyword'];
1924
}
20-
25+
//Tạo ra câu điều kiện theo keyword
2126
$where = '';
2227
if(!empty($keyword)) {
2328
$where = "WHERE title LIKE '%$keyword%' OR slug LIKE '%$keyword%'";
2429
}
2530

26-
//Delete record
31+
//Thực hiện xử lý xóa bản ghi
2732
if(isset($_GET['action']) && isset($_GET['id']) && $_GET['action']=='delete'){
2833
try {
29-
$oDBAccess->deleteById('category', $_GET['id']);
30-
$oFlashMessage->setFlashMessage('success', 'Đã xóa bản ghi có id là '.$_GET['id']);
34+
$id = $_GET['id'];
35+
$oDBAccess->deleteById('category', $id);
36+
$oFlashMessage->setFlashMessage('success', 'Đã xóa bản ghi có id là '.$id);
37+
} catch (HttpException $e) {
38+
$oFlashMessage->setFlashMessage('error', "Không thể xóa bản ghi có id $id được.");
39+
}
40+
41+
header("Location: admin_$pageAliasName.php");
42+
exit;
43+
}
44+
45+
//Thực hiện thay đổi trạng thái bản ghi
46+
if(isset($_GET['action']) && isset($_GET['id']) && $_GET['action']=='active'){
47+
try {
48+
$id = $_GET['id'];
49+
$record = $oDBAccess->findOneById('category', $id);
50+
$attributes['id'] = $id;
51+
$attributes['is_active'] = ($record->is_active == 0)?1:0;
52+
$record = $oDBAccess->save('category', $attributes, 'id');
53+
$oFlashMessage->setFlashMessage('success', 'Cập nhật bản ghi có id là '.$id);
3154
} catch (HttpException $e) {
32-
$oFlashMessage->setFlashMessage('error', "Không thể xóa bản ghi có id {$_GET['id']} được.");
55+
$oFlashMessage->setFlashMessage('error', "Không thể cập nhật bản ghi có id $id được.");
3356
}
3457

3558
header("Location: admin_$pageAliasName.php");
3659
exit;
3760
}
3861

39-
//Get total record for pagination
62+
//Lấy ra tổng số bản ghi
4063
$totalRecord = intval($oDBAccess->scalarBySQL("SELECT COUNT(*) FROM category ".$where));
64+
//Tạo ra đối tượng phân trang
4165
$oDBPagination = new DBPagination($totalRecord, 10);
42-
//Get list
66+
//Lấy ra danh sách các bản ghi
4367
$list = $oDBAccess->findAllBySql("SELECT * FROM category $where ORDER BY created_at DESC {$oDBPagination->getLimit()}");
4468
?>
4569

admin_category_form.php

100644100755
+31-10
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
<?php
2+
//Gọi cấu hình, thư viện được sử dụng
23
include 'libs/config.php';
34
include 'libs/functions.php';
45

6+
//Khai báo các class sử dụng
57
use libs\classes\DBAccess;
68
use libs\classes\FlashMessage;
79
use libs\classes\DBPagination;
810
use libs\classes\HttpException;
911
use libs\classes\Validator;
1012

13+
//Tạo các đối tượng cần dùng
1114
$oFlashMessage = new FlashMessage();
1215
$oDBAccess = new DBAccess();
1316

17+
//Khai báo tiêu đề và module cho page
1418
$pageAliasName = 'category';
1519
$pageTitle = 'Quản lý Danh mục';
1620

1721
$isAddNew = true;
1822
$id = 0;
1923

24+
//Khởi tạo đối tượng đầu tiên cho form, các trường của đối tượng là các trường của form
2025
$record = new stdClass();
2126
$record->title = '';
2227
$record->slug = '';
2328
$record->is_active = 1;
2429

30+
//Kiểm tra xem id có tồn tại trên URL hay không, nếu tồn tại có nghĩa là form đang
31+
//ở trạng thái cập nhật. Còn không thì là trạng thái thêm mới
2532
if(isset($_GET['id'])) {
2633
$isAddNew = false;
2734
$id = $_GET['id'];
2835
$record = $oDBAccess->findOneById('category', $id);
2936
}
3037

38+
//Khai báo mảng danh sách kiểm tra
3139
$validates = array(
3240
array('type'=>'required', 'field'=>'title', 'message'=>'Cần nhập Tiêu đề'),
3341
array('type'=>'required', 'field'=>'slug', 'message'=>'Cần nhập Slug'),
@@ -37,30 +45,41 @@
3745
);
3846
$oValidator = new Validator($validates, $oDBAccess);
3947

40-
//Check POST
48+
//Xử lý khi có một POST form từ client lên
4149
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
4250
$attributes = $_POST;
43-
51+
4452
if(!isset($attributes['is_active'])) {
4553
$attributes['is_active'] = 0;
4654
}
4755

48-
$oValidator->bindData($attributes);
49-
//Bind input data to object
56+
//Truyền lại giá trị cho đối tượng form
5057
foreach($attributes as $key => $value){
5158
$record->$key = $value;
5259
}
53-
60+
61+
//Nếu slug là rỗng thì tạo slug từ title
62+
if(!isset($attributes['slug'])) {
63+
$attributes['slug'] = slugify($attributes['title']);
64+
$record->slug = $attributes['slug'];
65+
}
66+
67+
//Đẩy giá trị vào cho đối tượng kiểm tra
68+
$oValidator->bindData($attributes);
69+
70+
//Nếu việc kiểm tra không có lỗi thì thực hiện ghi hoặc cập nhật dữ liệu vào database
5471
if($oValidator->validate()) {
5572
if($isAddNew) {
56-
//Add Record
73+
//Trường hợp thêm mới
5774
$attributes['created_at'] = date('Y-m-d H:i:s');
5875
$record = $oDBAccess->save('category', $attributes);
76+
//Ghi flash message
5977
$oFlashMessage->setFlashMessage('success', 'Thêm mới bản ghi thành công');
6078
} else {
61-
//Update Record
79+
//Trường hợp cập nhật
6280
$attributes['updated_at'] = date('Y-m-d H:i:s');
6381
$record = $oDBAccess->save('category', $attributes, 'id');
82+
//Ghi flash message
6483
$oFlashMessage->setFlashMessage('success', 'Cập nhật bản ghi thành công');
6584
}
6685
header("Location: admin_{$pageAliasName}_form.php?id={$record->id}");
@@ -82,18 +101,20 @@
82101
<div class="form-row clearfix">
83102
<label class="form-label">Tiêu đề <span class="required">*</span>:</label>
84103
<div class="form-control">
85-
<input type="text" name="title" value="<?= $record->title ?>" class="input-md <?= $oValidator->checkError('title')?'invalid':'valid' ?>"/>
104+
<input type="text" name="title" value="<?= $record->title ?>" class="input-md <?= $oValidator->checkError('title')?'invalid':'' ?>"/>
86105
<?= $oValidator->fieldError('title') ?>
87106
</div>
88107
</div><!-- /.form-row clearfix -->
89-
108+
109+
<?php if($record->slug != ''): ?>
90110
<div class="form-row clearfix">
91111
<label class="form-label">Slug <span class="required">*</span>:</label>
92112
<div class="form-control">
93-
<input type="text" name="slug" value="<?= $record->slug ?>" class="input-md <?= $oValidator->checkError('slug')?'invalid':'valid' ?>"/>
113+
<input type="text" name="slug" value="<?= $record->slug ?>" class="input-md <?= $oValidator->checkError('slug')?'invalid':'' ?>"/>
94114
<?= $oValidator->fieldError('slug') ?>
95115
</div>
96116
</div><!-- /.form-row clearfix -->
117+
<?php endif; ?>
97118

98119
<div class="form-row clearfix">
99120
<label class="form-label">Trạng thái:</label>

blank.html

100644100755
File mode changed.

css/.htaccess

100644100755
File mode changed.

css/admin.css

100644100755
+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Admin style
3+
*
4+
* @author Nguyễn Như Tuấn <tuanquynh0508@gmail.com>
5+
* @link https://github.com/tuanquynh0508/phpstore
6+
* @copyright 2015 I-Designer
7+
* @license https://github.com/tuanquynh0508/phpstore/license/
8+
* @package css
9+
* @since 1.0
10+
*/
11+
12+
/* COMMON */
113
* {
214
outline: 0;
315
box-sizing: border-box;
@@ -56,6 +68,7 @@ p {
5668
margin: 0px auto;
5769
}
5870

71+
/* DASHBOARD */
5972
#adminBoard {
6073
border: 1px solid #ccc;
6174
}
@@ -84,6 +97,7 @@ p {
8497
padding: 30px;
8598
}
8699

100+
/* MENU TOP */
87101
#pageNav {
88102
border-bottom: 1px solid #ccc;
89103
}
@@ -104,8 +118,9 @@ p {
104118
line-height: 30px;
105119
text-decoration: none;
106120
color: #999;
107-
padding: 0px 20px;
121+
padding: 0px 10px;
108122
text-transform: uppercase;
123+
font-size: 11px;
109124
}
110125
#pageNav ul li.active a,
111126
#pageNav ul li a:hover {
@@ -128,6 +143,7 @@ p {
128143
top: 15px;
129144
}
130145

146+
/* PAGINATION LINK */
131147
.pagination-link ul {
132148
list-style: none;
133149
padding: 0px;
@@ -153,12 +169,15 @@ p {
153169
color: red;
154170
}
155171

172+
/* FLASH MESSAGE, ERROR, ALERT BOX */
156173
.alert-box {
157174
color: green;
158175
}
159176
.error-box, .required {
160177
color: red;
161178
}
179+
180+
/* FORM */
162181
.form-row {
163182
margin-bottom: 10px;
164183
}

css/reset.css

100644100755
File mode changed.

img/.htaccess

100644100755
File mode changed.

img/admin/edit.png

100644100755
File mode changed.

img/admin/first.png

100644100755
File mode changed.

img/admin/invalid.png

100644100755
File mode changed.

img/admin/last.png

100644100755
File mode changed.

img/admin/lock.png

100644100755
File mode changed.

img/admin/next.png

100644100755
File mode changed.

img/admin/prev.png

100644100755
File mode changed.

img/admin/refresh.png

100644100755
File mode changed.

img/admin/search.png

100644100755
File mode changed.

img/admin/trash.png

100644100755
File mode changed.

img/admin/unlock.png

100644100755
File mode changed.

img/admin/valid.png

100644100755
File mode changed.

img/admin/view.png

100644100755
File mode changed.

js/.htaccess

100644100755
File mode changed.

js/admin.js

100644100755
File mode changed.

js/jquery-2.1.4.min.js

100644100755
File mode changed.

libs/.htaccess

100644100755
File mode changed.

0 commit comments

Comments
 (0)