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