430426a83751973710a930576a0a4ffcfc8b7ab5
[atutor.git] / docs / mods / _standard / gradebook / grade_scale.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 authenticate(AT_PRIV_GRADEBOOK);
19
20 function print_row($grade_scale_id, $scale_name, $value, $created_date, $post_grade_scale_id, $print_radio_button=true)
21 {
22 ?>
23                 <tr onmousedown="document.form['m<?php echo $grade_scale_id; ?>'].checked = true; rowselect(this);" id="r_<?php echo $grade_scale_id; ?>">
24 <?php
25         if ($print_radio_button)
26         {
27 ?>
28                         <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>
29                         <td><label for="m<?php echo $grade_scale_id; ?>"><?php echo $scale_name; ?></label></td>
30 <?php
31         }
32         else
33         {
34 ?>
35                         <td><?php echo $scale_name; ?></td>
36 <?php
37         }
38 ?>
39                         <td><?php echo $value; ?></td>
40                         <td><?php echo $created_date; ?></td>
41                 </tr>
42 <?php
43 }
44
45 if (isset($_POST['remove'], $_POST['grade_scale_id'])) 
46 {
47         header('Location: grade_scale_delete.php?grade_scale_id='.$_POST['grade_scale_id']);
48         exit;
49
50 else if (isset($_POST['edit'], $_POST['grade_scale_id'])) 
51 {
52         header('Location: grade_scale_edit.php?grade_scale_id='.$_POST['grade_scale_id']);
53         exit;
54
55 else if (!empty($_POST) && !isset($_POST['grade_scale_id'])) {
56         $msg->addError('NO_ITEM_SELECTED');
57 }
58
59 require(AT_INCLUDE_PATH.'header.inc.php'); 
60 ?>
61 <div class="toolcontainer">
62 <form name="form" method="post" action="mods/_standard/gradebook/grade_scale.php">
63
64 <h3 align="center"><?php echo _AT('custom_grade_scale'); ?></h3>
65
66 <table summary="" class="data" rules="cols" align="center" style="width: 90%;">
67
68 <thead>
69 <tr>
70         <th scope="col">&nbsp;</th>
71         <th scope="col"><?php echo _AT('name'); ?></th>
72         <th scope="col"><?php echo _AT('grade_scale'); ?></th>
73         <th scope="col"><?php echo _AT('created_date'); ?></th>
74 </tr>
75 </thead>
76 <tfoot>
77 <tr>
78         <td colspan="5">
79                 <div class="row buttons">
80                 <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" /> 
81                 <input type="submit" name="remove" value="<?php echo _AT('remove'); ?>" /> 
82                 </div>
83         </td>
84 </tr>
85 <tr>
86         <td colspan="5"></td>
87 </tr>
88 </tfoot>
89 <tbody>
90 <?php
91
92 $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";
93
94 $result = mysql_query($sql, $db) or die(mysql_error());
95
96 if (mysql_num_rows($result) == 0)
97 {
98 ?>
99         <tr>
100                 <td colspan="5"><?php echo _AT('none_found'); ?></td>
101         </tr>
102 <?php 
103 }
104 else
105 {
106         $prev_row['grade_scale_id'] = 0;
107         while ($row = mysql_fetch_assoc($result))
108         {
109                 if ($row['grade_scale_id'] <> $prev_row['grade_scale_id'])
110                 {
111                         // print row
112                         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']);
113
114                         // initialize next $whole_scale_value
115                         $whole_scale_value = $row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';
116                         $prev_row = $row;
117                 }
118                 else
119                 {
120                         $whole_scale_value .= '<br />'.$row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';
121                 }
122         }
123         // print last row
124         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']);
125 }
126 ?>
127
128 </tbody>
129 </table>
130 </form>
131
132 <h3 align="center"><?php echo _AT('preset_grade_scale'); ?></h3>
133 <table summary="" class="data" rules="cols" align="center" style="width: 90%;">
134 <thead>
135 <tr>
136         <th scope="col"><?php echo _AT('name'); ?></th>
137         <th scope="col"><?php echo _AT('grade_scale'); ?></th>
138         <th scope="col"><?php echo _AT('created_date'); ?></th>
139 </tr>
140 </thead>
141
142 <tbody>
143 <?php
144
145 // print preset scale table
146 $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";
147
148 $result = mysql_query($sql, $db) or die(mysql_error());
149
150 if (mysql_num_rows($result) == 0)
151 {
152 ?>
153         <tr>
154                 <td colspan="5"><?php echo _AT('none_found'); ?></td>
155         </tr>
156 <?php 
157 }
158 else
159 {
160         $prev_row['grade_scale_id'] = 0;
161         while ($row = mysql_fetch_assoc($result))
162         {
163                 if ($row['grade_scale_id'] <> $prev_row['grade_scale_id'])
164                 {
165                         // print row
166                         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);
167
168                         // initialize next $whole_scale_value
169                         $whole_scale_value = $row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';
170                         $prev_row = $row;
171                 }
172                 else
173                 {
174                         $whole_scale_value .= '<br />'.$row['scale_value'] . ' = ' . $row['percentage_from'] . ' to ' . $row['percentage_to'] . '%';
175                 }
176         }
177         // print last row
178         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);
179 }
180 ?>
181
182 </tbody>
183 </table>
184 </div>
185 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>