1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<?php require("configure.php"); ?> <? $ProductId = $_POST["ProductId"]; $ProductGradeId = $_POST["ProductGradeId"]; $Sort = $_POST["Sort"]; $Hotproduct = $_POST["Hotproduct"];
$NameEN = htmlspecialchars($_POST["pdetnameen"],ENT_QUOTES); $DescEN = $_POST["pdetdescen"];
$NameTC = htmlspecialchars($_POST["pdetnametc"],ENT_QUOTES); $DescTC = $_POST["pdetdesctc"];
//print_r($_POST);
if ($_FILES['pdetimage']['name'] <> '') { copy ($_FILES['pdetimage']['tmp_name'], "product/".$ProductId.$_FILES['pdetimage']['name']) or die ("Could not copy"); $pdetimage = $ProductId.$_FILES['pdetimage']['name']; $image = "product/".$ProductId.$_FILES['pdetimage']['name']; createthumb($image, $image, 600, 600); copy ($_FILES['pdetimage']['tmp_name'], "productthumb/".$ProductId.$_FILES['pdetimage']['name']) or die ("Could not copy"); $imagethumb = "productthumb/".$ProductId.$_FILES['pdetimage']['name']; createthumb($imagethumb, $imagethumb, 145, 145); } else { $pdetimage = ""; }
function createthumb($name,$filename,$new_w,$new_h) { $system=explode('.',$name); if (preg_match('/jpg|jpeg|JPG|JPEG/',$system[1])){ $src_img=imagecreatefromjpeg($name); } if (preg_match('/gif|GIF/',$system[1])){ $src_img=imagecreatefromgif($name); } if (preg_match('/png|PNG/',$system[1])){ $src_img=imagecreatefrompng($name); }
$old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; }
$dst_img = imagecreatetruecolor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); $red = imagecolorallocate($dst_img, 255, 0, 0); $green = imagecolorallocate($dst_img, 0, 255, 0); $blue = imagecolorallocate($dst_img, 0, 0, 255); $black = imagecolorallocate($dst_img, 0, 0, 0); // Make the background transparent imagecolortransparent($dst_img, $black);
// Draw a red rectangle imagefilledrectangle($dst_img, 4, 4, 50, 25, $red, $green, $blue);
if (preg_match("/png|PNG/",$system[1])){ imagepng($dst_img, './imagecolortransparent.png'); } else if (preg_match("/gif|GIF/",$system[1])) { imagegif($dst_img, './imagecolortransparent.gif'); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
// Check current category $result = mysql_query("SELECT Product.ProductId, Product.ProductGradeId, Product.Sort from Product WHERE ProductId = $ProductId"); $current = mysql_fetch_array($result,MYSQL_ASSOC);
// change category if ($ProductGradeId <> $current{'ProductGradeId'}) { //echo ">>$ProductGradeId >>".$current{'ProductGradeId'}; $sql = "select max(Sort) as maxid "; $sql .= "from Product where ProductGradeId = $ProductGradeId"; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $Sort = $row{maxid}+1; // update old category sort mysql_query("UPDATE Product SET Sort = Sort-1 WHERE ProductGradeId = ". $current{'ProductGradeId'} ." AND Sort >= ". $current{'Sort'}); }
$sql = "update Product set ProductId='$ProductId', ProductGradeId='$ProductGradeId', NameEN='$NameEN', NameTC='$NameTC', DescEN='$DescEN', DescTC='$DescTC' "; if ($Sort <> '') $sql .= ", Sort='$Sort' "; if ($Hotproduct <> '') $sql .= ", Hotproduct='1' "; else $sql .= ", Hotproduct='0' ";
if ($pdetimage <> '') $sql .= ", ImagePath='$pdetimage' "; $sql .= "where ProductId=". $ProductId ." "; //echo $sql; mysql_query($sql); mysql_close($dbh);
header("Location: productdetail_index.php?ProductGradeId=$ProductGradeId&msg=Update Successful"); ?>
|