2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 */
6 /* Written by Greg Gay, Joel Kronenberg & Chris Ridpath */
7 /* Inclusive Design Institute */
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 /****************************************************************/
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_READING_LIST);
19 // initial values for form
20 $id = intval($_REQUEST['id']);
25 $page_return = $_GET['page_return'];
27 // check if user has submitted form
28 if (isset($_POST['cancel'])) {
29 $msg->addFeedback('CANCELLED');
31 header('Location: display_resources.php');
33 } else if (isset($_POST['submit'])) {
34 $missing_fields = array();
36 if (trim($_POST['title']) == '') {
37 $missing_fields[] = _AT('title');
39 if (trim($_POST['author']) == '') {
40 $missing_fields[] = _AT('author');
43 if ($missing_fields) {
44 $missing_fields = implode(', ', $missing_fields);
45 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
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));
55 if ($id == '0'){ // creating a new handout resource
56 $sql = "INSERT INTO ".TABLE_PREFIX."external_resources VALUES (NULL, $_SESSION[course_id],
65 $result = mysql_query($sql,$db);
67 // index to new handout resource
68 $id_new = mysql_insert_id($db);
70 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
71 } else { // modifying an existing handout resource
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]";
75 $result = mysql_query($sql,$db);
77 // index to handout resource
80 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
83 if (trim($_POST['page_return']) != ''){
84 header('Location: '. $_POST['page_return']. '?existingbook='. $id_new);
86 header('Location: index_instructor.php');
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']);
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']);
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');
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';
114 $_pages['mods/_standard/reading_list/add_resource_handout.php']['title_var'] = 'rl_edit_resource_handout';
117 $onload = 'document.form.name.focus();';
119 require(AT_INCLUDE_PATH.'header.inc.php');
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; ?>" />
126 <div class="input-form">
127 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('rl_add_resource_handout'); ?></legend>
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; ?>" />
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; ?>" />
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; ?>" />
144 <label for="comments"><?php echo _AT('comment'); ?></label><br />
145 <textarea name="comments" cols="30" rows="2" id="comments"><?php echo $comments; ?></textarea>
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'); ?>" />
156 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>