Exemplo n.º 1
0
function extractFormElementsQuick($sqlQuery, $showLinks, $userID, $displayType, $originalDisplayType)
{
    global $tableRefs, $tableUserData;
    // defined in 'db.inc.php'
    global $defaultFieldsListViewMajor;
    // these variables are specified in 'ini.inc.php'
    global $defaultFieldsListViewMinor;
    global $query;
    $quickSearchSelector = $_REQUEST['quickSearchSelector'];
    // extract field name chosen by the user
    $quickSearchName = $_REQUEST['quickSearchName'];
    // extract search text entered by the user
    $userMainFieldsArray = preg_split("/ *, */", $_SESSION['userMainFields']);
    // get the list of "main fields" preferred by the current user
    if (!empty($originalDisplayType)) {
        // NOTE: if the user submits the 'quickSearch' form from Browse view, we currently don't display
        //       the new search results in Browse view but switch to the user's default view instead
        if ($originalDisplayType == "Browse") {
            // note that, as long as the 'quickSearch' 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 'Search' button of the 'quickSearch' form):
            $displayType = $originalDisplayType;
        }
    }
    // Build SELECT clause:
    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);
        }
    } else {
        if ($quickSearchSelector == "main_fields") {
            $additionalFields = $defaultFieldsListViewMinor;
            // note that for the "main fields" option, we simply display the default list of columns
        } else {
            // if the default list of "major" fields (to be displayed in List view) doesn't already contain the chosen field name...
            // (which is e.g. the case for the 'keywords' & 'abstract' fields)
            if (!preg_match("/" . $quickSearchSelector . "/", $defaultFieldsListViewMajor)) {
                $additionalFields = $quickSearchSelector;
            } else {
                $additionalFields = $defaultFieldsListViewMinor;
            }
            // ...otherwise, add further default columns
        }
        $query = buildSELECTclause("", $showLinks, $additionalFields, false, true, $defaultFieldsListViewMajor);
    }
    // Build FROM clause:
    if (isset($_SESSION['loginEmail'])) {
        // if a user is logged in...
        $query .= " FROM {$tableRefs} LEFT JOIN {$tableUserData} ON serial = record_id AND user_id = " . $userID;
    } else {
        // NO user logged in
        $query .= " FROM {$tableRefs}";
    }
    // Build WHERE clause:
    $query .= " WHERE";
    // we construct a hierarchical '$searchArray' from the given search field name(s) & value;
    // this array then gets merged into a full SQL WHERE clause by function 'appendToWhereClause()'
    $searchArray = array();
    $searchArray[] = array("_boolean" => "", "_query" => "serial RLIKE \".+\"");
    if ($quickSearchName != "") {
        if ($quickSearchSelector == "main_fields") {
            $searchSubArray = array();
            foreach ($userMainFieldsArray as $userMainField) {
                $searchSubArray[] = array("_boolean" => "OR", "_query" => $userMainField . " RLIKE " . quote_smart($quickSearchName));
            }
            $searchArray[] = array("_boolean" => "AND", "_query" => $searchSubArray);
        } else {
            $searchArray[] = array("_boolean" => "AND", "_query" => $quickSearchSelector . " RLIKE " . quote_smart($quickSearchName));
        }
    }
    appendToWhereClause($searchArray);
    // function 'appendToWhereClause()' is defined in 'include.inc.php'
    // Build ORDER BY clause:
    $query .= " ORDER BY ";
    if ($originalDisplayType != "Browse" and !empty($sqlQuery)) {
        // use the custom ORDER BY clause chosen by the user:
        $query .= extractORDERBYclause($sqlQuery);
    } else {
        // add the default ORDER BY clause:
        $query .= "author, year DESC, publication";
    }
    return array($query, $displayType);
}
Exemplo n.º 2
0
}
// -------------------------------------------------------------------------------------------------------------------
// Handle the special index 'main_fields':
if (!(preg_match("/^suggest\$/i", $operation) and preg_match("/^(html|json)\$/i", $recordSchema)) and preg_match("/^main_fields( +(all|any|exact|within) +| *(<>|<=|>=|<|>|=) *)/i", $cqlQuery)) {
    // if the 'main_fields' index is used in conjunction with a non-"suggest" operation
    $cqlQuery = preg_replace("/^main_fields(?= +(all|any|exact|within) +| *(<>|<=|>=|<|>|=) *)/i", "cql.serverChoice", $cqlQuery);
}
// replace 'main_fields' index (which, ATM, is only supported for search suggestions) with 'cql.serverChoice'
// Parse CQL query:
$searchArray = parseCQL("1.1", $cqlQuery, $operation);
// function 'parseCQL()' is defined in 'webservice.inc.php'
// Build SQL WHERE clause:
$query = "";
// NOTE: although we don't supply a full SQL query here, the variable MUST be named '$query' to have function 'appendToWhereClause()' work correctly
if (!empty($searchArray)) {
    appendToWhereClause($searchArray);
}
// function 'appendToWhereClause()' is defined in 'include.inc.php'
// -------------------------------------------------------------------------------------------------------------------
// Check that mandatory parameters have been passed:
// - if 'opensearch.php' was called with 'operation=explain', we'll return an appropriate OpenSearch description document:
if (preg_match("/^explain\$/i", $operation)) {
    // Use an appropriate default stylesheet:
    if ($exportStylesheet == "DEFAULT") {
        $exportStylesheet = "";
    }
    // TODO: create a stylesheet ('opensearchDescription2html.xsl') that's appropriate for the OpenSearch description
    // Set the appropriate mimetype & set the character encoding to the one given
    // in '$contentTypeCharset' (which is defined in 'ini.inc.php'):
    setHeaderContentType("application/opensearchdescription+xml", $contentTypeCharset);
    // function 'setHeaderContentType()' is defined in 'include.inc.php'
Exemplo n.º 3
0
function appendToWhereClause($searchArray)
{
    global $query;
    foreach ($searchArray as $searchArrayItem) {
        if (!preg_match("/\\(\$/", $query)) {
            $query .= " ";
            if (!empty($searchArrayItem["_boolean"])) {
                $query .= $searchArrayItem["_boolean"] . " ";
            }
        }
        if (is_array($searchArrayItem["_query"])) {
            $query .= "(";
            // NOTE: the parentheses must be on their own code lines to allow for correct recursion
            $query .= appendToWhereClause($searchArrayItem["_query"]);
            $query .= ")";
        } else {
            $query .= $searchArrayItem["_query"];
        }
    }
}