/var/www/hkosl.com/sinomax/survey/webadmin/sys_cms_user_add.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
<?php
    
require_once('check_login.php');
    require_once 
'function_auth.php';

    if (!isset(
$_SESSION['role']) || $_SESSION['role'] == "user") {
        echo 
"<script>alert('You cannot create user.'); location.href='index.php';</script>";
        exit;
    }

    
$strength Password::strength($_POST["loginpw"], $_POST["username"]);
    if (!
$strength) {
        exit(
'Insufficient password strength');
    }
    
$loginpw Password::hash($_POST["loginpw"]);
    
$nowdate date("Y-m-d H:i:s");
    
//print_r($_POST);

    
$sth1 $dbh->prepare("SELECT * FROM sys_cms_login where cmsloginname = ? and deleted = ?");
    
//$sth1->execute(array($_POST["loginname"]));
    
if (!$sth1->execute(array($_POST["loginname"], 0)))
        throw new 
Exception('[' $sth1->errorCode() . ']: ' $sth1->errorInfo());

    if (
$sth1->fetchColumn() > 0) {
        
header("Location: sys_cms_user_index.php?msg=5");
        exit;
    }

    
$sth2 $dbh->prepare("select max(cmsloginid) as maxid from sys_cms_login ");
    
$sth2->execute();
    
$row2 $sth2->fetch(PDO::FETCH_ASSOC);

    
$loginid $row2{"maxid"} + 1;

    
$sth3 $dbh->prepare("insert into sys_cms_login (cmsloginid, cmsusername, cmsloginname, cmsloginpw, cmsrole, cmsstatus, createdate, lastupdate) values (?, ?, ?, ?, ?, ?, ?, ?)");

    if (!
$sth3->execute(array($loginid$_POST["username"], $_POST["loginname"], $loginpw$_POST["role"], "1"$nowdate$nowdate)))
        throw new 
Exception('[' $sth3->errorCode() . ']: ' $sth3->errorInfo());


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