24e17df1105c525a6542a4115296df586c8c1d28
[atutor.git] / docs / mods / _standard / gradebook / my_gradebook.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 $page = 'gradebook';
15
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require (AT_INCLUDE_PATH.'vitals.inc.php');
18
19 require ('lib/gradebook.inc.php');
20
21 require(AT_INCLUDE_PATH.'header.inc.php'); 
22
23 ?>
24
25 <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
26
27 <table summary="" class="data" rules="cols" align="center" style="width: 95%;">
28
29 <thead>
30 <tr>
31         <th scope="col"><?php echo _AT('title'); ?></th>
32         <th scope="col"><?php echo _AT('your_mark'); ?></th>
33         <th scope="col"><?php echo _AT('class_avg'); ?></th>
34         <th scope="col"><?php echo _AT('due_date'); ?></th>
35         <th scope="col"><?php echo _AT('completed_date'); ?></th>
36         <th scope="col"><?php echo _AT('time_spent'); ?></th>
37 </tr>
38 </thead>
39
40 <tbody>
41 <?php
42
43 $sql = "(SELECT g.gradebook_test_id, g.id, type, t.title, t.end_date due_date, grade_scale_id, t.result_release ".
44                                 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t".
45                                 " WHERE g.type='ATutor Test'".
46                                 " AND g.id = t.test_id".
47                                 " AND t.course_id=".$_SESSION["course_id"].
48                                 " ORDER BY t.title) ".
49                                 " UNION (SELECT g.gradebook_test_id, g.id, g.type, a.title, a.date_due due_date, grade_scale_id, '' result_release ".
50                                 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."assignments a".
51                                 " WHERE g.type='ATutor Assignment'".
52                                 " AND g.id = a.assignment_id".
53                                 " AND a.course_id=".$_SESSION["course_id"].
54                                 " ORDER BY title)".
55                                 " UNION (SELECT gradebook_test_id, id, type, title, due_date, grade_scale_id, '' result_release ".
56                                 " FROM ".TABLE_PREFIX."gradebook_tests".
57                                 " WHERE course_id=".$_SESSION["course_id"].
58                                 " ORDER BY title)";
59 $result = mysql_query($sql, $db) or die(mysql_error());
60
61 if (mysql_num_rows($result) == 0)
62 {
63 ?>
64         <tr>
65                 <td colspan="6"><?php echo _AT('none_found'); ?></td>
66         </tr>
67 <?php 
68 }
69 else
70 {
71         while ($row = mysql_fetch_assoc($result))
72         {
73                 $sql_grade = "SELECT grade FROM ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id=".$row["gradebook_test_id"]." AND member_id=".$_SESSION["member_id"];
74                 $result_grade = mysql_query($sql_grade, $db) or die(mysql_error());
75                 $row_grade = mysql_fetch_assoc($result_grade);
76                 
77                 if (mysql_num_rows($result_grade) == 0)
78                         $grade = "";
79                 else
80                 {
81                         $grade = $row_grade["grade"];
82                 }
83                 
84                 if ($row["type"] == "ATutor Test")
85                 {
86                         // get "completed date" and "time spent"
87                         if ($grade <> "")
88                         {
89                                 $sql_tr = "SELECT R.result_id, R.date_taken, (UNIX_TIMESTAMP(R.end_time) - UNIX_TIMESTAMP(R.date_taken)) AS diff FROM ".TABLE_PREFIX."tests_results R WHERE R.status=1 AND R.test_id=".$row["id"]." AND R.member_id='".$_SESSION[member_id]."'";
90                                 $result_tr = mysql_query($sql_tr, $db) or die(mysql_error());
91                                 $row_tr = mysql_fetch_assoc($result_tr);
92                         }
93 ?>
94                 <tr>
95 <?php 
96                         if ( ($grade != '') && (($row['result_release']==AT_RELEASE_IMMEDIATE) || ($row['result_release']==AT_RELEASE_MARKED)) )
97                                 echo '                  <td><a href="mods/_standard/tests/view_results.php?tid='.$row['id'].'&amp;rid='.$row_tr['result_id'].'">'.$row["title"].'</a></td>'."\n\r";
98                         else
99                                 echo '                  <td>'.$row["title"].'</td>'."\n\r";
100 ?>
101                         <td><?php echo ($grade=="") ? _AT("na") : $grade; ?></td>
102                         <td><?php echo get_class_avg($row["gradebook_test_id"]); ?></td>
103                         <td><?php echo $row["due_date"]; ?></td>
104                         <td><?php echo ($grade=="") ? _AT("na") : $row_tr["date_taken"]; ?></td>
105                         <td><?php echo ($grade=="") ? _AT("na") : get_human_time($row_tr['diff']); ?></td>
106                 </tr>
107 <?php 
108                 }
109                 else
110                 {
111 ?>
112                 <tr>
113                         <td><?php echo $row["title"]; ?></td>
114                         <td><?php echo ($grade=="") ? _AT("na") : $grade; ?></td>
115                         <td><?php echo get_class_avg($row["gradebook_test_id"]); ?></td>
116                         <td><?php echo $row["due_date"]; ?></td>
117                         <td><?php echo ($grade=="") ? _AT("pending") : _AT("completed"); ?></td>
118                         <td><?php echo _AT("na"); ?></td>
119                 </tr>
120 <?php 
121                 }
122         }
123 }
124 ?>
125
126 </tbody>
127 </table>
128 </form>
129
130 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>