<?php
/**
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: opfile.php 6 2011-05-28 09:17:59Z along $
#
#	Copyright (C) 2008-2011 PHPDisk Team. All Rights Reserved.
#
*/
include '../../includes/commons.inc.php';

$username = rawurldecode(trim(gpc('user','P','')));
$password = trim(gpc('pwd','P',''));
$hash = trim(gpc('hash','P',''));
$cmd = trim(gpc('cmd','P',''));

$client_info = @$db->result_first("select client_info from {$tpf}client_set limit 1");
if($client_info){
	$ci = unserialize($client_info);
	$ci['server_key'] = pd_encode($ci['server_key'],'DECODE');
}
if($hash != strtoupper(md5($ci['server_key']))){
	$str = 'of_hash_key_error';
}
if(!$username){
	$str = 'of_username_error';
}else{
	$username = is_utf8() ? $username : convert_str('utf-8','gbk',$username);
	$username = $db->escape($username);
}
$rs = $db->fetch_one_array("select username,password,userid from {$tpf}users where username='$username'");
if($rs){
	if(strtoupper($rs['password']) <> $password){
		$str = 'of_password_error';
	}else{
		$pd_uid = $rs['userid'];
		get_exe_notify($cmd);
	}
}else{
	$str = 'of_username_error';
}
unset($rs);

function get_exe_notify($cmd){
	global $db,$tpf,$pd_uid,$settings,$username;
	$arr = explode('|',strtolower($cmd));
	if(is_array($arr)){
		switch ($arr[0]){
			case 'upfiledone':
				$tmp = explode('/',$arr[1]);
				$folder_name = $tmp[count($tmp)-1];
				$folder_name = is_utf8() ? convert_str('utf-8','gbk',$folder_name) : $folder_name;
				$rs = $db->fetch_one_array("select folder_id,folder_node from {$tpf}folders where userid='$pd_uid' and folder_name='".$db->escape($folder_name)."'");
				$folder_id = $rs['folder_id'] ? (int)$rs['folder_id'] : -1;
				$folder_node = $rs['folder_node'] ? (int)$rs['folder_node'] : 0;
				unset($rs);
				$tmp_username = is_utf8() ? $username : convert_str('utf-8','gbk',$username);
				$dir = PHPDISK_ROOT.$settings['file_path'].'/'.$tmp_username.tree_path($folder_id);

				syn_file_data($dir,$folder_node,$folder_id);

				break;
			default:
				echo '0';
		}
	}else{
		echo '0';
	}
}
?>