<? 
define('ADMIN',true);
define('AJAX',true);
define('ROOT','../../..');
header('Content-Type: application/json; charset=utf-8');
require_once(ROOT.'/.config.php');
require_once(LIBS_PATH.'/system/sys_start.php');
require_once(LIBS_PATH.'/system/load_libs.php');
///////////////////////////
$X->STR->post_filter();


switch($_POST['type']) {
	case 'dir':
		$dir=base64_decode($_POST['dir']);
		$R['exists'] = (is_dir($dir));

		$exclude=@unserialize(base64_decode($_POST['exclude']));

		$post_skip=explode("\n",trim($_POST['exclude_textarea']));
		if(count($post_skip)>0 && !empty($post_skip[0])) {
			$exclude_sum=@array_merge($exclude, $post_skip);
			unset($exclude);
			foreach($exclude_sum as $x) $exclude[]=trim($x);
		}

		$ftp_data = $X->UTIL->count_dir_size($dir, $exclude);

		$R['size'] = $ftp_data['size'];
		$R['nice_size'] = @round($ftp_data['size']/(1024*1024), 1).' MB';
		$R['files'] = $ftp_data['files'];
		$R['dirs'] = $ftp_data['dirs'];
	break;
}


echo json_encode($R);
?>