<?php
/**
 * @version 1.0
 * @author [飄在北京] <week9@263.net>
 * @write 2003-03-29
 * 社區虛擬形象系統
 * 版權所有: 飄在北京
 * http://www.week9.com
 */

define('IN_PHPBB', 1);
$phpbb_root_path = "./";
require($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
require($phpbb_root_path."includes/functions_face.php");
$userdata = session_pagestart($user_ip, PAGE_FACE);
init_userprefs($userdata);

if ( !$userdata['session_logged_in'] )
{
	$redirect = ( isset($post_id) ) ? POST_POST_URL . "=$post_id" : POST_TOPIC_URL . "=$topic_id";
	$redirect .= ( isset($start) ) ? "&start=$start" : '';
	redirect(append_sid("login.$phpEx?redirect=viewtopic.$phpEx&$redirect", true));
}
if(!isset($_GET[action]) && !isset($_POST[action]))
{
	$action="showroom";
}


if ($action=="showroom") {

//	$link = "<normalfont><a href=\"index.php?s=$session[sessionhash]\">$bbtitle</a> &gt; <a href=face.php>形象設計中心</a>  &gt;拍賣場交易大廳 </normalfont>";		

	//現實保存照片開始
	$facedatas = $db->sql_query("SELECT * FROM week9_ershou order by selldata DESC");
	$break = 1;
	while ($facedata=$db->sql_fetchrow($facedatas))
	{
		
		$result = $db->sql_query("SELECT sp_name FROM week9_data WHERE sort = '$facedata[classid]' and sp_graphic = '$facedata[facepicid].gif'");
		$spname = $db->sql_fetchrow($result);
		$buydate = create_date($board_config['default_dateformat'], $facedata[buydata], $board_config['board_timezone']);
//		$buydate =  vbdate("Y-m-d H:i:s",$facedata[buydata]);
//		$buytime =  vbdate("Y-m-d H:i:s",$facedata[selldata]);
		$face_weardate = floor((time() - $facedata[selldata])/86400);
		$pic = "<img style=\"CURSOR: hand\" alt=\"購買日期：$buydate&#13;&#10;上架天數：$face_weardate 天\" src = images/face/".$facedata[classid]."/".$facedata[facepicid]."x.gif height=84 border=0\">";
		if($facedata[face_fitherd] == 'm')
		{
			$face_fitherd = "帥哥";
		}
		elseif($facedata[face_fitherd] == 'f')
		{
			$face_fitherd = "美女";
		}
		else
		{
			$face_fitherd = "全部";
		}
		//剩餘天數
		//$face_weardate = floor((time() - $facedata[selldata])/86400);
		if ($face_weardate > 7)
		{
			$pic = $facedata[facepicid].".gif";
			$db->sql_query("delete from week9_ershou where userid = '$facedata[userid]' and classid = '$facedata[classid]' and facepicid = '$facedata[facepicid]' LIMIT 1");
	        $db->sql_query("UPDATE week9_data SET sp_number=sp_number+1 WHERE sp_graphic = '$pic' and sort = '$facedata[classid]'"); 

		}
		eval('$yifu1 .= "' . gettemplate('face_ershouyifu') . '";');	
		if ($break%4 == 0)
		{
			$huanhang = "</td></tr><tr><td>";
		}
		else
		{
			$huanhang = "";
		}
		$break++;
		$yifu1 = $yifu1.$huanhang;
	}
	$db->sql_freeresult($facedatas);

	//eval("\$center = \"".gettemplate('face_data_center')."\";");
//    eval("\$center = \"".gettemplate('face_faceershouallcenter')."\";");

//	eval("dooutput(\"".gettemplate('face_facealbum_home')."\");");
	//結束	
//##### phpbb templates #######

	$template->set_filenames(array( 'body' => 'face_album.tpl'));
	$template->assign_vars(array(
		'LEFT' => $left,
		'CENTER' => $yifu1,
		'SITENAME'=>$board_config['sitename']
	));
	//
	// Start output of page
	//
	include($phpbb_root_path . 'includes/page_header.' . $phpEx);

	//
	// Generate the page
	//
	$template->pparse('body');

	include($phpbb_root_path . 'includes/page_tail.' . $phpEx);

}

/////////////////////添加二手商品
if ($_GET[action] == "addsp")
{
	$faceclass = $_REQUEST[classid];
    $faceid = trim($_REQUEST[id]); 
/*	
	$userbank = $result = $db->sql_query("
		SELECT user_bank as bank,user_money as money,user_gender as gender FROM xoops_users WHERE user_id=$userdata[uid]"); 
	$userbankmoney = $userbank[bank];
	$usernm = $userdata[uname];
	$usermoney = $userbank[money];
	$allmoney = $userbank[bank]+$userbank[money];
	//$userlevel = $bbuserinfo[usertitle];
	$gender = $userbank[gender];
*/
	$userbankmoney = $userdata[user_bank];
	$usernm = $userdata[uname];
	$usermoney = $userdata[user_money];
	$allmoney = $userdata[user_money]+$userdata[user_bank];
	$gender = $userdata[user_gender];
	if ($gender == 1)
	{
		$sex = "m";
		$usergender = "帥哥";
		$tempequip = '0-0-0-0-0-0-0-0-init-init-0-init-0-init-init-0-0-0-init-0-0-0-0-0-0-0';	
	}
	elseif($gender == 2)
	{
		$usergender = "美女";
		$tempequip = '0-0-0-0-0-0-0-0-initf-initf-0-initf-0-initf-initf-0-0-0-initf-0-0-0-0-0-0-0'; 
		$sex = "f";		
	}
	else
	{
		message_die(GENERAL_MESSAGE,"你還沒有選擇性別，本功能需要用戶選擇性別，如果你要使用本功能，請你返回修改你的論壇性別！ <a href=".getenv("HTTP_REFERER")." class=nav>返回舊衣服</a>");
	}
	$facecookie1 = $db->sql_query("SELECT * FROM week9_userdata where userid = $userdata[uid]  and dafaultuse = '1'");
	while ($usercaifu1 = $db->sql_fetchrow($facecookie1))
	{
		if (($usercaifu1[face_fitherd] != $sex) and ($usercaifu1[face_fitherd] != 't'))
		{
			$db->sql_query("UPDATE week9_userdata SET 
										  dafaultuse = '0'
								where userid = $userdata[uid] and classid = '$usercaifu1[classid]' and facepicid = '$usercaifu1[facepicid]' 
								 ");
		}				
	}
	$db->sql_freeresult($facecookie1);
	$facecookie = $db->sql_query("SELECT * FROM week9_userdata where userid = $userdata[uid]  and dafaultuse = '1'");		
	$break = 1;
	while ($usercaifu = $db->sql_fetchrow($facecookie))
	{
		$cookiearray = split('-', $tempequip);		
		$tempequip = "0";
		if ($cookiearray[6] != '0')
		{
			$cookiearray[8] = '0';
			$cookiearray[9] = '0';
		}
		for ($i=1; $i<26; $i++)
		{
			if($i != $usercaifu[classid])
			{
				$temp = $cookiearray[$i];
				$tempequip .= "-".$temp."";
			}
			else
			{
				$tempequip .= "-".$usercaifu[facepicid]."";
			}
		}
		$rtempequip = $tempequip;			
	}
	$db->sql_freeresult($facecookie);
	$userfacecookie = $rtempequip;
	setcookie("tempequip", "$tempequip");
	eval("\$left = \"".gettemplate('face_left')."\";");	
	eval("\$center = \"".gettemplate('face_ershouenter')."\";");
//##### phpbb templates #######
	$banklocation = ' -> <a href="'.append_sid("face.".$phpEx).'" class="nav">'.$lang['Face'].'</a>'.' -> <a href="'.append_sid("faceershou.".$phpEx).'" class="nav">拍賣場</a>';
	$template->set_filenames(array( 'body' => 'face_body.tpl'));
	$template->assign_vars(array(
		'BANKLOCATION' => $banklocation,
		'LEFT' => $left,
		'CENTER' => $center,
		'SITENAME'=>$board_config['sitename']
	));
	//
	// Start output of page
	//
	include($phpbb_root_path . 'includes/page_header.' . $phpEx);

	//
	// Generate the page
	//
	$template->pparse('body');

	include($phpbb_root_path . 'includes/page_tail.' . $phpEx);
}

?>
