<?php

class view_sxExe extends xIExecutor {

	public function main() {
		global $_APP;
		$file = new xFile($_GET['key']);
		if($file->isValid()) {
			define('FILE_ID',			$file->id);
			define('FILE_NAME',			$file->name);
			define('FILE_DOWNLOADS',	$file->downloads);
			define('FILE_EXT',			$file->name_ext);
			define('FILE_PREVIEW',		in_array($file->name_ext, $_APP['preview']));
			define('FILE_SIZE',			xFile::toStrSize($file->size));
			define('FILE_ADDED',		date('Y-m-d H:i', $file->added));
			define('FILE_ISSHARE',		($share = xShare::access($file, false)) ? true : false);
			if(FILE_ISSHARE) {
				define('FILE_SHARETIME',	date('Y-m-d H:i', $share->shared));
			} else {
				define('FILE_SHARETIME',	'私密文件');
			}
			if(FILE_ISSHARE || (!xUser::$cur->isGuest() && $file->isOwner(xUser::$cur))) {
				xUI::loadPage('view.php');
			} else {
				header('Location: ./');
			}
		} else {
			header('Location: ./');
		}
	}

	public function onError($result) {

	}
}