Added discussion feature to site.
[Assignment-Trapper.git] / detail_root.php
blob2458245c95fe483b6a61b3dcbe091857df4e04e1
1 <?php
3 include_once("auth.php");
4 include_once("header.php");
5 include_once("time.php");
6 include_once("user_details.php");
8 $file_count = "";
9 $files = "";
10 $comm = "";
11 $student_list = "";
12 $help_icon = "";
13 $user = "";
14 $user_id_role = "";
15 $user_data_sent = "";
16 $student_user_name = "";
17 $comment_form = "";
20 function taunt_user()
22 $taunt[0] = "No Soup For You";
23 $taunt[1] = "My Dog Ate It";
24 $taunt[2] = "Alien Invasion";
25 $taunt[3] = "Alien Abduction";
26 $taunt[4] = "Epic Fail";
27 $taunt[5] = "You Have Failed To Fail";
28 $taunt[6] = "None Shall Pass";
29 $taunt[7] = "You'll Get Nothing And Like It";
30 $taunt[8] = "Virus";
31 $taunt[9] = "Fries With That?";
32 $taunt[10] = "You're Still Here?";
33 $taunt[11] = "About Time...";
34 $rand = rand (0, 11);
35 return $taunt[$rand];
38 if(isset($_GET["user"])) { $user_sent = true; } else { $user_sent = false; }
40 // prevents students from seeing other's work
41 if($role != 0) { $_GET["user"] = $user_id; }
43 if (!$_GET["sched"]) { die("No Assignment Requested"); }
45 if(isset($_GET["user"])) { $user_data_sent = true; }
47 if(isset($_GET["sched"])) { $_GET["sched"] = mysql_real_escape_string($_GET["sched"]); }
48 if(isset($_GET["user"] )) { $_GET["user"] = mysql_real_escape_string($_GET["user"]); }
50 /* get help status for this assignment */
51 if($role == 0) {
53 if(isset($_GET["user"])) {
54 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$_GET["user"];
56 $result = mysql_query($sql);
58 $row = mysql_fetch_row($result);
60 if($row[0] == 1) {
61 $help_stat = 'Disable';
62 $help_icon = '<img src=gfx/flag_red.png>';
63 } else {
64 $help_stat = 'Enable';
65 $help_icon = '<img src=gfx/flag_white.png>';
68 } else {
69 $sql = 'select help_me from sched_details where sched_id ='.$_GET["sched"].' and user_id = '.$user_id;
71 $result = mysql_query($sql);
73 $row = mysql_fetch_row($result);
75 if($row[0] == 1) {
76 $help_stat = 'Disable';
77 $help_icon = '<img src=gfx/flag_red.png>';
78 } else {
79 $help_stat = 'Enable';
80 $help_icon = '<img src=gfx/flag_white.png>';
84 /* get files / late status for this assignment */
85 if($role == 0 ) {
86 if($user_sent) {
87 if(assignment_late($_GET["user"], $_GET["sched"])) {
88 $file_count .= '<img src=gfx/tick_off.png>';
89 } else {
90 if(file_count($_GET["user"], $_GET["sched"])) {
91 $file_count .= '<img src=gfx/star.png>';
92 } else { $file_count .= '<img src=gfx/error.png>'; }
96 } else {
97 if(assignment_late($user_id, $_GET["sched"])) {
98 $file_count .= '<img src=gfx/tick_off.png>';
99 } else {
100 if(file_count($user_id, $_GET["sched"])) {
101 $file_count .= '<img src=gfx/star.png>';
102 } else { $file_count .= '<img src=gfx/error.png>'; }
106 $discussion .= '<a href="discussion.php?sched='.$_GET["sched"].'"><img src="./gfx/comments_small.png"></a></td>';
108 /* get assignment details */
109 $html = "";
111 $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";
113 $result = mysql_query($sql);
115 //echo $sql;
117 if (!$result) { die("SQL ERROR"); }
119 while($row = mysql_fetch_array($result))
121 $html .= '<tr>';
123 $html .= '<td>'.$row['sched_id'].'</td>';
125 // assignment started?
126 if($row['ava'] < 0){
127 $html .= "<td><img src=gfx/bullet_black.png>";
128 $started = false;
129 } else {
130 // assignment open?
131 if($row['status'] > 0 || $row['ava'] < 0) { $html .= "<td><img src=gfx/bullet_delete.png>"; } else { $html .= "<td><img src=gfx/bullet_add.png>"; }
132 $started = true;
135 // assignment graded?
136 if($row['graded']) { $html .= "<img src=gfx/bullet_disk.png>"; } else { $html .= "<img src=gfx/bullet_wrench.png>"; }
138 $html .= $help_icon;
139 $html .= $file_count;
140 $html .= $discussion;
141 $html .= '<td><a href="detail_root.php?sched='.$row['sched_id'].'">'.$row['title'].'</a></td><td>'.$row['type_name'].'</td><td>'.$row['chapter'].'</td>';
142 $html .= '<td>'.$row['section_id'].'</td><td>'.$row['ava_date'].'</td><td>'.$row['due_date'].'</td>';
144 if($started) {
145 $html .= '<td>'.absHumanTiming($row['due_date']).'</td>';
146 } else {
147 $html .= '<td>'.absHumanTiming($row['ava_date']).'</td>';
150 if($role != 0 ) { $html .= '<td><a href=help_me.php?sched='.$_GET["sched"].'>'.$help_stat.'</a></td>'; }
151 $html .= '</tr>';
154 /* get class this assignment is from for breadcrumbs */
155 $sql = 'select schedule.class_id, class.class_name from schedule, class where (schedule.class_id = class.class_id) and schedule.sched_id = '.$_GET["sched"];
157 //echo $sql;
159 $result = mysql_query($sql);
161 if (!$result) { die("SQL ERROR"); }
163 $row = mysql_fetch_array($result);
165 $breadcrumb = '<a href=assignment.php?class='.$row['class_id'].'>'.$row['class_name'].'</a>&nbsp;';
167 if($_GET["user"] == '' ) {
168 /* get class id for this schedule id */
170 $sql = 'select class_id from schedule where sched_id='.$_GET["sched"];
172 $result = mysql_query($sql);
174 if (!$result) { die("SQL ERROR"); }
176 $row = mysql_fetch_row($result);
178 $class_id = $row[0];
180 /* get list of students that are in this class and generate a list of them */
181 $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';
183 $result = mysql_query($sql);
185 if (!$result) { die("SQL ERROR"); }
187 $student_list = '<table class="gridtable"><tr><th>Student</th><th>Student</th><th>Student</th><th>Student</th></tr>';
189 $i = 1;
191 $student_list .= '<tr>';
193 while($row = mysql_fetch_array($result)) // getting list of students
195 $student_list .= '<td>';
196 //if(assignment_late($user_id, $_GET[$sched]) { } else { }
198 if(need_help($row['user_id'], $_GET['sched'])) {
199 $student_list .= '<img src=gfx/flag_red.png>';
200 } else { $student_list .= '<img src=gfx/flag_white.png>'; }
202 if(assignment_late($row['user_id'], $_GET['sched'])) {
203 $student_list .= '<img src=gfx/tick_off.png>';
204 } else {
205 if(file_count($row['user_id'], $_GET['sched'])) {
206 $student_list .= '<img src=gfx/star.png>';
207 } else { $student_list .= '<img src=gfx/error.png>'; }
210 //if($row['role'] == 0) { $student_list .= '<img src="gfx/user_suit.png">'; } else { $student_list .= '<img src="gfx/user_green.png">'; }
211 $student_list .= '<a href=detail_root.php?sched='.$_GET["sched"].'&user='.$row['user_id'].'>'.$row['name'].'</a></td>';
212 if( $i == 4) { $i = 1; $student_list .= '</tr><tr>'; } else { $i++; }
215 $student_list .= '</table>';
216 } else {
217 /* get latest versions of each file for this assignment ---------------------------------------------------------------------*/
219 // determine if we are logged in as root and if user ID has been sent...
220 if($_GET["user"] && $role == 0 ) { $this_user = $_GET["user"]; } else { $this_user = $user_id; }
222 // first get list of file_ids that are distinct names and the latest versions
223 $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';
225 //echo $sql;
227 $result = mysql_query($sql);
229 if (!$result) { die("SQL ERROR: File List"); }
231 $i = 0;
233 while($row = mysql_fetch_row($result)) // moving through list of files for this user and assignment
236 // get all comments for this particular file
237 //$sql = "select filecom_id, file_id, line_no, user_id, txt, timeposted from filecom where file_id=".$row[0]." order by line_no, timeposted";
238 $sql = 'select line_no, filecom.user_id, name, timeposted, txt, role from filecom, users
239 where (users.user_id = filecom.user_id) and file_id='.$row[1].' order by line_no, timeposted';
241 //echo $sql;
243 $filecom = mysql_query($sql);
244 if (!$filecom) { die("SQL ERROR: File Comments"); }
246 // only get first line comment
247 $filecoms = mysql_fetch_array($filecom);
249 if(isset($row[5])) { $code = $row[5]; }
251 // get file contents and details for each file
252 $sql = 'select file_id, time_post, file_name, file_size, time_post, file_1 from files where file_id ='.$row[1];
254 //echo $sql;
256 $result2 = mysql_query($sql);
257 if (!$result2) { die("SQL ERROR: File Details"); }
258 while($row2 = mysql_fetch_array($result2)) // moving through contents of each specific file
260 //echo sql;
262 //echo $row2['file_name'];
263 $code = $row2['file_1'];
264 $code = htmlspecialchars($code);
265 // convert tabs into spaces
266 $code = tab2space($code);
268 /* add line numbers to code */
269 $lines = explode("\n", $code);
271 $i = 1; $code = "";
272 foreach($lines AS $line) // moving through each line of code in file
274 if($role == 0) { $comm_class = "line_comment_fac"; } else { $comm_class = "line_comment_stu"; }
275 // we only get line comments as they are needed
276 if($filecoms['line_no'] == $i) { // comment exists for this line
278 do {
279 // run through comment rows for this line for display
280 if($filecoms['role'] == 0) {
281 $code .= "<div class=line_comment_display_fac>";
282 } else {
283 $code .= "<div class=line_comment_display_stu>";
285 $code .= "<img src='gfx/down_arrow.png'>";
286 $code .= "<span class=line_comment_txt>".$filecoms['txt']."</span>";
287 $code .= "<span class=line_comment_name>".$filecoms['name']."</span>";
288 $code .= "<span class=line_comment_time>".absHumanTiming($filecoms['timeposted'])."</span>";
289 $code .= "</div>";
291 $filecoms = mysql_fetch_array($filecom); // get next line comment
293 } while ($filecoms['line_no'] == $i);
295 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
296 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
297 $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;";
298 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
299 } else { // no comment for this line
300 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
301 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
302 $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;";
303 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
306 $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>";
307 if($line == '') { $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
308 } elseif($line == "\r") {
309 $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
310 } else { $code .= "<pre id='line_dat' class='line_dat'>".$line."</pre></div>\n"; }
311 $i++;
314 // header for file
316 if(file_late($row2['file_id'])) { $late_indicator = '<div class="file_head_late">'; } else { $late_indicator = '<div class="file_head">'; }
318 $files .= '<div class="file">
319 '.$late_indicator.'<img src="gfx/page_white_gear.png">
320 <span class="fname"><a href=file_raw.php?file_id='.$row2['file_id'].'>'.$row2['file_name'].'</a></span>
321 <span class="fsize">'.$row2['file_size'].'B</span>
322 <span class="fdate">'.$row2['time_post'].'</span>
323 <span class="fhuman">'.absHumanTiming($row2['time_post']).'</span>
324 <!-- <span class="fedit"><button>Edit</button></span>
325 <span class="fraw"><button>Raw</button></span>-->
326 </div>
327 <div class="highlight">
328 <div>
329 '.$code.'
331 </div>
332 </div>
333 </div><br><br>';
338 /* get comments for this assignment */
339 $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';
341 //echo $sql;
343 $result = mysql_query($sql);
345 if (!$result) { die("SQL ERROR"); }
347 while($row = mysql_fetch_array($result))
349 if($row['role'] != 0) {
350 $comm .= '<div class="comment"><div class="com_head">';
351 } else {
352 $comm .= '<div class="comment"><div class="com_head_fac">';
355 if($row['facname']) { $comm .= '<img src="gfx/user_suit.png">'; } else { $comm .= '<img src="gfx/user_green.png">'; }
357 if(!$row['facname']) {
358 $comm .= '<span class="com_name">'.$row['name'].'</span>';
359 } else {
360 $comm .= '<span class="com_name">'.$row['facname'].'</span>';
363 $comm .= '<span class="com_date">'.$row['timeposted'].'</span>';
364 $comm .= '<span class="com_human">'.absHumanTiming($row['timeposted']).'</span></div>';
366 $row['txt'] = htmlspecialchars($row['txt']);
367 $row['txt'] = tab2space($row['txt']);
368 // add breaks to text of comment - for readability
369 $row['txt'] = str_replace("\n", "<br>", $row['txt']);
371 $comm .= '<div class="com_body">
372 '.$row['txt'].'
373 </div>
374 </div><br><br>';
378 if($role != 0) {
379 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
380 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
381 <input name="sched" type="hidden" value='.$_GET["sched"].'>
382 <input name="user" type="hidden" value='.$_GET["user"].'>
383 <input type="submit" value="Add Comment" />
384 </form></div>';
385 } else { // returns root user back to same page after a post - otherwise would return to list of students
386 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
387 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
388 <input name="sched" type="hidden" value='.$_GET["sched"].'>
389 <input name="user" type="hidden" value='.$_GET["user"].'>
390 <input name="action" type="hidden" value="ret">
391 <input type="submit" value="Add Comment" />
392 </form></div>';
396 if(isset($_GET["user"])) {
397 $sql = 'select name, role from users where user_id='.$_GET["user"];
399 $result = mysql_query($sql);
401 $row = mysql_fetch_row($result);
403 if($role == 0) { $student_user_name = $row[0]; }
404 $user_id_role = $row[1];
407 /* determine if assignment is still open */
409 $sql = 'select count(*) from schedule where ava_date < NOW() and due_date > NOW() and sched_id ='.$_GET["sched"];
411 //echo $sql;
413 $result = mysql_query($sql);
415 $row = mysql_fetch_row($result);
417 if($row[0] == 1) { // assignment is open
419 if($role == 0 && $user_id_role == 0 && $user_data_sent) { // my role is root, student role is root and a user has been sent...
420 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
421 <input type="file" name="file" size="40"><br><br>
422 <input name="user" type="hidden" value='.$_GET["user"].'>
423 <input name="action" type="hidden" value="ret">
424 <input type="submit" name="submit" value="Submit"/>
425 </form></div>';
426 } else if($role != 0) {
427 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
428 <input type="file" name="file" size="40"><br><br>
429 <input type="submit" name="submit" value="Submit"/>
430 </form></div>';
431 } else {
432 $upload_form = '';
435 } else { // assignment is closed - show as a red upload box
436 if($role == 0 && $user_id_role == 0 && $user_data_sent) {
437 $upload_form = '<div class="comment_box_closed"><div class="comment_box_closed_message">'. taunt_user().'</div>
438 Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
439 <input type="file" name="file" size="40"><br><br>
440 <input name="user" type="hidden" value='.$_GET["user"].'>
441 <input name="action" type="hidden" value="ret">
442 <input type="submit" name="submit" value="Submit"/>
443 </form></div>';
444 } else if($role != 0) {
445 $upload_form = '<div class="comment_box_closed"><div class="comment_box_closed_message">'. taunt_user().'</div>
446 Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
447 <input type="file" name="file" size="40"><br><br>
448 <input type="submit" name="submit" value="Submit"/>
449 </form></div>';
450 } else {
451 $upload_form = '';
455 /* generate next and back buttons */
457 if($role == 0) {
459 // list of all students alphabetically in this class
460 $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';
462 $result = mysql_query($sql);
464 $row = mysql_fetch_array($result);
466 //echo $sql;
468 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">'; }
470 $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';
472 $result = mysql_query($sql);
474 $row = mysql_fetch_array($result);
476 //echo "<br>".$sql;
478 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">'; }
484 <h3><?php echo $breadcrumb; ?> -> Assignment Details</h3>
486 <table class="gridtable">
487 <tr>
488 <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>
490 <?php if($role != 0 ) { echo "<th>Help</th>"; } ?>
491 </tr>
492 <a name="top">
493 <?php echo $html; ?>
494 </table>
495 <br><br>
497 <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>
498 <?php echo $upload_form; ?>
500 <br><br>
501 <?php echo $student_list; ?>
502 <?php echo "<h1>".$student_user_name."</h1>"; ?>
503 <?php echo $files; ?>
504 <a name="bottom">
505 <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>
506 <?php echo "<h1>".$student_user_name."</h1>"; ?>
508 <?php echo $comm; ?>
509 <?php echo $comment_form; ?>
513 </html>