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