Esempio n. 1
0
function register($login, $password, $nick)
{
    global $MYSQL_HANDLE, $SALT;
    $login = protect_string($login);
    $nick = protect_string($nick);
    $passwd = md5($password . $SALT);
    if (strlen($login) <= 10 && strlen($password) <= 10 && strlen($nick) <= 15 && is_user_exist($login, $password) == false) {
        mysqli_query($MYSQL_HANDLE, "insert into `users` set `login`='{$login}', `password`='{$passwd}', `nickname`='{$nick}';");
        return true;
    } else {
        return false;
    }
}
function read_excel_and_insert_into_database($target_file, $userid)
{
    // return {"status":, error:[{"line":"1", "message":"xxx error"},{"line":"", "message":""}, ...]}
    $users = array();
    global $file_status;
    // load file
    try {
        $input_file_type = PHPExcel_IOFactory::identify($target_file);
        $reader = PHPExcel_IOFactory::createReader($input_file_type);
        $excel = $reader->load($target_file);
    } catch (Exception $e) {
        $file_status->status = ERR_FILE_LOAD;
        array_push($file_status->errors, array("sheet" => 0, "lines" => 0, "message" => $e->getMessage()));
        return $file_status->status;
    }
    // parse file
    $sheet_count = $excel->getSheetCount();
    for ($cur_sheet = 0; $cur_sheet < $sheet_count; $cur_sheet++) {
        $sheet = $excel->getSheet($cur_sheet);
        $sheet_title = $sheet->getTitle();
        //print_r($sheet_title);
        if ($sheet_title == "上传名单说明") {
            continue;
        }
        // if sheet name is xxxx, skip it
        $highest_row = $sheet->getHighestRow();
        $highest_col = count($file_status->upload_user_syntax);
        $tmp = array();
        for ($col = 0; $col <= $highest_col; $col++) {
            array_push($tmp, trim($sheet->getCellByColumnAndRow($col, 1)->getValue()));
        }
        if (!is_valid_syntax_import_file($tmp)) {
            $file_status->status = ERR_FILE_LOAD;
            array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => 0, "message" => MSG_ERR_FILE_CONTENT_SYNTAX));
            return $file_status->status;
        }
        for ($row = 2; $row <= $highest_row; $row++) {
            $tmp = array();
            $functions = array();
            for ($col = 0; $col <= $highest_col; $col++) {
                array_push($tmp, trim($sheet->getCellByColumnAndRow($col, $row)->getValue()));
            }
            if (is_empty_row($tmp)) {
                continue;
            }
            $cur_user = new UploadUser($tmp);
            if (!is_correct_user_eid_format($cur_user->EmployeeId)) {
                $file_status->status = ERR_FILE_LOAD;
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "message" => MSG_ERR_USER_EID_FORMAT));
            }
            if (!is_correct_user_name_format($cur_user->UserName)) {
                $file_status->status = ERR_FILE_LOAD;
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "message" => MSG_ERR_USER_NAME_FORMAT));
            }
            if (!is_correct_user_email_format($cur_user->Email)) {
                $file_status->status = ERR_FILE_LOAD;
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "message" => MSG_ERR_USER_EMAIL_FORMAT));
            }
            if (!is_correct_user_dept_format($cur_user->DeptCode)) {
                $file_status->status = ERR_FILE_LOAD;
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "message" => MSG_ERR_USER_DEPT_FORMAT));
            }
            $detp_id = get_dept_id_from_database($cur_user->DeptCode);
            if ($detp_id == ERR_USER_DEPT_NOT_EXIST) {
                $file_status->status = ERR_FILE_LOAD;
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "message" => "{$product_name} 不存在"));
            } else {
                $cur_user->DeptId = $detp_id;
            }
            $canapprove = get_canapprove_from_tf($cur_user->CanApprovestr);
            $cur_user->CanApprove = $canapprove;
            if (is_user_exist($cur_user)) {
                array_push($file_status->errors, array("sheet" => $cur_sheet, "lines" => $row, "UserName" => $cur_user->UserName, "EmployeeId" => $cur_user->EmployeeId, "message" => "此用户系统中已存在!"));
            } else {
                array_push($users, $cur_user);
            }
        }
    }
    if ($file_status->status == UPLOAD_SUCCESS) {
        return write_into_database($users, $userid);
    } else {
        return $file_status->status;
    }
}
Esempio n. 3
0
<?php

include 'API.php';
set_connection("localhost", "root", "", "kekuruso");
if (isset($_POST['login']) && isset($_POST['password'])) {
    $logi = htmlspecialchars($_POST['login']);
    $pas = htmlspecialchars($_POST['password']);
    if (is_user_exist($logi, $pas) == false) {
        header("Location: reg.html");
    } else {
        login($logi, $pas);
        header("Location: action3.php");
    }
}
?>

<html>
	<head>
		<title>login</title>
		<link rel="stylesheet" href="login.css">
	</head>
	<body>
	<div class ="div_a">
		<a href ="index.php" class = "a1">log in</a>
		<a href ="reg.html" class = "a2">registration</a>
	</div>
	<div class= "formachka">
		<form action="" method="post">
			<p class ="ppp"> login: <br> <input type="text" name="login" maxlength="10"/></p>
			<p class ="ppp"> password: <br> <input type="password" name="password" maxlength="10"/></p>
			<p class ="pp"><input type="submit" value="Login in" class = "mysubmit"/></p>