<?php
	if ( !defined('IN_MFA') )
		die("Hacking attempt");
	
	$user->DieNotValid();
	
	if(is_locked_for_me($user->user_root_dir.$_GET['object']))
		message_die("Invalid Object","This file is changed by another user at the moment");
	
	$validated = validateObject($user->user_root_dir.$_GET['object']);
	if(gettype($validated) != "boolean") message_die("Invalid Object",$validated);
	
	if(!IsSet($_GET['dir'])) $escape = $lang['nodir'];
	if(!IsSet($_GET['object'])) $escape = $lang['noobject'];
	
	if(IsSet($escape))
		$show_after_header = "<p class='error'>".$escape."</p>";
	else
	{
		if(! IsSet($_GET['step'])) $_GET['step'] = 1;
		
		if($_GET['step'] == 1)
		{
				$show_after_header = "<a href='index.php?dir=".$_GET['dir']."'>".$lang['back']."</a><p class='error' width='100%' align='center'>".$lang['rename_request']."</p>
															<div width='100%' align='center'>
															<table border='0'>
															<form action='index.php?dir=".$verzname."&amp;mode=rename&amp;object=".$_GET['object']."&amp;step=2' method='POST'>
																<tr>
																	<td><b>".$lang['oldname'].":</b></td>
																	<td>".$_GET['object']."</td>
																</tr>
																<tr>
																	<td><b>".$lang['newname'].":</b></td>
																	<td><input type='text' name='newname'> <b>.</b> <input type='text' name='extension' maxlength='4' size='4'></td>
																</tr>
																<tr><td colspan='2'><input type='submit' name='subrename' value='".$lang['rename']."'></td></tr>
															</form>
															</table>
															</div><p class='hr'></p>";
		}
		if(($_GET['step'] == 2) && (IsSet($_POST['newname'])))
		{
			if(is_file(ROOT_DIR."/".$user->user_root_dir."/".$_GET['object']))
			{
				$to_rename = new file($user->user_root_dir.$_GET['object']);
				$new_name = $_POST['newname'];
				if($_POST['extension'] != "") $new_name .= ".".$_POST['extension'];
				
				$newfile = new file_info($user->user_root_dir.$verzname.$new_name);				
				//IST DAS ETWA EIN SCRIPT
				if($newfile->isScript() && !$user->has_right("scripting")) message_die("No Access",$lang['norights']);
				if(! file_exists(ROOT_DIR."/".$newfile->file_path))$to_rename->rename($newfile->file_path);
					
				//history aktualisieren
				$newfile = new file_info($user->user_root_dir.$verzname.$new_name);	
				if(LOG_USED == 1)	
					$newfile->add_action("'".ROOT_DIR."/".$_GET['object']."' renamed in '".$newfile->file_name."'");
			}
			
			if(is_dir(ROOT_DIR."/".$user->user_root_dir.$_GET['object']) && ! file_exists(ROOT_DIR."/".$user->user_root_dir.$verzname."/".$_POST['newname']))
			{
					$to_rename = new dir($user->user_root_dir.$_GET['object']);
					$to_rename->rename($user->user_root_dir.$verzname.$_POST['newname']);
			}
			if(LOG_USED == 1) write_in_log("File/dir '".ROOT_DIR."/".$_GET['object']."'renamed in ".$_POST['newname']);	
			//hm vll jetzt doch
			$show_explorer = 1;
		}
	}
?>