Skip to content

Commit

Permalink
update query for some models
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Jan 3, 2024
1 parent 971d6a3 commit 3daac23
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 53 deletions.
3 changes: 3 additions & 0 deletions admin/controllers/feedback/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

if (!empty($_POST)) {
addFeedbackOrder();
echo "<div style='padding-top: 200px' class='container'><div style='text-align: center;' class='alert alert-success'><strong>Done!</strong> Thư phản hồi của bạn đã được gửi đến hệ thống của quán Chị Kòi. Cảm ơn bạn đã gửi lại phản hồi về quán. <br><br>Hãy đến <a href='admin.php'>Dashboard</a></div></div>";
require('content/views/feedback/result.php');
exit;
}

if (isset($_GET['order_id'])) {
Expand Down
78 changes: 52 additions & 26 deletions admin/models/feedbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;

function addFeedbackOrder()
/**
* @return void
*/
function addFeedbackOrder(): void
{
$feedback_add = [
'id' => intval($_POST['feedback_id']),
Expand All @@ -18,18 +21,29 @@ function addFeedbackOrder()
'status' => 0,
];
save('feedbacks', $feedback_add);
echo "<div style='padding-top: 200px' class='container'><div style='text-align: center;' class='alert alert-success'><strong>Done!</strong> Thư phản hồi của bạn đã được gửi đến hệ thống của quán Chị Kòi. Cảm ơn bạn đã gửi lại phải hồi về quán. <br><br>Hãy đến <a href='admin.php'>Dashboard</a></div></div>";
require('content/views/feedback/result.php');
exit;
}
function deleteFeedback($id)

/**
* @param int $id
*
* @return void
*/
function deleteFeedback(int $id): void
{
global $linkConnectDB;
$id = intval($id);
$sql = "DELETE FROM feedbacks WHERE id=$id";
mysqli_query($linkConnectDB, $sql) or die(mysqli_error($linkConnectDB));
$sql = "DELETE FROM feedbacks WHERE id = ?";

try {
$stmt = executeQuery($sql, [$id]);
$stmt->close();
} catch (\Exception $e) {
die($e->getMessage());
}
}
function updateFeedback()

/**
* @return void
*/
function updateFeedback(): void
{
$feedback = [
'id' => intval($_POST['feedback_id']),
Expand Down Expand Up @@ -81,25 +95,37 @@ function feedbackReplyMail($html, $email)
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
function approveFeedback($id)

/**
* @param int $id
*
* @return void
*/
function approveFeedback(int $id): void
{
if (isset($_GET['feedback_id'])) {
$id = intval($_GET['feedback_id']);
} else {
show404NotFound();
$sql = "UPDATE feedbacks SET status=1 where id= ?";

try {
$stmt = executeQuery($sql, [$id]);
$stmt->close();
} catch (\Exception $e) {
die($e->getMessage());
}
global $linkConnectDB;
$sql = "UPDATE feedbacks SET status=1 where id=" . $id;
mysqli_query($linkConnectDB, $sql) or die(mysqli_error($linkConnectDB));
}
function unApproveFeedback($id)

/**
* @param int $id
*
* @return void
*/
function unApproveFeedback(int $id): void
{
if (isset($_GET['feedback_id'])) {
$id = intval($_GET['feedback_id']);
} else {
show404NotFound();
$sql = "UPDATE feedbacks SET status=0 where id= ?";

try {
$stmt = executeQuery($sql, [$id]);
$stmt->close();
} catch (\Exception $e) {
die($e->getMessage());
}
global $linkConnectDB;
$sql = "UPDATE feedbacks SET status=0 where id=" . $id;
mysqli_query($linkConnectDB, $sql) or die(mysqli_error($linkConnectDB));
}
8 changes: 1 addition & 7 deletions admin/models/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
*/
function mediaDestroy(int $id): void
{
if (isset($_GET['media_id'])) {
$id = intval($_GET['media_id']);
} else {
show404NotFound();
}

$media = getRecord('media', $id);
$image = 'public/upload/media/' . $media['slug'];
if (is_file($image)) {
Expand Down Expand Up @@ -60,7 +54,7 @@ function mediaSave(array $data): void
$slug = slug($_POST['name']);
$config = [
'name' => $slug,
'upload_path' => '/public/upload/media/',
'upload_path' => '../public/upload/media/',
'allowed_exts' => 'jpg|jpeg|png|gif',
];
$images = upload('imggggg', $config);
Expand Down
12 changes: 10 additions & 2 deletions admin/models/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ function orderDestroy($id)
$sql = "DELETE FROM orders WHERE id=$id";
mysqli_query($linkConnectDB, $sql) or die(mysqli_error($linkConnectDB));
}
function orderComplete($id)

/**
* @return void
*/
function orderComplete(): void
{
$id = intval($_POST['order_id']);
$order = [
Expand All @@ -38,7 +42,11 @@ function orderComplete($id)
];
save('orders', $order);
}
function orderInProcess($id)

/**
* @return void
*/
function orderInProcess(): void
{
$id = intval($_POST['order_id']);
$order = [
Expand Down
18 changes: 9 additions & 9 deletions admin/views/feedback/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@
<tbody>
<?php
$stt = 0;
$order_total = 0;
foreach ($orderDetail as $product) :
$stt++;
if ($product["product_typeid"] == 3) {
$order_total += ($product['product_price'] - (($product['product_price']) * ($product['percentoff']) / 100)) * $product['quantity'];
} else {
$order_total += $product['product_price'] * $product['quantity'];
}
?>
$order_total = 0;
foreach ($orderDetail as $product) :
$stt++;
if ($product["product_typeid"] == 3) {
$order_total += ($product['product_price'] - (($product['product_price']) * ($product['percentoff']) / 100)) * $product['quantity'];
} else {
$order_total += $product['product_price'] * $product['quantity'];
}
?>
<tr>
<td><?= $stt; ?></td>
<td><a href="product/<?= $product['id']; ?>-<?= $product['slug'] ?>"><?= $product['product_name']; ?></a></td>
Expand Down
19 changes: 11 additions & 8 deletions lib/counter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

require_once('lib/statistics.php');
$session = session_id();
$time = time();

//$time_check = $time - 30; //Ấn định thời gian là 10 phút

// function get_client_ip_env()
Expand All @@ -20,7 +22,6 @@
// Function to get the client ip address
function get_client_ip_env()
{
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if (getenv('HTTP_X_FORWARDED_FOR'))
Expand All @@ -37,6 +38,7 @@ function get_client_ip_env()
$ipaddress = 'UNKNOWN';
return $ipaddress;
}

// // Function to get the client ip address
// function get_client_ip_server() {
// $ipaddress = '';
Expand All @@ -59,18 +61,19 @@ function get_client_ip_env()
// }
$ip = get_client_ip_env();
$browser = $_SERVER['HTTP_USER_AGENT'];
$date = gmdate('Y-m-d H:i:s', time() + 7 * 3600);

global $linkConnectDB;
$date = gmdate('Y-m-d H:i:s', time() + 7 * 3600);
$sql = "SELECT * FROM users_online WHERE session='$session'";
$result = mysqli_query($linkConnectDB, $sql);
$count = mysqli_num_rows($result);
if ($count == "0") { //Truy cập lần đầu
// //sql2
$options = [
'session' => $session,
];
$count = getTotal('users_online', $options);

if ($count == 0) { //Truy cập lần đầu
insert_user_online($session, $time, $ip, $browser, $date);
} else { //Truy cập lần 2
update_user_online($session, $time, $ip, $browser, $date);
}

// $sql3 = "SELECT * FROM users_online";
// $result3 = mysqli_query($linkConnectDB, $sql3);
// $count_user_online = mysqli_num_rows($result3);
Expand Down
16 changes: 15 additions & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use JetBrains\PhpStorm\NoReturn;

function show404NotFound(): void
{
header('HTTP/1.1 404 Not Found', true, 404);
Expand Down Expand Up @@ -117,7 +119,7 @@ function slug($str): array|string
}

//only admin
function upload($field, $config = array())
function upload($field, $config = [])
{
$options = array(
'name' => '',
Expand Down Expand Up @@ -232,3 +234,15 @@ function adminPagination(string $url, $page, $total): string
$out .= '</ul>';
return $out;
}

/**
* @return void
*/
#[NoReturn] function dd(): void
{
echo '<pre>';
foreach (func_get_args() as $arg) {
var_dump($arg);
}
die;
}

0 comments on commit 3daac23

Please sign in to comment.