Location: PHPKode > projects > ACollab > drafting/revision_edit_file.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: revision_edit_file.php 297 2005-01-17 19:15:02Z joel $

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

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

$id  = intval($_REQUEST['id']);
$pid = intval($_REQUEST['pid']);

if (isset($_POST['cancel'])) {
	header('Location: revisions.php?id='.$pid);
	exit;
}

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

	if ($_POST['replacefile']) {
		if($_FILES['file']['name'] == '') {
			$error[] = E_DRAFT_EMPTY_FILE;
		} else if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
			$error[] = E_DRAFT_UPLOAD;
		} else {
			$ext = substr($_FILES['file']['name'], strrpos($_FILES['file']['name'], '.')+1);
			if (!isset($_file_types[$ext])) {
				$error[] = E_DRAFT_ILLEGAL_FILE_TYPE;
			}
		}
	}

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

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

			$sql	= "UPDATE ".TABLE_PREFIX."files_revisions SET description='$_POST[comments]', file_name='{$_FILES[file][name]}', file_size='{$_FILES[file][size]}' WHERE revision_id=$id AND member_id=$_SESSION[member_id]";

			if (mysql_query($sql, $db)) {
				$char = substr($id, 0, 1).'/';

				@unlink(UPLOAD_DIR.$char.$id);

				if (move_uploaded_file($_FILES['file']['tmp_name'], UPLOAD_DIR.$char.$id)) {
					@chmod(UPLOAD_DIR.$char.$id, 01600);

					header('Location: revisions.php?id='.$pid.SEP.'f='.F_DRAFT_EDITED);
					exit;
				}
			}
		} else {
			$_POST['comments'] = $addslashes($_POST['comments']);

			$sql	= "UPDATE ".TABLE_PREFIX."files_revisions SET description='$_POST[comments]' WHERE revision_id=$id AND member_id=$_SESSION[member_id]";
			mysql_query($sql, $db);

			if (!$pid) {
				$pid = $id;
			}
			header('Location: revisions.php?id='.$pid.SEP.'f='.F_DRAFT_EDITED);
			exit;
		}
	}
}


$sql = "SELECT * FROM ".TABLE_PREFIX."files WHERE file_id=$pid AND group_id=$_SESSION[group_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('revisions');

		require(AC_INCLUDE_PATH.'header.inc.php');
		$errors[] = E_FILE_NOT_FOUND;
		print_errors($errors);
		require (AC_INCLUDE_PATH.'footer.inc.php');
		exit;
}
$title = $row['title'];
$description = $row['description'];
$locked = $row['locked'];
$folder = $row['folder_id'];

$_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'). ': '.$title;
$_SECTION[2][1] = 'drafting/revisions.php?id='.$pid;
$_SECTION[3][0] = _AC('edit_file');
$_SECTION[3][1] = 'drafting/edit_file.php';

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

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

$sql = "SELECT * FROM ".TABLE_PREFIX."files_revisions WHERE revision_id=$id AND file_id=$pid";
$result = mysql_query($sql,$db);

if (!($row = mysql_fetch_assoc($result))) {
	$errors[] = E_FILE_NOT_FOUND;
	print_errors($errors);
	require (AC_INCLUDE_PATH.'footer.inc.php');
	exit;
} else if ($folder == 0 && $row['member_id'] != $_SESSION['member_id'] && !authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {
	/* if file's in a private folder that is not yours and you're not grp admin */
	/* actually permission is denied, but for security we fake a "FNF" */
	$errors[] = E_FILE_NOT_FOUND;
	print_errors($errors);
	require (AC_INCLUDE_PATH.'footer.inc.php');
	exit;
} else if (!authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK) && $locked) {
	$errors[] = E_FILE_LOCKED;
	print_errors($errors);
	require (AC_INCLUDE_PATH.'footer.inc.php');
	exit;
}

if (isset($_POST['submit'])) {
	$row['description'] = $_POST['comments'];

	if ($_POST['replacefile']) {
		$repy = ' checked="checked"';
	} else {
		$repn = ' checked="checked"';
	}
} else {
	$repn = ' checked="checked"';
}

?>
<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="pid" value="<?php echo $pid; ?>" />
	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="5" class="box"><h3><?php echo _AC('edit_revision'); ?></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>
<?php if ($row['file_name'] != '') { ?>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" valign="top"><b><?php echo _AC('file'); ?>:</b></td>
		<td class="row1" valign="top">&nbsp;</td>
		<td class="row1"><small><?php echo _AC('drafting_replace_file'); ?></small><br /><input type="radio" name="replacefile" id="replacefile1" value="0" <?php echo $repn; ?> /><label for="replacefile1"><?php echo $row['file_name']; ?></label><br />
		<input type="radio" name="replacefile"  value="1" <?php echo $repy; ?> /><input type="file" name="file" id="file" class="input" size="30" onchange='selectFile(this);' onfocus="this.className='input highlight'" onblur="this.className='input'" /></td>
		<td class="row1">&nbsp;</td>
	</tr>
<?php } ?>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right" valign="top"><label for="comments"><b><?php echo _AC('comments'); ?>:</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="comments" id="comments" class="input" onfocus="this.className='input highlight'" onblur="this.className='input'" cols="45" rows="5"><?php echo $row['description']; ?></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>

<script type="text/javascript">
<!--
	function selectFile(o)
	{
		// Check upload option
		if (form.replacefile[1]) {
			form.replacefile[1].checked = true;
		}
	}
//-->
</script>

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