<?php
define('_VALID', true);
require 'include/config.php';
require 'include/function_global.php';
require 'include/function_smarty.php';

$sql            = "SELECT UID, username, photo, gender FROM signup WHERE account_status = 'Active'
                   ORDER BY popularity DESC LIMIT 6";
$rs             = $conn->execute($sql);
$popular_users  = $rs->getrows();

$sql            = "SELECT UID, username, photo, gender FROM signup WHERE account_status = 'Active' AND gender = 'Male'
                   ORDER BY addtime DESC LIMIT 6";
$rs             = $conn->execute($sql);
$male_users     = $rs->getrows();

$sql            = "SELECT UID, username, photo, gender FROM signup WHERE account_status = 'Active' AND gender = 'Female'
                   ORDER BY addtime DESC LIMIT 6";
$rs             = $conn->execute($sql);
$female_users   = $rs->getrows();

$sql            = "SELECT s.UID, s.username, s.photo, s.gender FROM signup AS s, users_online AS u
                   WHERE s.account_status = 'Active' AND u.online > " .(time()-300). "
                   AND s.gender = 'Male' AND s.UID = u.UID
                   ORDER BY s.addtime DESC LIMIT 6";
$rs             = $conn->execute($sql);
$online_m_users = $rs->getrows();

$sql            = "SELECT s.UID, s.username, s.photo, s.gender FROM signup AS s, users_online AS u
                   WHERE s.account_status = 'Active' AND u.online > " .(time()-300). "
                   AND s.gender = 'Female' AND s.UID = u.UID
                   ORDER BY s.addtime DESC LIMIT 6";
$rs             = $conn->execute($sql);
$online_f_users = $rs->getrows();

$sql            = "SELECT a.*, s.username FROM albums AS a, signup AS s WHERE a.status = '1' AND a.UID = s.UID
                   ORDER BY a.addtime DESC LIMIT 5";
$rs             = $conn->execute($sql);
$albums         = $rs->getrows();

$sql            = "SELECT VID, title, duration, viewnumber, rate, addtime, type, thumb FROM video 
                   WHERE type = 'private' AND active = '1' ORDER BY addtime DESC LIMIT 5";
$rs             = $conn->execute($sql);
$videos         = $rs->getrows();

$smarty->assign('errors',$errors);
$smarty->assign('messages',$messages);
$smarty->assign('menu', 'community');
$smarty->assign('community', true);
$smarty->assign('male_users', $male_users);
$smarty->assign('total_musers', count($male_users));
$smarty->assign('female_users', $female_users);
$smarty->assign('total_fusers', count($female_users));
$smarty->assign('online_male_users', $online_m_users);
$smarty->assign('total_omusers', count($online_m_users));
$smarty->assign('online_female_users', $online_f_users);
$smarty->assign('total_ofusers', count($online_f_users));
$smarty->assign('popular_users', $popular_users);
$smarty->assign('total_pusers', count($popular_users));
$smarty->assign('albums', $albums);
$smarty->assign('videos', $videos);
$smarty->assign('self_title', $seo['community_title']);
$smarty->assign('self_description', $seo['community_desc']);
$smarty->assign('self_keywords', $seo['community_keywords']);
$smarty->display('header.tpl');
$smarty->display('errors.tpl');
$smarty->display('messages.tpl');
$smarty->display('community.tpl');
$smarty->display('footer.tpl');
$smarty->gzip_encode();
?>
