<?php

	$tpl = new template;
	$tpl -> Load("!theme/{$GLOBALS["THEME"]}/templates/home.tpl");
	$tpl -> GetObjects();

	
/*
		Generate the "genders" form field options
	*/
	$genders = explode(",", $CONF["USERS_GENDERS"]);
	
	$i=0;
	foreach ($genders as $genderType) {
		$genderReplacementArray[$i]["gender.option"] = $genderType;
		$i++;
	}
	$tpl -> Loop("genderOptionDropdown", $genderReplacementArray);

		/*
			Latest Member
		*/
		$LatestmemberSelect = myQ("
			SELECT `username`,`country`,`age`,`id`,`mainpicture`,`gender`
			FROM `[x]users`
                        WHERE `mainpicture` != ''
                        AND `gender` != ''
			ORDER BY `id` DESC
			LIMIT 20
			
		");
			
		
		$i=0;
		while ($LatestmemberRow = myF($LatestmemberSelect)) {
			$LatestmemberReplacementArray[$i]["member.nick"] = $LatestmemberRow["username"];
			$LatestmemberReplacementArray[$i]["member.id"] = $LatestmemberRow["id"];
			$LatestmemberReplacementArray[$i]["member.country"] = $LatestmemberRow["country"];
			$LatestmemberReplacementArray[$i]["member.age"] = $LatestmemberRow["age"];
			$LatestmemberReplacementArray[$i]["member.pic"] = $LatestmemberRow["mainpicture"];
                        $LatestmemberReplacementArray[$i]["member.gender"] = $LatestmemberRow["gender"];
			
			$i++;
			}
			
			$tpl -> Zone("Latestmember", "enabled");
			$tpl -> Loop("LatestmemberLoop", $LatestmemberReplacementArray);		

	/*
			Latest Member of female
		*/
		$LatestfemalememberSelect = myQ("
			SELECT `username`,`country`,`age`,`id`,`mainpicture`,`gender`
			FROM `[x]users`
                        WHERE `mainpicture` != ''
                        AND `gender` != '先生'
			ORDER BY `id` DESC
			LIMIT 9
			
		");
			
		
		$i=0;
		while ($LatestfemalememberRow = myF($LatestfemalememberSelect)) {
			$LatestfemalememberReplacementArray[$i]["member.nick"] = $LatestfemalememberRow["username"];
			$LatestfemalememberReplacementArray[$i]["member.id"] = $LatestfemalememberRow["id"];
			$LatestfemalememberReplacementArray[$i]["member.country"] = $LatestfemalememberRow["country"];
			$LatestfemalememberReplacementArray[$i]["member.age"] = $LatestfemalememberRow["age"];
			$LatestfemalememberReplacementArray[$i]["member.pic"] = $LatestfemalememberRow["mainpicture"];
                        $LatestfemalememberReplacementArray[$i]["member.gender"] = $LatestfemalememberRow["gender"];
			
			$i++;
			}
			
			$tpl -> Zone("Latestfemalemember", "enabled");
			$tpl -> Loop("LatestfemalememberLoop", $LatestfemalememberReplacementArray);	
	
	/*
			Latest Member of male
		*/
		$LatestmalememberSelect = myQ("
			SELECT `username`,`country`,`age`,`id`,`mainpicture`,`gender`
			FROM `[x]users`
                        WHERE `mainpicture` != ''
                        AND `gender` != '女士'
			ORDER BY `id` DESC
			LIMIT 9
			
		");
			
		
		$i=0;
		while ($LatestmalememberRow = myF($LatestmalememberSelect)) {
			$LatestmalememberReplacementArray[$i]["member.nick"] = $LatestmalememberRow["username"];
			$LatestmalememberReplacementArray[$i]["member.id"] = $LatestmalememberRow["id"];
			$LatestmalememberReplacementArray[$i]["member.country"] = $LatestmalememberRow["country"];
			$LatestmalememberReplacementArray[$i]["member.age"] = $LatestmalememberRow["age"];
			$LatestmalememberReplacementArray[$i]["member.pic"] = $LatestmalememberRow["mainpicture"];
                        $LatestmalememberReplacementArray[$i]["member.gender"] = $LatestmalememberRow["gender"];
			
			$i++;
			}
			
			$tpl -> Zone("Latestmalemember", "enabled");
			$tpl -> Loop("LatestmalememberLoop", $LatestmalememberReplacementArray);	
	
	/*
			Latest Member of female(friendster)
		*/
		$Latestfemalemember1Select = myQ("
			SELECT `username`,`country`,`age`,`id`,`mainpicture`,`gender`
			FROM `[x]users`
                        WHERE `mainpicture` != ''
                        AND `gender` != '先生'
			ORDER BY `id` DESC
			LIMIT 8
			
		");
			
		
		$i=0;
		while ($Latestfemalemember1Row = myF($Latestfemalemember1Select)) {
			$Latestfemalemember1ReplacementArray[$i]["member.nick"] = $Latestfemalemember1Row["username"];
			$Latestfemalemember1ReplacementArray[$i]["member.id"] = $Latestfemalemember1Row["id"];
			$Latestfemalemember1ReplacementArray[$i]["member.country"] = $Latestfemalemember1Row["country"];
			$Latestfemalemember1ReplacementArray[$i]["member.age"] = $Latestfemalemember1Row["age"];
			$Latestfemalemember1ReplacementArray[$i]["member.pic"] = $Latestfemalemember1Row["mainpicture"];
                        $Latestfemalemember1ReplacementArray[$i]["member.gender"] = $Latestfemalemember1Row["gender"];
			
			$i++;
			}
			
			$tpl -> Zone("Latestfemalemember1", "enabled");
			$tpl -> Loop("Latestfemalemember1Loop", $Latestfemalemember1ReplacementArray);	
	
	/*
			Latest Member of male(friendster)
		*/
		$Latestmalemember1Select = myQ("
			SELECT `username`,`country`,`age`,`id`,`mainpicture`,`gender`
			FROM `[x]users`
                        WHERE `mainpicture` != ''
                        AND `gender` != '女士'
			ORDER BY `id` DESC
			LIMIT 8
			
		");
			
		
		$i=0;
		while ($Latestmalemember1Row = myF($Latestmalemember1Select)) {
			$Latestmalemember1ReplacementArray[$i]["member.nick"] = $Latestmalemember1Row["username"];
			$Latestmalemember1ReplacementArray[$i]["member.id"] = $Latestmalemember1Row["id"];
			$Latestmalemember1ReplacementArray[$i]["member.country"] = $Latestmalemember1Row["country"];
			$Latestmalemember1ReplacementArray[$i]["member.age"] = $Latestmalemember1Row["age"];
			$Latestmalemember1ReplacementArray[$i]["member.pic"] = $Latestmalemember1Row["mainpicture"];
                        $Latestmalemember1ReplacementArray[$i]["member.gender"] = $Latestmalemember1Row["gender"];
			
			$i++;
			}
			
			$tpl -> Zone("Latestmalemember1", "enabled");
			$tpl -> Loop("Latestmalemember1Loop", $Latestmalemember1ReplacementArray);	
			//LASTED BLOGS--start//
		
			/*
		Let's get the last 50 blogs and show them
	*/
	$select = myQ("SELECT * FROM `[x]blogs` ORDER BY `date` DESC LIMIT 5");
	
	/*
		... and loop inside those results, creating
		the replacement array
	*/
	$i=0;

	$blogArticle = false;

	if(myNum($select) > 0){

	while ($row = myF($select)) {

		$blogArticle[$i]["blog.title"] = $row["title"];
		$blogArticle[$i]["blog.body"] = _fnc("strtrim", _fnc("clearBodyCodes", html_entity_decode($row["body"])), 100);
		$blogArticle[$i]["blog.id"] = $row["id"];
		$blogArticle[$i]["blog.userid"] = $row["user"];
		$blogArticle[$i]["blog.date"] = date($CONF["LOCALE_SHORT_DATE_TIME"], $row["date"]);
		$blogArticle[$i]["blog.views"] = $row["views"];
		$blogArticle[$i]["blog.comments"] = $row["comments"];
		$blogArticle[$i]["blog.mainpicture"] = _fnc("user", $row["user"], "mainpicture");
		$blogArticle[$i]["blog.username"] = _fnc("user", $row["user"], "username");
	
		$i++;
	}
	
	/*
		Pass the replacement array to the template 
		engine
	*/
	if (isset($blogArticle)) {

		$tpl->Zone("blogArticles","enabled");

		$tpl->Loop("blogArticles", $blogArticle);

		}

}
     //LASTED BLOGS--end//
	/*
			Login.failMessage
		*/
	if (isset($GLOBALS["LOGIN_FAIL_TYPE"])) {
		if ($GLOBALS[" LOGIN_FAIL_TYPE"] == "e.password") $loginError = $GLOBALS["OBJ"]["loginError.password"];
		elseif ($GLOBALS["LOGIN_FAIL_TYPE"] == "e.user") $loginError = $GLOBALS["OBJ"]["loginError.username"];
		elseif ($GLOBALS["LOGIN_FAIL_TYPE"] == "e.bruteforce") $loginError = $GLOBALS["OBJ"]["loginError.bruteforce"];
		elseif ($GLOBALS["LOGIN_FAIL_TYPE"] == "e.active") $loginError = $GLOBALS["OBJ"]["loginError.active"];
	}
	
	$tpl -> AssignArray(array(
		"login.failMessage" => (isset($loginError)?$loginError:NULL)
	));
	
	$tpl -> Flush();

?>