/var/www/hkosl.com/littleark/webadmin/sys_cms_user_modify.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
<?php
    $page_settings 
= array(
        
'formid'     => 'Sys_cms_user'// for permission
        
'section'    => 'System Setting'// parent/page title
        
'subsection' => 'User Management'// page title
        
'domain'     => 'sys_cms_user'// table/model name
        
'access'     => 'GNu'// for permission
    
);

    require_once 
"check_login.php";
    require_once 
'function_auth.php';

    
// error_reporting(E_ALL);
    // ini_set('display_errors', 1);

    
$cmsloginid    = (int)$_POST["cmsloginid"];
    
$cms_user_info SysCmsLogin::where('cmsloginid''='$_SESSION["cmsloginid"])->first();

    
$message "";

    if (empty(
$_POST["username"])) {
        
$message .= _lang("Please enter User Name.") . "\\n\\n";
    }

    
$supplier_id 0;
    
$agent_id 0;
    if (
$cms_user_info["cmsrole"] != "user") {

        if (
$cms_user_info["is_platform"] == 1) {

            if (empty(
$_POST["role_type"])) {
                
$message .= _lang("Please select Role Type.") . "\\n\\n";
            } else {
                if (
$_POST["role_type"] == "SUPPLIER") {
                    
$is_platform 0;
                    
$is_supplier 1;
                    
$is_agent    0;
                    if (empty(
$_POST["supplier_id"])) {
                        
$message .= _lang("Please select Supplier.") . "\\n\\n";
                    }

                    
$supplier_id $_POST["supplier_id"];
                } else if (
$_POST["role_type"] == "PLATFORM") {
                    
$is_platform 1;
                    
$is_supplier 0;
                    
$is_agent    0;
                    
$supplier_id 0;
                } else if (
$_POST["role_type"] == "AGENT") {
                    
$is_platform 0;
                    
$is_supplier 0;
                    
$is_agent    1;
                    if (empty(
$_POST["agent_id"])) {
                        
$message .= _lang("Please select Agent.") . "\\n\\n";
                    }
                    
$agent_id    $_POST["agent_id"];
                }
            }
        }

    }

    if (empty(
$_POST["loginname"])) {
        
$message .= _lang("Please enter Login Name.") . "\\n\\n";
    }

    if (!empty(
$message)) {
        echo 
"<script>alert('" $message "'); history.back();</script>";
        exit;
    }


    if (
strlen($_POST["loginpw"]) > 0) {
        
$strength Password::strength($_POST["loginpw"], $_POST["username"]);
        if (!
$strength) {
            exit(
_lang('Insufficient password strength'));
        }
        
$cmsloginpw Password::hash($_POST["loginpw"]);

    }
    
$nowdate date("Y-m-d H:i:s");

    
$sql        "SELECT * FROM sys_cms_login where cmsloginname = ? AND cmsloginid <> ? and deleted = ?";
    
$parameters = array($_POST["loginname"], $_POST["cmsloginid"], 0);
    
$result     bind_pdo($sql$parameters"selectone");
    if (!empty(
$result)) {
        
header("Location: sys_cms_user_index.php?msg=" _lang("You have already been assigned a login name."));
        exit;
    }

    
// Modify

    
if (strlen($_POST["loginpw"]) > 0) {
        if (
$cms_user_info["cmsrole"] == "user" || $cms_user_info["is_platform"] == 0) {
            
$sql        "update sys_cms_login set cmsusername=?, cmsloginname=?, cmsrole=?, lastupdate=?, lastupby=?, cmsloginpw=? where cmsloginid=?";
            
$parameters = array($_POST["username"], $_POST["loginname"], $_POST["role_level"], $nowdate$_SESSION["cmsloginid"], $cmsloginpw$_POST["cmsloginid"]);
            
bind_pdo($sql$parameters);
        } else {
            
$sql        "update sys_cms_login set cmsusername=?, cmsloginname=?, cmsrole=?, lastupdate=?, lastupby=?, cmsloginpw=?, is_platform=?, is_supplier=?, supplier_id=?, is_agent=?, agent_id=? where cmsloginid=?";
            
$parameters = array($_POST["username"], $_POST["loginname"], $_POST["role_level"], $nowdate$_SESSION["cmsloginid"], $cmsloginpw$is_platform$is_supplier$supplier_id$is_agent$agent_id$_POST["cmsloginid"]);
            
bind_pdo($sql$parameters);
        }


        unset(
$_SESSION['loginname']);
        unset(
$_SESSION['password']);
        unset(
$_SESSION['loginid']);
        unset(
$_SESSION['cmsloginid']);
        unset(
$_SESSION['role']);
        unset(
$_SESSION['cmsrole']);

        
header("Location: sys_cms_user_index.php?msg=2");

        
/*header("Location: login.php");
        exit;*/

    
} else {
        if (
$cms_user_info["cmsrole"] == "user" || $cms_user_info["is_platform"] == 0) {
            
$sql        "update sys_cms_login set cmsusername=?, cmsloginname=?, cmsrole=?, lastupdate=?, lastupby=? where cmsloginid=?";
            
$parameters = array($_POST["username"], $_POST["loginname"], $_POST["role_level"], $nowdate$_SESSION["cmsloginid"], $_POST["cmsloginid"]);
            
bind_pdo($sql$parameters);
        } else {
            
$sql        "update sys_cms_login set cmsusername=?, cmsloginname=?, cmsrole=?, lastupdate=?, lastupby=?,is_platform=?, is_supplier=?, supplier_id=?, is_agent=?, agent_id=? where cmsloginid=?";
            
$parameters = array($_POST["username"], $_POST["loginname"], $_POST["role_level"], $nowdate$_SESSION["cmsloginid"], $is_platform$is_supplier$supplier_id$is_agent$agent_id$_POST["cmsloginid"]);
            
bind_pdo($sql$parameters);
        }

        
header("Location: sys_cms_user_index.php?msg=2");
    }