<?php
if (! defined ( 'ADMIN_FILE' ))
	die ( "Illegal File Access" );

function DeleteCache() {
	global $admin_file;
	begin_frame ( "Очистра кеша" );
	if (! $_GET ['sure'])
		print ( '<table align="center"><tr><td>Вы уверены, что хотите очистить кеш? <a href="./' . $admin_file . '.php?op=DeleteCache&sure=1">Да</a> | <a href="./' . $admin_file . '.php">НЕТ</a>.</td></tr></table>' );
	else {
		$folders = array ("главного кеша" => "", 'кеша блока "новинк"' => "block-nowvink", "кеша деталей торрента" => "details", "кеша пользовательских деталей" => "userdetails" );
		foreach ( $folders as $keyfold => $folder ) {
			$dir = opendir ( './include/cache/' . ($folder ? $folder . "/" : "") );
			$filename = array ();
			while ( $file = readdir ( $dir ) ) {
				if (preg_match ( '#[a-zA-Z0-9+_-].html#si', $file ) && ! is_link ( $dir . '/' . $file ) && ! is_dir ( $dir . '/' . $file )) {
					$filename [] = trim ( $file );
				}
			}
			if ($filename) {
				foreach ( $filename as $file ) {
					$err [$file] = @unlink ( './include/cache/' . ($folder ? $folder . "/" : "") . $file );
				}
				foreach ( $err as $key => $val )
					if (! $val)
						$errs [] = $key;
			}
			if (! $errs)
				print ( '<table align="center"><tr><td><font color="green"><b>Очистка ' . $keyfold . ': Успешно!</b></font></td></tr></table>' );
			else
				print ( '<table align="center"><tr><td><font color="red"><b>Очистка ' . $keyfold . ': Ошибка в файлах : ' . implode ( ', ', $errs ) . '!</b></font></td></tr></table>' );
		}
	}
}
switch ($op) {
	case "DeleteCache" :
		DeleteCache ();
		break;
}
?>