Skip to content

Commit

Permalink
Merge pull request #30 from tanhongit/fix/clean-code
Browse files Browse the repository at this point in the history
Fix/clean code
  • Loading branch information
tanhongit authored Jan 8, 2024
2 parents 8f2d682 + 2f5cc18 commit de54230
Show file tree
Hide file tree
Showing 50 changed files with 316 additions and 234 deletions.
2 changes: 1 addition & 1 deletion admin/controllers/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'order_by' => 'id',
];
$title = 'Danh mục sản phẩm';
$subcategories = getAll('subcategory', $options);
$subCategoryData = getAll('subcategory', $options);
$navCategory = 'class="active open"';

require('admin/views/category/index.php');
2 changes: 1 addition & 1 deletion admin/controllers/feedback/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$orderDetail = orderDetail($orderId);

if (isset($userNav)) {
$user_action = getRecord('users', $userNav);
$userAction = getRecord('users', $userNav);
}

$status = [
Expand Down
4 changes: 2 additions & 2 deletions admin/controllers/home/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

global $userNav;

$user_login = getRecord('users', $userNav);
$userLogin = getRecord('users', $userNav);

unset($_SESSION['user']);
cartDestroy();

if ($user_login['role_id'] == 0) {
if ($userLogin['role_id'] == 0) {
header('location:index.php');
} else {
header('location:admin.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/controllers/product/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'select' => 'id,category_name',
'order_by' => 'id',
]);
$subcategories = getAll('subcategory', [
$subCategoryData = getAll('subcategory', [
'select' => 'id,subcategory_name',
'order_by' => 'subcategory_name',
]);
Expand Down
2 changes: 1 addition & 1 deletion admin/controllers/shared/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@

$options_posts_status = [
'order_by' => 'id DESC',
'where' => 'post_status="Publiced"',
'where' => 'post_status="Published"',
];
$total_posts_status = getTotal('posts', $options_posts_status);

Expand Down
1 change: 0 additions & 1 deletion admin/controllers/slide/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require_once('admin/models/slides.php');
if (!empty($_POST)) {
slide_update();
} else {
}
if (isset($_GET['slide_id'])) {
$slideId = intval($_GET['slide_id']);
Expand Down
1 change: 0 additions & 1 deletion admin/controllers/user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;

if (isset($_GET['user_id'])) {
$userId = intval($_GET['user_id']);
Expand Down
10 changes: 5 additions & 5 deletions admin/database/db-backup-tanhongit-2022-07-10-12-37-26.sql
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,20 @@ CREATE TABLE `posts` (
KEY `fk_id_author` (`post_author`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO posts VALUES("1","2","2020-04-08 05:57:42","","About","Publiced","2020-04-08 06:31:51","2","Tân Hồng ","48","about","about-1page.png");
INSERT INTO posts VALUES("9","3","2020-04-12 13:20:20","","Web developmwnt","Publiced","0000-00-00 00:00:00","2","","0","fewrfewrew","");
INSERT INTO posts VALUES("8","2","2020-04-08 23:13:53","","Điều khoản sử dụng","Publiced","0000-00-00 00:00:00","2","","1","terms-of-use-page","");
INSERT INTO posts VALUES("1","2","2020-04-08 05:57:42","","About","Published","2020-04-08 06:31:51","2","Tân Hồng ","48","about","about-1page.png");
INSERT INTO posts VALUES("9","3","2020-04-12 13:20:20","","Web developmwnt","Published","0000-00-00 00:00:00","2","","0","fewrfewrew","");
INSERT INTO posts VALUES("8","2","2020-04-08 23:13:53","","Điều khoản sử dụng","Published","0000-00-00 00:00:00","2","","1","terms-of-use-page","");
INSERT INTO posts VALUES("6","2","2020-04-08 11:47:48","","Dmca Luật bản quyền","Trash","2020-04-08 10:25:58","1","Tân Hồng ","5","dmca-luat-ban","");
INSERT INTO posts VALUES("5","2","2020-04-09 14:03:15","Phim việt chất lượng cao<br />
\n<img alt=\"\" src=\"/php-mvc-shop/public/upload/ckeditorimages/about-1page.png\" style=\"height:271px; width:482px\" />","Phim việt","Publiced","2020-04-08 10:13:10","1","Tân Hồng ","4","phim-viet","phim-viet-5post.png");
\n<img alt=\"\" src=\"/php-mvc-shop/public/upload/ckeditorimages/about-1page.png\" style=\"height:271px; width:482px\" />","Phim việt","Published","2020-04-08 10:13:10","1","Tân Hồng ","4","phim-viet","phim-viet-5post.png");
INSERT INTO posts VALUES("4","2","2020-04-12 12:54:02","ouhiuh<br />
\naad<br />
\n<img alt=\"\" src=\"/php-mvc-shop/public/upload/ckeditorimages/tenor.gif\" style=\"height:498px; width:498px\" /><br />
\n<br />
\nfhgtfrdhtrd<br />
\nỵytrj","Privacy Policy","Draft","2020-04-08 06:05:46","2","Tân Hồng ","7","privacy-policy","privacy-policy-4page.jpg");
INSERT INTO posts VALUES("3","2","2020-04-08 06:17:37","Luật bản quyền dựa tr&ecirc;n luật to&agrave;n cầu<br />
\n<img alt=\"\" src=\"/php-mvc-shop/public/upload/ckeditorimages/dmca-luat-ban-quyen-2page.jpg\" style=\"height:304px; width:650px\" />","Dmca Luật bản quyền","Publiced","2020-04-07 23:52:43","2","","1","dmca-luat-ban-quyen","");
\n<img alt=\"\" src=\"/php-mvc-shop/public/upload/ckeditorimages/dmca-luat-ban-quyen-2page.jpg\" style=\"height:304px; width:650px\" />","Dmca Luật bản quyền","Published","2020-04-07 23:52:43","2","","1","dmca-luat-ban-quyen","");


DROP TABLE IF EXISTS products;
Expand Down
2 changes: 1 addition & 1 deletion admin/models/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function publicPost($id)
show404NotFound();
}
global $linkConnectDB;
$sql = 'UPDATE posts SET post_status="Publiced", post_date="' . gmdate('Y-m-d H:i:s', time() + 7 * 3600) . '" where id=' . $id;
$sql = 'UPDATE posts SET post_status="Published", post_date="' . gmdate('Y-m-d H:i:s', time() + 7 * 3600) . '" where id=' . $id;
mysqli_query($linkConnectDB, $sql) or die(mysqli_error($linkConnectDB));
}
function postDelete($id)
Expand Down
6 changes: 3 additions & 3 deletions admin/models/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ function changePassword($id, $newpassword, $currentPassword)
function user_update()
{
global $userNav;
$user_login = getRecord('users', $userNav);
$userLogin = getRecord('users', $userNav);
if ($_POST['user_id'] <> 0) {
$editTime = gmdate('Y-m-d H:i:s', time() + 7 * 3600);
} else {
$editTime = '0000-00-00 00:00:00';
}

if (isset($_POST['roleid']) && $user_login['role_id'] == 1) {
if (isset($_POST['roleid']) && $userLogin['role_id'] == 1) {
$roleid = $_POST['roleid'];
} else {
$roleid = $user_login['role_id'];
$roleid = $userLogin['role_id'];
}

$user_edit = [
Expand Down
2 changes: 1 addition & 1 deletion admin/views/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</tr>
</tfoot>
<tbody>
<?php foreach ($subcategories as $subcategory) : ?>
<?php foreach ($subCategoryData as $subcategory) : ?>
<tr>
<td><?= $subcategory['id'] ?></td>
<td><a href="admin.php?controller=category&amp;action=edit&amp;sub_cate_id=<?= $subcategory['id']; ?>"><?= $subcategory['subcategory_name']; ?></a></td>
Expand Down
6 changes: 3 additions & 3 deletions admin/views/feedback/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
<form action="admin.php?controller=feedback&action=add&order_id=<?= $order['id'] ?>" method="post">
<input type="hidden" name="feedback_id" value="0">
<input type="hidden" class="form-control" name="user_id" value="<?= $userNav ?>">
<input type="hidden" name="name" value="<?= $user_action['user_name'] ?>" class="form-control">
<input type="hidden" name="email" value="<?= $user_action['user_email'] ?>" class="form-control">
<input type="hidden" value="<?= $user_action['user_phone'] ?>" name="phone" class="form-control">
<input type="hidden" name="name" value="<?= $userAction['user_name'] ?>" class="form-control">
<input type="hidden" name="email" value="<?= $userAction['user_email'] ?>" class="form-control">
<input type="hidden" value="<?= $userAction['user_phone'] ?>" name="phone" class="form-control">
<input type="hidden" value="<?= $order['id'] ?>" name="order_id" class="form-control">
<h4>Nhập dòng tin phản hồi về đơn hàng này</h4>
<textarea name="message" placeholder="Nhập phản hồi của bạn" required style="width: 100%;" rows="10"></textarea>
Expand Down
4 changes: 2 additions & 2 deletions admin/views/product/formEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</tr>
<tr>
<td><strong>Thuộc danh mục con</strong> </td>
<td><?php foreach ($subcategories as $subcategory) {
<td><?php foreach ($subCategoryData as $subcategory) {
if ($product && ($product['sub_category_id'] == $subcategory['id'])) {
echo $subcategory['subcategory_name'];
}
Expand Down Expand Up @@ -151,7 +151,7 @@
<div class="row clearfix">
<div class="col-sm-12">
<select name="subcategory_id" class="form-control show-tick">
<?php foreach ($subcategories as $subcategory) {
<?php foreach ($subCategoryData as $subcategory) {
$selected = '';
if ($product && ($product['sub_category_id'] == $subcategory['id'])) {
$selected = 'selected=""';
Expand Down
5 changes: 3 additions & 2 deletions content/controllers/cart/delete.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

if (isset($_GET['id'])) {
$productId = intval($_GET['id']);
if (!isset($_GET['id'])) {
show404NotFound();
}
$productId = intval($_GET['id']);
cart_delete($productId);
global $userNav;
if (isset($userNav)) {
Expand Down
2 changes: 1 addition & 1 deletion content/controllers/cart/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
global $userNav;
if (isset($userNav)) {
$user_login = getRecord('users', $userNav);
$userLogin = getRecord('users', $userNav);
}
//load view
require('content/views/cart/order.php');
7 changes: 4 additions & 3 deletions content/controllers/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$categoryId = intval($_GET['id']);

$category = getRecord('subcategory', $categoryId);

if (!$category) {
show404NotFound();
}
Expand Down Expand Up @@ -40,9 +41,9 @@
$products = getAll('products', $options);
$pagination = pagination($url, $page, $total);

$subcategories = getRecord('subcategory', $_GET["id"]);
if ($subcategories['id'] != 0) {
$breadCrumb = $subcategories['subcategory_name'];
$subCategoryData = getRecord('subcategory', $_GET["id"]);
if ($subCategoryData['id'] != 0) {
$breadCrumb = $subCategoryData['subcategory_name'];
}
$title = $category['subcategory_name'] . ' - Quán Chị Kòi';
require('content/views/category/index.php');
2 changes: 1 addition & 1 deletion content/controllers/feedback/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

$product = getRecord('products', $productId);
if (isset($userNav)) {
$user_action = getRecord('users', $userNav);
$userAction = getRecord('users', $userNav);
}
$title = 'Gửi phản hồi của bạn đến Chị Kòi Quán';
require('content/views/feedback/index.php');
7 changes: 4 additions & 3 deletions content/controllers/forgot-password/change-password.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

if (isset($_GET['id'])) {
$userId = $_GET['id'];
if (!isset($_GET['id'])) {
show404NotFound();
}
$user_info = getRecord('users', $userId);

$user_info = getRecord('users', intval($_GET['id']));
$title = 'Change Password - Forgot Password';
require('content/views/forgot-password/change-password.php');
4 changes: 2 additions & 2 deletions content/controllers/forgot-password/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
$users = getAll('users', $option);
foreach ($users as $user) {
if ($user['user_email'] == $email) {
$verification_Code = $user['verificationCode'];
$verificationCode = $user['verificationCode'];
}
}
include 'lib/config/sendmail.php';
$mail = new PHPMailer(true);

try {
$verificationLink = PATH_URL . "index.php?controller=forgot-password&action=resultcode&code=" . $verification_Code;
$verificationLink = PATH_URL . "index.php?controller=forgot-password&action=resultcode&code=" . $verificationCode;
//content
$htmlStr = "";
$htmlStr .= "Xin chào " . $username . ' (' . $email . "),<br /><br />";
Expand Down
12 changes: 6 additions & 6 deletions content/controllers/forgot-password/resultcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

if (!empty($_GET['code'])) {

$select_user_option = [
$selectUserOption = [
'order_by' => 'id',
];
$verifi_id_user = 0;
$user_need_change_pass = getAll('users', $select_user_option);
foreach ($user_need_change_pass as $user) {
$userVerifyId = 0;
$needChangePassUsers = getAll('users', $selectUserOption);
foreach ($needChangePassUsers as $user) {
if ($user['verificationCode'] == $_GET['code']) {
$verifi_id_user = 1;
$userVerifyId = 1;
$userId = $user['id'];
}
}
if ($verifi_id_user != 1) {
if ($userVerifyId != 1) {
echo "<div style='padding-top: 200px' class='container'><div style='text-align: center;' class='alert alert-danger'><strong>Oh No!</strong> Link xác nhận tài khoản để đổi mật khẩu của bạn không đúng. Vui lòng kiểm tra lại. <br><br>Nếu đây là lỗi của hệ thống, mong bạn có thể gửi phản hổi <a href='index.php?controller=feedback'>Tại đây</a></div></div>";
require('content/views/forgot-password/result.php');
} else {
Expand Down
6 changes: 3 additions & 3 deletions content/controllers/home/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
'offset' => '0',
'order_by' => 'createDate DESC',
];
$hot_products = getAll('products', $options_hotproduct);
$hotProducts = getAll('products', $options_hotproduct);
$options_newproduct = [
'where' => 'product_typeid = 2',
'limit' => '12',
'offset' => '0',
'order_by' => 'createDate DESC',
];
$new_products = getAll('products', $options_newproduct);
$newProducts = getAll('products', $options_newproduct);
$options_saleproduct = [
'where' => 'product_typeid = 3',
'limit' => '12',
'offset' => '0',
'order_by' => 'createDate DESC',
];
$saleoff_products = getAll('products', $options_saleproduct);
$saleoffProducts = getAll('products', $options_saleproduct);
$title = 'Trang chủ - Quán Chị Kòi';
$option_slide = [
'order_by' => 'id asc',
Expand Down
9 changes: 5 additions & 4 deletions content/controllers/page/index.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

require_once('content/models/posts.php');
if (isset($_GET['id'])) {
$postId = intval($_GET['id']);
} else {

if (!isset($_GET['id'])) {
show404NotFound();
}

$postId = intval($_GET['id']);
$page = getRecord('posts', $postId);
$user = getRecord('users', $page['post_author']);
if (!$page || $page['post_status'] <> 'Publiced') {
if (!$page || $page['post_status'] <> 'Published') {
show404NotFound();
} else {
updateCountView($postId);
Expand Down
8 changes: 4 additions & 4 deletions content/controllers/post/index.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

require_once('content/models/posts.php');
if (isset($_GET['id'])) {
$postId = intval($_GET['id']);
} else {
if (!isset($_GET['id'])) {
show404NotFound();
}

$postId = intval($_GET['id']);
$post = getRecord('posts', $postId);
$user = getRecord('users', $post['post_author']);
if (!$post || $post['post_status'] <> 'Publiced') {
if (!$post || $post['post_status'] <> 'Published') {
show404NotFound();
} else {
updateCountView($postId);
Expand Down
2 changes: 1 addition & 1 deletion content/controllers/product/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
$total = ceil($totalRows / $limit);
$pagination = pagination($url, $page, $total);

$products_all = getAll('products', $options);
$products = getAll('products', $options);
require('content/views/product/all.php');
11 changes: 6 additions & 5 deletions content/controllers/product/index.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

require_once('content/models/products.php');
if (isset($_GET['id'])) {
$productId = intval($_GET['id']);
} else {

if (!isset($_GET['id'])) {
show404NotFound();
}

$productId = intval($_GET['id']);
$product = getRecord('products', $productId);

if (!$product) {
Expand All @@ -20,9 +21,9 @@
'select' => 'id, category_name',
'order_by' => 'id ASC',
]);
$subcategories = getRecord('subcategory', $product['sub_category_id']);
$subCategoryData = getRecord('subcategory', $product['sub_category_id']);
if ($product['sub_category_id'] != 0) {
$breadCrumb = $subcategories['subcategory_name'];
$breadCrumb = $subCategoryData['subcategory_name'];
}
$comment_option = [
'where' => 'product_id=' . $product['id'],
Expand Down
10 changes: 5 additions & 5 deletions content/controllers/register/activate.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

if (!empty($_GET['code'])) {
$select_user_option = [
$selectUserOption = [
'order_by' => 'id',
];
$user_need_activate = getAll('users', $select_user_option);
$user_need_activate = getAll('users', $selectUserOption);
foreach ($user_need_activate as $user) {
if ($user['verificationCode'] == $_GET['code']) {
$verifi_id_user = $user['id'];
$userVerifyId = $user['id'];
}
}
if (!isset($verifi_id_user)) {
if (!isset($userVerifyId)) {
show404NotFound();
}
$user_edit = [
'id' => $verifi_id_user,
'id' => $userVerifyId,
'verified' => 1,
];
save('users', $user_edit);
Expand Down
Loading

0 comments on commit de54230

Please sign in to comment.