<?php
/*
script: rename.php
purpose: allows registered users to rename images in their account.
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE

*/

// include site config / database initialization, etc stuff

require_once(dirname(__FILE__).'/includes/config.inc.php');

// include and initialize the images class which handles adding images, etc.

require_once(dirname(__FILE__).'/classes/images.class.php');
$images =& new images($ace, $user);
$images->setuser($user);

$uploaderrors = '';
$uploaded = array();
$ids = array();
$errors = array();
$renamed = false;

// include the site header

require_once(dirname(__FILE__).'/header.php');

if( $banned ){
	$pagecontent->display('IP Banned');
	require_once(dirname(__FILE__).'/footer.php');
	exit();
}elseif( !$loggedin ){

	// login is required to rename, so if the user is not logged in we display some content,
	// include the default "not logged in page", and exit.
	$pagecontent->display('Upload - Not Logged In');
	require(dirname(__FILE__).'/includes/notloggedin.inc.php');
}


// display the introduction / instructions for the rename image page.

$pagecontent->display('Rename Image');

// if the user is not allowed to rename images, tell them.

if( !$user->rename_images ){
	$pagecontent->display('Cannot Rename');
	require_once(dirname(__FILE__).'/footer.php');
	exit();
}

$iid = $ace->getint('i', $_REQUEST);
$image = 0;
if( $iid != 0 ) $image = $images->getimage(array('userid'=>$user->user_id, 'id'=>$iid));
if( $image == 0 ) $iid = 0;

if( $image == 0 ){
	$pagecontent->display('No Image Selected');
	require_once(dirname(__FILE__).'/footer.php');
	exit();

}

if( $ace->getstr('rename', $_POST) != '' ){
	$name = $ace->getstr('name', $_POST);
	if( $images->renameimage($image, $name) ){
		$renamed = true;
	}else{
		$errors = $images->errors;
	}
}

if( $renamed ){

	$pagecontent->display('Image Renamed');

}else{

	if( count($errors) > 0 ){
?>
<div class="errors">The following error occurred:<br /><br /><?php echo join("<br />\n", $errors);?></div>
<?php
	}

// display the image rename form and image thumbnail...

?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="i" value="<?php echo $iid;?>" />
<div class="renameform">
	<div class="renamethumb"><a onClick="return si('<?php echo $image->image_url;?>', <?php echo $image->width;?>, <?php echo $image->height;?>);"  target="_blank" href="<?php echo $image->image_url;?>"><img border="0" class="thumb" src="<?php echo $image->thumb_url;?>" alt="" /></a></div>
	<div class="renamefields">
		Rename "<?php echo $image->name.'.'.$image->type;?>" to:
		<br />
		<input class="renamename" type="text" name="name" />
		<br /><input class="renamesubmit" type="submit" name="rename" value="Rename Image" />
	</div>
	<br clear="all" />
</div>
</form>
<?php

}
// include the site footer.

require_once(dirname(__FILE__).'/footer.php');

?>
