summaryrefslogtreecommitdiff
path: root/groups.php
blob: b372712c1fc89a9a656d28fd1bb440c4ce2aef50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

require_once "init.php";

require_once BASE . "/lib/style.php";
require_once BASE . "/lib/mysql.php";

$uri_parts = explode('/', $_SERVER['REQUEST_URI']);

if ($uri_parts[0] != '' || $uri_parts[1] != 'groups')
  throw_http_error(422, 'Unprocessable Entity');

$options = '';

$last = array_pop($uri_parts);
if (substr($last, 0, 1) == '?') {
  $options = $last;
  $last = array_pop($uri_parts);
}
if ($last != '')
  array_push($uri_parts, $last);

array_splice(
  $uri_parts,
  0, 2
);

$arch_filter = '1';
if (count($uri_parts) != 0) {
  $repo_arch = $uri_parts[0];
  $arch_filter = '`r_a`.`name`=from_base64("' . base64_encode($repo_arch) . '")';
  array_splice(
    $uri_parts,
    0, 1
  );
}

if (count($uri_parts) == 0) {

  $sort = '';
  if (array_key_exists('sort', $_GET)) {
    $criterium = $_GET['sort'];
    if (
      array_key_exists($criterium, $grouplist_sorts) &&
      array_key_exists('mysql', $grouplist_sorts[$criterium])
    )
      $sort = $grouplist_sorts[$criterium]['mysql'] . ',';
    elseif (substr($criterium, 0, 1) == '-') {
      $criterium = substr($criterium, 1);
      if (
        array_key_exists($criterium, $grouplist_sorts) &&
        array_key_exists('mysql', $grouplist_sorts[$criterium])
      )
      $sort = $grouplist_sorts[$criterium]['mysql'] . ' DESC,';
    }
  }

  $result = mysql_run_query(
    'SELECT ' .
    '`install_targets`.`name`,' .
    'COUNT(DISTINCT `install_target_providers`.`package`) AS `count`,' .
    'MAX(`binary_packages_in_repositories`.`last_moved`) AS `last_moved`,' .
    '`architectures`.`name` AS `arch`' .
    ' FROM `install_targets`' .
    mysql_join_install_targets_install_target_providers() .
    mysql_join_install_target_providers_binary_packages_in_repositories() .
    mysql_join_binary_packages_in_repositories_repositories() .
    ' AND `repositories`.`is_on_master_mirror`' .
    mysql_join_repositories_architectures() .
    ' WHERE `install_target_providers`.`install_target_is_group`' .
    ' GROUP BY CONCAT(`architectures`.`name`,"/",`install_targets`.`name`)' .
    ' ORDER BY ' . $sort . '`install_targets`.`name`,`architectures`.`name`'
  );
  $groups = array();
  while ($row = $result -> fetch_assoc()) {
    $row['move_date'] = substr($row['last_moved'], 0, 10);
    $groups[] = $row;
  }

  print_header('Package Groups');
  print "      <div class=\"box\">\n";
  print "        <h2>Package Groups Overview</h2>\n";
  print_listing($groups, true, 'group');
  print "      </div>\n";
  print_footer();

  die();
}

if (count($uri_parts) != 1)
  throw_http_error(422, 'Unprocessable Entity');

$group = $uri_parts[0];
$group_filter = '`install_targets`.`name`=from_base64("' . base64_encode($group) . '")';

$packages = query_package_listing(
  mysql_join_binary_packages_install_target_providers() .
  mysql_join_install_target_providers_install_targets() .
  ' WHERE ' . $arch_filter .
  ' AND ' . $group_filter,
  '',
  array(),
  false,
  true
);

if (count($packages) == 0)
  throw_http_error(404, 'Not Found');

print_header('Group Details');

print "      <div class=\"box\">\n";
print "        <h2>\n";
print "          Group Details - " . $group . " (" . $repo_arch . ")\n";
print "        </h2>\n";
print "        <p>" . count($packages) . " packages found.</p>\n";

print_listing($packages, true, 'package');

print "      </div>\n";

print_footer();