8593b56747c27efa18933d7bc6fc2b25da6c432b
[atutor.git] / mods / gradebook / gradebook_edit_tests.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_add.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_once(AT_INCLUDE_PATH.'vitals.inc.php');\r
19 authenticate(AT_PRIV_GRADEBOOK);\r
20 \r
21 require_once("lib/gradebook.inc.php");\r
22 if (isset($_POST['cancel'])) \r
23 {\r
24         $msg->addFeedback('CANCELLED');\r
25         header('Location: gradebook_tests.php');\r
26         exit;\r
27\r
28 else if (isset($_POST['save'])) \r
29 {\r
30         $missing_fields = array();\r
31 \r
32         if (isset($_POST['title']) && $_POST['title'] == '') {\r
33                 $missing_fields[] = _AT('title');\r
34         }\r
35 \r
36         if ($missing_fields) {\r
37                 $missing_fields = implode(', ', $missing_fields);\r
38                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
39         }\r
40 \r
41         if (!$msg->containsErrors()) \r
42         {\r
43                 $sql = "UPDATE ".TABLE_PREFIX."gradebook_tests SET ";\r
44                 \r
45                 if (isset($_POST["title"])) $sql .= "title = '".$_POST["title"]. "', ";\r
46                 if ($_POST["has_due_date"] == 'true')\r
47                 {\r
48                         $due_date = $_POST["year_due"]. '-' .str_pad ($_POST["month_due"], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST["day_due"], 2, "0", STR_PAD_LEFT). ' '.str_pad ($_POST["hour_due"], 2, "0", STR_PAD_LEFT). ':' .str_pad ($_POST["min_due"], 2, "0", STR_PAD_LEFT) . ':00';\r
49                         $sql .= "due_date = '".$due_date. "', ";\r
50                 }\r
51                 else\r
52                         $sql .= "due_date = '', ";\r
53                 \r
54                 $sql .= "grade_scale_id=".$_POST["selected_grade_scale_id"]." WHERE gradebook_test_id = ". $_REQUEST["gradebook_test_id"];\r
55                 $result = mysql_query($sql, $db) or die(mysql_error());\r
56 \r
57                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
58                 header('Location: gradebook_tests.php');\r
59                 exit;\r
60         }\r
61\r
62 \r
63 $sql = "SELECT * FROM ".TABLE_PREFIX."gradebook_tests WHERE gradebook_test_id=" . $_REQUEST["gradebook_test_id"];\r
64 $result = mysql_query($sql, $db) or die(mysql_error());\r
65 \r
66 $sql = "(SELECT g.gradebook_test_id, g.type, t.title, DATE_FORMAT(end_date, '%Y-%m-%d %H:%i:00') AS due_date, g.grade_scale_id".\r
67                                 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t".\r
68                                 " WHERE g.type='ATutor Test'".\r
69                                 " AND g.id = t.test_id".\r
70                                 " AND g.gradebook_test_id=".$_GET['gradebook_test_id'].")".\r
71                                 " UNION (SELECT g.gradebook_test_id, g.type, a.title, DATE_FORMAT(date_due, '%Y-%m-%d %H:%i:00') AS due_date, g.grade_scale_id".\r
72                                 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."assignments a".\r
73                                 " WHERE g.type='ATutor Assignment'".\r
74                                 " AND g.id = a.assignment_id".\r
75                                 " AND g.gradebook_test_id=".$_GET['gradebook_test_id'].")".\r
76                                 " UNION (SELECT gradebook_test_id, type, title, DATE_FORMAT(due_date, '%Y-%m-%d %H:%i:00') AS due_date,grade_scale_id ".\r
77                                 " FROM ".TABLE_PREFIX."gradebook_tests".\r
78                                 " WHERE type='External'".\r
79                                 " AND gradebook_test_id=".$_GET['gradebook_test_id'].")";\r
80 $result = mysql_query($sql, $db) or die(mysql_error());\r
81 $row_this = mysql_fetch_assoc($result);\r
82 \r
83 if ($row_this["type"] == "External")\r
84 {\r
85         $array1                 = explode (' ', $row_this['due_date'], 2);\r
86         $array_date_due = explode ('-', $array1[0],3);\r
87         $array_time_due = explode (':', $array1[1]);\r
88         $today_year             = $array_date_due[0];\r
89         $today_mon              = $array_date_due[1];\r
90         $today_day                      = $array_date_due[2];\r
91         $today_hour             = $array_time_due[0];\r
92         $today_min              = $array_time_due[1];\r
93 \r
94         if ($today_year == '0000')\r
95         {\r
96                 $has_due_date = 'false';\r
97                 \r
98                 // if due date is not set, use today's date as default\r
99                 $today = getdate();\r
100                 $today_day              = $today['mday'];\r
101                 $today_mon      = $today['mon'];\r
102                 $today_year     = $today['year'];\r
103                 $today_hour     = $today['hours'];\r
104                 $today_min      = $today['minutes'];\r
105                 // round the minute to the next highest multiple of 5 \r
106                 $today_min = round($today_min / '5' ) * '5' + '5';\r
107                 if ($today_min > '55')  $today_min = '55';\r
108         } \r
109         else\r
110                 $has_due_date = 'true';\r
111 }\r
112 \r
113 if ($has_due_date == 'false') $onload .= ' disable_dates (true, \'_due\');';\r
114 require(AT_INCLUDE_PATH.'header.inc.php');\r
115 \r
116 ?>\r
117 <form method="post" name="form" action="<?php echo $_SERVER['PHP_SELF'].'?gradebook_test_id='.$_REQUEST['gradebook_test_id']; ?>">\r
118 <div class="input-form">\r
119         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_tests'); ?></legend>\r
120 \r
121 <?php\r
122 if ($row_this["type"] == "External")\r
123 {\r
124 ?>\r
125         <div class="row">\r
126                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="title"><?php echo _AT('title'); ?></label><br />\r
127                 <input type="text" id="title" size="40" name="title" value="<?php echo $row_this["title"]; ?>" />\r
128         </div>\r
129 \r
130 <?php\r
131 }\r
132 else\r
133 {\r
134 ?>\r
135         <div class="row">\r
136                 <?php echo _AT('title'); ?><br />\r
137                 <?php echo $row_this["title"]; ?>\r
138         </div>\r
139 \r
140 <?php\r
141 }\r
142 ?>\r
143         <div class="row">\r
144                 <label for="selected_grade_scale_id"><?php echo _AT('grade_scale'); ?></label><br />\r
145 <?php \r
146                 print_grade_scale_selectbox($row_this['grade_scale_id']); \r
147 ?>\r
148         </div>\r
149 \r
150         <div class="row">\r
151                 <?php  echo _AT('due_date'); ?><br />\r
152 \r
153 <?php \r
154 if ($row_this["type"] == "External")\r
155 {\r
156 ?>\r
157                 <input type="radio" name="has_due_date" value="false" id="noduedate"  <?php if ($has_due_date == 'false') { echo 'checked="checked"'; } ?> \r
158                 onfocus="disable_dates (true, '_due');" />\r
159                 <label for="noduedate" title="<?php echo _AT('due_date'). ': '. _AT('none');  ?>"><?php echo _AT('none'); ?></label><br />\r
160 \r
161                 <input type="radio" name="has_due_date" value="true" id="hasduedate"  <?php if ($has_due_date == 'true') { echo 'checked="checked"'; } ?> onfocus="disable_dates (false, '_due');" />\r
162                 <label for="hasduedate"  title="<?php echo _AT('due_date') ?>"><?php  echo _AT('date'); ?></label>\r
163 \r
164 <?php\r
165                 $name = '_due';\r
166                 require(AT_INCLUDE_PATH.'html/release_date.inc.php');\r
167         }\r
168         else\r
169         {\r
170                 echo $row_this["due_date"];\r
171         }\r
172 ?>\r
173         </div>\r
174 \r
175         <div class="row buttons">\r
176                 <input type="submit" name="save" value="<?php echo _AT('save'); ?>" />\r
177                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />\r
178         </div>\r
179 \r
180         </fieldset>\r
181 \r
182 </div>\r
183 </form>\r
184 \r
185 <script language="javascript" type="text/javascript">\r
186 function disable_dates (state, name) {\r
187         document.form['day' + name].disabled=state;\r
188         document.form['month' + name].disabled=state;\r
189         document.form['year' + name].disabled=state;\r
190         document.form['hour' + name].disabled=state;\r
191         document.form['min' + name].disabled=state;\r
192 }\r
193 </script>\r
194 \r
195 <?php require (AT_INCLUDE_PATH.'footer.inc.php');  ?>\r