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