<?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 4 2011-05-28 02:40: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');
// fix firefox
if($item =='upload'){
	$uid = (int)gpc('uid','GP',0);
	$pd_is_activated = @$db->result_first("select is_activated from {$tpf}users where userid='$uid'");
}
if($settings['user_active'] && $pd_is_activated<>1){
	echo '<script>alert("'.$L['account_not_actived'].'");document.location="./";</script>';
	exit;
}
if(empty($item) || $item == ''){
	require_once template_echo("mydisk",$user_tpl_dir);
	exit();
}
$op = trim(gpc('op','G',''));

if($item == "menu"){

	if($op =='file'){

		$folder_list = super_cache('file','folders_menu_cache',1,0,$pd_uid);
		
	}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'){

		$public_folder_tree = super_cache('folder','public_menu_cache|0',1,0);

		$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>' : '';
	}

	function mydisk_stat(){
		global $db,$tpf,$timestamp;
		$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);
	}
	super_cache('stat','mydisk_stat',1,0);

	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";

?>


