コード例 #1
0
 static function getSearchResults($view, $page = 1, $query = "", $sort = "id DESC", $group = false)
 {
     // Check to see if we've cached this table before.
     self::cacheViewData($view);
     $search_parts = explode(" ", strtolower($query));
     $view_columns = count($view["fields"]);
     if ($group !== false) {
         $query = "SELECT * FROM bigtree_module_view_cache WHERE view = '" . $view["id"] . "' AND group_field = '" . sqlescape($group) . "'" . self::getFilterQuery($view);
     } else {
         $query = "SELECT * FROM bigtree_module_view_cache WHERE view = '" . $view["id"] . "'" . self::getFilterQuery($view);
     }
     foreach ($search_parts as $part) {
         $x = 0;
         $qp = array();
         $part = sqlescape(strtolower($part));
         while ($x < $view_columns) {
             $x++;
             $qp[] = "column{$x} LIKE '%{$part}%'";
         }
         if (count($qp)) {
             $query .= " AND (" . implode(" OR ", $qp) . ")";
         }
     }
     $per_page = $view["options"]["per_page"] ? $view["options"]["per_page"] : BigTreeAdmin::$PerPage;
     $pages = ceil(sqlrows(sqlquery($query)) / $per_page);
     $pages = $pages > 0 ? $pages : 1;
     $results = array();
     // Get the correct column name for sorting
     if (strpos($sort, "`") !== false) {
         // New formatting
         $sort_field = BigTree::nextSQLColumnDefinition(substr($sort, 1));
         $sort_pieces = explode(" ", $sort);
         $sort_direction = end($sort_pieces);
     } else {
         // Old formatting
         list($sort_field, $sort_direction) = explode(" ", $sort);
     }
     if ($sort_field != "id") {
         $x = 0;
         if (isset($view["fields"][$sort_field]["numeric"]) && $view["fields"][$sort_field]["numeric"]) {
             $convert_numeric = true;
         } else {
             $convert_numeric = false;
         }
         foreach ($view["fields"] as $field => $options) {
             $x++;
             if ($field == $sort_field) {
                 $sort_field = "column{$x}";
             }
         }
         // If we didn't find a column, let's assume it's the default sort field.
         if (substr($sort_field, 0, 6) != "column") {
             $sort_field = "sort_field";
         }
         if ($convert_numeric) {
             $sort_field = "CONVERT(" . $sort_field . ",SIGNED)";
         }
     } else {
         $sort_field = "CONVERT(id,UNSIGNED)";
     }
     if (strtolower($sort) == "position desc, id asc") {
         $sort_field = "position DESC, id ASC";
         $sort_direction = "";
     } else {
         $sort_direction = strtolower($sort_direction) == "asc" ? "ASC" : "DESC";
     }
     if ($page === "all") {
         $q = sqlquery($query . " ORDER BY {$sort_field} {$sort_direction}");
     } else {
         $q = sqlquery($query . " ORDER BY {$sort_field} {$sort_direction} LIMIT " . ($page - 1) * $per_page . ",{$per_page}");
     }
     while ($f = sqlfetch($q)) {
         unset($f["hash"]);
         $results[] = $f;
     }
     return array("pages" => $pages, "results" => $results);
 }
コード例 #2
0
ファイル: searchable.php プロジェクト: matthisamoto/Graphfan
BigTree::globalizeArray($bigtree["view"]);
$m = BigTreeAutoModule::getModuleForView($bigtree["view"]);
$perm = $admin->checkAccess($m);
if (isset($_GET["sort"])) {
    $sort = $_GET["sort"] . " " . $_GET["sort_direction"];
} elseif (isset($options["sort_column"])) {
    $sort = $options["sort_column"] . " " . $options["sort_direction"];
} elseif (isset($options["sort"])) {
    $sort = $options["sort"];
} else {
    $sort = "id DESC";
}
// Retrieve the column and the sort direction from the consolidated ORDER BY statement.
$sort = ltrim($sort, "`");
$sort_column = BigTree::nextSQLColumnDefinition($sort);
$sort_pieces = explode(" ", $sort);
$sort_direction = end($sort_pieces);
// See if we're searching for anything.
$search = isset($_GET["search"]) ? $_GET["search"] : "";
?>
<div class="table auto_modules">
	<summary>
		<input type="search" class="form_search" id="search" placeholder="Search" value="<?php 
echo htmlspecialchars($search);
?>
" />
		<span class="form_search_icon"></span>
		<nav id="view_paging" class="view_paging"></nav>
	</summary>
	<header>