/var/www/hkosl.com/ergofito/webadmin/content/banner/banner_process.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
<?php
    
include_once('../../check_login.php');
    
ini_set('display_errors',0);
    
    
$id $_POST['id'];
    
    if(
$id){
        
//update db
        
$data $_POST;
        unset(
$data['x']);
        unset(
$data['y']);
        unset(
$data['id']);
        
$data['lastupdate'] = $nowdate;
        
$data['lastupby'] = $_SESSION['cmsloginid'];
        
$sql mysql_install($data,'banner','edit','refid');
        
$data['refid'] = $id;
        
$arraykey=array_keys($data);
        for(
$i=0;$i<count($arraykey);$i++){
            
$parameters[$i]=$data[$arraykey[$i]];
        }
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        
$action 'Save Success';
    }else{
        
//insert db
        
$sql "select max(refid) as max_refid from banner";
        
$parameters = array("0");
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        
$member_info $sth->fetch(PDO::FETCH_ASSOC);
        
$data $_POST;
        unset(
$data['x']);
        unset(
$data['y']);
        
$data['refid'] = $member_info{"max_refid"} + 1;
        
$data['status'] = 1;
        
$data['createdate'] = $nowdate;
        
$data['createby'] = $_SESSION['cmsloginid'];
        
$data['lastupdate'] = $nowdate;
        
$data['lastupby'] = $_SESSION['cmsloginid'];
        
$sql mysql_install($data,'banner','add');
        
$arraykey=array_keys($data);
        for(
$i=0;$i<count($arraykey);$i++){
            
$parameters[$i]=$data[$arraykey[$i]];
        }
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        
$id $data['refid'];
        
$action 'Add Success';
    }
    
// Upload File
    
if ($_FILES["photo"]['name'] <> '') {
        
//check if image type is valid or not
        
$filename $_FILES["photo"]['name'];
        
preg_match("/\.([^\.]+)$/"$filename$file_ext);
        
$newfilename random_string(10) . "_banner_refid_" $id "." $file_ext[1]; // default length 8
        
move_uploaded_file($_FILES["photo"]['tmp_name'], "../../../file/banner/" $newfilename) or die ("Could not copy the file");
        
$photo $newfilename;
        unset(
$data);
        unset(
$parameters);
        
$data['photo'] = $photo;
        
$sql mysql_install($data,'banner','edit','refid');
        
$data['refid']=$id;
        
$arraykey=array_keys($data);
        for(
$i=0;$i<count($arraykey);$i++){
            
$parameters[$i]=$data[$arraykey[$i]];
        }
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
        }
    }
    
header("Location: banner_index.php?msg=".$action);    
?>