コード例 #1
0
ファイル: include.inc.php プロジェクト: Olari0/Finugriling
function getFieldContents($tableName, $columnName, $userID = "", $queryWhereClause = "", $orderBy = "", $getDistinctValues = true)
{
    global $tableRefs, $tableUserData;
    // defined in 'db.inc.php'
    connectToMySQLDatabase();
    if ($getDistinctValues) {
        $distinct = "DISTINCT ";
    } else {
        $distinct = "";
    }
    // CONSTRUCT SQL QUERY:
    $query = "SELECT " . $distinct . $columnName . " FROM " . $tableName;
    if ($tableName == $tableRefs and isset($_SESSION['loginEmail']) and !empty($userID)) {
        // when querying table 'refs', and if a user is logged in...
        $query .= " LEFT JOIN " . $tableUserData . " ON serial = record_id AND user_id = " . quote_smart($userID);
    }
    if (!empty($queryWhereClause)) {
        $query .= " WHERE " . $queryWhereClause;
    }
    if (!empty($orderBy)) {
        $query .= " ORDER BY " . $orderBy;
    }
    $result = queryMySQLDatabase($query);
    // RUN the query on the database through the connection
    $fieldContentsArray = array();
    // initialize array variable
    $rowsFound = @mysql_num_rows($result);
    if ($rowsFound > 0) {
        while ($row = @mysql_fetch_array($result)) {
            // for all rows found
            $fieldContentsArray[] = $row[$columnName];
        }
        // append this row's field value to the array of extracted field values
    }
    return $fieldContentsArray;
}
コード例 #2
0
} else {
    $origRecord = "";
}
if (isset($formVars['dupRecords'])) {
    $dupRecords = $formVars['dupRecords'];
} else {
    $dupRecords = "";
}
// Extract serial numbers (i.e. discard any non-digit characters from the original user input):
$origRecordSerial = preg_replace("/\\D*(\\d+).*/", "\\1", $origRecord);
// extract the first number given
$dupRecordSerialsArray = preg_split("/\\D+/", $dupRecords, -1, PREG_SPLIT_NO_EMPTY);
// extract all given serial numbers (the 'PREG_SPLIT_NO_EMPTY' flag causes only non-empty pieces to be returned)
// --------------------------------------------------------------------
// (1) OPEN CONNECTION, (2) SELECT DATABASE
connectToMySQLDatabase();
// function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
// --------------------------------------------------------------------
// VALIDATE data fields:
// NOTE: for all fields that are validated here must exist error parsing code (of the form: " . fieldError("origRecord", $errors) . ")
//       in front of the respective <input> form field in 'duplicate_manager.php'! Otherwise the generated error won't be displayed!
// Validate the 'Original' field:
if (empty($origRecord) or !preg_match("/\\d/", $origRecord)) {
    $errors["origRecord"] = "You must specify a serial number for the original record:";
} elseif (preg_match("/\\d\\D+\\d/", $origRecord)) {
    $errors["origRecord"] = "You can only specify a single record as original entry:";
} elseif (in_array($origRecordSerial, $dupRecordSerialsArray)) {
    $errors["origRecord"] = "The original record cannot be one of the duplicate records:";
}
// the serial number of the original record must not be given within the list of duplicate serial numbers
// Validate the 'Duplicates' field:
コード例 #3
0
ファイル: user_login.php プロジェクト: Olari0/Finugriling
function check_login($referer, $loginEmail, $loginPassword)
{
    global $username;
    global $password;
    global $hostName;
    global $databaseName;
    global $connection;
    global $HeaderString;
    global $loginUserID;
    global $loginFirstName;
    global $loginLastName;
    global $adminLoginEmail;
    global $abbrevInstitution;
    global $tableAuth, $tableUserData, $tableUsers;
    // defined in 'db.inc.php'
    global $loc;
    // Get the two character salt from the email address collected from the challenge
    $salt = substr($loginEmail, 0, 2);
    // Encrypt the loginPassword collected from the challenge (so that we can compare it to the encrypted passwords that are stored in the 'auth' table)
    $crypted_password = crypt($loginPassword, $salt);
    // CONSTRUCT SQL QUERY:
    $query = "SELECT user_id FROM {$tableAuth} WHERE email = " . quote_smart($loginEmail) . " AND password = "******"errors");
        }
        // function 'deleteSessionVariable()' is defined in 'include.inc.php'
        if (isset($_SESSION['formVars'])) {
            // delete the 'formVars' session variable:
            deleteSessionVariable("formVars");
        }
        // function 'deleteSessionVariable()' is defined in 'include.inc.php'
        $userID = $row["user_id"];
        // extract the user's userID from the last query
        // Now we need to get the user's first name and last name (e.g., in order to display them within the login welcome message)
        $query = "SELECT user_id, first_name, last_name, abbrev_institution, language, last_login FROM {$tableUsers} WHERE user_id = " . quote_smart($userID);
        // CONSTRUCT SQL QUERY
        $result = queryMySQLDatabase($query);
        // RUN the query on the database through the connection (function 'queryMySQLDatabase()' is defined in 'include.inc.php')
        $row2 = mysql_fetch_array($result);
        // EXTRACT results: fetch the one row into the array '$row2'
        // Save the fetched user details to the session file:
        // Write back session variables:
        saveSessionVariable("loginEmail", $loginEmail);
        // function 'saveSessionVariable()' is defined in 'include.inc.php'
        saveSessionVariable("loginUserID", $row2["user_id"]);
        saveSessionVariable("loginFirstName", $row2["first_name"]);
        saveSessionVariable("loginLastName", $row2["last_name"]);
        saveSessionVariable("abbrevInstitution", $row2["abbrev_institution"]);
        saveSessionVariable("userLanguage", $row2["language"]);
        saveSessionVariable("lastLogin", $row2["last_login"]);
        // Get all user groups specified by the current user
        // and (if some groups were found) save them as semicolon-delimited string to the session variable 'userGroups':
        getUserGroups($tableUserData, $row2["user_id"]);
        // function 'getUserGroups()' is defined in 'include.inc.php'
        if ($loginEmail == $adminLoginEmail) {
            // ('$adminLoginEmail' is specified in 'ini.inc.php')
            // Get all user groups specified by the admin
            // and (if some groups were found) save them as semicolon-delimited string to the session variable 'adminUserGroups':
            getUserGroups($tableUsers, $row2["user_id"]);
        }
        // function 'getUserGroups()' is defined in 'include.inc.php'
        // Get all user queries that were saved previously by the current user
        // and (if some queries were found) save them as semicolon-delimited string to the session variable 'userQueries':
        getUserQueries($row2["user_id"]);
        // function 'getUserQueries()' is defined in 'include.inc.php'
        // Get all export formats that were selected previously by the current user
        // and (if some formats were found) save them as semicolon-delimited string to the session variable 'user_export_formats':
        getVisibleUserFormatsStylesTypes($row2["user_id"], "format", "export");
        // function 'getVisibleUserFormatsStylesTypes()' is defined in 'include.inc.php'
        // Get all citation formats that were selected previously by the current user
        // and (if some formats were found) save them as semicolon-delimited string to the session variable 'user_cite_formats':
        getVisibleUserFormatsStylesTypes($row2["user_id"], "format", "cite");
        // function 'getVisibleUserFormatsStylesTypes()' is defined in 'include.inc.php'
        // Get all citation styles that were selected previously by the current user
        // and (if some styles were found) save them as semicolon-delimited string to the session variable 'user_styles':
        getVisibleUserFormatsStylesTypes($row2["user_id"], "style", "");
        // function 'getVisibleUserFormatsStylesTypes()' is defined in 'include.inc.php'
        // Get all document types that were selected previously by the current user
        // and (if some types were found) save them as semicolon-delimited string to the session variable 'user_types':
        getVisibleUserFormatsStylesTypes($row2["user_id"], "type", "");
        // function 'getVisibleUserFormatsStylesTypes()' is defined in 'include.inc.php'
        // Get the user permissions for the current user
        // and save all allowed user actions as semicolon-delimited string to the session variable 'user_permissions':
        getPermissions($row2["user_id"], "user", true);
        // function 'getPermissions()' is defined in 'include.inc.php'
        // Get the default view for the current user
        // and save it to the session variable 'userDefaultView':
        getDefaultView($row2["user_id"]);
        // function 'getDefaultView()' is defined in 'include.inc.php'
        // Get the default number of records per page preferred by the current user
        // and save it to the session variable 'userRecordsPerPage':
        getDefaultNumberOfRecords($row2["user_id"]);
        // function 'getDefaultNumberOfRecords()' is defined in 'include.inc.php'
        // Get the user's preference for displaying auto-completions
        // and save it to the session variable 'userAutoCompletions':
        getPrefAutoCompletions($row2["user_id"]);
        // function 'getPrefAutoCompletions()' is defined in 'include.inc.php'
        // Get the list of "main fields" for the current user
        // and save the list of fields as comma-delimited string to the session variable 'userMainFields':
        getMainFields($row2["user_id"]);
        // function 'getMainFields()' is defined in 'include.inc.php'
        // We also update the user's entry within the 'users' table:
        $query = "UPDATE {$tableUsers} SET " . "last_login = NOW(), " . "logins = logins+1 " . "WHERE user_id = {$userID}";
        // RUN the query on the database through the connection:
        $result = queryMySQLDatabase($query);
        // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
        if (!preg_match("#/(error|user_login|install)\\.php#i", $referer)) {
            header("Location: " . $referer);
        } else {
            header("Location: index.php");
        }
        // back to main page
    } else {
        // Ensure 'loginEmail' is not registered, so the user is not logged in
        if (isset($_SESSION['loginEmail'])) {
            // delete the 'loginEmail' session variable:
            deleteSessionVariable("loginEmail");
        }
        // function 'deleteSessionVariable()' is defined in 'include.inc.php'
        // Save an error message:
        $HeaderString = "<b><span class=\"warning\">" . $loc["LoginFailedYouProvidedAnIncorrectEmailAddressOrPassword"] . "</span></b>";
        // Write back session variables:
        saveSessionVariable("HeaderString", $HeaderString);
        // function 'saveSessionVariable()' is defined in 'include.inc.php'
        login_page($referer);
    }
    // -------------------
    // (5) CLOSE the database connection:
    disconnectFromMySQLDatabase();
    // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
}