Esempio n. 1
0
function extractFormElementsGroup($sqlQuery, $showLinks, $userID, $displayType, $originalDisplayType)
{
    global $tableRefs, $tableUserData;
    // defined in 'db.inc.php'
    $groupSearchSelector = $_REQUEST['groupSearchSelector'];
    // extract the user group chosen by the user
    $groupSearchSelector = preg_quote($groupSearchSelector, "/");
    // escape possible meta characters within group names (otherwise the RLIKE SQL query that's generated below might fail)
    if (!empty($originalDisplayType)) {
        // NOTE: if the user submits the 'groupSearch' form from Browse view, we currently don't display
        //       the group's entries in Browse view but switch to the user's default view instead
        if ($originalDisplayType == "Browse") {
            // note that, as long as the 'groupSearch' form doesn't transmit a 'submit' parameter, the next line
            // isn't strictly necessary (since then '$displayType' will already contain the user's default view)
            $displayType = $_SESSION['userDefaultView'];
        } else {
            // re-assign the correct display type (i.e. the view that was active when the user clicked the 'Show' button of the 'groupSearch' form):
            $displayType = $originalDisplayType;
        }
    }
    if (preg_match("/^(Cite|Display)\$/i", $displayType)) {
        if (preg_match("/^Display\$/i", $displayType) and isset($_SESSION['lastDetailsViewQuery'])) {
            $previousSelectClause = extractSELECTclause($_SESSION['lastDetailsViewQuery']);
            // function 'extractSELECTclause()' is defined in 'include.inc.php'
            $query = buildSELECTclause($displayType, $showLinks, "", false, true, $previousSelectClause);
            // function 'buildSELECTclause()' is defined in 'include.inc.php'
        } else {
            // generate a new SELECT clause that's appropriate for Citation view (or Details view):
            $query = buildSELECTclause($displayType, $showLinks);
        }
    } elseif ($originalDisplayType != "Browse" and !empty($sqlQuery)) {
        // use the custom set of colums chosen by the user:
        $previousSelectClause = extractSELECTclause($sqlQuery);
        $query = buildSELECTclause("", $showLinks, "", false, true, $previousSelectClause);
    } else {
        // use the default SELECT statement:
        $query = buildSELECTclause("", $showLinks, "user_groups", false, true);
    }
    if ($originalDisplayType != "Browse" and !empty($sqlQuery)) {
        // use the custom ORDER BY clause chosen by the user:
        $queryOrderBy = extractORDERBYclause($sqlQuery);
    } else {
        // add the default ORDER BY clause:
        $queryOrderBy = "author, year DESC, publication";
    }
    $query .= " FROM {$tableRefs} LEFT JOIN {$tableUserData} ON serial = record_id AND user_id = " . $userID;
    // add FROM clause
    $query .= " WHERE user_groups RLIKE " . quote_smart("(^|.*;) *" . $groupSearchSelector . " *(;.*|\$)");
    // add WHERE clause
    $query .= " ORDER BY " . $queryOrderBy;
    // add ORDER BY clause
    return array($query, $displayType);
}
Esempio n. 2
0
function extractFormElementsGroup($sqlQuery)
{
    global $tableUsers;
    // defined in 'db.inc.php'
    if (!empty($sqlQuery)) {
        // use the custom set of colums chosen by the user:
        $query = "SELECT " . extractSELECTclause($sqlQuery);
        // function 'extractSELECTclause()' is defined in 'include.inc.php'
        // user the custom ORDER BY clause chosen by the user:
        $queryOrderBy = extractORDERBYclause($sqlQuery);
        // function 'extractORDERBYclause()' is defined in 'include.inc.php'
    } else {
        $query = "SELECT first_name, last_name, abbrev_institution, email, last_login, logins, user_id";
        // use the default SELECT statement
        $queryOrderBy = "last_login DESC, last_name, first_name";
        // add the default ORDER BY clause
    }
    $groupSearchSelector = $_REQUEST['groupSearchSelector'];
    // extract the user group chosen by the user
    $query .= ", user_id";
    // add 'user_id' column (although it won't be visible the 'user_id' column gets included in every search query)
    // (which is required in order to obtain unique checkbox names as well as for use in the 'getUserID()' function)
    $query .= " FROM {$tableUsers}";
    // add FROM clause
    $query .= " WHERE user_groups RLIKE " . quote_smart("(^|.*;) *" . $groupSearchSelector . " *(;.*|\$)");
    // add WHERE clause
    $query .= " ORDER BY " . $queryOrderBy;
    // add ORDER BY clause
    return $query;
}