Exemplo n.º 1
0
function ProcessBulkPics($filename, &$error_msg)
{
    global $config;
    $loc = "members_bulkpics.php->ProcessBulkPics";
    $file = fopen($filename, "r");
    if ($file === false) {
        $error_msg = "Unable to open file.";
        return;
    }
    $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("Picture", $header)) {
        $error_msg = "Input file does not required columns.";
        return;
    }
    $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);
        // Skip lines that don't have required data
        if (!isset($fields["UserName"]) || !isset($fields["Picture"])) {
            continue;
        }
        $username = $fields["UserName"];
        $picfile = $fields["Picture"];
        if (empty($username) || empty($picfile)) {
            continue;
        }
        $result = AddPictureToUser($username, $picfile);
        if ($result === true) {
            $n_okay++;
        } else {
            $n_fail++;
        }
        $telp = microtime(true) - $tstart;
        if ($telp > 240.0) {
            $btimeout = true;
            break;
        }
    }
    $error_msg = $n_okay . ' pictures imported. ' . $n_fail . ' failures. ' . $ln . ' lines processed.';
    if ($btimeout) {
        $error_msg .= ' ** TimeOut Occured, Process aborted. **';
    }
    log_msg($loc, $error_msg);
}
Exemplo n.º 2
0
function ProcessCorrectionFile($filename)
{
    $loc = 'readerlib.php=>ProcessLogFile';
    $file = fopen($filename, "r");
    if ($file === false) {
        $error_msg = "Unable to open file.";
        return false;
    }
    $ln = 1;
    $ncorrections = 0;
    $nbad = 0;
    // The first line is the column headers.
    $header = fgetcsv($file);
    $ln++;
    if ($header === false) {
        $m = 'No header for input corrections file, line ' . $ln;
        log_msg($loc, $m);
        echo $m . "<br>";
        return false;
    }
    // Trim the header values...
    $hh = array();
    foreach ($header as $h) {
        $hh[] = trim($h);
    }
    $header = $hh;
    // Now, do some sanity checks to make sure we have
    // an appropriate file.
    if (!in_array("Action", $header) || !in_array("BadgeID", $header) || !in_array("T0", $header) || !in_array("Reason", $header)) {
        dumpit($header);
        $m = "Invalid columns for correction file, line " . $ln;
        log_msg($loc, $m);
        echo $m . "<br>";
        return false;
    }
    while (true) {
        $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 we have required data
        if (!isset($fields["Action"]) || !isset($fields["BadgeID"]) || !isset($fields["T0"])) {
            $m = 'Required data not found in correction file, line ' . $ln;
            log_msg($loc, $m);
            echo $m . "<br>";
            $nbad++;
            continue;
        }
        $action = $fields["Action"];
        $badgeid = strtolower($fields["BadgeID"]);
        if (isset($fields["Reason"])) {
            $reason = $fields["Reason"];
        } else {
            $reason = "(Unknown)";
        }
        // Make sure T0 is a valid time between 2000 and 2030.
        $tme = strtotime($fields["T0"]);
        if ($tme === false) {
            $nbad++;
            continue;
        }
        $d0 = strtotime("2000-01-01");
        $d1 = strtotime("2030-01-01");
        if ($tme < $d0 || $tme > $d1) {
            $nbad++;
            continue;
        }
        // Okay, store the record.
        AddCorrection($action, $badgeid, date("Y-m-d H:i:s", $tme), $reason);
        $ncorrections++;
    }
    return array($ln, $ncorrections, $nbad);
}
Exemplo n.º 3
0
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);
}
function ProcessEventFile($filename)
{
    global $config;
    $loc = "attendance_uploadevents.php->ProcessEventFile";
    $file = fopen($filename, "r");
    if ($file === false) {
        return array(false, "Unable to open file.");
    }
    $n_okay = 0;
    $n_fail = 0;
    $ln = 1;
    // The first line is the column headers.
    $header = fgetcsv($file);
    $ln++;
    if ($header === false) {
        return $n;
    }
    foreach ($header as &$h) {
        $h = trim($h);
    }
    // Now, do some sanity checks to make sure we have
    // an appropriate file.
    if (!in_array("Name", $header) || !in_array("StartTime", $header) || !in_array("EndTime", $header) || !in_array("Type", $header) || !in_array("Purpose", $header)) {
        return array(false, "Input file does not have required columns.");
    }
    $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;
        }
        foreach ($data as &$d) {
            $d = trim($d);
        }
        // Organize the data into an associtive array
        $fields = JoinKeyValues($header, $data);
        // Make sure we have required data
        if (!isset($fields["Name"]) || !isset($fields["StartTime"]) || !isset($fields["EndTime"]) || !isset($fields["Type"]) || !isset($fields["Purpose"])) {
            log_msg($loc, 'Event not added. Fields missing, line ' . $ln);
            $n_fail++;
            continue;
        }
        // Make sure none of the required fields are empty.
        if (empty($fields["Name"]) || empty($fields["StartTime"]) || empty($fields["EndTime"]) || empty($fields["Type"]) || empty($fields["Purpose"])) {
            log_msg($loc, 'Event not added. Some requried fields are empty. Line ' . $ln);
            $n_fail++;
            continue;
        }
        StoreEvent($fields);
        $n_okay++;
        $telp = microtime(true) - $tstart;
        if ($telp > 240.0) {
            $btimeout = true;
            break;
        }
    }
    $msg = $n_okay . ' events added. ' . $n_fail . ' failures. ' . $ln . ' lines processed.';
    if ($btimeout) {
        $msg .= ' ** TimeOut Occured, Process aborted. **';
    }
    log_msg($loc, $msg);
    return array(true, $msg);
}