PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/mods/_standard/reading_list/edit_reading_book.php

https://github.com/harriswong/ATutor
PHP | 185 lines | 136 code | 34 blank | 15 comment | 37 complexity | a73fea93e70066143ba39dc4f222b2d8 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. if (isset($_POST['cancel'])) {
  19. $msg->addFeedback('CANCELLED');
  20. header('Location: index_instructor.php');
  21. exit;
  22. } else if (isset($_POST['submit'])) {
  23. $_POST['id'] = intval($_POST['id']);
  24. $_POST['existingbook'] = intval($_POST['existingbook']);
  25. $_POST['hasdate'] = $addslashes($_POST['hasdate']);
  26. $_POST['readstatus'] = $addslashes($_POST['readstatus']);
  27. $_POST['comment'] = $addslashes($_POST['comment']);
  28. $_POST['startday'] = intval($_POST['startday']);
  29. $_POST['startmonth'] = intval($_POST['startmonth']);
  30. $_POST['startyear'] = intval($_POST['startyear']);
  31. $_POST['endday'] = intval($_POST['endday']);
  32. $_POST['endmonth'] = intval($_POST['endmonth']);
  33. $_POST['endyear'] = intval($_POST['endyear']);
  34. $date_start = '0000-00-00';
  35. $date_end = '0000-00-00';
  36. if ($_POST['hasdate'] == 'true'){
  37. $date_start = $_POST['startyear']. '-' .str_pad ($_POST['startmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['startday'], 2, "0", STR_PAD_LEFT);
  38. $date_end = $_POST['endyear']. '-' .str_pad ($_POST['endmonth'], 2, "0", STR_PAD_LEFT). '-' .str_pad ($_POST['endday'], 2, "0", STR_PAD_LEFT);
  39. }
  40. $sql = "UPDATE ".TABLE_PREFIX."reading_list SET resource_id='$_POST[existingbook]', required='$_POST[readstatus]', comment='$_POST[comment]', date_start='$date_start', date_end='$date_end' WHERE reading_id='$_POST[id]' AND course_id=$_SESSION[course_id]";
  41. $result = mysql_query($sql,$db);
  42. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  43. header('Location: index_instructor.php');
  44. exit;
  45. }
  46. $onload = 'document.form.name.focus();';
  47. $today = getdate();
  48. $_GET['id'] = intval($_GET['id']);
  49. $reading_id = $_GET['id'];
  50. $resource_id = 0;
  51. // get the resource ID using the reading ID
  52. $sql = "SELECT * FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] AND reading_id=$reading_id";
  53. $result = mysql_query($sql, $db);
  54. if ($rowreading = mysql_fetch_assoc($result)) {
  55. $resource_id = $rowreading['resource_id'];
  56. }
  57. // fill the select control using all the book resources
  58. $sql = "SELECT title, resource_id FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND type=".RL_TYPE_BOOK." ORDER BY title";
  59. $book_result = mysql_query($sql, $db);
  60. $num_books = mysql_num_rows($book_result);
  61. if ($num_books == 0) {
  62. header('Location: add_resource_book.php');
  63. exit;
  64. }
  65. require(AT_INCLUDE_PATH.'header.inc.php');
  66. ?>
  67. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
  68. <input type="hidden" name="id" value="<?php echo $reading_id ?>" />
  69. <div class="input-form">
  70. <fieldset class="group_form"><legend class="group_form"><?php echo _AT('rl_book_to_read'); ?></legend>
  71. <h3><?php echo _AT('rl_book_to_read'); ?></h3>
  72. <div class="row">
  73. <label for="booktitle"><?php echo _AT('rl_select_book'); ?>:</label>
  74. <select name="existingbook" id="booktitle">
  75. <?php while ($rowbook = mysql_fetch_assoc($book_result)): ?>
  76. <option value="<?php echo $rowbook['resource_id']; ?>"<?php if ($rowbook['resource_id'] == $resource_id) { echo ' selected="selected"'; } ?>><?php echo AT_print($rowbook['title'], 'input.text'); ?></option>
  77. <?php endwhile; ?>
  78. </select>
  79. </div>
  80. <div class="row">
  81. <input type="radio" name="readstatus" value="required" id="required" <?php
  82. if ($rowreading['required'] == 'required'){
  83. echo 'checked="checked"';
  84. }?>/>
  85. <label for="required"><?php echo _AT('required'); ?></label>
  86. <input type="radio" name="readstatus" value="optional" id="optional" <?php
  87. if ($rowreading['required'] == 'optional'){
  88. echo 'checked="checked"';
  89. }?>/>
  90. <label for="optional"><?php echo _AT('optional'); ?></label>
  91. </div>
  92. <div class="row">
  93. <label for="comment"><?php echo _AT('comment'); ?>:</label><input type="text" id="comment" size="75" name="comment" value="<?php echo AT_print($rowreading['comment'], 'reading_list.comment'); ?>" />
  94. </div>
  95. <h3><?php echo _AT('rl_read_by_date'); ?></h3>
  96. <div class="row">
  97. <input type="radio" id="nodate" name="hasdate" value="false" <?php
  98. if ($rowreading['date_start'] == '0000-00-00'){
  99. echo 'checked="checked"';
  100. }?>/>
  101. <label for="nodate"><?php echo _AT('rl_no_read_by_date'); ?></label>
  102. </div>
  103. <div class="row">
  104. <input type="radio" id="hasdate" name="hasdate" value="true" <?php
  105. if ($rowreading['date_start'] != '0000-00-00'){
  106. echo 'checked="checked"';
  107. }?>/>
  108. <label for="hasdate"><?php echo _AT('rl_reading_date'); ?></label><br/>
  109. <label for="startdate"><?php echo _AT('start_date'); ?>:</label>
  110. <?php $array_date_start = explode ('-', $rowreading['date_start'], 3); ?>
  111. <select name="startday" id="startdate">
  112. <?php for ($i = 1; $i <= 31; $i++){ ?>
  113. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
  114. <?php } ?>
  115. </select>
  116. <select name="startmonth">
  117. <?php for ($i = 1; $i <= 12; $i++){ ?>
  118. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[1]) { echo ' selected="selected"'; } ?>><?php echo AT_Date('%M', intval($i), AT_DATE_INDEX_VALUE) ?></option>
  119. <?php } ?>
  120. </select>
  121. <select name="startyear">
  122. <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
  123. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_start[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
  124. <?php } ?>
  125. </select>
  126. <br/><label for="enddate"><?php echo _AT('end_date'); ?>:</label>
  127. <?php $array_date_end = explode ('-', $rowreading['date_end'], 3); ?>
  128. <select name="endday" id="enddate">
  129. <?php for ($i = 1; $i <= 31; $i++){ ?>
  130. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[2]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
  131. <?php } ?>
  132. </select>
  133. <select name="endmonth">
  134. <?php for ($i = 1; $i <= 12; $i++){ ?>
  135. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[1]) { echo ' selected="selected"'; } ?>><?php echo AT_Date('%M', intval($i), AT_DATE_INDEX_VALUE) ?></option>
  136. <?php } ?>
  137. </select>
  138. <select name="endyear">
  139. <?php for ($i = ($today['year'] - '1'); $i <= ($today['year'] + '4'); $i++){ ?>
  140. <option value="<?php echo intval($i); ?>" <?php if ($i == $array_date_end[0]) { echo ' selected="selected"'; } ?>><?php echo intval($i); ?></option>
  141. <?php } ?>
  142. </select>
  143. </div>
  144. <div class="row buttons">
  145. <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
  146. <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
  147. </div>
  148. </fieldset>
  149. </div>
  150. </form>
  151. <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>