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);
}
function ProcessBulkUsers($filename, &$error_msg)
{
    global $config;
    $loc = "adduserbulk.php->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) || !in_array("Password", $header)) {
        $error_msg = "Input file does not 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;
        }
        // Organize the data into an associtive array
        $fields = JoinKeyValues($header, $data);
        // Make sure we have required data
        if (!isset($fields["UserName"]) || !isset($fields["LastName"]) || !isset($fields["FirstName"]) || !isset($fields["Password"])) {
            log_msg($loc, 'User not added. Fields missing, line ' . $ln);
            $n_fail++;
            continue;
        }
        // Make sure none of the required fields are empty.
        if (empty($fields["UserName"]) || empty($fields["LastName"]) || empty($fields["FirstName"]) || empty($fields["Password"])) {
            log_msg($loc, 'User not added. Some requried fields are empty. Line ' . $ln);
            $n_fail++;
            continue;
        }
        if (!isset($fields["NickName"])) {
            $fields["NickName"] = "";
        }
        if (!isset($fields["Title"])) {
            $fields["Title"] = "";
        }
        if (!isset($fields["BadgeID"])) {
            $fields["BadgeID"] = "";
        }
        if (!isset($fields["Email"])) {
            $fields["Email"] = "";
        }
        if (!isset($fields["Active"])) {
            $fields["Active"] = 0;
        }
        if (!isset($fields["Tags"])) {
            $fields["Tags"] = "";
        }
        if (!isset($fields["Picture"])) {
            $fields["Picture"] = "";
        }
        $error_msg = CreateNewUser($fields);
        if ($error_msg === true) {
            $n_okay++;
            // Now, try to upload thier pic... if any.
            if (!empty($fields["Picture"])) {
                AddPictureToUser($fields);
            }
        } 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);
}