/var/www/(Del)yuecreations.com.hk/webadmin/productcat_add.php


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
<?php require("configure.php"); 

$DescEN    htmlspecialchars($_POST["DescEN"],ENT_QUOTES);
$DescTC    htmlspecialchars($_POST["DescTC"],ENT_QUOTES);
//$ProductCatDate        = htmlspecialchars($_POST["ProductCatDate"],ENT_QUOTES);
$Sort        $_POST["Sort"];
$ProductColourId    $_POST["ProductColourId"];
//print_r($_POST); 

$sql "select max(ProductCatId) as maxid ";
$sql .= "from ProductCat ";
$result=mysql_query($sql);
$row mysql_fetch_array($result,MYSQL_ASSOC);
$ProductCatId $row{maxid}+1;

// copy image 
if ($_FILES['ProductCatCover']['name'] <> '')
{
    
copy ($_FILES['ProductCatCover']['tmp_name'], "productcover/".$ProductCatId."_".$_FILES['ProductCatCover']['name']) 
        or die (
"Could not copy");
         
    
$ProductCatCover $ProductCatId."_".$_FILES['ProductCatCover']['name'];

    
$image "productcover/".$ProductCatId."_".$_FILES['ProductCatCover']['name'];
    
createthumb($image$image120120);

}
else
{    
    
$ProductCatCover "";
}
// End upload image code

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);*/
        
$thumb_w=$old_x*($new_w/$old_y);
        
$thumb_h=$new_h;
    }
    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_img25500);
    
$green imagecolorallocate($dst_img02550);
    
$blue imagecolorallocate($dst_img00255);
    
$black imagecolorallocate($dst_img000);
    
// Make the background transparent
    
imagecolortransparent($dst_img$black);

    
// Draw a red rectangle
    
imagefilledrectangle($dst_img445025$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); 
}


if (
$Sort == '' || $Sort == '0') {
    
$sql "select max(Sort) as maxid ";
    
$sql .= "from ProductCat where ProductColourId=$ProductColourId";
    
$result=mysql_query($sql);
    
$row mysql_fetch_array($result,MYSQL_ASSOC);
    
$Sort $row{maxid}+1;
}
if( 
mysql_num_rows(mysql_query("SELECT ProductCatId FROM ProductCat WHERE ProductColourId = $ProductColourId AND Sort=$Sort ")) > 0){
    
mysql_query("UPDATE ProductCat SET Sort= Sort+1 WHERE ProductColourId = $ProductColourId AND Sort >=$Sort ");
}

$sql "insert into ProductCat (ProductCatId, ProductColourId, DescEN, DescTC, Sort) values ('$ProductCatId', '$ProductColourId', '$DescEN', '$DescTC', '$Sort')";

//echo $sql;

mysql_query($sql);
if( 
mysql_errno() > ){
    echo 
'Product Category Add Error:<br />'mysql_error() .'<br />SQL: '$sql;
    exit;
}

mysql_close($dbh);

header("Location: productcat_index.php?msg=Add Successful");
?>