#####################################################
## Mod for Obschiy razmer vseh razdach i zakachek  ##
## ReCoded (c) 2008, Pandora                       ##
#####################################################

########################
##   Open index.php   ##
##   and Search       ##
########################

print_page('index.tpl');

#####################
##    Before add   ##
#####################

//up_down total
$sql = "SELECT ROUND(SUM(u_up_total+u_down_total))  AS pumped, ROUND(SUM(u_up_total)) AS upl, ROUND(SUM(u_down_total)) AS donl
        FROM " . BT_USERS_TABLE . "   " ;
  if (!$result = $db->sql_query($sql))  {    message_die(GENERAL_ERROR, 'Could not query ', '', __LINE__, __FILE__, $sql);  }

  $row = $db->sql_fetchrow($result);

    $ud_all    =  $row['pumped']   ;
    $up   =  $row['upl'] ;
    $dn   =  $row['donl']  ;

  $template->assign_vars( array(

             'UD_ALL' => ($ud_all) ? humn_size($ud_all) : 0 ,
             'UPL'    => ($up) ? humn_size($up) : 0    ,
             'DNL'    => ($dn) ? humn_size($dn) : 0

  ));
//up_down total end

//active seeders begin
$sql = 'SELECT COUNT(DISTINCT user_id) AS st   FROM '. BT_TRACKER_TABLE .'   WHERE seeder = 1      ';
   if (!$result = $db->sql_query($sql))    {    message_die(GENERAL_ERROR, 'Could not query ', '', __LINE__, __FILE__, $sql);    }
      $row = $db->sql_fetchrow($result);
        $cur_seed  =  $row['st']    ;
        $template->assign_vars( array(
             'ST' => $cur_seed   ));
//active seeders end

//active leechers begin
$sql = 'SELECT COUNT(DISTINCT user_id) AS lt  FROM '. BT_TRACKER_TABLE .'   WHERE seeder = 0     ';
   if (!$result = $db->sql_query($sql))    {    message_die(GENERAL_ERROR, 'Could not query ', '', __LINE__, __FILE__, $sql);    }
      $row = $db->sql_fetchrow($result);
        $cur_leech  =  $row['lt']    ;
        $template->assign_vars( array(
             'LT' => $cur_leech   ));
//active leechers end

//active torrents begin
$sql = 'SELECT COUNT(DISTINCT tor.topic_id) AS tt , SUM(tor.size) AS ts
        FROM '. BT_TRACKER_TABLE .'  tr , '. BT_TORRENTS_TABLE .' tor
        WHERE tr.topic_id = tor.topic_id
         ';
  if (!$result = $db->sql_query($sql))    {    message_die(GENERAL_ERROR, 'Could not query ', '', __LINE__, __FILE__, $sql);    }
      $row = $db->sql_fetchrow($result);
        $cur_tor  =  $row['tt']    ;
        $cur_ts   =  $row['ts']    ;
        $template->assign_vars( array(
             'TT' => $cur_tor ,
             'TS' => humn_size($cur_ts)
              ));
//active torrents end

//all torrents begin
$sql = ' SELECT COUNT(*) as tn, SUM(size) AS tos
         FROM '.BT_TORRENTS_TABLE .'' ;
   if (!$result = $db->sql_query($sql))    {    message_die(GENERAL_ERROR, 'Could not query ', '', __LINE__, __FILE__, $sql);    }
      $row = $db->sql_fetchrow($result);
        $tn = $row['tn'];
        $tos = $row['tos'];
        $template->assign_vars( array(
           'TN' => $tn        ,
           'TOS' => humn_size($tos)
           ));
//all torrents end

################################
##  Save and close  index.php ##
################################


#########################################
##  Open templates/default/index.tpl   ##
#########################################

#################
##   Search    ##
#################
		<td class="row1 f_icon"><img class="forum_icon" src="{IMG}whosonline.gif" alt="" /></td>
		<td class="row1 small last_td">
			<p>{TOTAL_POSTS}</p>
			<p>{TOTAL_USERS}</p>
			<p>{NEWEST_USER}</p>

####################
##   After add    ##
####################

         <div class="hr1" style="margin: 5px 0 4px;"></div>
         <b>Статистика по трекеру:</b><br/>
         <span class="seedmed">Раздающих (seeders):&nbsp<b>{ST}</b>&nbsp&nbsp</span> <span class="leechmed">Качающих (leechers):&nbsp<b>{LT}</b></span><br/>
         <span class="genmed">Количество активных торрентов (где есть seeder или leecher):<b> {TT} [{TS}]</b></span></span><br/>
         <div class="hr1" style="margin: 5px 0 4px;"></div>
         Через трекер скачано: &nbsp <span class="leechmed"><b> {DNL}</b></span><br/>
         Через трекер отдано: &nbsp <span class="seedmed"><b>&nbsp {UPL}</b></span><br/>
         Суммарно прошло через трекер: <span class="genmed"><b>{UD_ALL}</b></span><br/>
         На трекере зарегистрировано <b>{TN}</b> торрента(ов), общим объемом <b>{TOS}</b></span><br/>


#####################################################
##  Save and close  templates/theme/index_body.tpl ##
#####################################################