示例#1
0
function make_rand_accounts()
{
    global $WOIPTeams;
    $names = random_names();
    $n_names = count($names) / 2;
    $d = array();
    $nsuccess = 0;
    for ($i = 0; $i < $n_names; $i++) {
        $d["FirstName"] = $names[$i * 2];
        $d["LastName"] = $names[$i * 2 + 1];
        $d["UserName"] = strtolower(substr($d["FirstName"], 0, 1) . $d["LastName"]);
        $d["Email"] = $d["FirstName"] . $d["LastName"] . "@vcsschools.org";
        $d["Password"] = "******";
        $n = count($WOIPTeams);
        $d["IPT"] = $WOIPTeams[rand(0, $n - 1)];
        $mentor = false;
        $lead = false;
        $member = true;
        $active = true;
        if (rand(0, 9) >= 9) {
            $mentor = true;
        }
        if (!$mentor && rand(0, 9) >= 8) {
            $lead = true;
        }
        if (rand(0, 20) > 19) {
            $active = false;
        }
        $d["Tags"] = "Member/Worker";
        if ($lead) {
            $d["Tags"] .= "/IPTLead";
        }
        if ($mentor) {
            $d["Tags"] .= "/Mentor";
        }
        $d["Active"] = $active;
        $msg = CreateNewUser($d);
        if ($msg === true) {
            $nsuccess++;
        }
        //else echo 'Create Fail.';
    }
    return "Number of Accounts Generated: " . $nsuccess;
}
    // Check for password errors...
    if (!empty($_POST["Password"]) || !empty($_POST["Password2"])) {
        if ($_POST["Password"] != $_POST["Password2"]) {
            $error_msg = "Error: new passwords do not match.";
            goto GenerateHtml;
        }
    }
    if (empty($_POST["Password"]) || empty($_POST["Password2"])) {
        $error_msg = "Error: Password cannot be blank.";
        goto GenerateHtml;
    }
    $data = ExtractValuesFromParamList($param_list);
    // Add or modify important, hidden keys.
    $data["Tags"] = "Member";
    $data["Active"] = true;
    $okay = CreateNewUser($data);
    if ($okay === true) {
        $success_msg = 'User "' . $_POST["UserName"] . '" successfully added.';
        foreach ($param_list as &$param_spec) {
            unset($param_spec["Value"]);
        }
    } else {
        $error_msg = $okay;
    }
}
// Render the page based on state variables that were set above...
// These are: $error_msg, $success_msg, $param_list.
GenerateHtml:
include "forms/header.php";
include "forms/navform.php";
include "forms/members_menubar.php";
function ProcessBulkUsers($filename, &$error_msg)
{
    global $config;
    $loc = rmabs(__FILE__ . ".ProcessBulkUsers");
    $file = fopen($filename, "r");
    if ($file === false) {
        $error_msg = "Unable to open file.";
        return 0;
    }
    $n_okay = 0;
    $n_fail = 0;
    $ln = 1;
    // The first line is the column headers.
    $header = fgetcsv($file);
    $ln++;
    if ($header === false) {
        return $n;
    }
    // Now, do some sanity checks to make sure we have
    // an appropriate file.
    if (!in_array("UserName", $header) || !in_array("LastName", $header) || !in_array("FirstName", $header)) {
        $error_msg = "Input file does not required columns.";
    }
    if (!in_array("Password", $header) && !in_array("PasswordHash", $header)) {
        $error_msg = "Input file does not a password column.";
    }
    $tstart = microtime(true);
    // Time the entire operation...  Don't go over 4 minutes.
    $btimeout = false;
    while (true) {
        $result = set_time_limit(60);
        if ($result == false) {
            log_error($loc, "Unable to set/reset time limit to 20 seconds.");
        }
        $data = fgetcsv($file);
        $ln++;
        if ($data === false) {
            break;
        }
        // Don't process blank lines.
        if (count($data) <= 0) {
            continue;
        }
        if (is_null($data[0])) {
            continue;
        }
        // Organize the data into an associtive array
        $fields = JoinKeyValues($header, $data);
        // Make sure none of the required fields are empty.
        if (empty($fields["UserName"]) || empty($fields["LastName"]) || empty($fields["FirstName"]) || empty($fields["Password"]) && empty($fields["PasswordHash"])) {
            log_msg($loc, 'User not added. Some requried fields are empty. Line ' . $ln);
            $n_fail++;
            continue;
        }
        if (empty($fields["NickName"])) {
            $fields["NickName"] = "";
        }
        if (empty($fields["Title"])) {
            $fields["Title"] = "";
        }
        if (empty($fields["Email"])) {
            $fields["Email"] = "";
        }
        if (empty($fields["Active"])) {
            $fields["Active"] = 0;
        }
        if (empty($fields["Tags"])) {
            $fields["Tags"] = "";
        }
        if (empty($fields["Picture"])) {
            $fields["Picture"] = "";
        }
        if (empty($fields["BadgeID"])) {
            $fields["BadgeID"] = "";
        }
        if (empty($fields["IPT"])) {
            $fields["IPT"] = "";
        }
        $error_msg = CreateNewUser($fields);
        if ($error_msg === true) {
            $n_okay++;
        } else {
            log_msg($loc, array('User not added. Line ' . $ln, $error_msg));
            $n_fail++;
        }
        $telp = microtime(true) - $tstart;
        if ($telp > 240.0) {
            $btimeout = true;
            break;
        }
    }
    $error_msg = $n_okay . ' users added. ' . $n_fail . ' failures. ' . $ln . ' lines processed.';
    if ($btimeout) {
        $error_msg .= ' ** TimeOut Occured, Process aborted. **';
    }
    log_msg($loc, $error_msg);
}