Added classes menu for students with more than one class.
[Assignment-Trapper.git] / detail_root.php
blobe00fccabf2b22711844531da8c746583ea530737
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'; }
24 /* get assignment details */
25 $html = "";
27 $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";
29 $result = mysql_query($sql);
31 //echo $sql;
33 if (!$result) { die("SQL ERROR"); }
35 while($row = mysql_fetch_row($result))
37 $html .= '<tr>';
39 // assignment open?
40 if($row[8] > 0) { $html .= "<td><img src=gfx/bullet_delete.png>"; } else { $html .= "<td><img src=gfx/bullet_add.png>"; }
42 // assignment graded?
43 if($row[12]) { $html .= "<img src=gfx/bullet_disk.png></td>"; } else { $html .= "<img src=gfx/bullet_wrench.png></td>"; }
46 $html .= '<td><a href="detail_root.php?sched='.$row[7].'">'.$row[2].'</a></td><td>'.$row[9].'</td><td>'.$row[0].'</td>';
47 $html .= '<td>'.$row[1].'</td><td>'.$row[5].'</td><td>'.$row[6].'</td>';
48 $html .= '<td>'.absHumanTiming($row[6]).'</td></tr>';
51 /* get class this assignment is from for breadcrumbs */
52 $sql = 'select schedule.class_id, class.class_name from schedule, class where (schedule.class_id = class.class_id) and schedule.sched_id = '.$_GET["sched"];
54 //echo $sql;
56 $result = mysql_query($sql);
58 if (!$result) { die("SQL ERROR"); }
60 $row = mysql_fetch_array($result);
62 $breadcrumb = '<a href=assignment.php?class='.$row['class_id'].'>'.$row['class_name'].'</a>&nbsp;';
64 if($_GET["user"] == '' ) {
65 /* get class id for this schedule id */
67 $sql = 'select class_id from schedule where sched_id='.$_GET["sched"];
69 $result = mysql_query($sql);
71 if (!$result) { die("SQL ERROR"); }
73 $row = mysql_fetch_row($result);
75 $class_id = $row[0];
77 /* get list of students that are in this class and generate a list of them */
78 $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';
80 //echo $sql;
82 $result = mysql_query($sql);
84 if (!$result) { die("SQL ERROR"); }
86 $student_list = '<table class="gridtable">
87 <tr>
88 <th>Role</th><th>Name</th><th>Email</th><th>Grade</th>
89 </tr>';
91 while($row = mysql_fetch_array($result)) // getting list of students
93 $student_list .= '<tr><td>';
94 if($row['role'] == 0) { $student_list .= '<img src="gfx/user_suit.png">'; } else { $student_list .= '<img src="gfx/user_green.png">'; }
95 $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>';
98 $student_list .= '</table>';
99 } else {
100 /* get latest versions of each file for this assignment ---------------------------------------------------------------------*/
102 // determine if we are logged in as root and if user ID has been sent...
103 if($_GET["user"] && $role == 0 ) { $this_user = $_GET["user"]; } else { $this_user = $user_id; }
105 // first get list of file_ids that are distinct names and the latest versions
106 $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';
108 //echo $sql;
110 $result = mysql_query($sql);
112 if (!$result) { die("SQL ERROR: File List"); }
114 $i = 0;
116 while($row = mysql_fetch_row($result)) // moving through list of files for this user and assignment
119 // get all comments for this particular file
120 //$sql = "select filecom_id, file_id, line_no, user_id, txt, timeposted from filecom where file_id=".$row[0]." order by line_no, timeposted";
121 $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';
123 //echo $sql;
125 $filecom = mysql_query($sql);
126 if (!$filecom) { die("SQL ERROR: File Comments"); }
128 // only get first line comment
129 $filecoms = mysql_fetch_array($filecom);
131 $code = $row[5];
133 // get file contents and details for each file
134 $sql = 'select file_id, time_post, file_name, file_size, time_post, file_1 from files where file_id ='.$row[1];
136 //echo $sql;
138 $result2 = mysql_query($sql);
139 if (!$result2) { die("SQL ERROR: File Details"); }
140 while($row2 = mysql_fetch_array($result2)) // moving through contents of each specific file
142 //echo $sql;
144 //echo $row2['file_name'];
145 $code = $row2['file_1'];
146 $code = htmlspecialchars($code);
147 // convert tabs into spaces
148 $code = tab2space($code);
150 /* add line numbers to code */
151 $lines = explode("\n", $code);
153 $i = 1; $code = "";
154 foreach($lines AS $line) // moving through each line of code in file
156 if($role == 0) { $comm_class = "line_comment_fac"; } else { $comm_class = "line_comment_stu"; }
157 // we only get line comments as they are needed
158 if($filecoms['line_no'] == $i) { // comment exists for this line
160 do {
161 // run through comment rows for this line for display
162 if($filecoms['role'] == 0) {
163 $code .= "<div class=line_comment_display_fac>";
164 } else {
165 $code .= "<div class=line_comment_display_stu>";
167 $code .= "<img src='gfx/down_arrow.png'>";
168 $code .= "<span class=line_comment_txt>".$filecoms['txt']."</span>";
169 $code .= "<span class=line_comment_name>".$filecoms['name']."</span>";
170 $code .= "<span class=line_comment_time>".absHumanTiming($filecoms['timeposted'])."</span>";
171 $code .= "</div>";
173 $filecoms = mysql_fetch_array($filecom); // get next line comment
175 } while ($filecoms['line_no'] == $i);
177 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
178 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
179 $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;";
180 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
181 } else { // no comment for this line
182 $code .= "<div id='line_com_".$row2['file_id']."_".$i."' class='".$comm_class."'>";
183 $code .= "<img src='gfx/down_arrow.png'><input id='line_com_val_".$row2['file_id']."_".$i."' type=text size=100>&nbsp;&nbsp;";
184 $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;";
185 $code .= "<button onClick='line_comment_cancel(\"line_com_".$row2['file_id']."_".$i."\");'>Cancel</button></div>";
188 $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>";
189 if($line == '') { $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
190 } elseif($line == "\r") {
191 $code .= "<pre id='line_dat' class='line_dat'> </pre></div>\n";
192 } else { $code .= "<pre id='line_dat' class='line_dat'>".$line."</pre></div>\n"; }
193 $i++;
196 // header for file
197 $files .= '<div class="file">
198 <div class="file_head"><img src="gfx/page_white_gear.png">
199 <span class="fname"><a href=file_raw.php?file_id='.$row2['file_id'].'>'.$row2['file_name'].'</a></span>
200 <span class="fsize">'.$row2['file_size'].'B</span>
201 <span class="fdate">'.$row2['time_post'].'</span>
202 <span class="fhuman">'.absHumanTiming($row2['time_post']).'</span>
203 <!-- <span class="fedit"><button>Edit</button></span>
204 <span class="fraw"><button>Raw</button></span>-->
205 </div>
206 <div class="highlight">
207 <div>
208 '.$code.'
210 </div>
211 </div>
212 </div><br><br>';
217 /* get comments for this assignment */
218 $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';
220 //echo $sql;
222 $result = mysql_query($sql);
224 if (!$result) { die("SQL ERROR"); }
226 while($row = mysql_fetch_array($result))
229 if($row['role'] != 0) {
230 $comm .= '<div class="comment"><div class="com_head">';
231 } else {
232 $comm .= '<div class="comment"><div class="com_head_fac">';
235 if($row['facname']) { $comm .= '<img src="gfx/user_suit.png">'; } else { $comm .= '<img src="gfx/user_green.png">'; }
237 if(!$row['facname']) {
238 $comm .= '<span class="com_name">'.$row['name'].'</span>';
239 } else {
240 $comm .= '<span class="com_name">'.$row['facname'].'</span>';
243 $comm .= '<span class="com_date">'.$row['timeposted'].'</span>';
244 $comm .= '<span class="com_human">'.absHumanTiming($row['timeposted']).'</span></div>';
246 $row['txt'] = htmlspecialchars($row['txt']);
247 $row['txt'] = tab2space($row['txt']);
249 $comm .= '<div class="com_body"><pre>
250 '.$row['txt'].'
251 </pre></div>
252 </div><br><br>';
256 if($role != 0) {
257 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
258 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
259 <input name="sched" type="hidden" value='.$_GET["sched"].'>
260 <input name="user" type="hidden" value='.$_GET["user"].'>
261 <input type="submit" value="Add Comment" />
262 </form></div>';
263 } else { // returns root user back to same page after a post - otherwise would return to list of students
264 $comment_form = '<div class="comment_box">Add Comment:<form action="comment.php" method="get">
265 <textarea name="comment" id="comment" cols="85" rows="6"></textarea><br><br>
266 <input name="sched" type="hidden" value='.$_GET["sched"].'>
267 <input name="user" type="hidden" value='.$_GET["user"].'>
268 <input name="action" type="hidden" value="ret">
269 <input type="submit" value="Add Comment" />
270 </form></div>';
274 if(isset($_GET["user"])) {
275 $sql = 'select name, role from users where user_id='.$_GET["user"];
277 $result = mysql_query($sql);
279 $row = mysql_fetch_row($result);
281 if($role == 0) { $student_user_name = $row[0]; }
282 $user_id_role = $row[1];
285 /* determine if assignment is still open */
287 $sql = 'select count(*) from schedule where ava_date < NOW() and due_date > NOW() and sched_id ='.$_GET["sched"];
289 $result = mysql_query($sql);
291 $row = mysql_fetch_row($result);
293 if($row[0] == 1) { // assignment is open
294 if($role == 0 && $user_id_role == 0 && isset($_GET["user"])) {
295 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
296 <input type="file" name="file" size="40"><br><br>
297 <input name="user" type="hidden" value='.$_GET["user"].'>
298 <input name="action" type="hidden" value="ret">
299 <input type="submit" name="submit" value="Submit"/>
300 </form></div>';
301 } else if($role != 0) {
302 $upload_form = '<div class="comment_box">Upload File:<form action="upload.php?sched='.$_GET["sched"].'" method="post" enctype="multipart/form-data">
303 <input type="file" name="file" size="40"><br><br>
304 <input type="submit" name="submit" value="Submit"/>
305 </form></div>';
306 } else {
307 $upload_form = '';
309 } else { // assignment is closed
310 $upload_form = '';
313 /* generate next and back buttons */
315 if($role == 0) {
317 // list of all students alphabetically in this class
318 $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';
320 $result = mysql_query($sql);
322 $row = mysql_fetch_array($result);
324 //echo $sql;
326 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">'; }
328 $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';
330 $result = mysql_query($sql);
332 $row = mysql_fetch_array($result);
334 //echo "<br>".$sql;
336 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">'; }
338 $next_back_buttons = '<center>'.$back_button;
339 $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;';
340 $next_back_buttons .= $next_button.'</center>';
345 <h3><?php echo $breadcrumb; ?> -> Assignment Details</h3>
347 <table class="gridtable">
348 <tr>
349 <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>
350 </tr>
352 <?php echo $html; ?>
353 </table>
354 <br><br>
355 <?php echo $next_back_buttons; ?>
357 <?php echo $upload_form; ?>
359 <br><br>
360 <?php echo $student_list; ?>
361 <?php echo "<h1>".$student_user_name."</h1>"; ?>
362 <?php echo $files; ?>
363 <?php echo $next_back_buttons; ?>
364 <?php echo "<h1>".$student_user_name."</h1>"; ?>
365 <?php echo $comm; ?>
366 <?php echo $comment_form; ?>
370 </html>