<?php

class remove_sxExe extends xIExecutor {

	public function main() {
		$removeCount = array('result'=>'1','folders'=>0,'files'=>0);
		if(isset($_POST['checkbox']['folder'])) {
			// --- 删除文件夹 ---
			foreach($_POST['checkbox']['folder'] as $folderID) {
				$folder = new xFolder((int)$folderID);
				if($folder->isValid() && $folder->isOwner(xUser::$cur)) {
					// --- 检测是不是 AppData 文件夹 ---
					$folderPath = substr($folder->paths, strlen(xUser::$cur->username));
					if($folderPath . $folder->name . '/' != '/AppData/') {
						// --- 不是 AppData，那是否在 AppData 内部 ---
						if(substr($folderPath,0,9) != '/AppData/') {
							$rtn = $folder->delete();
							$removeCount['folders'] = $removeCount['folders'] + $rtn['folders'];
							$removeCount['files'] = $removeCount['files'] + $rtn['files'];
						}
					}
				}
			}
		}
		if(isset($_POST['checkbox']['file'])) {
			// --- 删除文件 ---
			foreach($_POST['checkbox']['file'] as $fileID) {
				$file = new xFile((int)$fileID);
				if($file->isValid() && $file->isOwner(xUser::$cur)) {
					// --- 是否在 AppData 内部 ---
					$filePath = substr($file->paths, strlen(xUser::$cur->username));
					if(substr($filePath,0,9) != '/AppData/') {
						if($rtn = $file->delete())
							$removeCount['files'] = $removeCount['files'] + 1;
					}
				}
			}
		}
		xUser::$cur->select(xUser::$cur->id+0, 1);
		$removeCount['diskUsageStr'] = xFile::toStrSize(xUser::$cur->disk_usage);
		$removeCount['diskMaxStr'] = xFile::toStrSize(xUser::$cur->disk_max);
		$removeCount['usagePer'] = round(xUser::$cur->disk_usage/xUser::$cur->disk_max*100);
		echo json_encode($removeCount);
	}

	public function onError($result) {

	}
}

