2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_ASSIGNMENTS);
18 // initial values for controls
22 // Are we editing an existing assignment or creating a new assignment?
23 if (isset ($_GET['id'])){
24 // editing an existing assignment
25 $id = intval($_GET['id']);
27 $sql = "SELECT *, DATE_FORMAT(date_due, '%Y-%m-%d %H:%i:00') AS date_due, DATE_FORMAT(date_cutoff, '%Y-%m-%d %H:%i:00') AS date_cutoff FROM ".TABLE_PREFIX."assignments WHERE course_id=$_SESSION[course_id] AND assignment_id=$id";
29 $result = mysql_query($sql,$db);
30 if (!($row = mysql_fetch_assoc($result))) {
32 $msg->addFeedback('ASSIGNMENT_NOT_FOUND');
33 header('Location: index_instructor.php');
37 // get values of existing assignment from database
38 $title = $row['title'];
39 $assign_to = $row['assign_to'];
40 $multi_submit = $row['multi_submit'];
42 $array1 = explode (' ', $row['date_due'], 2);
43 $array_date_due = explode ('-', $array1[0],3);
44 $array_time_due = explode (':', $array1[1]);
45 $dueyear = $array_date_due[0];
46 $duemonth = $array_date_due[1];
47 $dueday = $array_date_due[2];
48 $duehour = $array_time_due[0];
49 $dueminute = $array_time_due[1];
51 if ($dueyear == '0000'){
52 $has_due_date = 'false';
54 $has_due_date = 'true';
57 // use date from database
58 $array2 = explode (' ', $row['date_cutoff'], 2);
59 $array_date_cutoff = explode ('-', $array2[0],3);
60 $array_time_cutoff = explode (':', $array2[1]);
61 $cutoffyear = $array_date_cutoff[0];
62 $cutoffmonth = $array_date_cutoff[1];
63 $cutoffday = $array_date_cutoff[2];
64 $cutoffhour = $array_time_cutoff[0];
65 $cutoffminute = $array_time_cutoff[1];
67 if ($cutoffyear == '0000'){
68 $late_submit = '0'; // allow late submissions always
69 } else if ($row['date_cutoff'] == $row['date_due']){
70 $late_submit = '1'; // allow late submissions never
71 // use today's date as default
72 $cutoffday = $today['mday'];
73 $cutoffmonth = $today['mon'];
74 $cutoffyear = $today['year'];
75 $cutoffhour = $today['hours'];
76 $cutoffminute = $today['minutes'];
77 // round the minute to the next highest multiple of 5
78 $cutoffminute = round($cutoffminute / '5' ) * '5' + '5';
79 if ($cutoffminute > '55'){ $cutoffminute = '55'; }
81 $late_submit = '2'; // allow late submissions until (date)
84 else if (isset($_POST['cancel'])) {
85 // cancel, nothing happened
86 $msg->addFeedback('CANCELLED');
87 header('Location: index_instructor.php');
90 else if (isset($_POST['submit'])) {
91 // user has submitted form to update database
92 $id = intval ($_POST['id']);
94 if ($_POST['multi_submit'] == 'on'){
98 // get values from form that was just submitted
99 $title = $addslashes($_POST['title']);
100 $assign_to = intval($_POST['assign_to']);
101 $has_due_date = $addslashes($_POST['has_due_date']);
102 $late_submit = intval($_POST['late_submit']);
104 $dueday = intval($_POST['day_due']);
105 $duemonth = intval($_POST['month_due']);
106 $dueyear = intval($_POST['year_due']);
107 $duehour = intval($_POST['hour_due']);
108 $dueminute = intval($_POST['min_due']);
110 $cutoffday = intval($_POST['day_cutoff']);
111 $cutoffmonth = intval($_POST['month_cutoff']);
112 $cutoffyear = intval($_POST['year_cutoff']);
113 $cutoffhour = intval($_POST['hour_cutoff']);
114 $cutoffminute = intval($_POST['min_cutoff']);
116 // ensure title is not empty
117 if (trim($title) == '') {
118 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
120 //ensure the title does not exceed db length, 60
121 $title = validate_length($title, 60);
124 // If due date is set and user has selected 'accept late submission until'
125 // then ensure cutoff date is greater or equal to due date.
126 if (($has_due_date == 'true') && ($late_submit == '2')){
127 if ($cutoffyear < $dueyear){
128 $msg->addError('CUTOFF_DATE_WRONG');
129 } else if ($cutoffyear == $dueyear){
130 if ($cutoffmonth < $duemonth){
131 $msg->addError('CUTOFF_DATE_WRONG');
132 } else if ($cutoffmonth == $duemonth){
133 if ($cutoffday < $dueday){
134 $msg->addError('CUTOFF_DATE_WRONG');
135 } else if ($cutoffday == $dueday){
136 if ($cutoffhour < $duehour){
137 $msg->addError('CUTOFF_DATE_WRONG');
138 } else if ($cutoffhour == $duehour) {
139 if ($cutoffminute < $dueminute){
140 $msg->addError('CUTOFF_DATE_WRONG');
148 if (!$msg->containsErrors()) {
151 // create the date strings
155 // note: if due date is NOT set then ignore the late submission date
156 if ($has_due_date == 'true'){
157 $date_due = $dueyear. '-' .str_pad ($duemonth, 2, "0", STR_PAD_LEFT). '-' .str_pad ($dueday, 2, "0", STR_PAD_LEFT). ' '.str_pad ($duehour, 2, "0", STR_PAD_LEFT). ':' .str_pad ($dueminute, 2, "0", STR_PAD_LEFT) . ':00';
160 if ($late_submit == '1'){ // never accept late submissions
161 $date_cutoff = $date_due; // cutoff date will be same as due date
162 } else if ($late_submit == '2'){ // accept late submissions until date
163 $date_cutoff = $cutoffyear. '-' .str_pad ($cutoffmonth, 2, "0", STR_PAD_LEFT). '-' .str_pad ($cutoffday, 2, "0", STR_PAD_LEFT). ' '.str_pad ($cutoffhour, 2, "0", STR_PAD_LEFT). ':' .str_pad ($cutoffminute, 2, "0", STR_PAD_LEFT) . ':00';
166 // Are we creating a new assignment or updating an existing assignment?
168 // creating a new assignment
169 $sql = "INSERT INTO ".TABLE_PREFIX."assignments VALUES (NULL, $_SESSION[course_id],
177 $result = mysql_query($sql,$db);
178 $msg->addFeedback('ASSIGNMENT_ADDED');
179 } else { // updating an existing assignment
180 $assign_to = 'assign_to';
182 $sql = "UPDATE ".TABLE_PREFIX."assignments SET title='$title', assign_to=$assign_to, date_due='$date_due', date_cutoff='$date_cutoff' WHERE assignment_id='$id' AND course_id=$_SESSION[course_id]";
184 $result = mysql_query($sql,$db);
185 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
187 header('Location: index_instructor.php');
190 } else { // creating a new assignment
194 $has_due_date = 'false';
195 $late_submit = '0'; // 0 == always, 1 == never, 2 = until (date)
197 $dueday = $today['mday'];
198 $duemonth = $today['mon'];
199 $dueyear = $today['year'];
203 $cutoffday = $today['mday'];
204 $cutoffmonth = $today['mon'];
205 $cutoffyear = $today['year'];
210 // ensure the dates are valid
211 if ($dueyear == '0'){
212 // use today's date as default
213 $dueday = $today['mday'];
214 $duemonth = $today['mon'];
215 $dueyear = $today['year'];
216 $duehour = $today['hours'];
217 $dueminute = $today['minutes'];
218 // round the minute to the next highest multiple of 5
219 $dueminute = round($dueminute / '5' ) * '5' + '5';
220 if ($dueminute > '55'){ $dueminute = '55'; }
222 if ($cutoffyear == '0'){
223 // use today's date as default
224 $cutoffday = $today['mday'];
225 $cutoffmonth = $today['mon'];
226 $cutoffyear = $today['year'];
227 $cutoffhour = $today['hours'];
228 $cutoffminute = $today['minutes'];
229 // round the minute to the next highest multiple of 5
230 $cutoffminute = round($cutoffminute / '5' ) * '5' + '5';
231 if ($cutoffminute > '55'){ $cutoffminute = '55'; }
234 $onload = 'document.form.title.focus();';
236 // enable/disable date controls
237 if ($has_due_date == 'false'){
238 $onload .= ' disable_dates (true, \'_due\');';
241 if ($late_submit != '2'){
242 $onload .= ' disable_dates (true, \'_cutoff\');';
245 require(AT_INCLUDE_PATH.'header.inc.php');
248 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
249 <input type="hidden" name="id" value="<?php echo $id ?>" />
250 <div class="input-form">
251 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('add_assignment'); ?></legend>
253 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br/>
254 <input type="text" name="title" size="50" id="title" value="<?php echo AT_print($title, 'assignment.title'); ?>" />
258 <label for="assignto"><?php echo _AT('assign_to'); ?></label><br/>
260 <?php // Are we editing an assignment?
262 // editing an existing assignment
263 if ($assign_to == '0'){
264 echo _AT('all_students');
265 } else { // name of group goes here
266 $sql = "SELECT title FROM ".TABLE_PREFIX."groups_types WHERE type_id=$assign_to AND course_id=$_SESSION[course_id]";
267 $result = mysql_query($sql, $db);
268 $type_row = mysql_fetch_assoc($result);
269 echo $type_row['title'];
272 <?php } else { // creating a new assignment
274 <select name="assign_to" size="5" id="assignto">
275 <option value="0" <?php if ($assign_to == '0'){ echo 'selected="selected"'; } ?> label="<?php echo _AT('all_students'); ?>"><?php echo _AT('all_students'); ?></option>
276 <optgroup label="<?php echo _AT('specific_groups'); ?>">
278 $sql = "SELECT type_id, title FROM ".TABLE_PREFIX."groups_types WHERE course_id={$_SESSION['course_id']} ORDER BY title";
279 $result = mysql_query($sql, $db);
280 while ($type_row = mysql_fetch_assoc($result)) {
281 echo '<option value="'.$type_row['type_id'].'" ';
282 if ($assign_to == $type_row['type_id']) {
283 echo 'selected="selected"';
285 echo '>'.$type_row['title'].'</option>';
294 <?php echo _AT('due_date'); ?><br />
295 <input type="radio" name="has_due_date" value="false" id="noduedate" <?php if ($has_due_date == 'false') { echo 'checked="checked"'; } ?>
296 onfocus="disable_dates (true, '_due');" />
297 <label for="noduedate" title="<?php echo _AT('due_date'). ': '. _AT('none'); ?>"><?php echo _AT('none'); ?></label><br />
299 <input type="radio" name="has_due_date" value="true" id="hasduedate" <?php if ($has_due_date == 'true'){echo 'checked="checked"'; } ?>
300 onfocus="disable_dates (false, '_due');" />
301 <label for="hasduedate" title="<?php echo _AT('due_date') ?>"><?php echo _AT('date'); ?></label>
304 $today_day = $dueday;
305 $today_mon = $duemonth;
306 $today_year = $dueyear;
307 $today_hour = $duehour;
308 $today_min = $dueminute;
311 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
316 <?php echo _AT('accept_late_submissions'); ?><br />
317 <input type="radio" name="late_submit" value="0" id="always" <?php if ($late_submit == '0'){echo 'checked="checked"';} ?>
318 onfocus="disable_dates (true, '_cutoff');" />
320 <label for="always" title="<?php echo _AT('accept_late_submissions'). ': '. _AT('always'); ?>"><?php echo _AT('always'); ?></label><br />
322 <input type="radio" name="late_submit" value="1" id="never" <?php if ($late_submit == '1'){echo 'checked="checked"';} ?>
323 onfocus="disable_dates (true, '_cutoff');" />
325 <label for="never" title="<?php echo _AT('accept_late_submissions'). ': '. _AT('never'); ?>"><?php echo _AT('never'); ?></label><br />
327 <input type="radio" name="late_submit" value="2" id="until" <?php if ($late_submit == '2'){echo 'checked="checked"';} ?>
328 onfocus="disable_dates (false, '_cutoff');" />
330 <label for="until" title="<?php echo _AT('accept_late_submissions'). ': '. _AT('until'); ?>"><?php echo _AT('until'); ?></label>
333 $today_day = $cutoffday;
334 $today_mon = $cutoffmonth;
335 $today_year = $cutoffyear;
336 $today_hour = $cutoffhour;
337 $today_min = $cutoffminute;
340 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
345 * not included in the initial release.
348 <?php echo _AT('options'); <br/>
349 <input type="checkbox" name="multi_submit" id="multisubmit" <?php if ($multi_submit == '1'){ echo 'checked="checked"'; } />
350 <label for="multisubmit"><?php echo _AT('allow_re_submissions'); </label>
355 <div class="row buttons">
356 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" class="button"/>
357 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" class="button"/>
364 <script language="javascript" type="text/javascript">
365 function disable_dates (state, name) {
366 document.form['day' + name].disabled=state;
367 document.form['month' + name].disabled=state;
368 document.form['year' + name].disabled=state;
369 document.form['hour' + name].disabled=state;
370 document.form['min' + name].disabled=state;
374 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>