<?php 
/**
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: mydisk.php 25 2011-03-04 07:36:51Z along $
#
#	Copyright (C) 2008-2011 PHPDisk Team. All Rights Reserved.
#
*/

include "includes/commons.inc.php";

phpdisk_core::user_login();

define('IN_MYDISK' ,true);

lang('mydisk');

if(empty($item) || $item == ''){
	require_once template_echo("mydisk",$user_tpl_dir);
	exit();
}
$op = trim(gpc('op','G',''));

if($item == "menu"){

	if($op =='file'){
	
		$cache_file = PHPDISK_ROOT."system/cache/$pd_uid/my_menu.inc.php";
		file_exists($cache_file) ? require_once $cache_file : $folder_list = folders_menu_cache();
	
	}elseif($op =='folder'){	
		$tmp = (int)@$db->result_first("select sum(file_size) from {$tpf}files where in_recycle=0 and userid='$pd_uid'");
		$total_space = get_size($tmp);
		$file_count = (int)@$db->result_first("select count(*) from {$tpf}files where in_recycle=0 and userid='$pd_uid'");
		$folder_count = (int)@$db->result_first("select count(*) from {$tpf}folders where in_recycle=0 and userid='$pd_uid'"); 
		
	}elseif($op =='public'){
	
		$cache_file = PHPDISK_ROOT."system/cache/pub_menu.inc.php";
		file_exists($cache_file) ? require_once $cache_file : $public_folder_tree = public_menu_cache();
		
		$my_file_store = @$db->result_first("select sum(file_size) from {$tpf}files where is_public=1 and cate_id>0 and userid='$pd_uid'");
		
		$file_count = @$db->result_first("select count(*) from {$tpf}files where is_public=1 and cate_id>0 and userid='$pd_uid'");
		$total_space = get_size($my_file_store);
		
	}elseif($op =='recycle'){
		$tmp = (int)@$db->result_first("select sum(file_size) from {$tpf}files where in_recycle=1 and userid='$pd_uid'");
		$total_space = get_size($tmp);
		$file_count = (int)@$db->result_first("select count(*) from {$tpf}files where in_recycle=1 and userid='$pd_uid'");
		$folder_count = (int)@$db->result_first("select count(*) from {$tpf}folders where in_recycle=1 and userid='$pd_uid'"); 
		
	}elseif($op == 'profile'){
		$num = @$db->result_first("select count(*) as total from {$tpf}messages where touserid='$pd_uid' and is_new=1");
		$new_msg = $num ? '<span class="txtred" title="'.$L['new_msg'].'">('.$num.')</span>' : '';
	}	
	
	$q = $db->query("select * from {$tpf}stats ");
	while($rs = $db->fetch_array($q)){
		$set[$rs['vars']] = trim($rs['value']);
	}
	$db->free($q);
	unset($rs);
	if(!$set['stat_time'] || $timestamp-$set['stat_time'] >3600){
		$stats['user_folders_count'] = (int)@$db->result_first("select count(*) from {$tpf}folders");
		$stats['user_files_count'] = (int)@$db->result_first("select count(*) from {$tpf}files where is_public=0");
		$stats['users_count'] = (int)@$db->result_first("select count(*) from {$tpf}users ");
		$stats['users_locked_count'] = (int)@$db->result_first("select count(*) from {$tpf}users where is_locked=1");
		$stats['extract_code_count'] = (int)@$db->result_first("select count(*) from {$tpf}extracts");
		$stats['all_files_count'] = (int)@$db->result_first("select count(*) from {$tpf}files");
		$storage_count_tmp = (float)@$db->result_first("select sum(file_size) from {$tpf}files where is_public=0");
		$public_storage_count_tmp = (float)@$db->result_first("select sum(file_size) from {$tpf}files where is_public=1");
		$stats['user_storage_count'] = get_size($storage_count_tmp);
		$stats['public_storage_count'] = get_size($public_storage_count_tmp);
		$stats['total_storage_count'] = get_size($storage_count_tmp+$public_storage_count_tmp);
		$stats['stat_time'] = $timestamp;
		
		stats_cache($stats);
	}

	require_once template_echo($item,$user_tpl_dir);
}else{	
	if($item =='folders' && $action !='index'){
		$inner_box = true;
	}
	if($item == 'upload'){
		$inner_box = true;
	}
	if($item == 'files' && in_array($action,array('file_modify','file_delete','view_extract_file','unshare_file','short_url'))){
		$inner_box = true;
	}
	if($item =='share'){
		$inner_box = true;
	}
	if($item =='recycle' && in_array($action,array('show_files','folder_delete_complete','file_delete_complete','folder_restore','file_restore'))){
		$inner_box = true;
	}
	if($item =='public' && in_array($action, array('file_modify','file_delete'))){
		$inner_box = true;
	}
	if($item =='message' && in_array($action,array('sendmsg','view','reply'))){
		$inner_box = true;
	}
	if($item =='buddy' && in_array($action,array('addbuddy','delbuddy','s_addbuddy'))){
		$inner_box = true;
	}
	
	require_once template_echo('my_header',$user_tpl_dir);
	
	$items = array('files','folders','upload','profile','main','recycle','share','stats','public','message','buddy','disk');
	if(in_array($item,$items)){
		require_once PHPDISK_ROOT."modules/".$item.".inc.php";
	}else{
		echo "Error operation, system halt!";
	}	
	$site_stat = $settings['site_stat'] ? '&nbsp;'.html_entity_decode($settings['site_stat']) : '';
	$debug_info = $settings['debug_info'] ? '' : 'none';
	
	$pageinfo = page_end_time();	
	
	require_once template_echo('my_footer',$user_tpl_dir);
}

include PHPDISK_ROOT."./includes/footer.inc.php";

?>


