Location: PHPKode > projects > ACollab > drafting/revision_edit_comment.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2005  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 

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

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

$id  = intval($_REQUEST['id']);
$fid  = intval($_REQUEST['fid']);
$ffid  = intval($_REQUEST['ffid']);
$r  = intval($_REQUEST['r']);

	$sql = "SELECT * FROM ".TABLE_PREFIX."revisions_comments WHERE comment_id=$id";
	$result = mysql_query($sql,$db);
	if (!($row = mysql_fetch_assoc($result))) {
		$_SECTION[0][0] = _AC('home');
		$_SECTION[0][1] = 'home.php';
		$_SECTION[1][0] = _AC('drafting_room');
		$_SECTION[1][1] = 'drafting/';
		$_SECTION[2][0] = _AC('delete_revision_comment');

		require(AC_INCLUDE_PATH.'header.inc.php');

		$errors[] = E_DRAFT_COMMENT_NOT_FOUND;
		print_errors($errors);
		require (AC_INCLUDE_PATH.'footer.inc.php');
		exit;
	} else if (($row['member_id'] != $_SESSION['member_id'])  && !authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)){
			
		$_SECTION[0][0] = _AC('home');
		$_SECTION[0][1] = 'home.php';
		$_SECTION[1][0] = _AC('drafting_room');
		$_SECTION[1][1] = 'drafting/';
		$_SECTION[2][0] = _AC('delete_revision_comment');

		require(AC_INCLUDE_PATH.'header.inc.php');

		/* actually permission is denied, but for security we fake a "FNF" */
		$errors[] = E_DRAFT_COMMENT_NOT_FOUND;
		print_errors($errors);
		require (AC_INCLUDE_PATH.'footer.inc.php');
		exit;
	}

if (isset($_POST['submit'])) {
	$_POST['comment']  = trim($_POST['comment']);

	if ($_POST['comment'] == '') {
		$error[] = E_DRAFT_EMPTY_COMM;
	}

	if (!isset($error)) {
		$_POST['comment'] = $addslashes($_POST['comment']);

		$sql	= "UPDATE ".TABLE_PREFIX."revisions_comments SET comment='$_POST[comment]' WHERE comment_id=$id AND revision_id=$fid";
		mysql_query($sql, $db);

		header('Location: comments.php?id='.$fid.SEP.'r='.$r.SEP.'fid='.$ffid.'f='.F_DRAFT_EDITED);
		exit;
	}
}

if (isset($_POST['cancel'])) {
	header('Location: comments.php?id='.$fid.SEP.'r='.$r.SEP.'fid='.$ffid);
	exit;
}

/* should really be replaced with a function :S */
$sql = "SELECT * FROM ".TABLE_PREFIX."files WHERE file_id=$ffid";
$result = mysql_query($sql,$db);
$row = mysql_fetch_assoc($result);

$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('drafting_room');
$_SECTION[1][1] = 'drafting/';
$_SECTION[2][0] = _AC('revisions'). ': '.$row['title'];
$_SECTION[2][1] = 'drafting/revisions.php?id='. $ffid;
$_SECTION[3][0] = _AC('comments'). ': '._AC('revision') .' #'.$r;
$_SECTION[3][1] = 'drafting/comments.php?id=' . $fid.SEP.'r='.$r.SEP.'fid='.$ffid;
$_SECTION[4][0] = _AC('edit_revision_comment');

require(AC_INCLUDE_PATH.'header.inc.php');

if (isset($error)) {
	print_errors($error);
	unset($error);
}

	$sql = "SELECT * FROM ".TABLE_PREFIX."revisions_comments WHERE comment_id=$id AND revision_id=$fid";
	$result = mysql_query($sql,$db);
	$row = mysql_fetch_assoc($result);

	if (isset($_POST['submit'])) {
		$row['comment'] = $_POST['comment'];
	}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form" id="form">
	<input type="hidden" name="id" value="<?php echo $id; ?>">
	<input type="hidden" name="fid" value="<?php echo $fid; ?>">
	<input type="hidden" name="ffid" value="<?php echo $ffid; ?>">
	<input type="hidden" name="r" value="<?php echo $r; ?>">

	<p>
	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="5" class="box"><h3><?php echo _AC('edit_revision_comment'); ?></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 nobar">&nbsp;</td>
		<td class="row1 nobar" width="20%" align="right"><b><?php echo _AC('by'); ?>:</b></td>
		<td class="row1 nobar">&nbsp;</td>
		<td class="row1 nobar"><?php echo get_login($row['member_id']); ?></td>
		<td class="row1 nobar">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1 nobar">&nbsp;</td>
		<td class="row1 nobar" align="right"><b><?php echo _AC('date'); ?>:</b></td>
		<td class="row1 nobar">&nbsp;</td>
		<td class="row1 nobar"><?php echo $row['date']; ?></td>
		<td class="row1 nobar">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" valign="top"><label for="comment"><b><?php echo _AC('comment'); ?>:</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 name="comment" id="comment" class="input" onfocus="this.className='input highlight'" onblur="this.className='input'" cols="45" rows="5"><?php echo $row['comment']; ?></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>
	</p>
</form>

<br />

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