PageRenderTime 93ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/reading_list/add_resource_av.php

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