PageRenderTime 151ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/reading_list/index_instructor.php

https://github.com/harriswong/ATutor
PHP | 162 lines | 127 code | 17 blank | 18 comment | 20 complexity | ea4714dad95b57f80e3fe1c73ac9c96b 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($_GET['edit'])) {
  19. if (!isset($_GET['reading'])) {
  20. $msg->addError('NO_ITEM_SELECTED');
  21. header('Location: index_instructor.php');
  22. exit;
  23. }
  24. // reading ID of item that will be edited
  25. $_GET['reading'] = intval($_GET['reading']);
  26. // get resource ID of reading
  27. $sql = "SELECT resource_id FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] AND reading_id=$_GET[reading]";
  28. $result = mysql_query($sql, $db);
  29. if ($row = mysql_fetch_assoc($result)){
  30. // what kind of resource is it? (book, URL, file etc.)
  31. $sql = "SELECT type FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$row[resource_id]";
  32. $result = mysql_query($sql, $db);
  33. if ($row = mysql_fetch_assoc($result)){
  34. // display the correct page for editing the resource
  35. header('Location: edit_reading_'.substr($_rl_types[$row['type']], 3).'.php?id='. $_GET['reading']);
  36. exit;
  37. }
  38. }
  39. $msg->addError('ITEM_NOT_FOUND');
  40. } else if (isset($_GET['delete'])) {
  41. if (!isset($_GET['reading'])) {
  42. $msg->addError('NO_ITEM_SELECTED');
  43. header('Location: index_instructor.php');
  44. exit;
  45. }
  46. $_GET['reading'] = intval($_GET['reading']);
  47. header('Location: delete_reading.php?id='. $_GET['reading']);
  48. exit;
  49. } else if (isset($_GET['create'])){
  50. $_GET['new_reading'] = intval($_GET['new_reading']);
  51. if (isset($_rl_types[$_GET['new_reading']])){
  52. // Note: the '3' substring is used here to strip out the 'rl_' from the name
  53. header('Location: new_reading_'.substr($_rl_types[$_GET['new_reading']], 3).'.php');
  54. exit;
  55. }
  56. }
  57. require(AT_INCLUDE_PATH.'header.inc.php');
  58. ?>
  59. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  60. <div class="input-form" style="width: 90%">
  61. <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create'); ?></legend>
  62. <div class="row">
  63. <label for="question"><?php echo _AT('rl_type_of_reading'); ?></label><br />
  64. <select name="new_reading" class="dropdown" id="type">
  65. <?php foreach ($_rl_types as $key => $value): ?>
  66. <option value="<?php echo $key; ?>"><?php echo _AT($value); ?></option>
  67. <?php endforeach; ?>
  68. </select>
  69. </div>
  70. <div class="row buttons">
  71. <input type="submit" name="create" value="<?php echo _AT('create'); ?>" />
  72. </div>
  73. </fieldset>
  74. </div>
  75. </form>
  76. <?php
  77. $sql = "SELECT * FROM ".TABLE_PREFIX."reading_list WHERE course_id=$_SESSION[course_id] ORDER BY date_start";
  78. $result = mysql_query($sql, $db);
  79. ?>
  80. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
  81. <table class="data" style="width: 90%;">
  82. <thead>
  83. <tr>
  84. <th>&nbsp;</th>
  85. <th><?php echo _AT('rl_start'); ?></th>
  86. <th><?php echo _AT('rl_end'); ?></th>
  87. <th><?php echo _AT('title'); ?></th>
  88. <th><?php echo _AT('required'); ?></th>
  89. <th><?php echo _AT('comment'); ?></th>
  90. </tr>
  91. </thead>
  92. <tfoot>
  93. <tr>
  94. <td colspan="6">
  95. <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" />
  96. <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
  97. </td>
  98. </tr>
  99. </tfoot>
  100. <?php if ($row = mysql_fetch_assoc($result)): ?>
  101. <tbody>
  102. <?php do { ?>
  103. <?php // get the external resource using the resource ID from the reading
  104. $id = $row['resource_id'];
  105. $sql = "SELECT title FROM ".TABLE_PREFIX."external_resources WHERE course_id=$_SESSION[course_id] AND resource_id=$id";
  106. $resource_result = mysql_query($sql, $db);
  107. if ($resource_row = mysql_fetch_assoc($resource_result)){
  108. ?>
  109. <tr onmousedown="document.form['t<?php echo $row['reading_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['reading_id']; ?>_0">
  110. <td><input type="radio" id="t<?php echo $row['reading_id']; ?>" name="reading" value="<?php echo $row['reading_id']; ?>"
  111. <?php // set first item as checked if nothing selected
  112. if (isset($_GET['reading'])){
  113. if ($_GET['reading'] == $row['reading_id']){
  114. echo ' checked="checked"';
  115. }
  116. } else {
  117. echo ' checked="checked"';
  118. $_GET['reading'] = $row['reading_id'];
  119. }
  120. ?> /></td>
  121. <td><?php if ($row['date_start'] == '0000-00-00'){
  122. echo _AT ('none');
  123. }else {
  124. echo AT_Date(_AT('rl_date_format'), $row['date_start'], AT_DATE_MYSQL_DATETIME);
  125. }?></td>
  126. <td><?php if ($row['date_end'] == '0000-00-00'){
  127. echo _AT ('none');
  128. }else {
  129. echo AT_Date(_AT('rl_date_format'), $row['date_end'], AT_DATE_MYSQL_DATETIME);
  130. }?></td>
  131. <td><label for="t<?php echo $row['reading_id'];?>"><strong><?php echo AT_print($resource_row['title'], 'reading_list.title'); ?></strong></label></td>
  132. <td><?php echo _AT ($row['required']); ?></td>
  133. <td><?php echo AT_print($row['comment'], 'reading_list.comment'); ?></td>
  134. </tr>
  135. <?php } ?>
  136. <?php } while($row = mysql_fetch_assoc($result)); ?>
  137. </tbody>
  138. <?php else: ?>
  139. <tr>
  140. <td colspan="6"><strong><?php echo _AT('none_found'); ?></strong></td>
  141. </tr>
  142. <?php endif; ?>
  143. </table>
  144. </form>
  145. <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>