Chat window now opens with no messages inside.
[Assignment-Trapper.git] / detail_root.php
blobcea4b0277a40140d51de2285d66a7569e80cabc2
1 <?php
3 include_once("auth.php");
4 include_once("header.php");
5 include_once("time.php");
6 include_once("user_details.php");
8 function taunt_user()
10 $taunt[0] = "No Soup For You";
11 $taunt[1] = "My Dog Ate It";
12 $taunt[2] = "Alien Invasion";
13 $taunt[3] = "Alien Abduction";
14 $taunt[4] = "Epic Fail";
15 $taunt[5] = "You Have Failed To Fail";
16 $taunt[6] = "None Shall Pass";
17 $taunt[7] = "You'll Get Nothing And Like It";
18 $taunt[8] = "Virus";
19 $taunt[9] = "Fries With That?";
20 $taunt[10] = "You're Still Here?";
21 $taunt[11] = "About Time...";
22 $rand = rand (0, 11);
23 return $taunt[$rand];
26 if(isset($_GET["user"])) { $user_sent = true; } else { $user_sent = false; }
28 // prevents students from seeing other's work
29 if($role != 0) { $_GET["user"] = $user_id; }
31 if (!$_GET["sched"]) { die("No Assignment Requested"); }
33 if(isset($_GET["user"])) { $user_data_sent = true; }
35 $_GET["sched"] = mysql_real_escape_string($_GET["sched"]);
36 $_GET["user"] = mysql_real_escape_string($_GET["user"]);
38 /* get help status for this assignment */
39 if($role == 0) {
41 if($_GET["user"]) {
42 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$_GET["user"];
44 $result = mysql_query($sql);
46 $row = mysql_fetch_row($result);
48 if($row[0] == 1) {
49 $help_stat = 'Disable';
50 $help_icon = '<img src=gfx/flag_red.png>';
51 } else {
52 $help_stat = 'Enable';
53 $help_icon = '<img src=gfx/flag_white.png>';
56 } else {
57 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$user_id;
59 $result = mysql_query($sql);
61 $row = mysql_fetch_row($result);
63 if($row[0] == 1) {
64 $help_stat = 'Disable';
65 $help_icon = '<img src=gfx/flag_red.png>';
66 } else {
67 $help_stat = 'Enable';
68 $help_icon = '<img src=gfx/flag_white.png>';
72 /* get files / late status for this assignment */
73 if($role == 0 ) {
74 if($user_sent) {
75 if(assignment_late($_GET["user"], $_GET["sched"])) {
76 $file_count .= '<img src=gfx/tick_off.png></td>';
77 } else {
78 if(file_count($_GET["user"], $_GET["sched"])) {
79 $file_count .= '<img src=gfx/star.png></td>';
80 } else { $file_count .= '<img src=gfx/error.png></td>'; }
84 } else {
85 if(assignment_late($user_id, $_GET["sched"])) {
86 $file_count .= '<img src=gfx/tick_off.png></td>';
87 } else {
88 if(file_count($user_id, $_GET["sched"])) {
89 $file_count .= '<img src=gfx/star.png></td>';
90 } else { $file_count .= '<img src=gfx/error.png></td>'; }
94 /* get assignment details */
95 $html = "";
97 $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, NOW()-ava_date as ava from schedule, types where (schedule.assign_type = types.assign_type) and sched_id=".$_GET["sched"]." order by due_date desc, ava_date desc";
99 $result = mysql_query($sql);
101 //echo $sql;
103 if (!$result) { die("SQL ERROR"); }
105 while($row = mysql_fetch_array($result))
107 $html .= '<tr>';
109 $html .= '<td>'.$row['sched_id'].'</td>';
111 // assignment started?
112 if($row['ava'] < 0){
113 $html .= "<td><img src=gfx/bullet_black.png>";
114 $started = false;
115 } else {
116 // assignment open?
117 if($row['status'] > 0 || $row['ava'] < 0) { $html .= "<td><img src=gfx/bullet_delete.png>"; } else { $html .= "<td><img src=gfx/bullet_add.png>"; }
118 $started = true;
121 // assignment graded?
122 if($row['graded']) { $html .= "<img src=gfx/bullet_disk.png>"; } else { $html .= "<img src=gfx/bullet_wrench.png>"; }
124 $html .= $help_icon;
125 $html .= $file_count."</td>";
126 $html .= '<td><a href="detail_root.php?sched='.$row['sched_id'].'">'.$row['title'].'</a></td><td>'.$row['type_name'].'</td><td>'.$row['chapter'].'</td>';
127 $html .= '<td>'.$row['section_id'].'</td><td>'.$row['ava_date'].'</td><td>'.$row['due_date'].'</td>';
129 if($started) {
130 $html .= '<td>'.absHumanTiming($row['due_date']).'</td>';
131 } else {
132 $html .= '<td>'.absHumanTiming($row['ava_date']).'</td>';
135 if($role != 0 ) { $html .= '<td><a href=help_me.php?sched='.$_GET["sched"].'>'.$help_stat.'</a></td>'; }
136 $html .= '</tr>';
139 /* get class this assignment is from for breadcrumbs */
140 $sql = 'select schedule.class_id, class.class_name from schedule, class where (schedule.class_id = class.class_id) and schedule.sched_id = '.$_GET["sched"];
142 //echo $sql;
144 $result = mysql_query($sql);
146 if (!$result) { die("SQL ERROR"); }
148 $row = mysql_fetch_array($result);
150 $breadcrumb = '<a href=assignment.php?class='.$row['class_id'].'>'.$row['class_name'].'</a>&nbsp;';
152 if($_GET["user"] == '' ) {
153 /* get class id for this schedule id */
155 $sql = 'select class_id from schedule where sched_id='.$_GET["sched"];
157 $result = mysql_query($sql);
159 if (!$result) { die("SQL ERROR"); }
161 $row = mysql_fetch_row($result);
163 $class_id = $row[0];
165 /* get list of students that are in this class and generate a list of them */
166 $sql = 'select users.name, users.user_id, role from users, enrollment where (users.user_id = enrollment.user_id) and enrollment.class_id='.$class_id.' order by users.name';
168 $result = mysql_query($sql);
170 if (!$result) { die("SQL ERROR"); }
172 $student_list = '<table class="gridtable"><tr><th>Student</th><th>Student</th><th>Student</th><th>Student</th></tr>';
174 $i = 1;
176 $student_list .= '<tr>';
178 while($row = mysql_fetch_array($result)) // getting list of students
180 $student_list .= '<td>';
181 //if(assignment_late($user_id, $_GET[$sched]) { } else { }
183 if(need_help($row['user_id'], $_GET['sched'])) {
184 $student_list .= '<img src=gfx/flag_red.png>';
185 } else { $student_list .= '<img src=gfx/flag_white.png>'; }
187 if(assignment_late($row['user_id'], $_GET['sched'])) {
188 $student_list .= '<img src=gfx/tick_off.png>';
189 } else {
190 if(file_count($row['user_id'], $_GET['sched'])) {
191 $student_list .= '<img src=gfx/star.png>';
192 } else { $student_list .= '<img src=gfx/error.png>'; }
195 //if($row['role'] == 0) { $student_list .= '<img src="gfx/user_suit.png">'; } else { $student_list .= '<img src="gfx/user_green.png">'; }
196 $student_list .= '<a href=detail_root.php?sched='.$_GET["sched"].'&user='.$row['user_id'].'>'.$row['name'].'</a></td>';
197 if( $i == 4) { $i = 1; $student_list .= '</tr><tr>'; } else { $i++; }
200 $student_list .= '</table>';
201 } else {
202 /* get latest versions of each file for this assignment ---------------------------------------------------------------------*/
204 // determine if we are logged in as root and if user ID has been sent...
205 if($_GET["user"] && $role == 0 ) { $this_user = $_GET["user"]; } else { $this_user = $user_id; }
207 // first get list of file_ids that are distinct names and the latest versions
208 $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';
210 //echo $sql;
212 $result = mysql_query($sql);
214 if (!$result) { die("SQL ERROR: File List"); }
216 $i = 0;
218 while($row = mysql_fetch_row($result)) // moving through list of files for this user and assignment
221 // get all comments for this particular file
222 //$sql = "select filecom_id, file_id, line_no, user_id, txt, timeposted from filecom where file_id=".$row[0]." order by line_no, timeposted";
223 $sql = 'select line_no, filecom.user_id, name, timeposted, txt, role from filecom, users
224 where (users.user_id = filecom.user_id) and file_id='.$row[1].' order by line_no, timeposted';
226 //echo $sql;
228 $filecom = mysql_query($sql);
229 if (!$filecom) { die("SQL ERROR: File Comments"); }
231 // only get first line comment
232 $filecoms = mysql_fetch_array($filecom);
234 $code = $row[5];
236 // get file contents and details for each file
237 $sql = 'select file_id, time_post, file_name, file_size, time_post, file_1 from files where file_id ='.$row[1];
239 //echo $sql;
241 $result2 = mysql_query($sql);
242 if (!$result2) { die("SQL ERROR: File Details"); }
243 while($row2 = mysql_fetch_array($result2)) // moving through contents of each specific file
245 //echo sql;
247 //echo $row2['file_name'];
248 $code = $row2['file_1'];
249 $code = htmlspecialchars($code);
250 // convert tabs into spaces
251 $code = tab2space($code);
253 /* add line numbers to code */
254 $lines = explode("\n", $code);
256 $i = 1; $code = "";
257 foreach($lines AS $line) // moving through each line of code in file
259 if($role == 0) { $comm_class = "line_comment_fac"; } else { $comm_class = "line_comment_stu"; }
260 // we only get line comments as they are needed
261 if($filecoms['line_no'] == $i) { // comment exists for this line
263 do {
264 // run through comment rows for this line for display
265 if($filecoms['role'] == 0) {
266 $code .= "<div class=line_comment_display_fac>";
267 } else {
268 $code .= "<div class=line_comment_display_stu>";
270 $code .= "<img src='gfx/down_arrow.png'>";
271 $code .= "<span class=line_comment_txt>".$filecoms['txt']."</span>";
272 $code .= "<span class=line_comment_name>".$filecoms['name']."</span>";
273 $code .= "<span class=line_comment_time>".absHumanTiming($filecoms['timeposted'])."</span>";
274 $code .= "</div>";
276 $filecoms = mysql_fetch_array($filecom); // get next line comment
278 } while ($filecoms['line_no'] == $i);
280 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
281 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
282 $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;";
283 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
284 } else { // no comment for this line
285 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
286 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
287 $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;";
288 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
291 $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>";
292 if($line == '') { $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
293 } elseif($line == "\r") {
294 $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
295 } else { $code .= "<pre id='line_dat' class='line_dat'>".$line."</pre></div>\n"; }
296 $i++;
299 // header for file
301 if(file_late($row2['file_id'])) { $late_indicator = '<div class="file_head_late">'; } else { $late_indicator = '<div class="file_head">'; }
303 $files .= '<div class="file">
304 '.$late_indicator.'<img src="gfx/page_white_gear.png">
305 <span class="fname"><a href=file_raw.php?file_id='.$row2['file_id'].'>'.$row2['file_name'].'</a></span>
306 <span class="fsize">'.$row2['file_size'].'B</span>
307 <span class="fdate">'.$row2['time_post'].'</span>
308 <span class="fhuman">'.absHumanTiming($row2['time_post']).'</span>
309 <!-- <span class="fedit"><button>Edit</button></span>
310 <span class="fraw"><button>Raw</button></span>-->
311 </div>
312 <div class="highlight">
313 <div>
314 '.$code.'
316 </div>
317 </div>
318 </div><br><br>';
323 /* get comments for this assignment */
324 $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';
326 //echo $sql;
328 $result = mysql_query($sql);
330 if (!$result) { die("SQL ERROR"); }
332 while($row = mysql_fetch_array($result))
334 if($row['role'] != 0) {
335 $comm .= '<div class="comment"><div class="com_head">';
336 } else {
337 $comm .= '<div class="comment"><div class="com_head_fac">';
340 if($row['facname']) { $comm .= '<img src="gfx/user_suit.png">'; } else { $comm .= '<img src="gfx/user_green.png">'; }
342 if(!$row['facname']) {
343 $comm .= '<span class="com_name">'.$row['name'].'</span>';
344 } else {
345 $comm .= '<span class="com_name">'.$row['facname'].'</span>';
348 $comm .= '<span class="com_date">'.$row['timeposted'].'</span>';
349 $comm .= '<span class="com_human">'.absHumanTiming($row['timeposted']).'</span></div>';
351 $row['txt'] = htmlspecialchars($row['txt']);
352 $row['txt'] = tab2space($row['txt']);
353 // add breaks to text of comment - for readability
354 $row['txt'] = str_replace("\n", "<br>", $row['txt']);
356 $comm .= '<div class="com_body">
357 '.$row['txt'].'
358 </div>
359 </div><br><br>';
363 if($role != 0) {
364 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
365 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
366 <input name="sched" type="hidden" value='.$_GET["sched"].'>
367 <input name="user" type="hidden" value='.$_GET["user"].'>
368 <input type="submit" value="Add Comment" />
369 </form></div>';
370 } else { // returns root user back to same page after a post - otherwise would return to list of students
371 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
372 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
373 <input name="sched" type="hidden" value='.$_GET["sched"].'>
374 <input name="user" type="hidden" value='.$_GET["user"].'>
375 <input name="action" type="hidden" value="ret">
376 <input type="submit" value="Add Comment" />
377 </form></div>';
381 if(isset($_GET["user"])) {
382 $sql = 'select name, role from users where user_id='.$_GET["user"];
384 $result = mysql_query($sql);
386 $row = mysql_fetch_row($result);
388 if($role == 0) { $student_user_name = $row[0]; }
389 $user_id_role = $row[1];
392 /* determine if assignment is still open */
394 $sql = 'select count(*) from schedule where ava_date < NOW() and due_date > NOW() and sched_id ='.$_GET["sched"];
396 //echo $sql;
398 $result = mysql_query($sql);
400 $row = mysql_fetch_row($result);
402 if($row[0] == 1) { // assignment is open
404 if($role == 0 && $user_id_role == 0 && $user_data_sent) { // my role is root, student role is root and a user has been sent...
405 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
406 <input type="file" name="file" size="40"><br><br>
407 <input name="user" type="hidden" value='.$_GET["user"].'>
408 <input name="action" type="hidden" value="ret">
409 <input type="submit" name="submit" value="Submit"/>
410 </form></div>';
411 } else if($role != 0) {
412 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
413 <input type="file" name="file" size="40"><br><br>
414 <input type="submit" name="submit" value="Submit"/>
415 </form></div>';
416 } else {
417 $upload_form = '';
420 } else { // assignment is closed - show as a red upload box
421 if($role == 0 && $user_id_role == 0 && $user_data_sent) {
422 $upload_form = '<div class="comment_box_closed"><div class="comment_box_closed_message">'. taunt_user().'</div>
423 Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
424 <input type="file" name="file" size="40"><br><br>
425 <input name="user" type="hidden" value='.$_GET["user"].'>
426 <input name="action" type="hidden" value="ret">
427 <input type="submit" name="submit" value="Submit"/>
428 </form></div>';
429 } else if($role != 0) {
430 $upload_form = '<div class="comment_box_closed"><div class="comment_box_closed_message">'. taunt_user().'</div>
431 Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
432 <input type="file" name="file" size="40"><br><br>
433 <input type="submit" name="submit" value="Submit"/>
434 </form></div>';
435 } else {
436 $upload_form = '';
440 /* generate next and back buttons */
442 if($role == 0) {
444 // list of all students alphabetically in this class
445 $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';
447 $result = mysql_query($sql);
449 $row = mysql_fetch_array($result);
451 //echo $sql;
453 if ($row['name']) { $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">'; }
455 $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';
457 $result = mysql_query($sql);
459 $row = mysql_fetch_array($result);
461 //echo "<br>".$sql;
463 if ($row['name']) { $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">'; }
469 <h3><?php echo $breadcrumb; ?> -> Assignment Details</h3>
471 <table class="gridtable">
472 <tr>
473 <th>#</th><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>
475 <?php if($role != 0 ) { echo "<th>Help</th>"; } ?>
476 </tr>
477 <a name="top">
478 <?php echo $html; ?>
479 </table>
480 <br><br>
482 <center><?php echo $back_button; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#bottom"><img src="gfx/resultset_down.png" style="border-style: none"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $next_button; ?></center>
483 <?php echo $upload_form; ?>
485 <br><br>
486 <?php echo $student_list; ?>
487 <?php echo "<h1>".$student_user_name."</h1>"; ?>
488 <?php echo $files; ?>
489 <a name="bottom">
490 <center><?php echo $back_button; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#top"><img src="gfx/resultset_up.png" style="border-style: none"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $next_button; ?></center>
491 <?php echo "<h1>".$student_user_name."</h1>"; ?>
493 <?php echo $comm; ?>
494 <?php echo $comment_form; ?>
498 </html>