/
in_class.php
166 lines (145 loc) · 4.42 KB
/
in_class.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
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
<?php
require_once './database.php';
require_once "./session.php";
if ( !isset( $_GET['id'] ) )
{
$message = urlencode( "Missing the course number." );
header( "Location: error.php?error=${message}" );
exit();
}
//if the user is not logged in then redirect
if ( !Session::userLoggedIn() )
{
header( "Location: login.php" );
exit();
}
$token = Session::token();
$searchId = $_GET['id'];
$retrievedCourse = Database::getCoursebyID($searchId);
//if the id provided is not actually a valid course then redirect
if ( !isset( $retrievedCourse['id'] ) )
{
$message = urlencode( "The course provided does not exist" );
header( "Location: error.php?error=${message}" );
exit();
}
$retrievedCourse['name'];
$notes = Database::getNotesByCourse($searchId);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Arizona Notes</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/fonts.css">
<script>
<?php
echo "var PHP_token = \"{$token}\";\n";
echo "var PHP_course = \"{$_GET['id']}\";\n";
?>
</script>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/upload.js"></script>
</head>
<body>
<form id='removalForm' method='post' action='form.php'>
<input id='removeToken' type='hidden' name='token' value="<?php echo $token;?>">
<input id='removedValue' type='hidden' name='note'>
</form>
<div class="darken_div"></div>
<div class="main-logo">
<a href="index.php">
<img src="images/logo.png" height="90px" width=auto></a>
</div>
<article class="main-content">
<header>
<?php
$user = Database::getUserId( Session::user() );
$account = Database::getAccount( $user, $searchId );
//if the current user can upload notes, add a link to allow them to upload a file
if ( $account !== NULL && $account->canUpload() )
{
?>
<div id="uploadFrame" class="upload">
<a id="uploadLink" href="#">Upload Notes</a>
</div>
<?php
}
?>
<p>
<?php echo $retrievedCourse['name'] . " - " . $retrievedCourse['semester']; ?>
</p>
<p>
Instructor: <?php echo $retrievedCourse['instructor']; ?>
</p>
</header>
<main>
<?php
if (empty($notes)) {
echo "No notes found for this course.";
} else {
$note_limit = 12; // 12 notes per page
$note_count = count($notes);
if ( isset($_GET['page']))
{
$page = $_GET['page'] + 1;
$offset = $note_limit * $page;
}
else
{
$page = 0;
$offset = 0;
}
$current_notes = Database::getNotesByCourseLimited($searchId, $offset, $note_limit);
if ( empty( $current_notes ) )
{
echo "No notes found for this page.";
}
foreach ($current_notes as $note) {
?>
<div class="float"><a href="download.php?id=<?php echo $note['id']?>"><img src="images/pdf.png" alt="" height="150" width=auto></a>
<?php
//if the current user can delete notes files then add a delete link to every notes icon
if ( $account !== NULL && $account->canDelete() )
{
?>
<div title='Remove File' class="topleft" onclick='removeNote( <?php echo $note['id']; ?>)'></div>
<?php
}?>
<p><?php echo $note['lectureDate']; ?></p></div>
<?php }
echo "</main>";
echo "<div class='perNext'>";
$last = $page;
$perClass = "";
$nextClass = "";
//if past the first page, then add previous page link
if( $page > 0 )
{
//-2 since pages begin at -1 and are added 1 to
$last = $page - 2;
}
else if( $page == 0 )
{
//since this is the first page, give the previous link a disabled class so it does not do anything
$perClass = "disabled";
}
if( count( $current_notes ) < $note_limit )
{
//if there are less than the total possible notes on this page then it is the last page
//give the next page link a disabled class so it does nothing when clicked
$nextClass = "disabled";
}
?>
<a class="per <?php echo $perClass;?>" href = "in_class.php?id=<?php echo $searchId;?>&page=<?php echo $last;?>" > ❮ Prev </a> -
<a class="next <?php echo $nextClass;?>" href = "in_class.php?id=<?php echo $searchId;?>&page=<?php echo $page;?>" >Next ❯</a>
<?php
echo "</div>";
}?>
</article>
<footer id="foot1">
<p>The University of Arizona | All contents copyright © 2016. Arizona Board of Regents</p>
</footer>
</body>
</html>