<?php
if ( !defined('IN_MFA') )
		die("Hacking attempt");

$user->dieNotAdmin();

$layoutadminargs['admin_start'] = $lang['admin_start'];
$layoutadminargs['general_config'] = $lang['general_config'];
$layoutadminargs['user_management'] = $lang['user_management'];
$layoutadminargs['maintenance'] = $lang['maintenance'];
$layoutadminargs['back'] = $lang['back'];

$layoutadminargs['info_text'] = $lang['maintenance_info']."<div class='box' style='margin:5px'>".$lang['maintenance_start']."</div>";

if(IsSet($_GET['confirm']))
{
	$layoutadminargs['admin_main_content'] = "<div class='hr' style='text-align:left'><b>Starting Scan</b></div>";
	$layoutadminargs['admin_main_content'] .= "<div><b>Scaning 'work/data'</b></div>";
	$layoutadminargs['admin_main_content'] .= "<table>";
	//alle Dateien im Ordner work/data einlesen
	$dh = @opendir( ROOT_DIR."/".SCRIPT_PATH."/work/data") or die("<p class='error'>There is an error in the general configuration. Please open the Admin-Control-Panel -> general configruation and check the inputs!</p>");
	while ( gettype($file = readdir( $dh )) != "boolean")
	{
		if($file != "." && $file != ".." && !strstr($file,"user_") && $file != "constants.php") 
		{
			$dfile = new file(SCRIPT_PATH."/work/data/".$file);
			$fcontent = $dfile->getContent();
			$fcontent = explode("##;##",$fcontent);
			if(!file_exists(ROOT_DIR."/".$fcontent[0]))
			{
				if(!$dfile->delete())
					$layoutadminargs['admin_main_content'] .= "<tr><td><b>Deleting ".$file."</b></td><td class='error'>[FAILED]</td></tr>";
				else
					$layoutadminargs['admin_main_content'] .= "<tr><td><b>Deleting ".$file."</b></td><td class='success'>[DONE]</td></tr>";
			}	
		}
	}
	@closedir($dh);
	$layoutadminargs['admin_main_content'] .= "</table>";
	$layoutadminargs['admin_main_content'] .= "<div class='success'>[DONE]</div>";
	
	//noch den Ordner work/temp
	$layoutadminargs['admin_main_content'] .= "<div><b>Scaning 'work/temp'</b></div>";
	$layoutadminargs['admin_main_content'] .= "<table>";
	$dh = @opendir( ROOT_DIR."/".SCRIPT_PATH."/work/temp") or die("<p class='error'>There is an error in the general configuration. Please open the Admin-Control-Panel -> general configruation and check the inputs!</p>");
	while ( gettype($file = readdir( $dh )) != "boolean")
	{
		if($file != "." && $file != ".." && !strstr($file,".usf")) 
		{
			$dfile = new file(SCRIPT_PATH."/work/temp/".$file);
			if(!$dfile->delete())
				$show_after_header .= "<tr><td><b>Deleting ".$file."</b></td><td class='error'>[FAILED]</td></tr>";
			else
				$show_after_header .= "<tr><td><b>Deleting ".$file."</b></td><td class='success'>[DONE]</td></tr>";
		}
	}
	@closedir($dh);
	$layoutadminargs['admin_main_content'] .= "</table>";
	$layoutadminargs['admin_main_content'] .= "<div class='success'>[DONE]</div>";
}
else
	$layoutadminargs['admin_main_content'] = "";	

$show_after_header .= $template->layoutparser("adminpage",$layoutadminargs);
?>