From 8260111bcce49b73bd4973ae80296c913af2631d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 24 Jun 2014 23:22:08 +0200 Subject: Add a package request list Introduce a new navigation point "Requests" that shows a list of pending package requests. This functionality is only available to Trusted Users. Signed-off-by: Lukas Fleischer --- web/html/pkgreq.php | 58 ++++++++++++++++++++++++++++++++++++ web/lib/pkgbasefuncs.inc.php | 20 +++++++++++++ web/lib/routing.inc.php | 1 + web/template/header.php | 3 ++ web/template/pkgreq_results.php | 66 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 web/template/pkgreq_results.php (limited to 'web') diff --git a/web/html/pkgreq.php b/web/html/pkgreq.php index c8dd673..05eeb51 100644 --- a/web/html/pkgreq.php +++ b/web/html/pkgreq.php @@ -14,6 +14,62 @@ if (!check_user_privileges()) { header('Location: /'); exit(); } + +if (!isset($base_id)) { + $results = pkgbase_request_list(); + $total = count($results); + + /* Sanitize paging variables. */ + if (isset($_GET['O'])) { + $_GET['O'] = intval($_GET['O']); + if ($_GET['O'] < 0) + $_GET['O'] = 0; + } else { + $_GET['O'] = 0; + } + + if (isset($_GET["PP"])) { + $_GET["PP"] = intval($_GET["PP"]); + if ($_GET["PP"] < 50) + $_GET["PP"] = 50; + else if ($_GET["PP"] > 250) + $_GET["PP"] = 250; + } else { + $_GET["PP"] = 50; + } + + /* Calculate the results to use. */ + $first = $_GET['O'] + 1; + + /* Calculation of pagination links. */ + $per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 50; + $current = ceil($first / $per_page); + $pages = ceil($total / $per_page); + $templ_pages = array(); + + if ($current > 1) { + $templ_pages['« ' . __('First')] = 0; + $templ_pages['‹ ' . __('Previous')] = ($current - 2) * $per_page; + } + + if ($current - 5 > 1) + $templ_pages["..."] = false; + + for ($i = max($current - 5, 1); $i <= min($pages, $current + 5); $i++) { + $templ_pages[$i] = ($i - 1) * $per_page; + } + + if ($current + 5 < $pages) + $templ_pages["... "] = false; + + if ($current < $pages) { + $templ_pages[__('Next') . ' ›'] = $current * $per_page; + $templ_pages[__('Last') . ' »'] = ($pages - 1) * $per_page; + } + + $SID = $_COOKIE['AURSID']; + include('pkgreq_results.php'); +} else { ?>
@@ -51,5 +107,7 @@ if (!check_user_privileges()) {
exec($q); } +/** + * Get a list of all package requests + * + * @return array List of pacakge requests with details + */ +function pkgbase_request_list() { + $dbh = DB::connect(); + + $q = "SELECT PackageRequests.ID, "; + $q.= "PackageRequests.PackageBaseID AS BaseID, "; + $q.= "PackageRequests.PackageBaseName AS Name, "; + $q.= "RequestTypes.Name AS Type, PackageRequests.Comments, "; + $q.= "Users.Username AS User, PackageRequests.RequestTS "; + $q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; + $q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; + $q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID"; + + return $dbh->query($q)->fetchAll(); +} + /** * File a deletion/orphan request against a package base * diff --git a/web/lib/routing.inc.php b/web/lib/routing.inc.php index 1b2aa52..5836a13 100644 --- a/web/lib/routing.inc.php +++ b/web/lib/routing.inc.php @@ -5,6 +5,7 @@ $ROUTES = array( '/index.php' => 'home.php', '/packages' => 'packages.php', '/pkgbase' => 'pkgbase.php', + '/requests' => 'pkgreq.php', '/register' => 'account.php', '/account' => 'account.php', '/accounts' => 'account.php', diff --git a/web/template/header.php b/web/template/header.php index df83995..03ce536 100644 --- a/web/template/header.php +++ b/web/template/header.php @@ -57,6 +57,9 @@
  • ">
  • + +
  • +
  • diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php new file mode 100644 index 0000000..7cbdcc4 --- /dev/null +++ b/web/template/pkgreq_results.php @@ -0,0 +1,66 @@ +
    +
    +

    + 1): ?> +

    + $pagestart): ?> + + + + + + + + +

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    "> + +
    + +
    +

    + 1): ?> +

    + $pagestart): ?> + + + + + + + + +

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