Exemple #1
0
function SavePrefsForUser($userid, $prefs)
{
    $loc = "preflib.php->SavePrefsForUser";
    // First, start with current set of preferences so that we
    // don't duplicate any new ones.
    $current_prefs = GetPrefsForUser($userid);
    // Separate the new prefs into those that already exist,
    // and those that are truely new.
    $new_prefs = array();
    $changed_prefs = array();
    foreach ($prefs as $key => $value) {
        if (array_key_exists($key, $current_prefs)) {
            // The key is alreay in the database. If the value is the
            // same, then we don't need to re-save it.
            if ($value != $current_prefs[$key]) {
                $changed_prefs[$key] = $value;
            }
        } else {
            // The key is new.
            $new_prefs[$key] = $value;
        }
    }
    // Now, update the database table for each pref that is
    // already in the table.
    foreach ($changed_prefs as $key => $value) {
        $sql = 'UPDATE Prefs SET PrefValue = "' . $value . '" WHERE UserID=' . intval($userid) . ' AND PrefName="' . SqlClean($key) . '"';
        $result = SqlQuery($loc, $sql);
    }
    // Finally, insert the new prefereces into the table.
    foreach ($new_prefs as $key => $value) {
        $sql = 'INSERT INTO Prefs (UserID, PrefName, PrefValue) VALUES (' . intval($userid) . ', "' . SqlClean($key) . '", "' . SqlClean($value) . '")';
        $result = SqlQuery($loc, $sql);
    }
    log_msg($loc, count($prefs) . ' preferences updated/saved successfully for user ' . intval($userid));
}
Exemple #2
0
function StartLogin($name, $pw, $bypass)
{
    global $config;
    $loc = "userlib.php->StartLogin";
    $_SESSION["LoggedIn"] = false;
    log_msg($loc, "checking=" . $name . ', bypass='******'SELECT UserID, UserName, PasswordHash, LastName, FirstName, Tags, Active FROM Users ';
    $sql .= 'WHERE UserName="******"';
    $result = SqlQuery($loc, $sql);
    if ($result->num_rows < 1) {
        log_msg($loc, 'Login failure for username: "******". User not found.');
        return false;
    }
    $row = $result->fetch_assoc();
    if (empty($row["Active"])) {
        log_msg($loc, 'Login failure for username "' . $name . '". User not active.');
        return false;
    }
    $pwHash = crypt($pw, $config["Salt"]);
    if ($row["PasswordHash"] != $pwHash) {
        if (!$bypass) {
            log_msg($loc, 'Login failure for username "' . $name . '". Password mismatch. ');
            return false;
        }
        log_msg($loc, 'User "' . $name . '" used bypass feature to avoid password match.');
    }
    $_SESSION["LoggedIn"] = true;
    $_SESSION["Login_Time"] = time();
    $_SESSION["Login_UserID"] = $row["UserID"];
    $_SESSION["Login_UserName"] = $name;
    $_SESSION["Login_LastName"] = $row["LastName"];
    $_SESSION["Login_FirstName"] = $row["FirstName"];
    $_SESSION["Login_Tags"] = ArrayFromSlashStr($row["Tags"]);
    $_SESSION["Login_IsAdmin"] = CheckForTag("admin");
    $_SESSION["Login_IsGuest"] = CheckForTag("guest");
    $_SESSION["Login_IsEditor"] = CheckForTag("editor");
    $_SESSION["Login_IsIPTLead"] = CheckForTag("iptlead");
    $_SESSION["Login_IsCaptain"] = CheckForTag("captain");
    $_SESSION["Login_IsMentor"] = CheckForTag("mentor");
    $_SESSION["Login_IsWorker"] = CheckForTag("worker");
    // Get all the current preferences.
    $_SESSION["Prefs"] = GetPrefsForUser(GetUserID());
    $lines = array();
    array_push($lines, ">>>>>>>>>>> " . $row["LastName"] . ', ' . $row["FirstName"]);
    array_push($lines, "New Login!  UserName="******"UserName"] . ',   UserID=' . $row["UserID"]);
    array_push($lines, "IP Address= " . $_SERVER["REMOTE_ADDR"] . "    Tags=" . $row["Tags"]);
    array_push($lines, "Browser=" . $_SERVER["HTTP_USER_AGENT"]);
    log_msg($loc, $lines);
    return true;
}
function GetLastDayForAttendance()
{
    $prefs = GetPrefsForUser(0);
    if (isset($prefs["LastDay"])) {
        $r = strtotime($prefs["LastDay"]);
        if ($r === false) {
            return date("Y-m-d");
        }
        return $prefs["LastDay"];
    }
    return date("Y-m-d");
}
    if ($update === false) {
        $success_msg = "No changes given.";
        goto GenerateHtml;
    }
    // Looks like we are okay to update database!
    $newdata = array();
    foreach ($param_list as $param_spec) {
        $n = $param_spec["FieldName"];
        $v = $param_spec["Value"];
        if ($n == "LastDay") {
            $r = strtotime($v);
            if ($r === false) {
                $error_msg = "Undecodeable time value, try again.";
                goto GenerateHtml;
            }
            $v = date("Y-m-d", $r);
        }
        $newdata[$n] = $v;
    }
    SavePrefsForUser(0, $newdata);
    $data = GetPrefsForUser(0);
    PopulateParamList($param_list, $data);
    $success_msg = "Data Updated!";
    goto GenerateHtml;
}
GenerateHtml:
include "forms/header.php";
include "forms/navform.php";
include "forms/attendance_menubar.php";
include "forms/attendance_setup_form.php";
include "forms/footer.php";