C:\xampp\htdocs\kptv2\admin\php\inc\db\libfunc_old.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
function InsertRecord($valsArr$required$tableName$retCodes$parserFunc) {
    global 
$db_name;
    global 
$db_host;
    global 
$db_password;
    global 
$db_usrName;
    
    
$tableName_ "TBL_" $tableName;
    global $
$tableName_;
    
$tableP = $$tableName_;
    
$tableClassName_ "Data" $tableName;
    
$parsedVars = array();
    
    if(
$parserFunc != "") {
        
$parsedVars $parserFunc();
        if(!
is_array($parsedVars))
            return 
$parsedVars// error code
            
    
}
    
// loop table definition build insert
    
$values = array();    
    foreach(
$tableP->rows as $row_) {
        
$name $row_->name;
        
// try from parsed vars
        
if(array_key_exists($name$parsedVars)) {
            if((
$row_->IsNumeric()) && ($parsedVars[$name] == null))
                
$values[] = 0;
            else                
                
$values[] = $parsedVars[$name];
        }
        else if(
array_key_exists($name$valsArr)) { // try from get 
            
if(($row_->IsNumeric()) && ($valsArr[$name] == null))
                
$values[] = 0;
            else
                
$values[] = $valsArr[$name];
        }
        else { 
// temporary check if id replace when setting auto_increment
            
if($name == "ID")
                
$values[] = 0;            
            else {
                
print_r($name "Missing");
                
header("location:index.html?st=5&cnt_=" $retCodes[1]);
                exit();
            }
        }
    }
    
$db = new DbMySql($db_host$db_usrName$db_password$db_name);
    
//$db->query_echo = 1;
    
if(!$db->bConnected) {
        
header("location:index.html?st=2&mod=" $retCodes[1]);
        exit();
    }
    else {
        if(
$db->Insert($$tableName_$values))
            
header("location:index.html?st=" $retCodes[0] ."&cnt_=" $retCodes[1]);            
        else
            
header("location:index.html?st=5&cnt_=" $retCodes[1]);            
    }
}


function 
UpdateRecord($whereName$whereValue$tableName$required$fieldsName$fieldsValues$retCodes$parserFunc ="") {
    global 
$db_name;
    global 
$db_host;
    global 
$db_password;
    global 
$db_usrName;
    
    
$tableName_ "TBL_" $tableName;
    global $
$tableName_;
    
$tableP = $$tableName_;
    
$tableClassName_ "Data" $tableName;
    
$parsedVars = array();
    
    if(
$parserFunc != "") {
        
$parsedVars $parserFunc();
        if(!
is_array($parsedVars))
            return 
$parsedVars// error code
    
}

    
$values = array();    
    
$names = array();
    foreach(
$fieldsName as $field) {
        if(
array_key_exists($field$parsedVars)) {
            
$values[] = $parsedVars[$field];
            
$names[] = $field;
        }
        else if(
array_key_exists($field$fieldsValues)) {
            
$values[] = $fieldsValues[$field];
            
$names[] = $field;
        }
    }
    
    global 
$LIBPATH;
    require_once(
$LIBPATH "DataFeeder/DataFeeder.php");
    
$feeder = new DataFeeder();
    
    if(
$ret $feeder->ParseGetPost($whereValue)) {
        
header("location:index.html?st=$ret&mod=" $retCodes[1]);
        exit();
    }
    
    
// connect and update
    
$db = new DbMySql($db_host$db_usrName$db_password$db_name);
//    $db->query_echo = 1;
    
if(!$db->bConnected) {
        
header("location:index.html?st=2&mod=" $retCodes[1]);
        exit();
    }
    else {
        if(
$db->Update($$tableName_$whereName$whereValue$values$names))
            
header("location:index.html?st=" $retCodes[0] ."&cnt_=" $retCodes[1]);            
        else
            
header("location:index.html?st=5&cnt_=" $retCodes[1]);            
    }    
}

function 
DeleteRecord($tableName$fieldName$values$retCodes) {
    global 
$db_name;
    global 
$db_host;
    global 
$db_password;
    global 
$db_usrName;
    
$db = new DbMySql($db_host$db_usrName$db_password$db_name);
//    $db->query_echo = 1;
    
if(!$db->bConnected) {
        
header("location:index.html?st=2&mod=" $retCodes[1]);
        exit();
    }
    else {
        
$retCode $retCodes[0];
        global $
$tableName;
        foreach(
$values as $value) {
            if(!
$db->Delete($$tableName$fieldName$value))
                
$retCode $retCodes[0];
        }
    }
    
header("location:index.html?cnt_=" $retCodes[1] . "&st=$retCode"); 
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586