<?php

class shareList_sxExe extends xIExecutor {

	public function main() {
		$type = $_POST['type'];
		if($type == 'all' || $type == 'forMe') {
			$shares = xShare::listItems();
		} else {
			$shares = xShare::listItems(xUser::$cur);
		}
		$list = array();
		while($share = $shares->fetch_assoc()) {
			if($share['restype'] == SHARE_TYPE_FILE) {
				$list[] = array(
					'type' => 'file',
					'filekey' => $share['filekey'],
					'filename' => $share['filename'],
					'filesize' => xFile::toStrSize($share['filesize']),
					'username' => $share['username'],
					'date' => date('Y-m-d H:i', $share['shared'])
				);
			} else {
				$list[] = array(
					'type' => 'folder',
					'folderkey' => $share['folderkey'],
					'foldername' => $share['foldername'],
					'foldersize' => xFile::toStrSize($share['foldersize']),
					'username' => $share['username'],
					'date' => date('Y-m-d H:i', $share['shared'])
				);
			}
		}
		$shares->free();
		echo json_encode(array(
			'result' => '1',
			'list' => $list
		));
	}

	public function onError($result) {

	}
}

