/var/www/hkosl.com/oneMotorChunHing_delete20240201/html/useradd.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
<?
require("inc/configure.php");
require(
"inc/global.php");
require(
"inc/checklogin.php");
if (
$logged_in == 0) {
    
//echo 'Not logged in. <a href="login.php">Login</a>';
    
header('Window-target: _parent');
    
header('Location: login.php');
    exit();
}
if (
checkObject(18) <> 1){
    die(
"Unauthorized Access");
    exit();
}
?>
<?
/*
if ($role){
    foreach ($role as $t)
    {
        echo 'You selected ',$t,'<br />';
    }
}
*/

$userid            $_POST['userid'];
$username        $_POST['username'];
$uname            $_POST['uname'];
$upwd            $_POST['upwd'];
$roleid            $_POST['roleid'];
$status            $_POST['status'];
$creationdate    date("YmdGis");
$creationby     9999;

if (
$userid == "")
{
    
$sql "select * from SYS_USER where uname = '$uname'";
    
$result mysql_query($sql);
    if (
$row mysql_fetch_array($result,MYSQL_ASSOC))
    {
        
$msg "User duplicate!";
    }
    else
    {
        
//**addnew
        
$sql "select max(userid) as maxuserid from SYS_USER";
        
$result mysql_query($sql);
        if (
$row mysql_fetch_array($result,MYSQL_ASSOC))
        {
            if (
strlen($row{'maxuserid'}) == 0)
            {
                
$userid 1001;
            }
            else
            {
                
$userid $row{'maxuserid'} + 1;
            }
        }
        else
        {
            
$userid 1001;
        }

        
$sql =    "insert into SYS_USER 
                (userid, username, uname, upwd, status, creationdate, creationby)
                values(
$userid, '$username', '$uname', '".md5($upwd)."', $status, '$creationdate', $creationby)";

        
$result mysql_query($sql);

        if (!
$result) {
            die(
'Invalid query: ' mysql_error());
        }


        
$sql =    "delete from SYS_USERROLE where userid = $userid";
        
$result mysql_query($sql);
        if (!
$result) {
            die(
'Invalid query: ' mysql_error());
        }

        if (
$roleid){
            foreach (
$roleid as $t)
            {
            
$sql =    "insert into SYS_USERROLE (userid, roleid) values($userid$t)";
            
$result mysql_query($sql);
            if (!
$result) {
                die(
'Invalid query: ' mysql_error());
            }

            }
        }

        
$msg "Created!";
    }
}
else
{
    
$sql "select * from SYS_USER where uname = '$uname' and userid <> $userid";
    
$result mysql_query($sql);
    if (
$row mysql_fetch_array($result,MYSQL_ASSOC))
    {
        
$msg "User duplicate!";
    }
    else
    {
        
//**update
        
if ($upwd == "")
        {
        
$sql =    "update SYS_USER 
                set username    = '
$username'
                , uname            = '
$uname'
                , status        = 
$status
                , updateddate    = '
$creationdate'
                , updatedby        = 
$creationby
                where userid = 
$userid
                "
;
        }
        else
        {
        
$sql =    "update SYS_USER 
                set username    = '
$username'
                , uname            = '
$uname'
                , upwd            = '"
.md5($upwd)."'
                , status        = 
$status
                , updateddate    = '
$creationdate'
                , updatedby        = 
$creationby
                where userid = 
$userid
                "
;
        }
        
$result mysql_query($sql);

        if (!
$result) {
            die(
'Invalid query: ' mysql_error());
        }

        
$sql =    "delete from SYS_USERROLE where userid = $userid";
        
$result mysql_query($sql);
        if (!
$result) {
            die(
'Invalid query: ' mysql_error());
        }

        if (
$roleid){
            foreach (
$roleid as $t)
            {
            
$sql =    "insert into SYS_USERROLE (userid, roleid) values($userid$t)";
            
$result mysql_query($sql);
            if (!
$result) {
                die(
'Invalid query: ' mysql_error());
            }

            }
        }

        
$msg "Updated!";
    }
}
header("Location: user.php?msg=$msg");
?>