remove old readme
[atutor.git] / docs / mods / _standard / reading_list / edit_reading_book.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
25         $_POST['id'] = intval($_POST['id']);
26         $_POST['existingbook'] = intval($_POST['existingbook']);
27         $_POST['hasdate'] = $addslashes($_POST['hasdate']);
28         $_POST['readstatus'] = $addslashes($_POST['readstatus']);
29         $_POST['comment'] = $addslashes($_POST['comment']);
30         $_POST['startday'] = intval($_POST['startday']);
31         $_POST['startmonth'] = intval($_POST['startmonth']);
32         $_POST['startyear'] = intval($_POST['startyear']);
33         $_POST['endday'] = intval($_POST['endday']);
34         $_POST['endmonth'] = intval($_POST['endmonth']);
35         $_POST['endyear'] = intval($_POST['endyear']);
36
37         $date_start = '0000-00-00';
38         $date_end = '0000-00-00';
39         if ($_POST['hasdate'] == 'true'){
40                 $date_start = $_POST['startyear']. '-' .str_pad ($_POST['startmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['startday'], 2, "0", STR_PAD_LEFT);
41                 $date_end = $_POST['endyear']. '-' .str_pad ($_POST['endmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['endday'], 2, "0", STR_PAD_LEFT);
42         }
43
44         $sql = "UPDATE ".TABLE_PREFIX."reading_list SET resource_id='$_POST[existingbook]', 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]";
45
46         $result = mysql_query($sql,$db);
47
48         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
49         header('Location: index_instructor.php');
50         exit;
51 }
52
53 $onload = 'document.form.name.focus();';
54
55 $today = getdate();
56
57 $_GET['id'] = intval($_GET['id']);
58 $reading_id = $_GET['id'];
59 $resource_id = 0;
60
61 // get the resource ID using the reading ID
62 $sql = "SELECT * FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] AND reading_id=$reading_id";
63 $result = mysql_query($sql, $db);
64 if ($rowreading = mysql_fetch_assoc($result)) {
65         $resource_id = $rowreading['resource_id'];
66 }
67
68 // fill the select control using all the book resources
69 $sql = "SELECT title, resource_id FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND type=".RL_TYPE_BOOK." ORDER BY title";
70 $book_result = mysql_query($sql, $db);
71
72 $num_books = mysql_num_rows($book_result);
73
74 if ($num_books == 0) {
75         header('Location: add_resource_book.php');
76         exit;
77 }
78
79 require(AT_INCLUDE_PATH.'header.inc.php');
80
81 ?>
82
83 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
84 <input type="hidden" name="id" value="<?php echo $reading_id ?>" />
85 <div class="input-form">        
86         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('rl_book_to_read'); ?></legend>
87 <h3><?php echo _AT('rl_book_to_read'); ?></h3>
88         <div class="row">
89                 <label for="booktitle"><?php  echo _AT('rl_select_book'); ?>:</label>
90                 <select name="existingbook" id="booktitle">
91
92                         <?php while ($rowbook = mysql_fetch_assoc($book_result)): ?>
93                                 <option value="<?php echo $rowbook['resource_id']; ?>"<?php if ($rowbook['resource_id'] == $resource_id) { echo ' selected="selected"'; } ?>><?php echo AT_print($rowbook['title'], 'input.text'); ?></option>
94                         <?php endwhile; ?>
95                 
96                 </select>
97         </div>
98
99         <div class="row">
100                 <input type="radio" name="readstatus" value="required" id="required" <?php
101                 if ($rowreading['required'] == 'required'){
102                         echo 'checked="checked"';
103                 }?>/>
104                 <label for="required"><?php  echo _AT('required'); ?></label>
105                 <input type="radio" name="readstatus" value="optional" id="optional" <?php
106                 if ($rowreading['required'] == 'optional'){
107                         echo 'checked="checked"';
108                 }?>/>
109                 <label for="optional"><?php  echo _AT('optional'); ?></label>
110         </div>  
111         
112         <div class="row">
113         <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');  ?>" />
114         </div>
115
116 <h3><?php echo _AT('rl_read_by_date'); ?></h3>
117
118         <div class="row">
119                 <input type="radio" id="nodate" name="hasdate" value="false" <?php
120                 if ($rowreading['date_start'] == '0000-00-00'){
121                         echo 'checked="checked"';
122                 }?>/>
123                 <label for="nodate"><?php  echo _AT('rl_no_read_by_date'); ?></label>
124         </div>
125
126         <div class="row">
127                 <input type="radio" id="hasdate" name="hasdate" value="true" <?php
128                 if ($rowreading['date_start'] != '0000-00-00'){
129                         echo 'checked="checked"';
130                 }?>/>
131                 <label for="hasdate"><?php  echo _AT('rl_reading_date'); ?></label><br/>
132
133                 <label for="startdate"><?php  echo _AT('start_date'); ?>:</label>
134                 <?php  $array_date_start = explode ('-', $rowreading['date_start'], 3); ?>
135
136                 <select name="startday" id="startdate">
137                 <?php for ($i = 1; $i <= 31; $i++){ ?>
138                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
139                 <?php } ?>
140                 </select>
141                 
142                 <select name="startmonth">
143                 <?php for ($i = 1; $i <= 12; $i++){ ?>
144                         <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>
145                 <?php } ?>
146                 </select>
147
148                 <select name="startyear">
149                 <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
150                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
151                 <?php } ?>
152                 </select>
153         
154                 <br/><label for="enddate"><?php  echo _AT('end_date'); ?>:</label>
155                 <?php  $array_date_end = explode ('-', $rowreading['date_end'], 3); ?>
156
157                 <select name="endday" id="enddate">
158                 <?php for ($i = 1; $i <= 31; $i++){ ?>
159                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
160                 <?php } ?>
161                 </select>
162         
163                 <select name="endmonth">
164                 <?php for ($i = 1; $i <= 12; $i++){ ?>
165                         <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>
166                 <?php } ?>
167                 </select>
168         
169                 <select name="endyear">
170                 <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
171                         <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
172                 <?php } ?>
173                 </select>
174         
175         </div>
176
177         <div class="row buttons">
178                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
179                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
180         </div>
181         </fieldset>
182 </div>
183 </form>
184
185 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>