/var/www/hkosl.com/kelvin/webadmin/product_cat_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
<?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         check_input($_GET["pdcatid"]);
$parentid             check_input($_GET["parentid"]);
$pdcatsort     check_input($_GET["pdcatsort"]);

//Delete Category
function getAllCategoryID($pid){                
    
$rtnString "";
    
$sqlCmd " SELECT pdcatid FROM product_cat WHERE parentid="$pid ." ";
    
$result mysql_query($sqlCmd);
    if (
mysql_num_rows$result)>&& mysql_num_rows($result) >0)
    {                   
       while(
$row mysql_fetch_array($resultMYSQL_ASSOC))
       {
                 
$rtnString .= $row{'pdcatid'} .",".  getAllCategoryID($row{'pdcatid'});                 
                 
       }
    }
    return 
$rtnString;                                     
}

//Delete Image file
/*$result            = mysql_query("SELECT * FROM product_cat WHERE pdcatid='".$pdcatid."' ");
$row            = mysql_fetch_array($result,MYSQL_ASSOC);
if($row['pdcatimgen'] <> ''){
    unlink("../images/product/cat/".$row{'pdcatimgen'});
}
if($row['pdcatimgtc'] <> ''){
    unlink("../images/product/cat/".$row{'pdcatimgtc'});
}
*/

//Delete Category
$sql1 "DELETE FROM product_cat ";
$sql1 .= "where pdcatid in (".substr($pdcatid.','.getAllCategoryID($pdcatid),0, -1).")";
mysql_query($sql1);
if( 
mysql_errno() > ){
    echo 
'Delete Product Category Error:<br />'mysql_error() .'<br />SQL: '$sql1;
    exit;
}
// Update Category Sort
mysql_query("UPDATE product_cat SET pdcatsort = pdcatsort-1 WHERE parentid="$parentid ." AND pdcatsort >= $pdcatsort ");

mysql_close($dbh);

header("Location: product_cat_index.php?pid=$parentid&msg=Delete Successful");

?>