7e44dd2e9c7a7d521efc104ec46e48667def7d0e
[atutor.git] / mods / gradebook / grade_scale.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/\r
6 /* Adaptive Technology Resource Centre / University of Toronto                  */\r
7 /* http://atutor.ca                                                                                                             */\r
8 /*                                                                                                                                              */\r
9 /* This program is free software. You can redistribute it and/or                */\r
10 /* modify it under the terms of the GNU General Public License                  */\r
11 /* as published by the Free Software Foundation.                                                */\r
12 /************************************************************************/\r
13 // $Id: grade_scale.php 7208 2008-05-28 16:07:24Z cindy $\r
14 \r
15 $page = 'gradebook';\r
16 \r
17 define('AT_INCLUDE_PATH', '../../include/');\r
18 require (AT_INCLUDE_PATH.'vitals.inc.php');\r
19 authenticate(AT_PRIV_GRADEBOOK);\r
20 \r
21 function print_row($grade_scale_id, $scale_name, $value, $created_date, $post_grade_scale_id, $print_radio_button=true)\r
22 {\r
23 ?>\r
24                 <tr onmousedown="document.form['m<?php echo $grade_scale_id; ?>'].checked = true; rowselect(this);" id="r_<?php echo $grade_scale_id; ?>">\r
25 <?php\r
26         if ($print_radio_button)\r
27         {\r
28 ?>\r
29                         <td width="10"><input type="radio" name="grade_scale_id" value="<?php echo $grade_scale_id; ?>" id="m<?php echo $grade_scale_id; ?>" <?php if ($grade_scale_id==$post_grade_scale_id) echo 'checked'; ?> /></td>\r
30                         <td><label for="m<?php echo $grade_scale_id; ?>"><?php echo $scale_name; ?></label></td>\r
31 <?php\r
32         }\r
33         else\r
34         {\r
35 ?>\r
36                         <td><?php echo $scale_name; ?></td>\r
37 <?php\r
38         }\r
39 ?>\r
40                         <td><?php echo $value; ?></td>\r
41                         <td><?php echo $created_date; ?></td>\r
42                 </tr>\r
43 <?php\r
44 }\r
45 \r
46 if (isset($_POST['remove'], $_POST['grade_scale_id'])) \r
47 {\r
48         header('Location: grade_scale_delete.php?grade_scale_id='.$_POST['grade_scale_id']);\r
49         exit;\r
50\r
51 else if (isset($_POST['edit'], $_POST['grade_scale_id'])) \r
52 {\r
53         header('Location: grade_scale_edit.php?grade_scale_id='.$_POST['grade_scale_id']);\r
54         exit;\r
55\r
56 else if (!empty($_POST) && !isset($_POST['grade_scale_id'])) {\r
57         $msg->addError('NO_ITEM_SELECTED');\r
58 }\r
59 \r
60 require(AT_INCLUDE_PATH.'header.inc.php'); \r
61 ?>\r
62 \r
63 <form name="form" method="post" action="<?php echo 'mods/gradebook/grade_scale.php'; ?>">\r
64 \r
65 <h3 align="center"><?php echo _AT('custom_grade_scale'); ?></h3>\r
66 \r
67 <table summary="" class="data" rules="cols" align="center" style="width: 70%;">\r
68 \r
69 <thead>\r
70 <tr>\r
71         <th scope="col">&nbsp;</th>\r
72         <th scope="col"><?php echo _AT('name'); ?></th>\r
73         <th scope="col"><?php echo _AT('grade_scale'); ?></th>\r
74         <th scope="col"><?php echo _AT('created_date'); ?></th>\r
75 </tr>\r
76 </thead>\r
77 <tfoot>\r
78 <tr>\r
79         <td colspan="5">\r
80                 <div class="row buttons">\r
81                 <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> \r
82                 <input type="submit" name="remove" value="<?php echo _AT('remove'); ?>" /> \r
83                 </div>\r
84         </td>\r
85 </tr>\r
86 <tr>\r
87         <td colspan="5"></td>\r
88 </tr>\r
89 </tfoot>\r
90 <tbody>\r
91 <?php\r
92 \r
93 $sql = "SELECT g.*, d.* from ".TABLE_PREFIX."grade_scales g, ".TABLE_PREFIX."grade_scales_detail d WHERE g.member_id= ".$_SESSION["member_id"]." AND g.grade_scale_id = d.grade_scale_id ORDER BY g.grade_scale_id, d.percentage_to desc";\r
94 \r
95 $result = mysql_query($sql, $db) or die(mysql_error());\r
96 \r
97 if (mysql_num_rows($result) == 0)\r
98 {\r
99 ?>\r
100         <tr>\r
101                 <td colspan="5"><?php echo _AT('none_found'); ?></td>\r
102         </tr>\r
103 <?php \r
104 }\r
105 else\r
106 {\r
107         $prev_row['grade_scale_id'] = 0;\r
108         while ($row = mysql_fetch_assoc($result))\r
109         {\r
110                 if ($row['grade_scale_id'] <> $prev_row['grade_scale_id'])\r
111                 {\r
112                         // print row\r
113                         if ($prev_row['grade_scale_id'] <> 0) print_row($prev_row['grade_scale_id'], $prev_row['scale_name'], $whole_scale_value, $prev_row['created_date'], $_POST['grade_scale_id']);\r
114 \r
115                         // initialize next $whole_scale_value\r
116                         $whole_scale_value = $row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';\r
117                         $prev_row = $row;\r
118                 }\r
119                 else\r
120                 {\r
121                         $whole_scale_value .= '<br />'.$row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';\r
122                 }\r
123         }\r
124         // print last row\r
125         if ($prev_row['grade_scale_id'] <> 0) print_row($prev_row['grade_scale_id'], $prev_row['scale_name'], $whole_scale_value, $prev_row['created_date'], $_POST['grade_scale_id']);\r
126 }\r
127 ?>\r
128 \r
129 </tbody>\r
130 </table>\r
131 </form>\r
132 \r
133 <h3 align="center"><?php echo _AT('preset_grade_scale'); ?></h3>\r
134 <table summary="" class="data" rules="cols" align="center" style="width: 70%;">\r
135 <thead>\r
136 <tr>\r
137         <th scope="col"><?php echo _AT('name'); ?></th>\r
138         <th scope="col"><?php echo _AT('grade_scale'); ?></th>\r
139         <th scope="col"><?php echo _AT('created_date'); ?></th>\r
140 </tr>\r
141 </thead>\r
142 \r
143 <tbody>\r
144 <?php\r
145 \r
146 // print preset scale table\r
147 $sql = "SELECT g.*, d.* from ".TABLE_PREFIX."grade_scales g, ".TABLE_PREFIX."grade_scales_detail d WHERE g.member_id= 0 AND g.grade_scale_id = d.grade_scale_id ORDER BY g.grade_scale_id, d.percentage_to desc";\r
148 \r
149 $result = mysql_query($sql, $db) or die(mysql_error());\r
150 \r
151 if (mysql_num_rows($result) == 0)\r
152 {\r
153 ?>\r
154         <tr>\r
155                 <td colspan="5"><?php echo _AT('none_found'); ?></td>\r
156         </tr>\r
157 <?php \r
158 }\r
159 else\r
160 {\r
161         $prev_row['grade_scale_id'] = 0;\r
162         while ($row = mysql_fetch_assoc($result))\r
163         {\r
164                 if ($row['grade_scale_id'] <> $prev_row['grade_scale_id'])\r
165                 {\r
166                         // print row\r
167                         if ($prev_row['grade_scale_id'] <> 0) print_row($prev_row['grade_scale_id'], $prev_row['scale_name'], $whole_scale_value, $prev_row['created_date'], $_POST['grade_scale_id'], false);\r
168 \r
169                         // initialize next $whole_scale_value\r
170                         $whole_scale_value = $row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';\r
171                         $prev_row = $row;\r
172                 }\r
173                 else\r
174                 {\r
175                         $whole_scale_value .= '<br />'.$row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';\r
176                 }\r
177         }\r
178         // print last row\r
179         if ($prev_row['grade_scale_id'] <> 0) print_row($prev_row['grade_scale_id'], $prev_row['scale_name'], $whole_scale_value, $prev_row['created_date'], $_POST['grade_scale_id'], false);\r
180 }\r
181 ?>\r
182 \r
183 </tbody>\r
184 </table>\r
185 \r
186 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>\r