Modified headers of pages to expire on load.
[Assignment-Trapper.git] / detail_root.php
bloba46a2a5bd30c502789bff70a8944df7faf29953b
1 <?php
3 include_once("auth.php");
4 include_once("header.php");
5 include_once("time.php");
7 // prevents students from seeing other's work
8 if($role != 0) { $_GET["user"] = $user_id; }
10 if (!$_GET["sched"]) { die("No Assignment Requested"); }
12 $_GET["sched"] = mysql_real_escape_string($_GET["sched"]);
14 /* determine if assignment is still open */
16 $sql = 'select count(*) from schedule where ava_date < NOW() and due_date > NOW() and sched_id ='.$_GET["sched"];
18 $result = mysql_query($sql);
20 $row = mysql_fetch_row($result);
22 if($row[0] == 1) { $submission = 'Open'; } else { $submission = 'Closed'; }
25 /* get help status for this assignment */
27 if($role == 0) {
28 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$_GET["user"];
29 } else {
30 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$user_id;
33 $result = mysql_query($sql);
35 $row = mysql_fetch_row($result);
37 if($row[0] == 1) {
38 $help_stat = 'Disable';
39 $help_icon = '<img src=gfx/flag_red.png>';
40 } else {
41 $help_stat = 'Enable';
42 $help_icon = '<img src=gfx/flag_white.png>';
45 /* get assignment details */
46 $html = "";
48 $sql = "select chapter, section_id, title, class_id, schedule.assign_type, ava_date, due_date, sched_id, NOW()-due_date as status, type_name, graded from schedule, types where (schedule.assign_type = types.assign_type) and sched_id=".$_GET["sched"]." order by due_date desc, ava_date desc";
50 $result = mysql_query($sql);
52 //echo $sql;
54 if (!$result) { die("SQL ERROR"); }
56 while($row = mysql_fetch_row($result))
58 $html .= '<tr>';
60 // assignment open?
61 if($row[8] > 0) { $html .= "<td><img src=gfx/bullet_delete.png>"; } else { $html .= "<td><img src=gfx/bullet_add.png>"; }
63 // assignment graded?
64 if($row[12]) { $html .= "<img src=gfx/bullet_disk.png>"; } else { $html .= "<img src=gfx/bullet_wrench.png>"; }
66 $html .= $help_icon."</td>";
67 $html .= '<td><a href="detail_root.php?sched='.$row[7].'">'.$row[2].'</a></td><td>'.$row[9].'</td><td>'.$row[0].'</td>';
68 $html .= '<td>'.$row[1].'</td><td>'.$row[5].'</td><td>'.$row[6].'</td>';
69 $html .= '<td>'.absHumanTiming($row[6]).'</td>';
70 if($role != 0 ) { $html .= '<td><a href=help_me.php?sched='.$_GET["sched"].'>'.$help_stat.'</a></td>'; }
71 $html .= '</tr>';
74 /* get class this assignment is from for breadcrumbs */
75 $sql = 'select schedule.class_id, class.class_name from schedule, class where (schedule.class_id = class.class_id) and schedule.sched_id = '.$_GET["sched"];
77 //echo $sql;
79 $result = mysql_query($sql);
81 if (!$result) { die("SQL ERROR"); }
83 $row = mysql_fetch_array($result);
85 $breadcrumb = '<a href=assignment.php?class='.$row['class_id'].'>'.$row['class_name'].'</a>&nbsp;';
87 if($_GET["user"] == '' ) {
88 /* get class id for this schedule id */
90 $sql = 'select class_id from schedule where sched_id='.$_GET["sched"];
92 $result = mysql_query($sql);
94 if (!$result) { die("SQL ERROR"); }
96 $row = mysql_fetch_row($result);
98 $class_id = $row[0];
100 /* get list of students that are in this class and generate a list of them */
101 $sql = 'select users.name, users.email, users.user_id, role from users, enrollment where (users.user_id = enrollment.user_id) and enrollment.class_id='.$class_id.' order by users.name';
103 //echo $sql;
105 $result = mysql_query($sql);
107 if (!$result) { die("SQL ERROR"); }
109 $student_list = '<table class="gridtable">
110 <tr>
111 <th>Role</th><th>Name</th><th>Email</th><th>Grade</th>
112 </tr>';
114 while($row = mysql_fetch_array($result)) // getting list of students
116 $student_list .= '<tr><td>';
117 if($row['role'] == 0) { $student_list .= '<img src="gfx/user_suit.png">'; } else { $student_list .= '<img src="gfx/user_green.png">'; }
118 $student_list .= '</td><td>'.$row['name'].'</td><td>'.$row['email'].'<td><a href=detail_root.php?sched='.$_GET["sched"].'&user='.$row['user_id'].'>Grade</a></td></tr>';
121 $student_list .= '</table>';
122 } else {
123 /* get latest versions of each file for this assignment ---------------------------------------------------------------------*/
125 // determine if we are logged in as root and if user ID has been sent...
126 if($_GET["user"] && $role == 0 ) { $this_user = $_GET["user"]; } else { $this_user = $user_id; }
128 // first get list of file_ids that are distinct names and the latest versions
129 $sql = 'select distinct file_name, max(file_id) from files where user_id='.$this_user.' and sched_id='.$_GET["sched"].' group by file_name order by file_name';
131 //echo $sql;
133 $result = mysql_query($sql);
135 if (!$result) { die("SQL ERROR: File List"); }
137 $i = 0;
139 while($row = mysql_fetch_row($result)) // moving through list of files for this user and assignment
142 // get all comments for this particular file
143 //$sql = "select filecom_id, file_id, line_no, user_id, txt, timeposted from filecom where file_id=".$row[0]." order by line_no, timeposted";
144 $sql = 'select line_no, filecom.user_id, name, timeposted, txt, role from filecom, users where (users.user_id = filecom.user_id) and file_id='.$row[1].' order by line_no, timeposted';
146 //echo $sql;
148 $filecom = mysql_query($sql);
149 if (!$filecom) { die("SQL ERROR: File Comments"); }
151 // only get first line comment
152 $filecoms = mysql_fetch_array($filecom);
154 $code = $row[5];
156 // get file contents and details for each file
157 $sql = 'select file_id, time_post, file_name, file_size, time_post, file_1 from files where file_id ='.$row[1];
159 //echo $sql;
161 $result2 = mysql_query($sql);
162 if (!$result2) { die("SQL ERROR: File Details"); }
163 while($row2 = mysql_fetch_array($result2)) // moving through contents of each specific file
165 //echo $sql;
167 //echo $row2['file_name'];
168 $code = $row2['file_1'];
169 $code = htmlspecialchars($code);
170 // convert tabs into spaces
171 $code = tab2space($code);
173 /* add line numbers to code */
174 $lines = explode("\n", $code);
176 $i = 1; $code = "";
177 foreach($lines AS $line) // moving through each line of code in file
179 if($role == 0) { $comm_class = "line_comment_fac"; } else { $comm_class = "line_comment_stu"; }
180 // we only get line comments as they are needed
181 if($filecoms['line_no'] == $i) { // comment exists for this line
183 do {
184 // run through comment rows for this line for display
185 if($filecoms['role'] == 0) {
186 $code .= "<div class=line_comment_display_fac>";
187 } else {
188 $code .= "<div class=line_comment_display_stu>";
190 $code .= "<img src='gfx/down_arrow.png'>";
191 $code .= "<span class=line_comment_txt>".$filecoms['txt']."</span>";
192 $code .= "<span class=line_comment_name>".$filecoms['name']."</span>";
193 $code .= "<span class=line_comment_time>".absHumanTiming($filecoms['timeposted'])."</span>";
194 $code .= "</div>";
196 $filecoms = mysql_fetch_array($filecom); // get next line comment
198 } while ($filecoms['line_no'] == $i);
200 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
201 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
202 $code .= "<button onClick='line_comment_save(".$row2['file_id'].", ".$i.", \"line_com_".$row2['file_id']."_".$i."\",\"line_com_val_".$row2['file_id']."_".$i."\");'>Save</button>&nbsp;&nbsp;";
203 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
204 } else { // no comment for this line
205 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
206 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
207 $code .= "<button onClick='line_comment_save(".$row2['file_id'].", ".$i.", \"line_com_".$row2['file_id']."_".$i."\",\"line_com_val_".$row2['file_id']."_".$i."\");'>Save</button>&nbsp;&nbsp;";
208 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
211 $code .= "<div id='line' onClick='line_comment(\"line_com_".$row2['file_id']."_".$i."\" , \"line_com_val_".$row2['file_id']."_".$i."\");' class='line'><span class='line_num'>".$i."</span>";
212 if($line == '') { $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
213 } elseif($line == "\r") {
214 $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
215 } else { $code .= "<pre id='line_dat' class='line_dat'>".$line."</pre></div>\n"; }
216 $i++;
219 // header for file
220 $files .= '<div class="file">
221 <div class="file_head"><img src="gfx/page_white_gear.png">
222 <span class="fname"><a href=file_raw.php?file_id='.$row2['file_id'].'>'.$row2['file_name'].'</a></span>
223 <span class="fsize">'.$row2['file_size'].'B</span>
224 <span class="fdate">'.$row2['time_post'].'</span>
225 <span class="fhuman">'.absHumanTiming($row2['time_post']).'</span>
226 <!-- <span class="fedit"><button>Edit</button></span>
227 <span class="fraw"><button>Raw</button></span>-->
228 </div>
229 <div class="highlight">
230 <div>
231 '.$code.'
233 </div>
234 </div>
235 </div><br><br>';
240 /* get comments for this assignment */
241 $sql = 'select comment_id, stdusers.name, sub_id, fac_id, facusers.name as facname, txt, timeposted, comments.role from users stdusers, comments LEFT JOIN users facusers on (facusers.user_id = comments.fac_id) where (stdusers.user_id = comments.user_id) and comments.user_id='.$_GET["user"].' and sub_id='.$_GET["sched"].' order by timeposted';
243 //echo $sql;
245 $result = mysql_query($sql);
247 if (!$result) { die("SQL ERROR"); }
249 while($row = mysql_fetch_array($result))
252 if($row['role'] != 0) {
253 $comm .= '<div class="comment"><div class="com_head">';
254 } else {
255 $comm .= '<div class="comment"><div class="com_head_fac">';
258 if($row['facname']) { $comm .= '<img src="gfx/user_suit.png">'; } else { $comm .= '<img src="gfx/user_green.png">'; }
260 if(!$row['facname']) {
261 $comm .= '<span class="com_name">'.$row['name'].'</span>';
262 } else {
263 $comm .= '<span class="com_name">'.$row['facname'].'</span>';
266 $comm .= '<span class="com_date">'.$row['timeposted'].'</span>';
267 $comm .= '<span class="com_human">'.absHumanTiming($row['timeposted']).'</span></div>';
269 $row['txt'] = htmlspecialchars($row['txt']);
270 $row['txt'] = tab2space($row['txt']);
272 $comm .= '<div class="com_body">
273 '.$row['txt'].'
274 </div>
275 </div><br><br>';
279 if($role != 0) {
280 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
281 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
282 <input name="sched" type="hidden" value='.$_GET["sched"].'>
283 <input name="user" type="hidden" value='.$_GET["user"].'>
284 <input type="submit" value="Add Comment" />
285 </form></div>';
286 } else { // returns root user back to same page after a post - otherwise would return to list of students
287 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
288 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
289 <input name="sched" type="hidden" value='.$_GET["sched"].'>
290 <input name="user" type="hidden" value='.$_GET["user"].'>
291 <input name="action" type="hidden" value="ret">
292 <input type="submit" value="Add Comment" />
293 </form></div>';
297 if(isset($_GET["user"])) {
298 $sql = 'select name, role from users where user_id='.$_GET["user"];
300 $result = mysql_query($sql);
302 $row = mysql_fetch_row($result);
304 if($role == 0) { $student_user_name = $row[0]; }
305 $user_id_role = $row[1];
308 /* determine if assignment is still open */
310 $sql = 'select count(*) from schedule where ava_date < NOW() and due_date > NOW() and sched_id ='.$_GET["sched"];
312 $result = mysql_query($sql);
314 $row = mysql_fetch_row($result);
316 if($row[0] == 1) { // assignment is open
317 if($role == 0 && $user_id_role == 0 && isset($_GET["user"])) {
318 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
319 <input type="file" name="file" size="40"><br><br>
320 <input name="user" type="hidden" value='.$_GET["user"].'>
321 <input name="action" type="hidden" value="ret">
322 <input type="submit" name="submit" value="Submit"/>
323 </form></div>';
324 } else if($role != 0) {
325 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
326 <input type="file" name="file" size="40"><br><br>
327 <input type="submit" name="submit" value="Submit"/>
328 </form></div>';
329 } else {
330 $upload_form = '';
332 } else { // assignment is closed
333 $upload_form = '';
336 /* generate next and back buttons */
338 if($role == 0) {
340 // list of all students alphabetically in this class
341 $sql = 'select enrollment.user_id, name from schedule, enrollment, users where (schedule.class_id = enrollment.class_id) and (enrollment.user_id = users.user_id) and sched_id = '.$_GET["sched"].' and name < "'.$student_user_name.'" order by name desc, email desc, user_id desc limit 1';
343 $result = mysql_query($sql);
345 $row = mysql_fetch_array($result);
347 //echo $sql;
349 if ($row['user_id']) { $back_button = '<a href=detail_root.php?sched='.$_GET["sched"].'&user='.$row['user_id'].'><img src="gfx/resultset_previous.png" style="border-style: none"></a>'; } else { $back_button = '<img src="gfx/resultset_previous_disabled.png" style="border-style: none">'; }
351 $sql = 'select enrollment.user_id, name from schedule, enrollment, users where (schedule.class_id = enrollment.class_id) and (enrollment.user_id = users.user_id) and sched_id = '.$_GET["sched"].' and name > "'.$student_user_name.'" order by name, email, user_id limit 1';
353 $result = mysql_query($sql);
355 $row = mysql_fetch_array($result);
357 //echo "<br>".$sql;
359 if ($row['user_id']) { $next_button = '<a href=detail_root.php?sched='.$_GET["sched"].'&user='.$row['user_id'].'><img src="gfx/resultset_next.png" style="border-style: none"></a>'; } else { $next_button = '<img src="gfx/resultset_next_disabled.png" style="border-style: none">'; }
361 $next_back_buttons = '<center>'.$back_button;
362 $next_back_buttons .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
363 $next_back_buttons .= $next_button.'</center>';
368 <h3><?php echo $breadcrumb; ?> -> Assignment Details</h3>
370 <table class="gridtable">
371 <tr>
372 <th>Status</th><th>Title</th><th>Type</th><th>Chapter</th><th>Section</th><th>Avalable Date</th><th>Due Date</th><th>Human Time</th>
374 <?php if($role != 0 ) { echo "<th>Help</th>"; } ?>
375 </tr>
377 <?php echo $html; ?>
378 </table>
379 <br><br>
380 <?php echo $next_back_buttons; ?>
382 <?php echo $upload_form; ?>
384 <br><br>
385 <?php echo $student_list; ?>
386 <?php echo "<h1>".$student_user_name."</h1>"; ?>
387 <?php echo $files; ?>
388 <?php echo $next_back_buttons; ?>
389 <?php echo "<h1>".$student_user_name."</h1>"; ?>
390 <?php echo $comm; ?>
391 <?php echo $comment_form; ?>
395 </html>