<?php

/****************************************/
// ИНФОРМАЦИЯ:
// ==== Форум: LogicBoard
// ==== Автор: Никита Курдин (ShapeShifter)
// ==== Copyright © Никита Курдин Игоревич 2011
// ==== Данный код защищен авторскими правами
// ==== Официальный сайт: http://logicboard.ru

/****************************************/

if (! defined ( 'LogicBoard' ))
{
	@include '../../logs/save_log.php';
	exit ( "Error, wrong way to file.<br><a href=\"/\">Go to main</a>." );
}

$lang_g_statistic = language_forum ("board/global/statistic");

$tpl->load_template( 'statistic.tpl' );

if (!$cache_group[$member_id['user_group']]['g_show_online'])
{
    $tpl->tags_blocks("group_online", false);
}
elseif (!$cache_config['online_status']['conf_value'])
{
    $tpl->tags_blocks("group_online", false);
}
else
{
    $tpl->tags_blocks("group_online");
}

if($do == "board" AND $op == "forum")
{
    if ($cache_group[$member_id['user_group']]['g_show_online'] AND $cache_config['online_status']['conf_value'])
        $online = online_members("all", "board", "forum", $id);
        
    $tpl->tags( '{online_title}', $lang_g_statistic['this_forum'] );
    $tpl->tags_blocks("topics");
    $tpl->tags_blocks("birthday", false);
    $tpl->tags_blocks("stats", false);
    $tpl->tags_blocks("posts", false);
}
elseif($do == "board" AND ($op == "topic" OR $op == "reply"))
{
    if ($cache_group[$member_id['user_group']]['g_show_online'] AND $cache_config['online_status']['conf_value'])
        $online = online_members("all", "board", $op, $id);
    
    $tpl->tags_blocks("topics", false);
    $tpl->tags_blocks("birthday", false);
    $tpl->tags_blocks("stats", false);
    $tpl->tags_blocks("posts");
    
    $tpl->tags( '{online_title}', $lang_g_statistic['this_topic'] );
}
else
{
    if ($cache_group[$member_id['user_group']]['g_show_online'] AND $cache_config['online_status']['conf_value'])
        $online = online_members();
    
    $tpl->tags( '{online_title}', $lang_g_statistic['forum'] );
    $online_max = $cache->take("online_max", "", "statistics");
    $online_max = explode("|", $online_max);
    list($online_max, $online_max_date) = $online_max;
    $tpl->tags( '{online_max}', intval($online_max) );
    $tpl->tags( '{online_max_date}', formatdate($online_max_date) );

    if (count($cache_birthday))
    {
        $tpl->tags_blocks("birthday");
        $tpl->tags( '{birthday_all}', count($cache_birthday) );
        $birthday_list = "";
        foreach($cache_birthday as $today)
        {
            $date_now_year = date("Y", $time);
            $date_now_day = date("d", $time); 
            $date_now_month = date("m", $time);

            $age_user_day = $today['lb_b_day'] - $date_now_day;
            $age_user_month = $today['lb_b_month'] - $date_now_month;

            if (($age_user_month < 0 AND $age_user_day < 0) OR ($age_user_month < 0 AND $age_user_day >= 0))
                $age_user = $date_now_year - $today['lb_b_year'];
            elseif (($age_user_month == 0 AND $age_user_day < 0) OR ($age_user_day == 0 AND $age_user_month == 0))
                $age_user = $date_now_year - $today['lb_b_year'];
            else
                $age_user = $date_now_year - 1 - $today['lb_b_year'];
            
            if (!$birthday_list)
                $birthday_list = "<li><a href=\"".profile_link($today['name'], $today['user_id'])."\" onclick=\"ProfileInfo(this, '".$today['user_id']."');return false;\">".$today['name']." (".$age_user.")</a></li>";
            else
                $birthday_list .= "<li>, <a href=\"".profile_link($today['name'], $today['user_id'])."\" onclick=\"ProfileInfo(this, '".$today['user_id']."');return false;\">".$today['name']." (".$age_user.")</a></li>";
        }
        $tpl->tags( '{birthday_list}', $birthday_list );
    }
    else
        $tpl->tags_blocks("birthday", false);
        
    $tpl->tags_blocks("stats");
    
    $stat_post = 0;
    foreach ($cache_forums as $num_posts)
    {
        $stat_post += $num_posts['posts'];
        $stat_post += $num_posts['topics'];
    }
    
    $tpl->tags( '{stat_post}', $stat_post );
    $tpl->tags( '{stat_users}', intval($cache_stats_users['users']) );
    $tpl->tags( '{stat_new_member}', $cache_stats_users['last_name'] );
    $tpl->tags( '{stat_new_member_link}', profile_link($cache_stats_users['last_name'], $cache_stats_users['last_id']) );
    
    $tpl->tags_blocks("topics", false);
    $tpl->tags_blocks("posts", false);
}

if ($cache_group[$member_id['user_group']]['g_show_online'])
{
    list($onl_g, $onl_u, $onl_a, $onl_h, $list) = $online;  
    $tpl->tags( '{online_members}', $list );
    $tpl->tags( '{online_i_u}', $onl_u );
    $tpl->tags( '{online_i_g}', $onl_g );
    $tpl->tags( '{online_i_a}', $onl_a );
    $tpl->tags( '{online_i_h}', $onl_h );
}
$tpl->tags( '{online_limit}', intval($cache_config['online_time']['conf_value']) );
     
$tpl->compile( 'statistic' );
$tpl->clear();

?>