/home/banprang/domains/plai.go.th/public_html/coremain/module/product/product_del.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
<?php
import_request_variables
('pG''p_');
if(
$p_id_product!="")                        {         $id_product=trim($p_id_product);                }

bar_header("ลบข้อมูล");

if(
id_top_permission("g"))
{
        
delete_product($id_product);
}

echo 
"<center><br><br>ลบข้อมูลเรียบร้อยแล้ว<br><br></center>"
        echo 
"<meta http-equiv='refresh' content='2; url=index.php?mod=product_firstpage&path=product'>" ;


function 
delete_product($my_id_product){

global 
$_SESSION;
     
$sql "SELECT * FROM cms_product WHERE id_product = $my_id_product";
    
$res mysql_query ($sql) or die (mysql_error());
    
    while (
$del mysql_fetch_array ($res))
    {
        
$sql2 "SELECT * FROM cms_product WHERE id_parent = $del[id_product]";
        
$res2 mysql_query ($sql2) or die (mysql_error());
        while (
$del2 mysql_fetch_array ($res2))
        {
            
delete_product($del2[id_product]);
        }
        
        if(
$del[data_type]==1){ // main delete
            
$sql_main "SELECT * FROM cms_product WHERE id_product = ".$del[id_product];
            
$res_main mysql_query ($sql_main);
            
$dat_main mysql_fetch_object ($res_main);
            
            
            if(
file_exists($_SESSION[web_name]."/module_product/picture_main/".$del[picture]))
            {
                @
unlink($_SESSION[web_name]."/module_product/picture_main/".$del[picture]);
            }
             
$sql_del_main "DELETE FROM cms_product WHERE id_product = ".$dat_main->id_product;
            
            
mysql_query ($sql_del_main) or die ("xxxx");
            
            
            
$sql_count "SELECT COUNT(*) as num FROM cms_product WHERE id_parent = ".$del[id_parent];
            
$res_count mysql_query ($sql_count) or die ("xxx");
            
$dat_count mysql_fetch_object ($res_count);
            
$num_child $dat_count->num;
            if (
$num_child == 0)
            {
                
$sql_update "UPDATE cms_product SET has_child = 0 WHERE id_product = ".$del[id_parent];
                
mysql_query ($sql_update) or die ("zzzz");
            }    
            
            
        }
        
        
// =====================================================================================
        
        
        
if($del[data_type]==2){ // sub delete
        
if(file_exists($_SESSION[web_name]."/module_product/picture/".$del[picture]))
            {
                @
unlink($_SESSION[web_name]."/module_product/picture/".$del[picture]);
            }
            if(
file_exists($_SESSION[web_name]."/module_product/attach/".$del[attach_file]))
            {
                @
unlink($_SESSION[web_name]."/module_product/attach/".$del[attach_file]);
            }
            
            
$sql_del "DELETE FROM cms_product WHERE id_product=$del[id_product] and is_static=0";
            
mysql_query ($sql_del) or die (mysql_error());
            
            
$sql_count "SELECT COUNT(*) as num FROM cms_product WHERE id_parent = ".$del[id_parent];
            
$res_count mysql_query ($sql_count) or die ("xxx");
            
$dat_count mysql_fetch_object ($res_count);
            
$num_child $dat_count->num;
            if (
$num_child == 0)
            {
                
$sql_update "UPDATE cms_product SET has_child = 0 WHERE id_product = ".$del[id_parent];
                
mysql_query ($sql_update) or die ("zzzz");
            }    
        
        }
        
        
    }
}
?>