/var/www/(Del)eizo.hkosl.com/global/webadmin/serial_number_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
<?php
    
include 'config.php';

    
// Check if the user is logged in

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

    $serial_number_id 
=(int)$_GET["serial_number_id"];

    
$sql "select * from serial_number where serial_number_id=?";
    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    if (!
$sth->execute(array($serial_number_id))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    
$row $sth->fetch(PDO::FETCH_ASSOC);

    
$series_code $row{"series_code"};
    
$model_code $row{"model_code"};
    
$serial_number $row{"serial_number"};
    
$regoin $row{"regoin"};

    
//check if this model has been record for a warranty
    
$sql "select * from serial_number where region=? and series_code=? and model_code=? and serial_number=? and deleted=?";
    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    if (!
$sth->execute(array($regoin,$series_code,$model_code,$serial_number"0"))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    if(
$sth->rowCount() > 0){
        echo 
"<script>alert('This model already linked with some customer warranty. You could not modify it.'); history.back();</script>";
        exit;
    }

    
// Delete db
    
$sql "update serial_number set deleted = ? WHERE serial_number_id=? ";

    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }

    if (!
$sth->execute(array("1"$serial_number_id))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
    }else{
        
header("Location: serial_number_index.php?msg=Delete Successfully");
    }

    
$dbh null;

?>