/home/banprang/.trash/files/coremain/module/product/product_sub_edit_output.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
// ส่วนจัดการ upload รูปขึ้น sever และ เก็บข้อมูลลง database
import_request_variables('pG''p_');
if(
$p_id_product!="")        {  $id_product=trim($p_id_product);                }
if(
$p_name!="")                {  $name=trim($p_name);                }
if(
$p_description!="")        {  $description=trim($p_description);                }
if(
$p_day_new_product!="")        {  $day_new_product=trim($p_day_new_product);                }
if(
$p_month_new_product!="")    {  $month_new_product=trim($p_month_new_product);            }
if(
$p_year_new_product!="")        {  $year_new_product=trim($p_year_new_product);                }
if(
$p_day_new_product_end!="")    {  $day_new_product_end=trim($p_day_new_product_end);        }
if(
$p_month_new_product_end!=""){  $month_new_product_end=trim($p_month_new_product_end);    }
if(
$p_year_new_product_end!="")    {  $year_new_product_end=trim($p_year_new_product_end);        }
if(
$p_day_promotion!="")        {  $day_promotion=trim($p_day_promotion);                    }
if(
$p_month_promotion!="")        {  $month_promotion=trim($p_month_promotion);                }
if(
$p_year_promotion!="")        {  $year_promotion=trim($p_year_promotion);                    }
if(
$p_day_promotion_end!="")    {  $day_promotion_end=trim($p_day_promotion_end);            }
if(
$p_month_promotion_end!="")    {  $month_promotion_end=trim($p_month_promotion_end);        }
if(
$p_year_promotion_end!="")    {  $year_promotion_end=trim($p_year_promotion_end);            }



$data_link select_query_object("*","cms_product","id_product",$id_product);

$picture=trim($_FILES['picture_file']['name']);
$attach_file=trim($_FILES['attach_file']['name']);

$fail_case = -1;
$pic_check 0;
bar_header("แก้ไขข้อมูลเรียบร้อย"); // Bar_Header


// promotion and new product check
if($_POST[is_new_product]){
    
$new_product_flag =1;
     
$date_start_product$year_new_product.$month_new_product.$day_new_product;
     
$date_end_product $year_new_product_end.$month_new_product_end.$day_new_product_end;
     
      
$sql "update cms_product set is_new_product = '1'  , start_new = '$date_start_product' , end_new = '$date_end_product' where id_product = $id_product";
     
mysql_query ($sql) or die (mysql_error());
}
else
{
    
$new_product_flag =0;
}
if (
$_POST[is_promotion])
{
    
$promotion_flag 1;
     
$date_start_promotion $year_promotion.$month_promotion.$day_promotion;
     
$date_end_promotion $year_promotion_end.$month_promotion_end.$day_promotion_end;
       
$sql "update cms_product set is_promotion = '1'  , start_promo = '$date_start_promotion' , end_promo = '$date_end_promotion' where id_product = $id_product";
     
mysql_query ($sql) or die (mysql_error());
}
else
{
    
$promotion_flag 0;
}

if(
$attach_file!=""){
        
$str  "123456789abcdefghijkmnpqrstuvwxyz";
        
$file_type explode(".",$attach_file);
        
$old_attach_name $attach_file;
        
$file_att substr(str_shuffle($str), 08);
        
$file_attach_name="file$file_att.$file_type[1]";
                
$dlink=$_SESSION['web_name']."/module_product/attach/".$file_attach_name;
                    
$temp_file_name=$_FILES['attach_file']['tmp_name'];
                    if (
is_uploaded_file($_FILES['attach_file']['tmp_name'])) {
                        if(!
move_uploaded_file($temp_file_name,$dlink)){ // check upload
                            
echo "กรุณาติดต่อผู้ดูแลระบบให้เปิดการเขียนไฟล์";
                            die;
                            }
                                else 
// remove old file
                            
{
                            
                            if(
file_exists($_SESSION['web_name']."/module_product/attach/".$data_link->attach_file))
                                
unlink ($_SESSION['web_name']."/module_product/attach/".$data_link->attach_file);
                                
                                
mysql_query ("update cms_product set old_attach_name = '$attach_file'  , attach_file = '$file_attach_name' where id_product = $id_product");
                        }
                    }
}

if(
$picture!=""){
$pic_check 1;

while(
$fail_case != 0)
{
        
$strings1=substr($picture,-4);
            if(
$strings1!=".gif" and $strings1!=".jpg" and $strings1!=".GIF" and $strings1!=".JPG"){
                
$fail_case 1;    
                break;
        }
        
$str  "123456789abcdefghijkmnpqrstuvwxyz";
        
$pic substr(str_shuffle($str), 05);
        
$strings=substr($picture,-4);
        
$name1="pic$pic$strings";
        
                     
$dlink=$_SESSION['web_name']."/module_product/picture/".$name1;
                    
                    
$temp_name=$_FILES['picture_file']['tmp_name'];
                    if (
is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
                        if(!
move_uploaded_file($temp_name,$dlink)){
                            
$fail_case 2;
                            break;
                        }
                        else 
// remove old file
                        
{
                            if(
file_exists($_SESSION['web_name']."/module_product/picture/".$data_link->picture))
                                
unlink ($_SESSION['web_name']."/module_product/picture/".$data_link->picture);    

                                
mysql_query ("update cms_product set picture = '$name1' where id_product = $id_product");
                            
                        }
                    }
    
    list(
$width$height$type$attr) = getimagesize("$_SESSION[web_name]/module_product/picture/$name1");
    if(
$width>500) {
        
unlink ("$_SESSION[web_name]/module_product/picture/$name1");
        
$fail_case 3;
        break;
    }
    if(
$height>500) {
        
unlink ("$_SESSION[web_name]/module_product/picture/$name1");
        
$fail_case 4;
        break;
    }
    
$fail_case 0;
    break;
 }
}
    if(
$fail_case==or $pic_check == 0)
    {
        if(
$fail_case == 0)
        {
            
$sql_new_pic "UPDATE cms_product SET picture = '$name1' WHERE id_product = $id_product";
            
mysql_query ($sql_new_pic);
        }
        
        
$sql "UPDATE cms_product SET name = '$name', description = '$description' WHERE id_product = $id_product";
    
        
mysql_query ($sql) or die (mysql_error());
        echo 
"<center><br><br>ข้อมูลได้ถูกแก้ไขแล้ว<br><br></center>"
        echo 
"<meta http-equiv='refresh' content='2; url=index.php?mod=product_firstpage&path=product'>" ;
    }else{
        if(
$fail_case==1)
            echo 
"<center><br><br>ชนิดของรูปต้องเป็น GIF หรือ JPEG เท่านั้น<br><br></center>"
        else if (
$fail_case==2)
            echo 
"<center><br><br>ไม่สามารถ Upload ไฟล์ได้ กรุณาติดต่อผู้ดูแลระบบ เพื่อเปิดการเขียนไฟล์<br><br></center>"
        else if (
$fail_case==3)
            echo 
"<center><br><br>รูปสูงเกินกว่าขนาดที่กำหนด<br><br></center>"
        else if (
$fail_case==4)
            echo 
"<center><br><br>รูปยาวกว่าขนาดที่กำหนด<br><br></center>"
        else 
            echo 
"<center><br><br>เกิดข้อผิดพลาด<br><br></center>"
        
// refresh    
        
echo "<meta http-equiv='refresh' content='2; url=index.php'>" ;
    
    }
?>