Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/packages/index.php
blob: fb568dacd12494263173e157b445778a4cbb2060 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
require_once "../init.php";

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


  foreach (array("bugs","sort","del","uses_upstream","uses_modification") as $expected_param)
    if (! array_key_exists($expected_param, $_GET))
      $_GET[$expected_param] = "";

  $multi_select_search_criteria = array(
    "arch" => array(
      "name" => "arch",
      "title" => "CPU architecture",
      "label" => "Arch",
      "table" => "architectures",
      "column" => "`architectures`.`name`",
      "extra_condition" => "",
      "values" => array()
    ),
    "repo" => array(
      "name" => "repo",
      "title" => "respository",
      "label" => "Repository",
      "table" => "repositories",
      "column" => "CONCAT(`architectures`.`name`,\"/\",`repositories`.`name`)",
      "extra_condition" => mysql_join_repositories_architectures() . " WHERE `repositories`.`is_on_master_mirror`",
      "values" => array()
    )
  );

  foreach ( $multi_select_search_criteria as $criterium => $content ) {
    $result = mysql_run_query(
      "SELECT " . $content["column"] . " AS `name` FROM `" . $content["table"] . "`" . $content["extra_condition"] . " ORDER BY `name`"
    );
    while ($row = $result -> fetch_assoc())
      $multi_select_search_criteria[$criterium]["values"][] = $row["name"];
  }

  $float_columns = array(
    "has_issues",
    "is_to_be_deleted"
  );

  $filter = " WHERE 1";
  foreach ($multi_select_search_criteria as $criterium)
    if (isset($_GET[$criterium["name"]])) {
      $filter .= " AND " . $criterium["column"] . " IN (";
      foreach ($criterium["values"] as $value)
        if (strpos("&" . urldecode($_SERVER["QUERY_STRING"]) . "&", "&" . $criterium["name"] . "=" . $value . "&") !== false)
          $filter .= "\"" . $value . "\",";
      $filter .= "\"\")";
    }

  $single_select_search_criteria = array(
    "bugs" => array(
      "name" => "bugs",
      "label" => "Bugs",
      "title" => "bug-tracker status",
      "options" => array(
        "All" => "1",
        "Bugs" => "`binary_packages`.`has_issues`",
        "No Bugs" => "NOT `binary_packages`.`has_issues`"
      )
    ),
    "del" => array(
      "name" => "del",
      "label" => "To Be Deleted",
      "title" => "to-be-deleted status",
      "options" => array(
        "All" => "1",
        "To Be Deleted" => "`binary_packages_in_repositories`.`is_to_be_deleted`",
        "Not To Be Deleted" => "NOT `binary_packages_in_repositories`.`is_to_be_deleted`"
      )
    ),
    "uses_upstream" => array(
      "name" => "uses_upstream",
      "label" => "Upstream",
      "title" => "wether upstream source exists",
      "options" => array(
        "All" => "1",
        "Uses Upstream" => "`package_sources`.`uses_upstream`",
        "Does Not Use Upstream" => "NOT `package_sources`.`uses_upstream`"
      )
    ),
    "uses_modification" => array(
      "name" => "uses_modification",
      "label" => "Modification",
      "title" => "wether modification exists",
      "options" => array(
        "All" => "1",
        "Uses Modification" => "`package_sources`.`uses_modification`",
        "Does Not Use Modification" => "NOT `package_sources`.`uses_modification`"
      )
    )
  );

  foreach ($single_select_search_criteria as $criterium)
    if (isset($_GET[$criterium["name"]]) &&
      isset($criterium["options"][$_GET[$criterium["name"]]]))
      $filter .= " AND " . $criterium["options"][$_GET[$criterium["name"]]];

  if (array_key_exists("q", $_GET)) {
    $extra_joins = "";
    $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"]."%")."\")";
  } elseif (array_key_exists("g", $_GET) && array_key_exists("ra", $_GET)) {
    $extra_joins =
      mysql_join_binary_packages_install_target_providers() .
      mysql_join_install_target_providers_install_targets();
    $fuzzy_filter =
      " AND `install_targets`.`name`=from_base64(\"" . base64_encode($_GET["g"]) . "\")" .
      " AND `r_a`.`name`=from_base64(\"" . base64_encode($_GET["ra"]) . "\")";
    $exact_filter = " AND 0";
  } else {
    $extra_joins = "";
    $exact_filter = " AND 0";
    $fuzzy_filter = "";
  }

  $exact_matches = query_package_listing(
    $extra_joins .
    $filter . $exact_filter,
    '',
    $float_columns,
    false,
    false
  );


  $num_results = query_package_listing(
    $extra_joins . $filter . $fuzzy_filter,
    '',
    array(),
    true,
    true
  );

  $pages = max(ceil($num_results / 100), 1);
  if (array_key_exists("page", $_GET))
    $page = max(min($_GET["page"]+0, $pages),1);
  else
    $page = 1;

  $fuzzy_matches = query_package_listing(
    $extra_joins . $filter . $fuzzy_filter,
    " LIMIT " . (($page-1)*100) . ", 100",
    $float_columns,
    false,
    true
  );

  function header_and_footer() {

    global $page, $pages, $num_results;

    print "        <div class=\"pkglist-stats\">\n";
    print "          <p>\n";
    print "            " . $num_results . " matching package";
    if ($num_results != 1)
      print "s";
    print " found.\n";

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

    print "          </p>\n";

    if ($pages != 1) {
      print "          <div class=\"pkglist-nav\">\n";
      print "            <span class=\"prev\">\n";

      print "              ";
      if ($page > 1) {
        print "<a href=\"?";
        print substr(str_replace(
          "&page=".$page."&",
          "&",
          "&".$_SERVER["QUERY_STRING"]."&"
        ),1)."page=".($page-1);
        print "\" title=\"Go to previous page\">";
      };
      print "&lt; Prev";
      if ($page > 1)
        print "</a>";
      print "\n";
      print "            </span>\n";
      print "            <span class=\"next\">\n";

      print "              ";
      if ($page < $pages) {
        print "<a href=\"?";
        print substr(str_replace(
          "&page=".$page."&",
          "&",
          "&".$_SERVER["QUERY_STRING"]."&"
        ),1)."page=".($page+1);
        print "\" title=\"Go to next page\">";
      };
      print "Next &gt;";
      if ($page < $pages)
        print "</a>";
      print "\n";
      print "            </span>\n";
      print "          </div>\n";
    };
    print "        </div>\n";

  };

  if (array_key_exists("exact", $_GET)) {
    export_as_requested(
      array(
        "All" => $exact_matches
      )
    );
    die();
  };

  if (array_key_exists("fuzzy", $_GET)) {
    export_as_requested(
      array(
        "All" => $fuzzy_matches
      )
    );
    die();
  };

  print_header("Package Search");

?>
      <div id="pkglist-search" class="box filter-criteria">
        <h2>Package Search</h2>
        <form id="pkg-search" method="get" action="/packages/">
          <p><input id="id_sort" name="sort" type="hidden" /></p>
          <fieldset>
            <legend>Enter search criteria</legend>
<?php
  foreach ($multi_select_search_criteria as $criterium) {
    print "            <div>\n";
    print "              <label for=\"id_" . $criterium["name"] . "\" title=\"Limit results to a specific " . $criterium["title"] . "\">";
    print $criterium["label"];
    print "</label>\n";
    print "              <select multiple=\"multiple\" id=\"id_" . $criterium["name"] . "\" name=\"" . $criterium["name"] . "\">\n";
    foreach ($criterium["values"] as $value) {
      print "                <option value=\"" . $value . "\"";
      if (strpos( "&" . urldecode($_SERVER["QUERY_STRING"]) . "&", "&" . $criterium["name"] . "=" . $value . "&") !== false)
        print " selected=\"selected\"";
      print ">" . $value . "</option>\n";
    }
    print "              </select>\n";
    print "            </div>\n";
  }
?>
            <div>
              <label for="id_q" title="Enter keywords as desired">Keywords</label>
              <input id="id_q" name="q" size="30" type="text" <?php
if (array_key_exists("q", $_GET))
  print "value=\"".$_GET["q"]."\"";
?>/>
            </div>
<?php
  foreach ($single_select_search_criteria as $criterium) {

    print "            <div>\n";
    print "              <label for=\"id_";
    print $criterium["name"];
    print "\" title=\"Limit results based on ";
    print $criterium["title"];
    print "\">";
    print $criterium["label"];
    print "</label><select id=\"id_";
    print $criterium["name"];
    print "\" name=\"";
    print $criterium["name"];
    print "\">\n";

    foreach ($criterium["options"] as $label => $option) {
      print "                <option value=\"";
      if ($label != "All")
        print $label;
      print "\"";
      if ($_GET[$criterium["name"]]==$label)
        print " selected=\"selected\"";
      print ">" . $label . "</option>\n";
    }
    print "              </select>\n";
    print "            </div>\n";
  }
?>
            <div>
              <label>&nbsp;</label>
              <input title="Search for packages using this criteria" type="submit" value="Search">
            </div>
          </fieldset>
        </form>
      </div>
<?php

if (count($exact_matches) > 0) {
?>
      <div id="exact-matches" class="box">
        <div class="pkglist-stats">
          <p><?php print count($exact_matches); ?> exact match<?php if (count($exact_matches) != 1) print "es"; ?> found.</p>
        </div>
<?php
  print_listing($exact_matches, false, $pkglist_sorts);
?>
      </div>
<?php
}

?>
      <div id="pkglist-results" class="box">
<?php

  header_and_footer();

  print_listing($fuzzy_matches, true, $pkglist_sorts);

  header_and_footer();

?>
      </div>
      <div id="pkglist-about" class="box">
        <p>
          Can't find what you are looking for? Try searching again
          using different criteria, or try
          searching the <a href="https://aur.archlinux.org/">AUR</a>
          to see if the package can be found there.
        </p>
        <p>
          You are browsing the Arch Linux 32 package database. From here you can find
          detailed information about packages located in the 32 bit repositories.
        </p>
      </div>
<?php

  print_footer();