2 /************************************************************************/
\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
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
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
32 if (isset($_POST['title']) && $_POST['title'] == '') {
\r
33 $missing_fields[] = _AT('title');
\r
36 if ($missing_fields) {
\r
37 $missing_fields = implode(', ', $missing_fields);
\r
38 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
\r
41 if (!$msg->containsErrors())
\r
43 $sql = "UPDATE ".TABLE_PREFIX."gradebook_tests SET ";
\r
45 if (isset($_POST["title"])) $sql .= "title = '".$_POST["title"]. "', ";
\r
46 if ($_POST["has_due_date"] == 'true')
\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
52 $sql .= "due_date = '', ";
\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
57 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
58 header('Location: gradebook_tests.php');
\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
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
83 if ($row_this["type"] == "External")
\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
94 if ($today_year == '0000')
\r
96 $has_due_date = 'false';
\r
98 // if due date is not set, use today's date as default
\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
110 $has_due_date = 'true';
\r
113 if ($has_due_date == 'false') $onload .= ' disable_dates (true, \'_due\');';
\r
114 require(AT_INCLUDE_PATH.'header.inc.php');
\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
122 if ($row_this["type"] == "External")
\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
136 <?php echo _AT('title'); ?><br />
\r
137 <?php echo $row_this["title"]; ?>
\r
144 <label for="selected_grade_scale_id"><?php echo _AT('grade_scale'); ?></label><br />
\r
146 print_grade_scale_selectbox($row_this['grade_scale_id']);
\r
151 <?php echo _AT('due_date'); ?><br />
\r
154 if ($row_this["type"] == "External")
\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
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
166 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
\r
170 echo $row_this["due_date"];
\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
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
195 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r