From 7e34ea6c100f8c7946134b4d348b6f44c0bb61b4 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 17 Apr 2018 11:17:11 +0200 Subject: use lib/mysql.php, fix indentation --- packages/index.php | 612 +++++++++++++++++++++++++++-------------------------- 1 file changed, 313 insertions(+), 299 deletions(-) (limited to 'packages/index.php') diff --git a/packages/index.php b/packages/index.php index e9a78c1..3c0d0ba 100644 --- a/packages/index.php +++ b/packages/index.php @@ -6,222 +6,87 @@ if (! isset($_GET[$expected_param])) $_GET[$expected_param] = ""; - $result = mysql_run_query( - "SELECT `name` FROM `architectures` ORDER BY `name`" + $search_criteria = array( + "arch" => array( + "name" => "arch", + "title" => "CPU architecture", + "label" => "Arch", + "table" => "architectures", + "extra_condition" => "", + "values" => array() + ), + "repo" => array( + "name" => "repo", + "title" => "respository", + "label" => "Repository", + "table" => "repositories", + "extra_condition" => " WHERE `repositories`.`is_on_master_mirror`", + "values" => array() + ) ); -?> - - - - - Arch Linux 32 - Package Search - - - - - -
- - -
-
- - - - query( - "SELECT " . - "`binary_packages`.`pkgname`," . - "`repositories`.`name` AS `repo`," . - "`architectures`.`name` AS `arch`," . - "CONCAT(IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," . - "`binary_packages`.`pkgver`,\"-\"," . - "`binary_packages`.`pkgrel`,\".\"," . - "`binary_packages`.`sub_pkgrel`) AS `version`," . - "IF(`binary_packages`.`has_issues`,1,0) AS `has_issues`" . - $query - )) - die ($mysql -> error); - - function print_results() { - global $result; - $oddity="odd"; - while ($row = $result -> fetch_assoc()) { - print "\n"; - print "" . $row["arch"] . "\n"; - print "" . $row["repo"] . "\n"; - print "" . $row["pkgname"] ."\n"; - print "" . $row["version"] . "\n"; - print ""; - if ($row["has_issues"]) - print "has open bug reports"; - else - print " "; - print "\n"; - print "\n"; - if ($oddity == "odd" ) - $oddity = "even"; - else - $oddity = "odd"; + $filter = " WHERE 1"; + foreach ($search_criteria as $criterium) + if (isset($_GET[$criterium["name"]])) { + $filter .= " AND `" . $criterium["table"] . "`.`name` IN ("; + foreach ($criterium["values"] as $value) + if (strpos("&" . $_SERVER["QUERY_STRING"] . "&", "&" . $criterium["name"] . "=" . $value . "&") !== false) + $filter .= "\"" . $value . "\","; + $filter .= "\"\")"; } + + if ($_GET["bugs"] == "Bugs") + $filter .= " AND `binary_packages`.`has_issues`"; + if ($_GET["bugs"] == "No Bugs") + $filter .= " AND NOT `binary_packages`.`has_issues`"; + + if (isset($_GET["q"])) { + $exact_filter = " AND `binary_packages`.`pkgname` = from_base64(\"".base64_encode($_GET["q"])."\")"; + $fuzzy_filter = " AND `binary_packages`.`pkgname` LIKE from_base64(\"".base64_encode("%".$_GET["q"]."%")."\")"; + } else { + $exact_filter = " AND 0"; + $fuzzy_filter = ""; } -if ($result -> num_rows > 0) { -?> -
-
-

num_rows; ?> exact match num_rows != 1) print "es"; ?> found.

-
- - - - - - - - - - - - - -
ArchRepoNameVersionBugs
-
- + $query .= "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`"; -
- - fetch_assoc()) + $exact_matches[] = $row; $sorts = array( "arch" => array( @@ -251,27 +116,25 @@ if ($result -> num_rows > 0) { ) ); -$query = " FROM `binary_packages`" . - " JOIN `architectures` ON `architectures`.`id`=`binary_packages`.`architecture`" . - " JOIN `repositories` ON `repositories`.`id`=`binary_packages`.`repository`" . - " AND `repositories`.`is_on_master_mirror`" . - $filter . $fuzzy_filter . - " ORDER BY "; - -if (isset($_GET["sort"])) { - if (isset($sorts[$_GET["sort"]]["mysql"])) - $query .= $sorts[$_GET["sort"]]["mysql"] . ","; - elseif (isset($sorts[substr($_GET["sort"],1)]["mysql"])) - $query .= $sorts[substr($_GET["sort"],1)]["mysql"] . " DESC,"; -} - -$query .= "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`"; + $query = " FROM `binary_packages`" . + " JOIN `architectures` ON `architectures`.`id`=`binary_packages`.`architecture`" . + " JOIN `repositories` ON `repositories`.`id`=`binary_packages`.`repository`" . + " AND `repositories`.`is_on_master_mirror`" . + $filter . $fuzzy_filter . + " ORDER BY "; + + if (isset($_GET["sort"])) { + if (isset($sorts[$_GET["sort"]]["mysql"])) + $query .= $sorts[$_GET["sort"]]["mysql"] . ","; + elseif (isset($sorts[substr($_GET["sort"],1)]["mysql"])) + $query .= $sorts[substr($_GET["sort"],1)]["mysql"] . " DESC,"; + } -if (! $result = $mysql -> query( - "SELECT COUNT(1)" . $query - )) - die ($mysql -> error); + $query .= "`binary_packages`.`pkgname`,`repositories`.`stability`,`repositories`.`name`,`architectures`.`name`"; + $result = mysql_run_query( + "SELECT COUNT(1)" . $query + ); $num_results = implode($result -> fetch_assoc()); $pages = max(ceil($num_results / 100), 1); @@ -280,39 +143,77 @@ if (! $result = $mysql -> query( else $page = 1; -if (! $result = $mysql -> query( - "SELECT " . - "`binary_packages`.`pkgname`," . - "`repositories`.`name` AS `repo`," . - "`architectures`.`name` AS `arch`," . - "CONCAT(IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," . - "`binary_packages`.`pkgver`,\"-\"," . - "`binary_packages`.`pkgrel`,\".\"," . - "`binary_packages`.`sub_pkgrel`) AS `version`," . - "IF(`binary_packages`.`has_issues`,1,0) AS `has_issues`" . - $query . - " LIMIT " . (($page-1)*100) . ", 100" - )) - die ($mysql -> error); + $result = mysql_run_query( + "SELECT " . + "`binary_packages`.`pkgname`," . + "`repositories`.`name` AS `repo`," . + "`architectures`.`name` AS `arch`," . + "CONCAT(IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," . + "`binary_packages`.`pkgver`,\"-\"," . + "`binary_packages`.`pkgrel`,\".\"," . + "`binary_packages`.`sub_pkgrel`) AS `version`," . + "IF(`binary_packages`.`has_issues`,1,0) AS `has_issues`" . + $query . + " LIMIT " . (($page-1)*100) . ", 100" + ); + $fuzzy_matches = array(); + while ($row = $result -> fetch_assoc()) + $fuzzy_matches[] = $row; + function print_results($results) { + $oddity="odd"; + foreach ($results as $row) { + print " \n"; + print " \n"; + print " " . $row["arch"] . "\n"; + print " \n"; + print " \n"; + print " " . $row["repo"] . "\n"; + print " \n"; + print " \n"; + print " " . $row["pkgname"] . "\n"; + print " \n"; + print " \n"; + print " " . $row["version"] . "\n"; + print " \n"; + print " \n"; + print " "; + if ($row["has_issues"]) + print "has open bug reports"; + else + print " "; + print "\n"; + print " \n"; + print " \n"; + if ($oddity == "odd" ) + $oddity = "even"; + else + $oddity = "odd"; + } + } function header_and_footer() { global $page, $pages, $num_results; - print "
\n"; - - print "

" . $num_results . " matching package"; + print "

\n"; + print "

\n"; + print " " . $num_results . " matching package"; if ($num_results != 1) print "s"; print " found.\n"; - if ($pages != 1) { - print "Page " . $page . " of " . $pages . ".

\n"; + if ($pages != 1) + print " Page " . $page . " of " . $pages . ".\n"; + + print "

\n"; - print "
\n"; - print "\n"; + if ($pages != 1) { + print "
\n"; + print " \n"; + print " "; if ($page > 1) { print " query( print "< Prev"; if ($page > 1) print ""; - print "\n"; - print "\n"; + print "\n"; + print " \n"; + print " \n"; + print " "; if ($page < $pages) { print " query( print "Next >"; if ($page < $pages) print ""; - print "\n"; - print "
\n"; + print "\n"; + print "
\n"; + print "
\n"; }; - print "
\n"; + print "
\n"; }; - header_and_footer(); +?> + + + + + Arch Linux 32 - Package Search + + + + + + +
+ \n"; + } +?> +
+ + /> +
+
+ +
+
+ + +
+ + +
+ 0) { +?> +
+
+

exact match found.

+
+ + + + + + + + + + + + + +
ArchRepoNameVersionBugs
+
+ +
+ - - +?> + + + $sort) { - print "\n"; + print $get."\" title=\"Sort package by ".$sort["title"]."\">".$sort["label"]."\n"; + print " \n"; } ?> - - - + + + - -
\n"; + print " query( ),1)."sort="; if ($_GET["sort"] == $get) print "-"; - print $get."\" "; - print " title=\"Sort package by ".$sort["title"]."\">".$sort["label"]."
- + + - -
-

Can't find what you are looking for? Try searching again - using different criteria, or try - searching the AUR - to see if the package can be found there.

- -

You are browsing the Arch Linux 32 package database. From here you can find - detailed information about packages located in the 32 bit repositories.

-
- - +
+

+ Can't find what you are looking for? Try searching again + using different criteria, or try + searching the AUR + to see if the package can be found there. +

+

+ You are browsing the Arch Linux 32 package database. From here you can find + detailed information about packages located in the 32 bit repositories. +

+
+
- - + -- cgit v1.2.3-70-g09d2