<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

if ($_SESSION['USERID'] != "" && $_SESSION['USERID'] >= 0 && is_numeric($_SESSION['USERID']))
{
	$UID = intval(cleanit($_SESSION['USERID']));	
	if($_REQUEST['change']!="")
	{
		$firstname = cleanit($_REQUEST['firstname']);
		$lastname = cleanit($_REQUEST['lastname']);
		$description = cleanit($_REQUEST['description']);
		$url = cleanit($_REQUEST['url']);
		$city = cleanit($_REQUEST['city']);
		
		$moresql = "";
		if (is_numeric($_REQUEST['gender']))
		{
			if ($_REQUEST['gender'] == "0")
			{
				$moresql .= ", gender='0'";
			}
			elseif ($_REQUEST['gender'] == "1")
			{
				$moresql .= ", gender='1'";
			}
		}
		
		if (is_numeric($_REQUEST['bday']) && is_numeric($_REQUEST['bmonth']) && is_numeric($_REQUEST['byear']))
		{
			$joinbday = "$_REQUEST[byear]-$_REQUEST[bmonth]-$_REQUEST[bday]";
			$moresql .= ", birthday='".mysql_real_escape_string($joinbday)."'";
		}
		
		if ($_REQUEST['country'] != "Choose Country")
		{
			$country = cleanit($_REQUEST['country']);
			$moresql .= ", country='".mysql_real_escape_string($country)."'";
		}
				
		$query="UPDATE members SET firstname='".mysql_real_escape_string($firstname)."', lastname='".mysql_real_escape_string($lastname)."', description='".mysql_real_escape_string($description)."', url='".mysql_real_escape_string($url)."', city='".mysql_real_escape_string($city)."' $moresql WHERE USERID='".mysql_real_escape_string($UID)."'";
		$conn->execute($query);
		$message = $lang['548'];
	}
	$query = "SELECT * FROM members WHERE USERID='".mysql_real_escape_string($UID)."'";
    $executequery = $conn->execute($query);
    $memberarray = $executequery->getarray();
	STemplate::assign('memberarray',$memberarray);
	
	// Split Birthday Begin
	$birthday = explode("-",$memberarray[0]['birthday']);
	STemplate::assign('bdays',listdays($birthday[2]));
	STemplate::assign('bmonths',listmonths($birthday[1]));
	STemplate::assign('byears',listyears($birthday[0]));
	// Split Birthday End
	
	STemplate::assign('country',listcountries($memberarray[0]['country']));
	
	$templateselect = "editprofile.tpl";
}
else
{
	$redirect = base64_encode($thebaseurl."/editprofile.php");
	header("Location:$config[baseurl]/login.php?redirect=$redirect");exit;
}

$pagetitle = $lang['27'];
STemplate::assign('pagetitle',$pagetitle);

//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);
STemplate::display('header.tpl');
STemplate::display($templateselect);
STemplate::display('footer.tpl');
//TEMPLATES END
?>