-
Notifications
You must be signed in to change notification settings - Fork 2
/
Files.php
91 lines (70 loc) · 2.53 KB
/
Files.php
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
<?php
/*
* Files.php
* LHS Math Club Website
*/
require_once '.lib/functions.php';
show_page();
function show_page() {
page_header('Files');
echo <<<HEREDOC
<h1>Files</h1>
<br />
<div style='font-weight:bold'>2010-2013 files have been archived to <a href='https://www.dropbox.com/sh/6wo6f5i8il42m1c/RxpAYq6Pb1'>the Dropbox</a>.</div>
<br />
HEREDOC;
$admin_sql = '';
if (user_access('A'))
$admin_sql = ' OR files.permissions="A"';
if (isSet($_SESSION['is_captain']))
$admin_sql .= ' OR files.permissions="C"';
$query = 'SELECT files.file_id, files.name, files.category, file_categories.name AS category_name, files.permissions FROM files'
. ' INNER JOIN file_categories ON files.category=file_categories.category_id'
. ' WHERE ( files.permissions="P" OR files.permissions="M"' . $admin_sql . ' ) '
. ' AND ( files.category <> 2 && files.category <> 5 && files.category <> 8 && files.category <> 9 ) '//temporary
. ' ORDER BY category_name, category_id, order_num';
$result = DB::queryRaw($query);
$row = mysqli_fetch_assoc($result);
$current_category = -1;
while ($row) {
$category_name = $row['category_name'];
// If this row is the beginning of a new category
if ($row['category'] != $current_category) {
if ($current_category != -1)
echo ' </table><br />' . "\n";
echo <<<HEREDOC
<h4 class="smbottom">{$category_name}</h4>
<table class="contrasting files">
HEREDOC;
$current_category = $row['category'];
}
// Normal stuff
$admin_only_styling = ($row['permissions'] == 'A') ? ' class="i"' : '';
echo ' <tr><td' . $admin_only_styling . '><a href="Download?ID=' . $row['file_id'] . '">'
. $row['name'] . '</a></td></tr>' . "\n";
$row = mysqli_fetch_assoc($result);
}
// Last footer
if ($current_category != -1)
echo ' </table>' . "\n";
// Misc. table
$query = 'SELECT * FROM files WHERE category="0"'
. ' AND (files.permissions="P" OR files.permissions="M"' . $admin_sql
. ') ORDER BY order_num';
$result = DB::queryRaw($query);
if (mysqli_num_rows($result) > 0) {
echo <<<HEREDOC
<h4 class="smbottom">Miscellaneous</h4>
<table class="contrasting files">
HEREDOC;
$row = mysqli_fetch_assoc($result);
while ($row) {
$admin_only_styling = ($row['permissions'] == 'A') ? ' class="i"' : '';
echo ' <tr><td' . $admin_only_styling . '><a href="Download?ID=' . $row['file_id'] . '">'
. $row['name'] . '</a></td></tr>' . "\n";
$row = mysqli_fetch_assoc($result);
}
echo ' </table>' . "\n";
}
}
?>