/var/www/(Del)tsolpv.com/2013/webadmin/productcat_delete.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
include 'config.php';

// Check if the user is logged in

if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1'))
{
header("Location: login.php");
exit;
}
require(
"configure.php");

$pdcatid         $_GET["pdcatid"];
$parentid     $_GET["parentid"];
$pdcatsort     $_GET["pdcatsort"];

function 
getChildCategoryInfos($parentid, &$ids, &$bannerens, &$bannerscs)
{
    
$sql "select group_concat(pdcatid) as pdcatids, group_concat(pdcatbanneren) as pdcatbannerens, group_concat(pdcatbannersc) as pdcatbannerscs from product_cat where parentid = $parentid group by parentid ";
    
$result mysql_query($sql);
    if (
mysql_num_rows($result)>0)
    {
        
$row mysql_fetch_array($resultMYSQL_ASSOC);
        foreach (
explode(","$row['pdcatbannerens']) as $banneren)
            
$bannerens[] = $banneren;
        foreach (
explode(","$row['pdcatbannerscs']) as $bannersc)
            
$bannerscs[] = $bannersc;
        foreach (
explode(","$row['pdcatids']) as $id)
        {
            
$ids[] = $id;
            
getChildCategoryInfos($id$ids$bannerens$bannerscs);
        }
    }
}

$ids = array($pdcatid);
$bannerens = array();
$bannerscs = array();
getChildCategoryInfos($pdcatid$ids$bannerens$bannerscs);

//Delete image
$sql "SELECT * FROM product_cat WHERE pdcatid="$pdcatid ." ";
$result=mysql_query($sql);
$row mysql_fetch_array($result,MYSQL_ASSOC);
unlink("../pagebanner/".$row{'pdcatbanneren'});
unlink("../pagebanner/".$row{'pdcatbannersc'});
foreach (
$bannerens as $banneren)
    
unlink("../pagebanner/".$banneren);
foreach (
$bannerscs as $bannersc)
    
unlink("../pagebanner/".$bannersc);

// Delete db
$idString implode(','$ids);
$sql "DELETE FROM product_det_cat WHERE pdcatid IN ("$idString .") ";
mysql_query($sql);
if( 
mysql_errno() > ){
    echo 
'Delete 产品项目 Category Error:<br />'mysql_error() .'<br />SQL: '$sql;
    exit;
}

$sql "DELETE FROM product_cat WHERE pdcatid IN ("$idString .") ";
mysql_query($sql);
if( 
mysql_errno() > ){
    echo 
'Delete 产品类别 Error:<br />'mysql_error() .'<br />SQL: '$sql;
    exit;
}

mysql_query("UPDATE product_cat SET pdcatsort = pdcatsort-1 WHERE parentid=$parentid pdcatsort >= $pdcatsort ");

/*
// Because deleted category, but remain the product_det and product_img
// Find out all the non use product_det first
$sql = "
select group_concat(pd.pdid) as pdids from product_det pd
left join product_det_cat pdc on pdc.pdid = pd.pdid
where pdc.pdid is null
";
$result=mysql_query($sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$idString = $row['pdids'];
if (strlen($idString))
{
    $sql = "DELETE FROM product_det WHERE pdid IN ($idString)";
    mysql_query($sql);
    if( mysql_errno() > 0 )
    {
        echo 'Delete 产品项目 Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
        exit;
    }
    
    $sql = "SELECT * FROM product_img WHERE pdid IN ($idString)";
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
        unlink("../products/large/".$row['pimgfile']);
        unlink("../products/thumb/".$row['pimgfile']);
    }
    
    $sql = "DELETE FROM product_img WHERE pdid IN ($idString)";
    mysql_query($sql);
    if( mysql_errno() > 0 )
    {
        echo 'Delete 产品项目(Images) Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
        exit;
    }
}
*/

mysql_close($dbh);

header("Location: productcat_index.php?pid=$parentid&msg=删除成功");

?>