<?php
	if ( !defined('IN_MFA') )
		die("Hacking attempt");
	
	$user->DieNotValid();
 	if(! $user->has_right("delete"))
 		message_die("No Access",$lang['norights']);
	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");

	if(!IsSet($_GET['sure_to_delete']))	
	{
		if(!IsSet($_GET['object']))
			$_GET['object'] = "";  //dann soll auch kein object übergeben werden
		$show_after_header .= "<p class='error' width='100%' align='center'>".$lang['sure']."<p><div width='100%' align='center'><a href='index.php?dir=".$_GET['dir']."&amp;mode=delete&amp;object=".$_GET['object']."&amp;sure_to_delete=yes&amp;&amp;close=".$_GET['object']."'>".$lang['yes']."</a>&nbsp;|&nbsp;<a href='index.php?dir=".$_GET['dir']."'>".$lang['no']."</a></div><p class='hr'></p>";
	}
	else
	{
		if($_GET['sure_to_delete'] == "yes") // WENN JA
		{
			$deletelist = explode(";;",$_GET['object']);
			$to_delete = array();	
			foreach($deletelist as $file_to_delete)
			{
				//er soll nicht das ROOT-Verzeichnis löschen
				if(trim($file_to_delete) != "" && trim($file_to_delete) != "/")
					$to_delete[] = $file_to_delete;
			}
			
			foreach($to_delete as $file_to_delete)
			{
				if(! file_exists(ROOT_DIR."/".$user->user_root_dir.$file_to_delete))
					message_die("Missing file","Couldn´t delete file: ".$file_to_delete.". File doesn´t exist","Error");
			
				if(is_dir(ROOT_DIR."/".$user->user_root_dir.$file_to_delete))
				{
					$dieing_dir = new dir($user->user_root_dir.$file_to_delete);
					$dieing_dir->delete();
				}
				else	
				{
					$dieing_file = new file($user->user_root_dir.$file_to_delete);
					$working_user = is_locked($dieing_file->file_path);

					if($working_user == $user->user_name || $working_user == false)
					{
							if(!$dieing_file->delete())
								message_die("Error while deleting file","I can't delete this file: ".$dieing_file->file_path."");		
							unlock_file($dieing_file->file_path);
					}
					else
						message_die("Locked file","This file is locked by another person");
				}
				if(LOG_USED == 1)
					write_in_log("file/dir '".ROOT_DIR."/".$user->user_root_dir.$file_to_delete."' deleted");
			}
		}
	}
?>