/var/www/enzatesting.onesolution.hk/inc/webadminfunc.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php 
function substring_index($subject$delim$count){
    if(
$count 0){
        return 
implode($delimarray_slice(explode($delim$subject), $count));
    }else{
        return 
implode($delimarray_slice(explode($delim$subject), 0$count));
    }
}
//var_dump(substring_index("ABF0512-D01-V55", '-', 2));

function replace_space($str){
    return 
strtolower(str_replace(" ""-"$str));
}

function 
nvl (&$key$else "") {
    return (isset(
$key) ? $key : ((!empty($else)) ? $else ""));
}

function 
evl_old (&$key$else "") {
    return (!empty(
$key) ? $key : ((!empty($else)) ? $else ""));
}

function 
evl () {
    
//vdump(func_get_args());
    
$args func_get_args();
    foreach(
$args as $arg){
        if(!empty(
$arg)){
            return 
$arg;
        }
    }
    return 
"";
}

function 
zvl ($key$else "") {
    return (
$key==$key : ((!empty($else)) ? $else ""));
}

function 
StripTrailingComma ($StringToStrip){

    if (
strrpos($StringToStrip,"'")){
        return 
mb_substr($StringToStrip,0,strrpos($StringToStrip,"'"));
    } else {
        return 
$StringToStrip;
    }
}

function 
pdo_showerror($sth$q$param=''){
    
//global $sth;
    
if(!$q and DEBUG>)
    {
        
$dump error_get_last();
        print
"Execute query error, because: ".$dump['message']."<br/><pre>";
        print 
$sth->getSQL().HTML_EOL;
        
var_dump$sth->errorInfo() );
        print
"</pre>";
        
        
        
adderrorlog'SQL error'$dump['message'].PHP_EOL.$sth->getSQL( (array)$param) );
        exit;
    }
    
}

function 
createUserChangeLog($prefix '-'){
    return 
$pretix .  date("Y-m-d H:i:s") . ' (' filter_var($_SESSION['user'], FILTER_SANITIZE_STRING) . ')' PHP_EOL;
}
//echo createUserChangeLog();

function createthumb($name,$filename,$new_w,$new_h)
    {
    
$system=explode('.',$name);
    
//var_dump($system);
    
$extensionPos sizeof($system)-1;
    if (
preg_match('/jpg|jpeg|JPG|JPEG/i',$system[$extensionPos])){
        
$src_img=imagecreatefromjpeg($name);
        
//echo"jpg";
    
}
    if (
preg_match('/gif|GIF/i',$system[$extensionPos])){
        
$src_img=imagecreatefromgif($name);
        
//echo"gif";
    
}
    if (
preg_match('/png|PNG/i',$system[$extensionPos])){
        
$src_img=imagecreatefrompng($name);
        
//echo"png";
    
}

    
$old_x=imageSX($src_img);
    
$old_y=imageSY($src_img);
    if (
$old_x $old_y) {
        
$thumb_w=$new_w;
        
$thumb_h=$old_y*($new_h/$old_x);
        
/*$thumb_w=$old_x*($new_w/$old_y);
        $thumb_h=$new_h;*/
    
}
    if (
$old_x $old_y) {
        
/*$thumb_w=$old_x*($new_w/$old_y);
        $thumb_h=$new_h;*/
        
$thumb_w=$new_w;
        
$thumb_h=$old_y*($new_h/$old_x);
    }
    if (
$old_x == $old_y) {
        
$thumb_w=$new_w;
        
$thumb_h=$new_h;
    }

    
$dst_img imagecreatetruecolor($thumb_w,$thumb_h);
    
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
/*    $red = imagecolorallocate($dst_img, 255, 0, 0);
    $green = imagecolorallocate($dst_img, 0, 255, 0);
    $blue = imagecolorallocate($dst_img, 0, 0, 255);
    $black = imagecolorallocate($dst_img, 0, 0, 0);
    // Make the background transparent
    imagecolortransparent($dst_img, $black);

    // Draw a red rectangle
    imagefilledrectangle($dst_img, 4, 4, 50, 25, $red, $green, $blue);*/


    
if (preg_match("/png|PNG/i",$system[1])){        
        
imagepng($dst_img,$filename5); 
        
//die('imagepng');
    
} else if (preg_match("/gif|GIF/i",$system[1])) {
        
imagegif($dst_img,$filename); 
    } else {
        
imagejpeg($dst_img,$filename100); 
    }
    
imagedestroy($dst_img); 
    
imagedestroy($src_img); 


/*function logAction($logLevel, $sqlexec=""){
    
    global $dbh;
    $sql = "INSERT INTO audit_adminlog SET
            logLevel    = :logLevel
            page        = :page, 
            ipaddress    = :ipaddress, 
            sessionID    = :sessionID,
            userID        = :userID,
            sqlexec        = :sqlexec,
            created        = NOW()";
    $sth = $dbh->prepare($sql);  
    $sth->execute( array(    
                            ':logLevel'        => $logLevel,
                            ':page'            => $_SERVER['PHP_SELF'],
                            ':ipaddress'     => getRealIpAddr(),
                            ':userID'         => $_SESSION['oos_userID'],
                            ':sqlexec'         => $sqlexec,
                            ':sessionID'    => session_id()                            
                        ) ); 
}*/
/*
* logLevel : 1=page, 2=sqlexec
*

function logAction($logLevel){
    
    global $dbh;
    $sql = "INSERT INTO audit_adminlog SET
            logLevel    = :logLevel
            page        = :page, 
            ipaddress    = :ipaddress, 
            sessionID    = :sessionID,
            userID        = :userID,
            created        = NOW()";
    $sth = $dbh->prepare($sql);  
    $sth->execute( array(    
                            ':logLevel'        => $logLevel,
                            ':page'            => $_SERVER['PHP_SELF'],
                            ':ipaddress'     => getRealIpAddr(),
                            ':userID'         => $_SESSION['oos_userID'],
                            ':sessionID'    => session_id()                            
                        ) ); 
}*/
?>