remove old readme
[atutor.git] / docs / mods / _standard / reading_list / add_resource_file.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 // initial values for form
20 $id = intval($_REQUEST['id']);
21 $title = "";
22 $author = "";
23 $publisher = ""; 
24 $date = ""; 
25 $comments = "";
26 $isbn = "";
27 $page_return = $_GET['page_return'];
28
29 // check if user has submitted form
30 if (isset($_POST['cancel'])) {
31         $msg->addFeedback('CANCELLED');
32
33         header('Location: display_resources.php');
34         exit;
35 } else if (isset($_POST['submit'])) {
36         $missing_fields = array();
37
38         if (trim($_POST['title']) == '') {
39                 $missing_fields[] = _AT('title');
40         }
41         if (trim($_POST['author']) == '') {
42                 $missing_fields[] = _AT('author');
43         }
44
45         if ($missing_fields) {
46                 $missing_fields = implode(', ', $missing_fields);
47                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
48         }
49
50         if (!$msg->containsErrors()) {
51                 $_POST['title'] = $addslashes(validate_length($_POST['title'], 255));
52                 $_POST['author'] = $addslashes(validate_length($_POST['author'], 150));
53                 $_POST['publisher'] = $addslashes(validate_length($_POST['publisher'], 150));
54                 $_POST['date']      = $addslashes($_POST['date']);
55                 $_POST['comments'] = $addslashes(validate_length($_POST['comments'], 255));
56                 $_POST['isbn']      = $addslashes($_POST['isbn']);
57                 
58                 if ($id == '0'){ // creating a new file resource
59                         $sql = "INSERT INTO ".TABLE_PREFIX."external_resources VALUES (NULL, $_SESSION[course_id],
60                                 ".RL_TYPE_FILE.", 
61                                 '$_POST[title]', 
62                                 '$_POST[author]', 
63                                 '$_POST[publisher]', 
64                                 '$_POST[date]', 
65                                 '$_POST[comments]',
66                                 '$_POST[isbn]',
67                                 '')";
68                         $result = mysql_query($sql,$db);
69
70                         // index to new file resource
71                         $id_new = mysql_insert_id($db);
72
73                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
74                 } else { // modifying an existing file resource
75
76                         $sql = "UPDATE ".TABLE_PREFIX."external_resources SET title='$_POST[title]', author='$_POST[author]', publisher='$_POST[publisher]', date='$_POST[date]', comments='$_POST[comments]', id='$_POST[isbn]' WHERE resource_id='$id' AND course_id=$_SESSION[course_id]";
77
78                         $result = mysql_query($sql,$db);
79
80                         // index to file resource
81                         $id_new = $id;
82
83                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
84                 }
85
86                 if (trim($_POST['page_return']) != ''){
87                         header('Location: '. $_POST['page_return']. '?existingbook='. $id_new);
88                 } else {
89                         header('Location: index_instructor.php');
90                 }
91                 exit;
92         } else { // submission contained an error, update form values for redisplay
93                 $title       = $stripslashes($_POST['title']);
94                 $author      = $stripslashes($_POST['author']);
95                 $publisher   = $stripslashes($_POST['publisher']); 
96                 $date        = $stripslashes($_POST['date']);
97                 $comments    = $stripslashes($_POST['comments']);
98                 $isbn        = $stripslashes($_POST['id']);
99                 $page_return = $stripslashes($_POST['page_return']);
100         }
101 }
102
103 // is user modifying an existing file resource?
104 if ($id && !isset($_POST['submit'])){
105         // yes, get resource from database
106         $id = intval ($_GET['id']);
107
108         $sql = "SELECT * FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$id";
109         $result = mysql_query($sql, $db);
110         if ($row = mysql_fetch_assoc($result)){
111                 $title     = AT_print($row['title'], 'input.text');
112                 $author    = AT_print($row['author'], 'input.text');
113                 $publisher = AT_print($row['publisher'], 'input.text'); 
114                 $date      = AT_print($row['date'], 'input.text'); 
115                 $comments  = AT_print($row['comments'], 'input.text');
116                 $isbn      = AT_print($row['id'], 'input.text');
117         }
118         // change title of page to 'edit file resource' (default is 'add file resource')
119         $_pages['mods/_standard/reading_list/add_resource_file.php']['title_var'] = 'rl_edit_resource_file';
120 } else if ($id) {
121         $_pages['mods/_standard/reading_list/add_resource_file.php']['title_var'] = 'rl_edit_resource_file';
122 }
123
124 $onload = 'document.form.name.focus();';
125
126 require(AT_INCLUDE_PATH.'header.inc.php');
127 ?>
128
129 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
130 <input type="hidden" name="id" value="<?php echo $id ?>" />
131 <input type="hidden" name="page_return" value="<?php echo $page_return ?>" />
132
133 <div class="input-form">        
134         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('rl_add_resource_file'); ?></legend>
135         <div class="row">
136                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php  echo _AT('title'); ?></label><br />
137                 <input type="text" name="title" size="35" id="title" value="<?php echo $title; ?>" />
138         </div>
139
140         <div class="row">
141                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="author"><?php  echo _AT('author'); ?></label><br />
142                 <input type="text" name="author" size="25" id="author" value="<?php echo $author; ?>" />
143         </div>
144
145         <div class="row">
146                 <label for="date"><?php  echo _AT('rl_year_written'); ?></label><br />
147                 <input type="text" name="date" size="6" id="date" value="<?php echo $date; ?>" />
148         </div>
149
150         <div class="row">
151                 <label for="publisher"><?php  echo _AT('rl_publisher'); ?></label><br />
152                 <input type="text" name="publisher" size="20" id="publisher" value="<?php echo $publisher; ?>" />
153         </div>
154
155         <div class="row">
156                 <label for="isbn"><?php  echo _AT('rl_isbn_number'); ?></label><br />
157                 <input type="text" name="isbn" size="15" id="isbn" value="<?php echo $isbn; ?>" />
158         </div>
159
160         <div class="row">
161                 <label for="comments"><?php  echo _AT('comment'); ?></label><br />
162                 <textarea name="comments" cols="30" rows="2" id="comments"><?php echo $comments; ?></textarea>
163         </div>
164
165         <div class="row buttons">
166                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
167                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
168         </div>
169         </fieldset>
170 </div>
171 </form>
172
173 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>