move code up one directory
[atutor.git] / mods / _standard / reading_list / edit_reading_url.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008                                      */
6 /* Written by Greg Gay, Joel Kronenberg & Chris Ridpath         */
7 /* Inclusive Design Institute                                   */
8 /* http://atutor.ca                                                                                             */
9 /*                                                              */
10 /* This program is free software. You can redistribute it and/or*/
11 /* modify it under the terms of the GNU General Public License  */
12 /* as published by the Free Software Foundation.                                */
13 /****************************************************************/
14 // $Id$
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_READING_LIST);
18
19 if (isset($_POST['cancel'])) {
20         $msg->addFeedback('CANCELLED');
21         header('Location: index_instructor.php');
22         exit;
23 } else if (isset($_POST['submit'])) {
24         $_POST['id']         = intval($_POST['id']);
25         $_POST['existing']   = intval($_POST['existing']);
26         $_POST['hasdate']    = $addslashes($_POST['hasdate']);
27         $_POST['readstatus'] = $addslashes($_POST['readstatus']);
28         $_POST['comment']    = $addslashes($_POST['comment']);
29         $_POST['startday']   = intval($_POST['startday']);
30         $_POST['startmonth'] = intval($_POST['startmonth']);
31         $_POST['startyear']  = intval($_POST['startyear']);
32         $_POST['endday']     = intval($_POST['endday']);
33         $_POST['endmonth']   = intval($_POST['endmonth']);
34         $_POST['endyear']    = intval($_POST['endyear']);
35
36         $date_start = '0000-00-00';
37         $date_end = '0000-00-00';
38         if ($_POST['hasdate'] == 'true'){
39                 $date_start = $_POST['startyear']. '-' .str_pad ($_POST['startmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['startday'], 2, "0", STR_PAD_LEFT);
40                 $date_end = $_POST['endyear']. '-' .str_pad ($_POST['endmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['endday'], 2, "0", STR_PAD_LEFT);
41         }
42
43         $sql = "UPDATE ".TABLE_PREFIX."reading_list SET resource_id='$_POST[existing]', required='$_POST[readstatus]', comment='$_POST[comment]', date_start='$date_start', date_end='$date_end' WHERE reading_id='$_POST[id]' AND course_id=$_SESSION[course_id]";
44
45         $result = mysql_query($sql,$db);
46
47         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
48         header('Location: index_instructor.php');
49         exit;
50 }
51
52 $onload = 'document.form.name.focus();';
53
54 $today = getdate();
55
56 $_GET['id'] = intval($_GET['id']);
57 $reading_id = $_GET['id'];
58 $resource_id = 0;
59
60 // get the resource ID using the reading ID
61 $sql = "SELECT * FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] AND reading_id=$reading_id";
62 $result = mysql_query($sql, $db);
63 if ($rowreading = mysql_fetch_assoc($result)) {
64         $resource_id = $rowreading['resource_id'];
65 }
66
67 // fill the select control using all the URL resources
68 $sql = "SELECT title, resource_id FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND type=".RL_TYPE_URL." ORDER BY title";
69 $url_result = mysql_query($sql, $db);
70
71 $num_urls = mysql_num_rows($url_result);
72
73 if ($num_urls == 0) {
74         header('Location: add_resource_url.php');
75         exit;
76 }
77 require(AT_INCLUDE_PATH.'header.inc.php');
78 ?>
79
80 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
81 <input type="hidden" name="id" value="<?php echo $reading_id ?>" />
82 <div class="input-form">        
83         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('url_to_read'); ?></legend>
84
85         <div class="row">
86                 <label for="title"><?php  echo _AT('rl_select_url'); ?>:</label>
87                 <select name="existing" id="title">
88                         <?php while ($row = mysql_fetch_assoc($url_result)): ?>
89                                 <option value="<?php echo $row['resource_id']; ?>"<?php if ($row['resource_id'] == $resource_id) { echo ' selected="selected"'; } ?>><?php echo AT_print($row['title'], 'input.text'); ?></option>
90                         <?php endwhile; ?>
91                 </select>
92         </div>
93
94         <div class="row">
95                 <input type="radio" name="readstatus" value="required" id="required" <?php
96                 if ($rowreading['required'] == 'required'){
97                         echo 'checked="checked"';
98                 }?>/>
99                 <label for="required"><?php  echo _AT('required'); ?></label>
100                 <input type="radio" name="readstatus" value="optional" id="optional" <?php
101                 if ($rowreading['required'] == 'optional'){
102                         echo 'checked="checked"';
103                 }?>/>
104                 <label for="optional"><?php  echo _AT('optional'); ?></label>
105         </div>  
106         
107         <div class="row">
108         <label for="comment"><?php  echo _AT('comment'); ?>:</label><input type="text" id="comment" size="75" name="comment" value="<?php echo AT_print($rowreading['comment'], 'reading_list.comment');  ?>" />
109         </div>
110
111 <h3><?php echo _AT('rl_read_by_date'); ?></h3>
112
113         <div class="row">
114                 <input type="radio" id="nodate" name="hasdate" value="false" <?php
115                 if ($rowreading['date_start'] == '0000-00-00'){
116                         echo 'checked="checked"';
117                 }?>/>
118                 <label for="nodate"><?php  echo _AT('rl_no_read_by_date'); ?></label>
119         </div>
120
121         <div class="row">
122                 <input type="radio" id="hasdate" name="hasdate" value="true" <?php
123                 if ($rowreading['date_start'] != '0000-00-00'){
124                         echo 'checked="checked"';
125                 }?>/>
126                 <label for="hasdate"><?php  echo _AT('rl_reading_date'); ?></label><br/>
127
128                 <label for="startdate"><?php  echo _AT('start_date'); ?>:</label>
129                 <?php  $array_date_start = explode ('-', $rowreading['date_start'], 3); ?>
130
131                 <select name="startday" id="startdate">
132                 <?php for ($i = 1; $i <= 31; $i++){ ?>
133                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
134                 <?php } ?>
135                 </select>
136                 
137                 <select name="startmonth">
138                 <?php for ($i = 1; $i <= 12; $i++){ ?>
139                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[1]) { echo ' selected="selected"'; } ?>><?php echo AT_Date('%M', intval($i), AT_DATE_INDEX_VALUE) ?></option>
140                 <?php } ?>
141                 </select>
142
143                 <select name="startyear">
144                 <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
145                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
146                 <?php } ?>
147                 </select>
148         
149                 <br/><label for="enddate"><?php  echo _AT('end_date'); ?>:</label>
150                 <?php  $array_date_end = explode ('-', $rowreading['date_end'], 3); ?>
151
152                 <select name="endday" id="enddate">
153                 <?php for ($i = 1; $i <= 31; $i++){ ?>
154                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
155                 <?php } ?>
156                 </select>
157         
158                 <select name="endmonth">
159                 <?php for ($i = 1; $i <= 12; $i++){ ?>
160                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[1]) { echo ' selected="selected"'; } ?>><?php echo AT_Date('%M', intval($i), AT_DATE_INDEX_VALUE) ?></option>
161                 <?php } ?>
162                 </select>
163         
164                 <select name="endyear">
165                 <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
166                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
167                 <?php } ?>
168                 </select>
169         
170         </div>
171
172         <div class="row buttons">
173                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
174                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
175         </div>
176         </fieldset>
177 </div>
178 </form>
179
180 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>