<?php 
##
#	Project: PHPDisk Personal Edition
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: index.php 269 2010-01-12 15:03:13Z along $
#
#	Copyright (C) 2008-2010 PHPDisk Team. All Rights Reserved.
#
##

include "includes/commons.inc.php";

$in_front = true;

require_once lang('index');

$lang = array_merge($pub_lang,$lang);
$title = $settings['site_title'];
include PHPDISK_ROOT."./includes/header.inc.php";
$q = $db->query("select * from {$tpf}announces where is_hidden=0 order by show_order asc,annid desc");
$announces = array();
while($rs = $db->fetch_array($q)){
	$announces[] = $rs;
}
$db->free($q);
unset($rs);
$last = $db->fetch_one_array("select userid,username from {$tpf}users order by userid desc limit 1 ");
$last['username_all'] = $last['username'];
$last['username'] = cutstr($last['username'],18);
$a_last_user = urr("space","uid={$last['userid']}");
$q = $db->query("select * from {$tpf}links where is_hidden=0 order by logo desc,show_order asc,linkid desc");
$links = array();
while($rs = $db->fetch_array($q)){
	$rs['has_logo'] = $rs['logo'] ? 1 : 0;
	$links[] = $rs;
}
$db->free($q);
unset($rs);
$q = $db->query("select file_id,file_key,file_name,file_extension from {$tpf}files where (is_public=1 or in_share=1) and in_recycle=0 and report_status=0 and is_checked=1 and userid>0 order by file_id desc limit 10");
$last_file = array();
while($rs = $db->fetch_array($q)){
	$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
	$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,25);
	$rs['a_viewfile'] = urr("viewfile","file_id={$rs['file_id']}&file_key={$rs['file_key']}");
	$last_file[] = $rs;
}
$db->free($q);
unset($rs);
$q = $db->query("select file_id,file_key,file_name,file_extension from {$tpf}files where (is_public=1 or in_share=1) and in_recycle=0 and report_status=0 and is_checked=1 and userid>0 order by file_views desc limit 10");
$hot_file = array();
while($rs = $db->fetch_array($q)){
	$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
	$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,25);
	$rs['a_viewfile'] = urr("viewfile","file_id={$rs['file_id']}&file_key={$rs['file_key']}");
	$hot_file[] = $rs;
}
$db->free($q);
unset($rs);

$q = $db->query("select * from {$tpf}tags where is_hidden=0 and tag_count>0 order by tag_count desc,tag_id desc limit 30");
$hot_tags = array();
while($rs = $db->fetch_array($q)){
	$rs['a_view_tag'] = urr("tag","tag=".rawurlencode($rs['tag_name'])."");
	$rs['tag_count'] = $rs['tag_count'] ? "({$rs['tag_count']})" : '';
	$hot_tags[] = $rs;
}
$db->free($q);
unset($rs);

$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){
	
	$rs = $db->fetch_one_array("select count(*) as folder_total from {$tpf}folders");
	$stats['user_folders_count'] = (int)$rs['folder_total'];
	
	$rs = $db->fetch_one_array("select count(*) as file_total from {$tpf}files where is_public=0");
	$stats['user_files_count'] = (int)$rs['file_total'];
	
	$rs = $db->fetch_one_array("select count(*) as users_count from {$tpf}users ");
	$stats['users_count'] = $rs['users_count'];
	
	$rs = $db->fetch_one_array("select count(*) as users_locked_count from {$tpf}users where is_locked=1");
	$stats['users_locked_count'] = $rs['users_locked_count'];
	
	$rs = $db->fetch_one_array("select count(*) as extract_code_count from {$tpf}extracts");
	$stats['extract_code_count'] = (int)$rs['extract_code_count'];
	
	$rs = $db->fetch_one_array("select count(*) as total from {$tpf}files");
	$stats['all_files_count'] = (int)$rs['total'];
	
	$rs = $db->fetch_one_array("select sum(file_size) as total from {$tpf}files where is_public=0");
	$storage_count_tmp = $rs['total'];
	
	$rs = $db->fetch_one_array("select sum(file_size) as total from {$tpf}files where is_public=1");
	$public_storage_count_tmp = $rs['total'];
	
	$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;
	
	foreach($stats as $k => $v){
		$sqls .= "('$k','".$db->escape(trim($v))."'),";
	}
	$sqls = substr($sqls,0,-1);
	$db->query("replace into {$tpf}stats (vars,value) values $sqls;");
	
	write_cache('stats');
}
unset($rs);

require_once template_echo('pd_index',TPL_NAME);

include PHPDISK_ROOT."./includes/footer.inc.php";

?>