Skip to content

Commit 2acb1b5

Browse files
committed
maybe last
1 parent 77325eb commit 2acb1b5

File tree

179 files changed

+22315
-2016
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+22315
-2016
lines changed

admin/binhluan/duyet.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<td><?php echo $binhluan['hoten'];?></td>
2525
<td><?php echo $binhluan['email'];?></td>
2626
<td><span title="<?php echo $binhluan['noidung'];?>"><?php if(strlen($binhluan['noidung']) > 30) echo mb_substr($binhluan['noidung'], 0, strpos($binhluan['noidung'], ' ', 30))."..."; else echo $binhluan['noidung'];?><span></span></td>
27-
<td><a href="#" class="duyet" idbl="<?php echo $binhluan['id_comment'];?>">Duyệt</a> / <a onclick="xacnhan();" href="#" class="xoa" idbl="<?php echo $binhluan['id_comment'];?>">Xóa</a></td>
27+
<td><a href="#" class="duyet" idbl="<?php echo $binhluan['id_comment'];?>">Duyệt</a> / <a href="#" class="xoa" idbl="<?php echo $binhluan['id_comment'];?>">Xóa</a></td>
2828
</tr>
2929
<?php }?>
3030
</tbody>
@@ -46,6 +46,8 @@
4646
});
4747

4848
$("#dsbinhluan").on('click', '.xoa', function(){
49+
var confirm = xacnhan();
50+
if(confirm == false) return false;
4951
var idBL = $(this).attr("idbl");
5052
xoabinhluan(idBL);
5153
laybinhluan();
@@ -63,6 +65,7 @@ function duyetbinhluan(idBL){
6365
}
6466

6567
function xoabinhluan(idBL){
68+
6669
$.ajax({
6770
url: "process.php",
6871
type: "get",

admin/binhluan/sua.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
settype($_GET['id_comment'], "int");
23

3-
if(!isset($_GET['id_comment']) || $_GET['id_comment'] < 1) header("location: index.php?c=loaisp&a=xem");
4+
if($_GET['id_comment'] <= 0) header("location: index.php?c=loaisp&a=xem");
45

56
$binhluan = $qt->lay1binhluan($_GET['id_comment']);
67

admin/binhluan/xem.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<td><?php echo $binhluan['hoten'];?></td>
2525
<td><?php echo $binhluan['email'];?></td>
2626
<td><span title="<?php echo $binhluan['noidung'];?>"><?php if(strlen($binhluan['noidung']) > 30) echo mb_substr($binhluan['noidung'], 0, strpos($binhluan['noidung'], ' ', 30))."..."; else echo $binhluan['noidung'];?><span></span></td>
27-
<td><a href="index.php?a=binhluan-sua&id_comment=<?php echo $binhluan['id_comment'];?>">Sửa</a> / <a href="index.php?a=binhluan-xoa&id_comment=<?php echo $binhluan['id_comment'];?>">Xóa</a></td>
27+
<td><a href="index.php?a=binhluan-sua&id_comment=<?php echo $binhluan['id_comment'];?>">Sửa</a> / <a onclick="return xacnhan();" href="index.php?a=binhluan-xoa&id_comment=<?php echo $binhluan['id_comment'];?>">Xóa</a></td>
2828
</tr>
2929
<?php }?>
3030
</tbody>
@@ -35,6 +35,4 @@
3535
$url = "index.php?a=binhluan-xem";
3636
echo $qt->thanhphantrang($url, $totalrows, $current_page, $per_page, $pages_per_group);
3737
?>
38-
</div>
39-
<script>
40-
</script>
38+
</div>

admin/binhluan/xoa.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<?php
2-
3-
if(!isset($_GET['id_comment'])) header("location: index.php?a=binhluan-xem");
4-
52
settype($_GET['id_comment'], "int");
63

7-
if($_GET['id_comment'] == 0) header("location: index.php?a=binhluan-xem");
4+
if($_GET['id_comment'] <= 0) header("location: index.php?a=binhluan-xem");
85

96
$qt->xoabinhluan($_GET['id_comment']);
107

admin/chungloai/sua.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
settype($_GET['idCL'], "int");
23

3-
if(!isset($_GET['idCL']) || $_GET['idCL'] < 1) header("location: index.php?a=chungloai-xem");
4+
if($_GET['idCL'] <= 0) header("location: index.php?a=chungloai-xem");
45

56
$chungloai = $qt->laychungloai($_GET['idCL']);
67

admin/chungloai/xem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<td><?php echo $row['TenCL'];?></td>
2222
<td><?php echo $row['ThuTu'];?></td>
2323
<td><?php if($row['AnHien']==0) echo "Ẩn"; else echo "Hiện" ;?></td>
24-
<td><a href="index.php?a=chungloai-sua&idCL=<?php echo $row['idCL'];?>">Sửa</a> / <a href="index.php?a=chungloai-xoa&idCL=<?php echo $row['idCL'];?>">Xóa</a></td>
24+
<td><a href="index.php?a=chungloai-sua&idCL=<?php echo $row['idCL'];?>">Sửa</a> / <a onclick="return xacnhan();" href="index.php?a=chungloai-xoa&idCL=<?php echo $row['idCL'];?>">Xóa</a></td>
2525
</tr>
2626
<?php }?>
2727
</table>

admin/chungloai/xoa.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
settype($_GET['idCL'], "int");
44

5-
if(!isset($_GET['idCL']) || $_GET['idCL'] < 1) header("location: index.php?c=chungloai&a=xem");
5+
if($_GET['idCL'] <= 0) header("location: index.php?c=chungloai&a=xem");
66

77
$qt->xoachungloai($_GET['idCL']);

admin/classquantri.php

+157-13
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function themloaisp(){
155155

156156
$sql = "INSERT INTO loaisp VALUES (null, {$_POST['idCL']}, '$ten', {$_POST['ThuTu']}, {$_POST['AnHien']})";
157157
if(!$result = $this->db->query($sql)) die($sql);
158+
$_SESSION['success'] = 'Đã thêm thành công 1 loại sản phẩm';
158159
header("location: index.php?a=loaisp-xem");
159160
}
160161

@@ -176,10 +177,9 @@ public function sualoaisp($idLoai){
176177
if(count($this->errors) > 0) return false;
177178

178179
$ten = $this->db->escape_string($_POST['TenLoai']);
179-
180180
$sql = "UPDATE loaisp SET idCL={$_POST['idCL']}, TenLoai='$ten', ThuTu={$_POST['ThuTu']}, AnHien={$_POST['AnHien']} WHERE idLoai=$idLoai";
181181
if(!$result = $this->db->query($sql)) die("loi ket noi");
182-
header("location: index.php?a=loaisp-xem");
182+
$_SESSION['success'] = 'Loại sản phẩm đã được cập nhật thành công';
183183
}
184184

185185
public function xoaloaisp($idLoai){
@@ -194,6 +194,7 @@ public function xoaloaisp($idLoai){
194194

195195
$sql = "DELETE FROM loaisp WHERE idLoai=$idLoai";
196196
if(!$result = $this->db->query($sql)) die("loi ket noi");
197+
$_SESSION['success'] = 'Đã xóa thành công 1 loại sản phẩm';
197198
header("location: index.php?a=loaisp-xem");
198199
}
199200

@@ -238,12 +239,20 @@ public function themsanpham(){
238239
if(!is_numeric($_POST['Gia'])) $this->errors['Gia'] = "Trường này phải nhập số!";
239240
if(!empty($_POST['SoLuongTonKho']) && !is_numeric($_POST['SoLuongTonKho'])) $this->errors['SoLuongTonKho'] = "Trường này phải nhập số!";
240241
if(empty($_POST['Gia'])) $this->errors['Gia'] = "Không được bỏ trống trường này!";
241-
242+
243+
if(!empty($_POST['youtube'])){
244+
$youtube = $this->db->escape_string($_POST['youtube']);
245+
preg_match('/youtube\.com\/watch\?v=(\w+)/i', $youtube, $match);
246+
if(count($match) != 2) $this->errors['youtube'] = 'link không đúng định dạng';
247+
$youtube_value = $match[1];
248+
}
249+
242250
if(count($this->errors) > 0) return false;
243251

252+
//hình chính mặc định:
244253
$urlHinh = "updating.png";
245-
//nếu có up hình:
246-
if($_FILES['urlHinh']['error'] != 4){
254+
//nếu có up hình chính:
255+
if(!empty($_FILES['urlHinh']['name'])){
247256
//kiem tra dinh dang file hinh upload
248257
$ext_list = array("jpeg", "png", "jpg");
249258
$file_ext = pathinfo($_FILES['urlHinh']['name'], PATHINFO_EXTENSION);
@@ -276,7 +285,45 @@ public function themsanpham(){
276285
$urlHinh = $newname;
277286
}
278287
}
279-
288+
289+
//nếu có up hình phụ:
290+
if(!empty($_FILES['hinhphu']['name'][0])){
291+
$ext_list = array("jpeg", "png", "jpg");
292+
$max_size = 1024*1024*2;
293+
$arr_tenhinhphu = array();
294+
//kiểm tra xem có hình nào ko hợp lệ ko
295+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
296+
$file_ext = pathinfo($_FILES['hinhphu']['name'][$i], PATHINFO_EXTENSION);
297+
if(!in_array($file_ext, $ext_list)){
298+
$this->errors['hinhphu'] = 'Chỉ chấp nhận các định dạng: jpeg, png, jpg!';
299+
return false;
300+
}
301+
if($_FILES['hinhphu']['size'][$i] > $max_size){
302+
$this->errors['hinhphu'] = 'Chỉ chấp nhận hình dưới 2MB!';
303+
return false;
304+
}
305+
//loi he thong, mang:
306+
if($_FILES['hinhphu']['error'][$i] > 0){
307+
$this->errors['hinhphu'] = 'Có lỗi xảy ra, xin thử lại!';
308+
return false;
309+
}
310+
311+
}
312+
//tất cả các hình đều hợp lệ, bắt dầu upload
313+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
314+
$newname = $this->changeTitle($_POST['TenSP']) ."-"."hinhphu_".$i. "." . $file_ext;
315+
316+
//lưu tên để sau chèn vào database:
317+
$arr_tenhinhphu[] = $newname;
318+
319+
//đường dẫn lưu file:
320+
$path = '../upload/sanpham/hinhphu/' . $newname;
321+
if(move_uploaded_file($_FILES['hinhphu']['tmp_name'][$i], $path) == false){
322+
$this->errors['hinhphu'] = 'Có lỗi xảy ra, xin thử lại!';
323+
return false;
324+
}
325+
}
326+
}
280327

281328
$ngay = date('Y-m-d', time());
282329
$TenSP = $this->db->escape_string($_POST['TenSP']);
@@ -291,6 +338,22 @@ public function themsanpham(){
291338
'$baiviet', 0, {$_POST['SoLuongTonKho']},
292339
'$GhiChu', 0, {$_POST['AnHien']})";
293340
if(!$result = $this->db->query($sql)) die("loi ket noi");
341+
$idSP = $this->db->insert_id;
342+
343+
//insert youtube link:
344+
if(!empty($_POST['youtube'])){
345+
$sql = "INSERT INTO sanpham_youtube VALUES(null, $idSP, '$youtube_value')";
346+
if(!$result = $this->db->query($sql)) die("loi ket noi");
347+
}
348+
349+
//insert url hình phụ:
350+
if(!empty($_FILES['hinhphu']['name'][0])){
351+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
352+
$sql = "INSERT INTO sanpham_hinh VALUES(null, $idSP, '{$arr_tenhinhphu[$i]}')";
353+
if(!$result = $this->db->query($sql)) die("loi ket noi");
354+
}
355+
}
356+
294357
$_SESSION['success'] = 'Đã thêm thành công 1 sản phẩm';
295358
header("location: index.php?a=sanpham-xem");
296359
}
@@ -307,7 +370,14 @@ public function suasanpham($idSP){
307370
if(!is_numeric($_POST['Gia'])) $this->errors['Gia'] = "Trường này phải nhập số!";
308371
if(!empty($_POST['SoLuongTonKho']) && !is_numeric($_POST['SoLuongTonKho'])) $this->errors['SoLuongTonKho'] = "Trường này phải nhập số!";
309372
if(empty($_POST['Gia'])) $this->errors['Gia'] = "Không được bỏ trống trường này!";
310-
373+
374+
if(!empty($_POST['youtube'])){
375+
$youtube = $this->db->escape_string($_POST['youtube']);
376+
preg_match('/youtube\.com\/watch\?v=(\w+)/i', $youtube, $match);
377+
if(count($match) != 2) $this->errors['youtube'] = 'link không đúng định dạng';
378+
$youtube_value = $match[1];
379+
}
380+
311381
if(count($this->errors) > 0) return false;
312382

313383
//kiem tra neu upload hinh moi
@@ -367,6 +437,86 @@ public function suasanpham($idSP){
367437
//xoa hinh cu:
368438
if(!isset($hinhcu)) return true;
369439
if($hinhcu != "updating.png") unlink('../upload/sanpham/hinhchinh/'.$hinhcu);
440+
441+
//youtube:
442+
if(!empty($_FILES['hinhphu']['name'][0])){
443+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
444+
$sql = "INSERT INTO sanpham_hinh VALUES(null, $idSP, '{$arr_tenhinhphu[$i]}')";
445+
if(!$result = $this->db->query($sql)) die("loi ket noi");
446+
}
447+
}
448+
}
449+
450+
public function uphinhphu($idSP){
451+
//tìm số thứ tự cao nhất của hình phụ hiện tại:
452+
$dshinh = $this->layhinhsp($idSP);
453+
$max = 0;
454+
foreach($dshinh as $hinh){
455+
$urlHinh = $hinh['urlHinh'];
456+
preg_match('/(\d*)\.[a-z]*/', $urlHinh, $match);
457+
$num = $match[1];
458+
if($num > $max) $max = $num;
459+
}
460+
461+
462+
if(!empty($_FILES['hinhphu']['name'][0])){
463+
$ext_list = array("jpeg", "png", "jpg");
464+
$max_size = 1024*1024*2;
465+
$arr_tenhinhphu = array();
466+
//kiểm tra xem có hình nào ko hợp lệ ko
467+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
468+
$file_ext = pathinfo($_FILES['hinhphu']['name'][$i], PATHINFO_EXTENSION);
469+
if(!in_array($file_ext, $ext_list)){
470+
$this->errors['hinhphu'] = 'Chỉ chấp nhận các định dạng: jpeg, png, jpg!';
471+
}
472+
if($_FILES['hinhphu']['size'][$i] > $max_size){
473+
$this->errors['hinhphu'] = 'Chỉ chấp nhận hình dưới 2MB!';
474+
}
475+
//loi he thong, mang:
476+
if($_FILES['hinhphu']['error'][$i] > 0){
477+
$this->errors['hinhphu'] = 'Có lỗi xảy ra, xin thử lại!';
478+
}
479+
}
480+
481+
if(!empty($this->errors['hinhphu'])){
482+
$_SESSION['fail'] = '<p class="alert alert-danger">'.$this->errors['hinhphu'].'</p>';
483+
header("Location: index.php?a=sanpham-hinhphu&idSP=$idSP");
484+
return false;
485+
}
486+
487+
//tất cả các hình đều hợp lệ, bắt dầu upload
488+
for($i=0; $i<count($_FILES['hinhphu']['name']); $i++){
489+
$sql = "SELECT TenSP FROM sanpham WHERE idSP=$idSP";
490+
if(!$result = $this->db->query($sql)) die("loi ket noi");
491+
$row = $result->fetch_row();
492+
$TenSP = $row[0];
493+
$newname = $this->changeTitle($TenSP) ."-"."hinhphu_".($max+$i+1). "." . $file_ext;
494+
495+
//lưu tên để sau chèn vào database:
496+
$arr_tenhinhphu[] = $newname;
497+
498+
//đường dẫn lưu file:
499+
$path = '../upload/sanpham/hinhphu/' . $newname;
500+
if(move_uploaded_file($_FILES['hinhphu']['tmp_name'][$i], $path) == false){
501+
$this->errors['hinhphu'] = 'Có lỗi xảy ra, xin thử lại!';
502+
header("Location: index.php?a=sanpham-hinhphu&idSP=$idSP");
503+
return false;
504+
}
505+
506+
$sql = "INSERT INTO sanpham_hinh VALUES(null, $idSP, '{$arr_tenhinhphu[$i]}')";
507+
if(!$result = $this->db->query($sql)) die("loi ket noi");
508+
}
509+
$_SESSION['success'] = '<p class="alert alert-success">up thành công!</p>';
510+
header("Location: index.php?a=sanpham-hinhphu&idSP=$idSP");
511+
}
512+
}
513+
514+
public function xoahinhphu($idHinh, $urlHinh, $idSP){
515+
$sql = "DELETE FROM sanpham_hinh WHERE id_hinh=$idHinh";
516+
if(!$result = $this->db->query($sql)) die("loi ket noi");
517+
unlink('../upload/sanpham/hinhphu/'.$urlHinh);
518+
$_SESSION['success'] = 'Đã xóa thành công 1 hình phụ';
519+
header("location: index.php?a=sanpham-hinhphu&idSP=$idSP");
370520
}
371521

372522
public function xoasanpham($idSP){
@@ -543,11 +693,5 @@ public function xoauser($idUser){
543693
$_SESSION['message'] = 'Đã xóa thành công user';
544694
header("Location: index.php?a=user-xem");
545695
}
546-
547-
private function validate($input){
548-
$input = $this->db->escape_string($input);
549-
$input = trim($input);
550-
return $input;
551-
}
552696

553697
}

admin/donhang/chitiet.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
2-
if(!isset($_GET['idDH']) || $_GET['idDH'] <1) header("location: index.php");
2+
settype($_GET['idDH'], "int");
3+
4+
if($_GET['idDH'] <= 0) header("location: index.php");
5+
36
$chitietdonhang = $qt->laychitietdonhang($_GET['idDH']);
7+
48
$thongtin = $qt->laythongtindonhang($_GET['idDH']);
59
?>
610
<h2 class="">Chi tiết đơn hàng số <?php echo $_GET['idDH'] ?></h2>
@@ -95,7 +99,7 @@
9599
</div>
96100
</div>
97101
<?php if($thongtin['DaXuLy'] == 0){ ?>
98-
<a href="process.php?huydonhang=<?php echo $_GET['idDH'];?>" class="btn btn-lg btn-default">HỦY ĐƠN HÀNG</a>
102+
<a onclick="return xacnhan();" href="process.php?huydonhang=<?php echo $_GET['idDH'];?>" class="btn btn-lg btn-default">HỦY ĐƠN HÀNG</a>
99103
<a href="process.php?duyetdonhang=<?php echo $_GET['idDH'];?>" class="btn btn-lg btn-success">ĐÃ XỬ LÝ XONG</a>
100104
<?php } else {?>
101105
<a href="index.php?a=donhang-xem" class="btn btn-primary btn-lg">Back</a>

admin/index.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
$current_page = 1; if(isset($_GET['page'])) $current_page = $_GET['page'];
1313
$pages_per_group = 5;
1414

15-
1615
?>
1716
<!DOCTYPE html>
1817
<html>
1918
<head>
2019
<meta charset='utf-8'>
21-
<link rel="stylesheet" href="../css/bootstrap.css">
22-
<link rel="stylesheet" href="../css/style.css">
23-
<script src="../js/jquery.js"></script>
20+
<title>Quản trị</title>
21+
<link rel="stylesheet" href="<?php echo BASE_URL;?>css/bootstrap.css">
22+
<link rel="stylesheet" href="<?php echo BASE_URL;?>css/style.css">
23+
<script src="<?php echo BASE_URL;?>js/jquery.js"></script>
2424
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
2525
<script>tinymce.init({ selector:'.tinymce' });</script>
2626
</head>
@@ -54,7 +54,7 @@
5454
else $("nav#sidebar").height(h);
5555
});
5656
function xacnhan(){
57-
confirm("Bạn có chắc muốn xóa?");
57+
return confirm("Bạn có chắc muốn xóa?");
5858
}
5959
</script>
6060
</body>

0 commit comments

Comments
 (0)