/var/www/hkosl.com/e-ims/file_manager/user_management.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<script type="text/javascript">
$(document).ready(function(e) {
    $('#adduser_btn')
        .click(function() {
            $('#adduser').submit();
    });
    $("#adduser").validate({
        rules: {
            username: "required",
            loginname: "required"
        },
        messages: {
            username: {
                required: "Please Enter Your User Name"
            },
            loginname: {
                required: "Please Enter Your Login Name"
            }
        }
    });
    $('#modifyuser_btn')
        .click(function() {
            $('#modifyuser').submit();
    });
    $("#modifyuser").validate({
        rules: {
            username: "required",
            loginname: "required"
        },
        messages: {
            username: {
                required: "Please Enter Your User Name"
            },
            loginname: {
                required: "Please Enter Your Login Name"
            }
        }
    });
    $('#check_all')
        .click(function() {
            if($(this).is(':checked')) {
                $(".checkbox").prop('checked', true);
            }    else    {
                $(".checkbox").prop('checked', false);
            }
    });
});
</script>
<?php
include 'config.php';

// Check if the user is logged in

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

if(
$_SESSION['role'] == 'User'){
    
$company_check_sql "SELECT * FROM file_company_user Where userid=:userid";
    
$company_check Db::getDbh()->prepare($company_check_sql);
    
$company_check->execute(array(":userid" => $_SESSION['loginid']));
    if( 
$error $company_check->getError(array(":userid" => $_SESSION['loginid'])) ){
        
var_dump($error);
    }
    
$row_company_check $company_check->fetch(PDO::FETCH_ASSOC);
    
$companyid $row_company_check{'companyid'};
}    else    {
    if(empty(
$_GET["companyid"])){
        
$company_check_sql "SELECT * FROM file_company Where status = '1' order by sort ASC Limit 1";
        
$company_check Db::getDbh()->prepare($company_check_sql);
        
$company_check->execute();
        if( 
$error $company_check->getError() ){
            
var_dump($error);
        }
        
$row_company_check $company_check->fetch(PDO::FETCH_ASSOC);
        
$companyid $row_company_check{'companyid'};
    }    else    {
        
$companyid = (int)$_GET["companyid"];
    }
}
?>
<script type="text/javascript">
$(document).ready(function(e) {
    $('#cancel_btn')
        .click(function() {
            window.location.href = 'index.php?index=<?=$index;?>&companyid=<?=$companyid;?>';
    });
});
</script>
<?php
if($_REQUEST["modifyuser"] == "1"){
    
$modifyuserid = (int)$_GET["modifyuserid"];
    
$modify_user_sql "SELECT
                        file_company_user.companyid,
                        sys_login.loginid,
                        sys_login.username,
                        sys_login.loginname,
                        sys_login.loginpw,
                        sys_login.role,
                        sys_login.`status`,
                        sys_login.createby,
                        sys_login.createdate,
                        sys_login.lastupby,
                        sys_login.lastupdate,
                        sys_login.deleted
                        FROM
                        sys_login
                        INNER JOIN file_company_user ON file_company_user.userid = sys_login.loginid Where sys_login.loginid=:loginid"
;
    
$modify_user Db::getDbh()->prepare($modify_user_sql);
    
$modify_user->execute(array(":loginid" => $modifyuserid));
    if( 
$error $modify_user->getError(array(":loginid" => $modifyuserid)) ){
        
var_dump($error);
    }
    
$row_modify_user $modify_user->fetch(PDO::FETCH_ASSOC);
    echo
"<form action='modify_user.php' method='post' id='modifyuser' name='modifyuser' enctype='multipart/form-data'>
            <input type='hidden' name='loginid' value='"
.$modifyuserid."' />
            <input type='hidden' name='index' value='"
.$index."' />";
    echo
"    <div class='tab_title'>Modify User</div>
            <div class='tab_content'>
                <table class='tab_upload_table' width='400' border='0' cellspacing='0' cellpadding='0'>"
;
    if((
$_SESSION['role'] == 'Superadmin') || ($_SESSION['role'] == 'Admin')){
        echo
"      <tr>
                    <td width='100'>Company</td>
                    <td width='300'>"
;
                    echo
"<select name='companyid'>";
                    
$company_list_sql "SELECT * FROM file_company Where status = '1' ORDER BY sort ASC";
                    
$company_list Db::getDbh()->prepare($company_list_sql);
                    
$company_list->execute();
                    if( 
$error $company_list->getError() ){
                        
var_dump($error);
                    }
                    while (
$row_company_list $company_list->fetch(PDO::FETCH_ASSOC)){
                        echo
"<option value='".$row_company_list{'companyid'}."' ".getSelect($row_company_list{'companyid'}, $row_modify_user{'companyid'}).">".$row_company_list{'title'}."</option>";
                    }
                    echo
"</select>
                    </td>
                  </tr>"
;
    }    else    {
        echo
"<input type='hidden' name='companyid' value='".$row_modify_user{'companyid'}."' />";
    }
    
$modify_role_sql "SELECT * FROM file_role_user Where userid=:userid";
    
$modify_role Db::getDbh()->prepare($modify_role_sql);
    
$modify_role->execute(array(":userid" => $modifyuserid));
    if( 
$error $modify_role->getError(array(":userid" => $modifyuserid)) ){
        
var_dump($error);
    }
    
$row_modify_role $modify_role->fetch(PDO::FETCH_ASSOC);
    echo
"          <tr>
                    <td width='100'>Role</td>
                    <td width='300'>"
;
                    echo
"<select name='roleid'>";
                    
$role_list_sql "SELECT * FROM file_role WHERE status = '1' ORDER BY sort ASC";
                    
$role_list Db::getDbh()->prepare($role_list_sql);
                    
$role_list->execute();
                    if( 
$error $role_list->getError() ){
                        
var_dump($error);
                    }
                    while (
$row_role_list $role_list->fetch(PDO::FETCH_ASSOC)){
                        echo
"<option value='".$row_role_list{'roleid'}."' ".getSelect($row_role_list{'roleid'}, $row_modify_role{'roleid'}).">".$row_role_list{'title'}."</option>";
                    }
                    echo
"</select>";
    echo
"                </td>
                  </tr>
                  <tr>
                    <td width='100'>User Name</td>
                    <td width='300'>
                        <input type='text' id='username' name='username' value='"
.$row_modify_user{'username'}."'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Login Name</td>
                    <td width='300'>
                        <input type='text' id='loginname' name='loginname' value='"
.$row_modify_user{'loginname'}."'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Password</td>
                    <td width='300'>
                        <input type='password' id='loginpw' name='loginpw'>
                        "
.Password::ajax_validate('loginpw''ajax_passwordChecker.php''loginname'false)."
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Confirm Password</td>
                    <td width='300'>
                        <input type='password' name='loginpw_check'>
                    </td>
                  </tr>
                  <tr>
                    <td colspan='2'>
                        <a href='#' id='modifyuser_btn'><div class='tab_content_btn' style='width:50px; background:url(images/save_btn.png) center center no-repeat;'></div></a>
                        <a href='#' id='cancel_btn'><div class='tab_content_btn' style='width:50px; background:url(images/cancel_btn.png) center center no-repeat;'></div></a>
                    </td>
                  </tr>
                </table>
            </div>
        </form>"
;

}    elseif(
$_REQUEST["adduser"] == "1"){
    echo
"<form action='add_user.php' method='post' id='adduser' name='adduser' enctype='multipart/form-data'>
            <input type='hidden' name='index' value='"
.$index."' />";
    echo
"    <div class='tab_title'>Add User</div>
            <div class='tab_content'>
                <table class='tab_upload_table' width='400' border='0' cellspacing='0' cellpadding='0'>"
;
    if((
$_SESSION['role'] == 'Superadmin') || ($_SESSION['role'] == 'Admin')){
        echo
"      <tr>
                    <td width='100'>Company</td>
                    <td width='300'>"
;
                    echo
"<select name='companyid'>";
                    
$company_list_sql "SELECT * FROM file_company Where status = '1' ORDER BY sort ASC";
                    
$company_list Db::getDbh()->prepare($company_list_sql);
                    
$company_list->execute();
                    if( 
$error $company_list->getError() ){
                        
var_dump($error);
                    }
                    while (
$row_company_list $company_list->fetch(PDO::FETCH_ASSOC)){
                        echo
"<option value='".$row_company_list{'companyid'}."' ".getSelect($companyid$row_company_list{'companyid'}).">".$row_company_list{'title'}."</option>";
                    }
                    echo
"</select>
                    </td>
                  </tr>"
;
    }    else    {
        echo
"<input type='hidden' name='companyid' value='".$companyid."' />";
    }
    echo
"          <tr>
                    <td width='100'>Role</td>
                    <td width='300'>"
;
                    echo
"<select name='roleid'>";
                    
$role_list_sql "SELECT * FROM file_role WHERE status = '1' ORDER BY sort ASC";
                    
$role_list Db::getDbh()->prepare($role_list_sql);
                    
$role_list->execute();
                    if( 
$error $role_list->getError() ){
                        
var_dump($error);
                    }
                    while (
$row_role_list $role_list->fetch(PDO::FETCH_ASSOC)){
                        echo
"<option value='".$row_role_list{'roleid'}."'>".$row_role_list{'title'}."</option>";
                    }
                    echo
"</select>";
    echo
"                </td>
                  </tr>
                  <tr>
                    <td width='100'>User Name</td>
                    <td width='300'>
                        <input type='text' id='username' name='username'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Login Name</td>
                    <td width='300'>
                        <input type='text' id='loginname' name='loginname'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Password</td>
                    <td width='300'>
                        <input type='password' id='loginpw' name='loginpw'>
                        "
.Password::ajax_validate('loginpw''ajax_passwordChecker.php''loginname'true)."
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Confirm Password</td>
                    <td width='300'>
                        <input type='password' name='loginpw_check'>
                    </td>
                  </tr>
                  <tr>
                    <td colspan='2'>
                        <a href='#' id='adduser_btn'><div class='tab_content_btn' style='width:100px; background:url(images/add_user.png) center center no-repeat;'></div></a>
                        <a href='#' id='cancel_btn'><div class='tab_content_btn' style='width:50px; background:url(images/cancel_btn.png) center center no-repeat;'></div></a>
                    </td>
                  </tr>
                </table>
            </div>
        </form>"
;
    
}    else    {
    
$i=0;
    echo
"<form action='delete_user.php' method='post' name='deleteuser' enctype='multipart/form-data'>
            <input type='hidden' name='index' value='"
.$index."' />
            <input type='hidden' name='companyid' value='"
.$companyid."' />";
    echo
"<div class='tab_title'>User Management</div>
          <div class='tab_content'>
              <a href='index.php?index="
.$index."&companyid=".$companyid."&adduser=1'><div class='tab_content_btn' style='width:100px; background:url(images/add_user.png) center center no-repeat;'></div></a>
              <a href='#' onclick='deleteuser.submit()'><div class='tab_content_btn' style='width: 80px; background: url(images/delete_btn.png) center center no-repeat; float: right; margin-right: 0px;'></div></a>
              <div style='clear:both;'></div>"
;
    if((
$_SESSION['role'] == 'Superadmin') || ($_SESSION['role'] == 'Admin')){
        echo
"<br>";
        echo
"<select name='select_companyid' onChange=\"MM_jumpMenu('self',this,0)\">";
        
$company_list_sql "SELECT * FROM file_company Where status = '1' ORDER BY sort ASC";
        
$company_list Db::getDbh()->prepare($company_list_sql);
        
$company_list->execute();
        if( 
$error $company_list->getError() ){
            
var_dump($error);
        }
        while (
$row_company_list $company_list->fetch(PDO::FETCH_ASSOC)){
            echo
"<option value='index.php?index=".$index."&companyid=".$row_company_list{'companyid'}."' ".getSelect($companyid$row_company_list{'companyid'}).">".$row_company_list{'title'}."</option>";
        }
        echo
"</select>";
    }
    echo
"      <table class='tab_content_table' width='100%' border='0' cellspacing='0' cellpadding='0'>
                <tr>
                  <td class='title' width='40' align='center'>ID</td>
                  <td class='title' width='240'>User Name</td>
                  <td class='title' width='240'>Login Name</td>
                  <td class='title' width='100'>Role</td>
                  <td class='title' width='100'>Modify By</td>
                  <td class='title' width='150'>Modify Date</td>
                  <td class='title' width='20'></td>
                  <td class='title' width='20'></td>
                  <td class='title' width='20' align='center'><input type='checkbox' class='check_all' id='check_all'></td>
                </tr>"
;
    
$user_list_sql "SELECT
                      sys_login.loginid,
                      sys_login.username,
                      sys_login.loginname,
                      sys_login.lastupby,
                      sys_login.lastupdate,
                      file_company_user.companyid,
                      file_company_user.`status`,
                      file_company_user.sort,
                      file_company_user.deleted
                      FROM
                      file_company_user
                      INNER JOIN sys_login ON file_company_user.userid = sys_login.loginid where file_company_user.companyid=:companyid AND sys_login.status = '1' AND file_company_user.deleted = '0' order by file_company_user.sort ASC"
;
    
$user_list Db::getDbh()->prepare($user_list_sql);
    
$user_list->execute(array(":companyid" => $companyid));
    if( 
$error $user_list->getError(array(":companyid" => $companyid)) ){
        
var_dump($error);
    }
    while (
$row_user_list $user_list->fetch(PDO::FETCH_ASSOC)){
        
$role_info_sql "SELECT file_role.title FROM file_role_user INNER JOIN file_role ON file_role.roleid = file_role_user.roleid WHERE userid=:userid";
        
$role_info Db::getDbh()->prepare($role_info_sql);
        
$role_info->execute(array(":userid" => $row_user_list{'loginid'}));
        if( 
$error $role_info->getError(array(":userid" => $row_user_list{'loginid'})) ){
            
var_dump($error);
        }
        
$row_role_info $role_info->fetch(PDO::FETCH_ASSOC);

        
$modify_info_sql "SELECT * FROM sys_login WHERE loginid=:loginid";
        
$modify_info Db::getDbh()->prepare($modify_info_sql);
        
$modify_info->execute(array(":loginid" => $row_user_list{'lastupby'}));
        if( 
$error $modify_info->getError(array(":loginid" => $row_user_list{'lastupby'})) ){
            
var_dump($error);
        }
        
$row_modify_info $modify_info->fetch(PDO::FETCH_ASSOC);
        echo
"    <tr>
                  <td align='center'>"
.$row_user_list{'loginid'}."</td>
                  <td>"
.$row_user_list{'username'}."</td>
                  <td>"
.$row_user_list{'loginname'}."</td>
                  <td>"
.$row_role_info{'title'}."</td>
                  <td>"
.$row_modify_info{'username'}."</td>
                  <td>"
.$row_user_list{'lastupdate'}."</td>
                  <td align='center'>"
;
        if (
$row_user_list{'loginid'} <> $_SESSION['loginid']){
            if(
$row_user_list{'status'} == '1'){        
                echo
"<a href='status_user.php?index=".$index."&companyid=".$companyid."&loginid=".$row_user_list{'loginid'}."'><img src='images/status_tick.png' alt='Enable'></a>";
            }    else    {
                echo
"<a href='status_user.php?index=".$index."&companyid=".$companyid."&loginid=".$row_user_list{'loginid'}."'><img src='images/status_cross.png' alt='Disable'></a>";
            }
        }
        echo      
"</td>
                  <td align='center'><a href='index.php?index="
.$index."&companyid=".$companyid."&modifyuser=1&modifyuserid=".$row_user_list{'loginid'}."'><img src='images/modify_icon.png' alt='Modify'></a></td>
                  <td align='center'>"
;
        if (
$row_user_list{'loginid'} <> $_SESSION['loginid']){
            echo
"<input type='checkbox' class='checkbox' name='loginid[".$i."]' value='".$row_user_list{'loginid'}."'>";
        }
        echo
"      </td>
                </tr>"
;
        
$i++;
    }
    echo
"      </table>
          </div>"
;
}

function 
getSelect($field1$field2)
{
    if (
$field1 == $field2)
    {
        return 
"selected";
    }
    else
    {
        return 
"";
    }
}
?>