PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/forums/edit_post.php

https://github.com/harriswong/ATutor
PHP | 155 lines | 107 code | 32 blank | 16 comment | 21 complexity | 0d88c629ca86213f69ecb0e4747f086e MD5 | raw file
  1. <?php
  2. /****************************************************************************/
  3. /* ATutor */
  4. /****************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or */
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************************/
  13. // $Id$
  14. define('AT_INCLUDE_PATH', '../../../include/');
  15. require (AT_INCLUDE_PATH.'vitals.inc.php');
  16. require(AT_INCLUDE_PATH.'../mods/_standard/forums/lib/forums.inc.php');
  17. $fid = intval($_REQUEST['fid']);
  18. if (isset($_GET['pid'])) {
  19. $pid = intval($_GET['pid']);
  20. } else {
  21. $pid = intval($_POST['pid']);
  22. }
  23. if (!$pid || !$fid || !valid_forum_user($fid)) {
  24. $msg->addError('ITEM_NOT_FOUND');
  25. header('Location: ../../../forum/list.php');
  26. exit;
  27. }
  28. $sql = "SELECT *, UNIX_TIMESTAMP(date) AS udate FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$pid";
  29. $result = mysql_query($sql,$db);
  30. if (!($post_row = mysql_fetch_assoc($result))) {
  31. $msg->addError('ITEM_NOT_FOUND');
  32. header('Location: '.url_rewrite('/mods/_standard/forums/forum/list.php', AT_PRETTY_URL_IS_HEADER));
  33. exit;
  34. }
  35. $forum_info = get_forum($fid, $_SESSION['course_id']);
  36. $expiry = $post_row['udate'] + $forum_info['mins_to_edit'] * 60;
  37. // check if we're either a) an assistant or, b) own this post and within the time allowed:
  38. if (!( authenticate(AT_PRIV_FORUMS, AT_PRIV_RETURN)
  39. || ($post_row['member_id'] == $_SESSION['member_id'] && ($expiry > time() || isset($_POST['edit_post']) ) )
  40. )
  41. ) {
  42. $msg->addError('POST_EDIT_EXPIRE');
  43. header('Location: '.url_rewrite('mods/_standard/forums/forum/list.php', AT_PRETTY_URL_IS_HEADER));
  44. exit;
  45. }
  46. if ($_POST['cancel']) {
  47. $msg->addFeedback('CANCELLED');
  48. Header('Location: '.url_rewrite('mods/_standard/forums/forum/view.php?fid='.$_POST['fid'].SEP.'pid='.$_POST['pid'], AT_PRETTY_URL_IS_HEADER));
  49. exit;
  50. }
  51. if ($_POST['edit_post']) {
  52. $missing_fields = array();
  53. // $_POST['subject'] = str_replace('<', '&lt;', trim($_POST['subject']));
  54. // $_POST['body'] = str_replace('<', '&lt;', trim($_POST['body']));
  55. $_POST['pid'] = intval($_POST['pid']);
  56. $_POST['subject'] = $addslashes($_POST['subject']);
  57. //If subject > 60,then chop subject
  58. $_POST['subject'] = validate_length($_POST['subject'], 60);
  59. $_POST['body'] = $addslashes($_POST['body']);
  60. if ($_POST['subject'] == '') {
  61. $missing_fields[] = _AT('subject');
  62. }
  63. if ($_POST['body'] == '') {
  64. $missing_fields[] = _AT('body');
  65. }
  66. if ($missing_fields) {
  67. $missing_fields = implode(', ', $missing_fields);
  68. $msg->addError(array('EMPTY_FIELDS', $missing_fields));
  69. }
  70. if (!$msg->containsErrors()) {
  71. $sql = "UPDATE ".TABLE_PREFIX."forums_threads SET subject='$_POST[subject]', body='$_POST[body]', last_comment=last_comment, date=date WHERE post_id=$_POST[pid]";
  72. $result = mysql_query($sql,$db);
  73. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  74. if ($_POST['ppid'] == 0) {
  75. $_POST['ppid'] = $_POST['pid'];
  76. }
  77. header('Location: '.url_rewrite('mods/_standard/forums/forum/view.php?fid='.$_POST['fid'].SEP.'pid='.$_POST['ppid'], AT_PRETTY_URL_IS_HEADER));
  78. exit;
  79. }
  80. }
  81. $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['title'] = $forum_info['title'];
  82. $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['parent'] = 'mods/_standard/forums/forum/list.php';
  83. $_pages['mods/_standard/forums/forum/index.php?fid='.$fid]['children'] = array('mods/_standard/forums/forum/new_thread.php?fid='.$fid);
  84. $_pages['mods/_standard/forums/forum/new_thread.php?fid='.$fid]['title_var'] = 'new_thread';
  85. $_pages['mods/_standard/forums/forum/new_thread.php?fid='.$fid]['parent'] = 'mods/_standard/forums/forum/index.php?fid='.$fid;
  86. $_pages['mods/_standard/forums/forum/view.php']['title'] = $post_row['subject'];
  87. $_pages['mods/_standard/forums/forum/view.php']['parent'] = 'mods/_standard/forums/forum/index.php?fid='.$fid;
  88. $_pages['mods/_standard/forums/edit_post.php']['title_var'] = 'edit_post';
  89. $_pages['mods/_standard/forums/edit_post.php']['parent'] = 'mods/_standard/forums/forum/index.php?fid='.$fid;
  90. $_pages['mods/_standard/forums/edit_post.php']['children'] = array();
  91. $onload = 'document.form.subject.focus();';
  92. require(AT_INCLUDE_PATH.'header.inc.php');
  93. ?>
  94. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
  95. <input type="hidden" name="edit_post" value="true" />
  96. <input type="hidden" name="pid" value="<?php echo $pid; ?>" />
  97. <input type="hidden" name="ppid" value="<?php echo $post_row['parent_id']; ?>" />
  98. <input type="hidden" name="fid" value="<?php echo $post_row['forum_id']; ?>" />
  99. <div class="input-form">
  100. <div class="row">
  101. <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="subject"><?php echo _AT('subject'); ?></label><br />
  102. <input type="text" maxlength="80" name="subject" size="36" value="<?php echo stripslashes(htmlspecialchars($post_row['subject'])); ?>" id="subject" />
  103. </div>
  104. <div class="row">
  105. <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="body"><?php echo _AT('body'); ?></label><br />
  106. <textarea cols="65" name="body" rows="10" id="body"><?php echo AT_print($post_row['body'], 'text.input'); ?></textarea>
  107. </div>
  108. <div class="row">
  109. <small class="spacer"><br />&middot; <?php echo _AT('forum_links'); ?><br />
  110. &middot; <?php echo _AT('forum_email_links'); ?><br />
  111. &middot; <?php echo _AT('forum_html_disabled'); ?></small>
  112. </div>
  113. <div class="row">
  114. <a href="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); ?>#jumpcodes" title="<?php echo _AT('jump_codes'); ?>"><img src="images/clr.gif" height="1" width="1" alt="<?php echo _AT('jump_codes'); ?>" border="0" /></a><?php require(AT_INCLUDE_PATH.'html/code_picker.inc.php'); ?>
  115. <a name="jumpcodes"></a>
  116. </div>
  117. <div class="row buttons">
  118. <input name="submit" type="submit" value=" <?php echo _AT('save'); ?>" accesskey="s" />
  119. <input type="submit" name="cancel" value=" <?php echo _AT('cancel'); ?> " />
  120. </div>
  121. </div>
  122. </form>
  123. <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>