Location: PHPKode > projects > ACollab > forums/edit_post.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2004  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may redistribute it and/or                        */
/* modify it under the terms of the GNU General Public License                          */
/* as published by the Free Software Foundation; either version 2 of the License,       */
/* or (at your option) any later version.                                               */
/*                                                                                      */
/* This program is distributed in the hope that it will be useful, but                  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of                           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
/* See the GNU General Public License for more details.                                 */
/*                                                                                      */
/* You may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: edit_post.php 223 2004-06-07 16:52:54Z boonhau $

define('AC_INCLUDE_PATH', '../include/');

require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_GROUP_ADMIN);

$pid = intval($_REQUEST['pid']);
$ppid = intval($_REQUEST['ppid']);
$fid = intval($_REQUEST['fid']);

if (isset($_POST['cancel'])) {
	if ($ppid == 0) {
		$ppid = $pid;
	}
	Header('Location: view.php?fid='.$fid.SEP.'pid='.$ppid);
	exit;
}

if (isset($_POST['submit'])) {
	$_POST['subject']	= str_replace('<', '&lt;', trim($_POST['subject']));
	$_POST['body']		= str_replace('<', '&lt;', trim($_POST['body']));


	if ($_POST['subject'] == '') {
		$errors[] = E_THREAD_SUBJECT_EMPTY;
	}

	if ($_POST['body'] == '') {
		$errors[] = E_THREAD_BODY_EMPTY;
	}

	if (!isset($errors)) {
		$_POST['subject'] = $addslashes($_POST['subject']);
		$_POST['body'] = $addslashes($_POST['body']);

		$sql = "UPDATE ".TABLE_PREFIX."forums_threads SET subject='$_POST[subject]', body='$_POST[body]' WHERE post_id=$_POST[pid]";
		$result = mysql_query($sql,$db);

		if ($ppid == 0) {
			$ppid = $pid;
		}
		Header('Location: view.php?fid='.$fid.SEP.'pid='.$ppid.SEP.'f='.F_THREAD_EDITED);
		exit;
	}
}

$forum_info = get_forum_info($fid);
$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('forums');
$_SECTION[1][1] = 'forums/';
$_SECTION[2][0] = _AC('forum').': '.$forum_info['title'];
$_SECTION[2][1] = 'forums/forum.php?fid='.$fid;
$_SECTION[3][0] = _AC('edit_message');
$_SECTION[3][1] = 'forums/';

$onload = 'onload="document.form.subject.focus()"';

require(AC_INCLUDE_PATH.'header.inc.php');
	
	$sql = "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$pid";
	$result = mysql_query($sql,$db);
	if (!($row = mysql_fetch_array($result))) {
		$errors[] = E_THREAD_NOT_FOUND;
		print_errors($errors);
		require (AC_INCLUDE_PATH.'footer.inc.php');
		exit;
	}


	if (isset($errors)) {
		print_errors($errors);

		$row['subject'] = $_POST['subject'];
		$row['body']	= $_POST['body'];
	}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
	<input type="hidden" name="pid" value="<?php echo $pid; ?>" />
	<input type="hidden" name="fid" value="<?php echo $row['forum_id']; ?>" />
	<input type="hidden" name="ppid" value="<?php echo $row['parent_id']; ?>" />
	<br />
	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="5" class="box"><h3><?php echo _AC('edit_message'); ?></h3></th>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td colspan="3" class="row1"><img src="images/clr.gif" height="1" width="1" alt="" /><br /><?php
			echo _AC('denotes_required', '<img src="images/required.gif" height="14" width="14" alt="'._AC('required_field').'" />');
		?><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right"><label for="subject"><b><?php echo _AC('subject'); ?>:</b></label></td>
		<td class="row1"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" /></td>
		<td class="row1"><input class="input" maxlength="45" name="subject" size="36" value="<?php echo $row['subject']; ?>" id="subject" onfocus="this.className='input highlight'" onblur="this.className='input'" /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" valign="top"><label for="body"><b><?php echo _AC('message'); ?>:</b></label></td>
		<td class="row1" valign="top"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" class="img" /></td>
		<td class="row1"><textarea class="input" cols="65" name="body" rows="10" id="body" onfocus="this.className='input highlight'" onblur="this.className='input'"><?php echo $row['body']; ?></textarea></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" colspan="3" align="right"><br /><input type="submit" name="submit" value=" <?php echo _AC('edit'); ?> " class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> &nbsp; <input type="submit" name="cancel" value="<?php echo _AC('cancel'); ?>" class="submitN" onfocus="this.className='submitN highlight'" onblur="this.className='submitN'" /><br /><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	</table>
</form>

<?php
	require (AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab