/* valid requests are ID, CATEGORY, YEAR & MONTH or SEARCH
ID returns exactly one result, and can be accompanied by PREVIEW. This can also show hidden articles.
CATEGORY, YEAR & MONTH or SEARCH can be accompanied by PAGE to displayed paginated content
The default request is all stories, starting from the most recent in descending date order */
$page = 1;
if (array_key_exists("page",$_REQUEST)) {
$page = $_REQUEST["page"];
}
$sort = "d";
if (array_key_exists("sort",$_REQUEST)) {
$sort = $_REQUEST["sort"];
}
$query = "SELECT * FROM gallery WHERE gal_private='N'";
if ($sort=="a") {
$query .= " ORDER BY gal_name ASC";
} else if ($sort=="z") {
$query .= " ORDER BY gal_name DESC";
} else if ($sort=="d") {
$query .= " ORDER BY gal_date DESC";
} else {
$query .= " ORDER BY gal_date ASC";
}
$result = $link->query($query);
$rows = mysqli_num_rows($result);
$page_rows = 10;
$last = ceil($rows/$page_rows);
if ($page < 1) {
$page = 1;
} elseif ($page > $last) {
$page = $last;
}
$start = ($page - 1) * $page_rows;
$query .= ' LIMIT ' . $start . ',' .$page_rows;
/* pagination stuff */
if ($last>1) {
$page_nav = "";
}
/* end of pagination stuff */
/* sort buttons */
$sort_b = '