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['url']) == '') {
40 $missing_fields[] = _AT('url');
43 if ($missing_fields) {
44 $missing_fields = implode(', ', $missing_fields);
45 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
48 if (!$msg->containsErrors()) {
49 $_POST['title'] = $addslashes(validate_length($_POST['title'], 255));
50 $_POST['author'] = $addslashes(validate_length($_POST['author'], 150));
51 $_POST['url'] = $addslashes($_POST['url']);
52 $_POST['comments'] = $addslashes(validate_length($_POST['comments'], 255));
54 if ($id == '0'){ // creating a new URL resource
55 $sql = "INSERT INTO ".TABLE_PREFIX."external_resources VALUES (NULL, $_SESSION[course_id],
64 $result = mysql_query($sql,$db);
66 // index to new URL resource
67 $id_new = mysql_insert_id($db);
69 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
70 } else { // modifying an existing URL resource
72 $sql = "UPDATE ".TABLE_PREFIX."external_resources SET title='$_POST[title]', author='$_POST[author]', url='$_POST[url]', comments='$_POST[comments]', id='$_POST[isbn]' WHERE resource_id='$id' AND course_id=$_SESSION[course_id]";
74 $result = mysql_query($sql,$db);
76 // index to URL resource
79 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
82 if (trim($_POST['page_return']) != ''){
83 header('Location: '. $_POST['page_return']. '?existingbook='. $id_new);
85 header('Location: index_instructor.php');
88 } else { // submission contained an error, update form values for redisplay
89 $title = $stripslashes($_POST['title']);
90 $author = $stripslashes($_POST['author']);
91 $url = $stripslashes($_POST['url']);
92 $date = $stripslashes($_POST['date']);
93 $comments = $stripslashes($_POST['comments']);
94 $isbn = $stripslashes($_POST['id']);
95 $page_return = $stripslashes($_POST['page_return']);
99 // is user modifying an existing URL resource?
100 if ($id && !isset($_POST['submit'])){
101 // yes, get resource from database
102 $id = intval ($_GET['id']);
104 $sql = "SELECT * FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$id";
105 $result = mysql_query($sql, $db);
106 if ($row = mysql_fetch_assoc($result)){
107 $title = AT_print($row['title'], 'input.text');
108 $author = AT_print($row['author'], 'input.text');
109 $comments = AT_print($row['comments'], 'input.text');
110 $url = AT_print($row['url'], 'input.text');
112 // change title of page to 'edit URL resource' (default is 'add URL resource')
113 $_pages['mods/_standard/reading_list/add_resource_url.php']['title_var'] = 'rl_edit_resource_url';
115 $_pages['mods/_standard/reading_list/add_resource_url.php']['title_var'] = 'rl_edit_resource_url';
118 $onload = 'document.form.name.focus();';
120 require(AT_INCLUDE_PATH.'header.inc.php');
123 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
124 <input type="hidden" name="id" value="<?php echo $id ?>" />
125 <input type="hidden" name="page_return" value="<?php echo $page_return ?>" />
127 <div class="input-form">
128 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('rl_add_resource_url'); ?></legend>
130 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
131 <input type="text" name="title" size="35" id="title" value="<?php echo $title; ?>" />
135 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="url"><?php echo _AT('url'); ?></label><br />
136 <input type="text" name="url" size="50" id="url" value="<?php echo $url; ?>" />
140 <label for="author"><?php echo _AT('author'); ?></label><br />
141 <input type="text" name="author" size="25" id="author" value="<?php echo $author; ?>" />
145 <label for="comments"><?php echo _AT('comment'); ?></label><br />
146 <textarea name="comments" cols="30" rows="2" id="comments"><?php echo $comments; ?></textarea>
149 <div class="row buttons">
150 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
151 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
157 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>