2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\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
15 $page = 'gradebook';
\r
17 define('AT_INCLUDE_PATH', '../../../include/');
\r
18 require_once(AT_INCLUDE_PATH.'vitals.inc.php');
\r
19 authenticate(AT_PRIV_GRADEBOOK);
\r
21 require_once("lib/gradebook.inc.php");
\r
22 if (isset($_POST['cancel']))
\r
24 $msg->addFeedback('CANCELLED');
\r
25 header('Location: gradebook_tests.php');
\r
28 else if (isset($_POST['save']))
\r
30 $missing_fields = array();
\r
31 $_POST["selected_grade_scale_id"] = intval($_POST["selected_grade_scale_id"]);
\r
32 $_REQUEST["gradebook_test_id"] = intval($_REQUEST["gradebook_test_id"]);
\r
33 $_GET['gradebook_test_id'] = intval($_GET['gradebook_test_id']);
\r
34 $_POST["year_due"] = intval($_POST["year_due"]);
\r
35 $_POST["month_due"] = intval($_POST["month_due"]);
\r
36 $_POST["day_due"] = intval($_POST["day_due"]);
\r
37 $_POST["hour_due"] = intval($_POST["hour_due"]);
\r
38 $_POST["min_due"] = intval($_POST["min_due"]);
\r
40 if (isset($_POST['title']) && $_POST['title'] == '') {
\r
41 $missing_fields[] = _AT('title');
\r
44 if ($missing_fields) {
\r
45 $missing_fields = implode(', ', $missing_fields);
\r
46 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
\r
49 if (!$msg->containsErrors())
\r
51 $sql = "UPDATE ".TABLE_PREFIX."gradebook_tests SET ";
\r
53 if (isset($_POST["title"])) $sql .= "title = '".$_POST["title"]. "', ";
\r
54 if ($_POST["has_due_date"] == 'true')
\r
56 $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
57 $sql .= "due_date = '".$due_date. "', ";
\r
60 $sql .= "due_date = '', ";
\r
62 $sql .= "grade_scale_id=".$_POST["selected_grade_scale_id"]." WHERE gradebook_test_id = ". $_REQUEST["gradebook_test_id"];
\r
63 $result = mysql_query($sql, $db) or die(mysql_error());
\r
65 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
66 header('Location: gradebook_tests.php');
\r
71 $sql = "SELECT * FROM ".TABLE_PREFIX."gradebook_tests WHERE gradebook_test_id=" . $_REQUEST["gradebook_test_id"];
\r
72 $result = mysql_query($sql, $db) or die(mysql_error());
\r
74 $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
75 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t".
\r
76 " WHERE g.type='ATutor Test'".
\r
77 " AND g.id = t.test_id".
\r
78 " AND g.gradebook_test_id=".$_GET['gradebook_test_id'].")".
\r
79 " 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
80 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."assignments a".
\r
81 " WHERE g.type='ATutor Assignment'".
\r
82 " AND g.id = a.assignment_id".
\r
83 " AND g.gradebook_test_id=".$_GET['gradebook_test_id'].")".
\r
84 " UNION (SELECT gradebook_test_id, type, title, DATE_FORMAT(due_date, '%Y-%m-%d %H:%i:00') AS due_date,grade_scale_id ".
\r
85 " FROM ".TABLE_PREFIX."gradebook_tests".
\r
86 " WHERE type='External'".
\r
87 " AND gradebook_test_id=".$_GET['gradebook_test_id'].")";
\r
88 $result = mysql_query($sql, $db) or die(mysql_error());
\r
89 $row_this = mysql_fetch_assoc($result);
\r
91 if ($row_this["type"] == "External")
\r
93 $array1 = explode (' ', $row_this['due_date'], 2);
\r
94 $array_date_due = explode ('-', $array1[0],3);
\r
95 $array_time_due = explode (':', $array1[1]);
\r
96 $today_year = $array_date_due[0];
\r
97 $today_mon = $array_date_due[1];
\r
98 $today_day = $array_date_due[2];
\r
99 $today_hour = $array_time_due[0];
\r
100 $today_min = $array_time_due[1];
\r
102 if ($today_year == '0000')
\r
104 $has_due_date = 'false';
\r
106 // if due date is not set, use today's date as default
\r
107 $today = getdate();
\r
108 $today_day = $today['mday'];
\r
109 $today_mon = $today['mon'];
\r
110 $today_year = $today['year'];
\r
111 $today_hour = $today['hours'];
\r
112 $today_min = $today['minutes'];
\r
113 // round the minute to the next highest multiple of 5
\r
114 $today_min = round($today_min / '5' ) * '5' + '5';
\r
115 if ($today_min > '55') $today_min = '55';
\r
118 $has_due_date = 'true';
\r
121 if ($has_due_date == 'false') $onload .= ' disable_dates (true, \'_due\');';
\r
122 require(AT_INCLUDE_PATH.'header.inc.php');
\r
125 <form method="post" name="form" action="<?php echo $_SERVER['PHP_SELF'].'?gradebook_test_id='.$_REQUEST['gradebook_test_id']; ?>">
\r
126 <div class="input-form">
\r
127 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_tests'); ?></legend>
\r
130 if ($row_this["type"] == "External")
\r
134 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
\r
135 <input type="text" id="title" size="40" name="title" value="<?php echo $row_this["title"]; ?>" />
\r
144 <?php echo _AT('title'); ?><br />
\r
145 <?php echo $row_this["title"]; ?>
\r
152 <label for="selected_grade_scale_id"><?php echo _AT('grade_scale'); ?></label><br />
\r
154 print_grade_scale_selectbox($row_this['grade_scale_id']);
\r
159 <?php echo _AT('due_date'); ?><br />
\r
162 if ($row_this["type"] == "External")
\r
165 <input type="radio" name="has_due_date" value="false" id="noduedate" <?php if ($has_due_date == 'false') { echo 'checked="checked"'; } ?>
\r
166 onfocus="disable_dates (true, '_due');" />
\r
167 <label for="noduedate" title="<?php echo _AT('due_date'). ': '. _AT('none'); ?>"><?php echo _AT('none'); ?></label><br />
\r
169 <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
170 <label for="hasduedate" title="<?php echo _AT('due_date') ?>"><?php echo _AT('date'); ?></label>
\r
174 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
\r
178 echo $row_this["due_date"];
\r
183 <div class="row buttons">
\r
184 <input type="submit" name="save" value="<?php echo _AT('save'); ?>" />
\r
185 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
193 <script language="javascript" type="text/javascript">
\r
194 function disable_dates (state, name) {
\r
195 document.form['day' + name].disabled=state;
\r
196 document.form['month' + name].disabled=state;
\r
197 document.form['year' + name].disabled=state;
\r
198 document.form['hour' + name].disabled=state;
\r
199 document.form['min' + name].disabled=state;
\r
203 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r