Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('scripts/init.php');
- // Create query for SQL, search itself
- $search_query = $_GET["search-query"];
- $params = array();
- $params[] = $_GET["search-query"];
- switch ($_GET["search-in"]) {
- case "topics":
- $from = "topics";
- break;
- case "posts":
- $from = "posts";
- break;
- case "users":
- $from = "users";
- $in_what = "users.name";
- break;
- default:
- $from = "posts LEFT JOIN topics ON posts.topic = topics.id";
- $in_what = "1";
- $like = "position($1 in topics.text) > 0 OR position($1 in posts.text) > 0";
- break;
- }
- if(empty($like)) {
- $in_what = $in_what ?? $from . ".text";
- $like = "position($1 in $in_what) > 0";
- }
- if ($from !== "users") {
- $where = "(";
- $i = 2;
- foreach ($_GET as $key => $value) {
- if(strpos($key, "search-in-sections-")) {
- $params[] = $value;
- $where .= "sections.name LIKE $" . $i . " OR \n";
- $i++;
- } elseif (strpos($key, "search-in-subs-")) {
- $params[] = $value;
- $where .= "subsections.name LIKE $" . $i . " OR \n";
- $i++;
- }
- }
- if ($where !== "(") {
- $where .= ") AND " . $like;
- } else {
- unset($where);
- }
- }
- if(empty($where)) {
- $where = $like;
- }
- $query = "SELECT * FROM " . $from . " WHERE " . $where;
- // Make page
- $sections = pg_query("SELECT * FROM sections");
- $tree = "";
- while($section = pg_fetch_assoc($sections)) {
- ob_start();
- $id = $section["id"];
- $selectbox_is_radio = false;
- $selectbox_name = "search-in-sections-" . $id;
- $selectbox_value = $section["name"];
- $selectbox_caption = $section["name"];
- $selectbox_id = "section-" . $id;
- $selectbox_indented = false;
- if(@$_GET[$selectbox_name] === $selectbox_value) {
- $selectbox_default = true;
- } else {
- $selectbox_default = false;
- }
- include("widgets/selectbox.php");
- $tree .= ob_get_clean();
- $subsections = pg_query("SELECT * FROM subsections WHERE section=$id");
- while($sub = pg_fetch_assoc($subsections)) {
- ob_start();
- $selectbox_is_radio = false;
- $id = $sub["id"];
- $selectbox_id = "sub-" . $id;
- $selectbox_name = "search-in-subs-".$id;
- $selectbox_value = $sub["name"];
- $selectbox_caption = $sub["name"];
- $selectbox_indented = true;
- if(@$_GET[$selectbox_name] === $selectbox_value) {
- $selectbox_default = true;
- } else {
- $selectbox_default = false;
- }
- include("widgets/selectbox.php");
- $tree .= ob_get_clean();
- }
- }
- unset($selectbox_id);
- ob_get_clean();
- ob_start();
- include("layouts/search.php");
- $window_title = "Search preferences";
- $window_content = ob_get_clean();
- ob_start();
- include("widgets/window.php");
- $content = ob_get_clean();
- $items = pg_query_params($conn, $query, $params);
- while($item = pg_fetch_assoc($items)) {
- $window_content = $item["text"];
- ob_start();
- include("widgets/window.php");
- $content .= ob_get_clean();
- }
- include("layouts/template.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement