Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.81 KB | None | 0 0
  1. <?php
  2. include('scripts/init.php');
  3. // Create query for SQL, search itself
  4. $search_query = $_GET["search-query"];
  5. $params = array();
  6. $params[] = $_GET["search-query"];
  7. switch ($_GET["search-in"]) {
  8.     case "topics":
  9.         $from = "topics";
  10.         break;
  11.     case "posts":
  12.         $from = "posts";
  13.         break;
  14.     case "users":
  15.         $from = "users";
  16.         $in_what = "users.name";
  17.         break;
  18.     default:
  19.         $from = "posts LEFT JOIN topics ON posts.topic = topics.id";
  20.         $in_what = "1";
  21.         $like = "position($1 in topics.text) > 0 OR position($1 in posts.text) > 0";
  22.         break;
  23. }
  24.  
  25. if(empty($like)) {
  26.     $in_what = $in_what ?? $from . ".text";
  27.     $like = "position($1 in $in_what) > 0";
  28. }
  29.  
  30. if ($from !== "users") {
  31.     $where = "(";
  32.     $i = 2;
  33.     foreach ($_GET as $key => $value) {
  34.         if(strpos($key, "search-in-sections-")) {
  35.             $params[] = $value;
  36.             $where .= "sections.name LIKE $" . $i . " OR \n";
  37.             $i++;
  38.         } elseif (strpos($key, "search-in-subs-")) {
  39.             $params[] = $value;
  40.             $where .= "subsections.name LIKE $" . $i . " OR \n";
  41.             $i++;
  42.         }
  43.     }
  44.     if ($where !== "(") {
  45.         $where .= ") AND " . $like;
  46.     } else {
  47.         unset($where);
  48.     }
  49. }
  50. if(empty($where)) {
  51.     $where = $like;
  52. }
  53. $query = "SELECT * FROM " . $from . " WHERE " . $where;
  54.  
  55. // Make page
  56. $sections = pg_query("SELECT * FROM sections");
  57. $tree = "";
  58.  
  59. while($section = pg_fetch_assoc($sections)) {
  60.     ob_start();
  61.     $id = $section["id"];
  62.     $selectbox_is_radio = false;
  63.     $selectbox_name = "search-in-sections-" . $id;
  64.     $selectbox_value = $section["name"];
  65.     $selectbox_caption = $section["name"];
  66.     $selectbox_id = "section-" . $id;
  67.     $selectbox_indented = false;
  68.     if(@$_GET[$selectbox_name] === $selectbox_value) {
  69.         $selectbox_default = true;
  70.     } else {
  71.         $selectbox_default = false;
  72.     }
  73.     include("widgets/selectbox.php");
  74.     $tree .= ob_get_clean();
  75.     $subsections = pg_query("SELECT * FROM subsections WHERE section=$id");
  76.     while($sub = pg_fetch_assoc($subsections)) {
  77.         ob_start();
  78.         $selectbox_is_radio = false;
  79.         $id = $sub["id"];
  80.         $selectbox_id = "sub-" . $id;
  81.         $selectbox_name = "search-in-subs-".$id;
  82.         $selectbox_value = $sub["name"];
  83.         $selectbox_caption = $sub["name"];
  84.         $selectbox_indented = true;
  85.         if(@$_GET[$selectbox_name] === $selectbox_value) {
  86.             $selectbox_default = true;
  87.         } else {
  88.             $selectbox_default = false;
  89.         }
  90.         include("widgets/selectbox.php");
  91.         $tree .= ob_get_clean();
  92.     }
  93. }
  94. unset($selectbox_id);
  95. ob_get_clean();
  96.  
  97. ob_start();
  98. include("layouts/search.php");
  99. $window_title = "Search preferences";
  100. $window_content = ob_get_clean();
  101.  
  102. ob_start();
  103. include("widgets/window.php");
  104. $content = ob_get_clean();
  105. $items = pg_query_params($conn, $query, $params);
  106. while($item = pg_fetch_assoc($items)) {
  107.     $window_content = $item["text"];
  108.     ob_start();
  109.     include("widgets/window.php");
  110.     $content .= ob_get_clean();
  111. }
  112.  
  113. include("layouts/template.php");
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement