<?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'];

$mainmenu = "7";
STemplate::assign('mainmenu',$mainmenu);
$submenu = "0";
STemplate::assign('submenu',$submenu);

if (is_numeric($_REQUEST['pid']))
{
	$pid = intval(cleanit($_REQUEST['pid']));
	STemplate::assign('pid',$pid);
}
else
{
	$error = $lang['582'];
}

if ($error == "")
{
	if (does_profile_exist($pid))
	{
		$query = "SELECT * FROM members WHERE USERID='".mysql_real_escape_string($pid)."'";
       	$executequery = $conn->execute($query);
       	$profilearray = $executequery->getarray();
		STemplate::assign('profilearray',$profilearray);
		if(mysql_affected_rows()>=1)
		{
			$USERID = $profilearray[0]['USERID'];
			STemplate::assign('USERID',$USERID);
			STemplate::assign('pagetitle',$profilearray[0]['username']."'s $lang[26]");
			update_viewcount_profile($USERID);
			
			$query = "SELECT A.*, B.username FROM members_comments A, members B WHERE A.PROFILEID='".mysql_real_escape_string($USERID)."' AND A.USERID=B.USERID ORDER BY CID desc";
			$executequery = $conn->execute($query);
			$showcomments =  $executequery->getarray();
			STemplate::assign('showcomments',$showcomments);
			
			$query = "SELECT DID,title FROM docs WHERE USERID='".mysql_real_escape_string($USERID)."' and active='1' ORDER BY DID desc limit 8";
			$executequery = $conn->execute($query);
			$docs =  $executequery->getarray();
			STemplate::assign('docs',$docs);
			
			$query = "SELECT A.DID, A.title FROM docs A, docs_favorited B WHERE B.USERID='".mysql_real_escape_string($USERID)."' and A.active='1' AND A.DID=B.DID ORDER BY B.FID desc limit 8";
			$executequery = $conn->execute($query);
			$fdocs =  $executequery->getarray();
			STemplate::assign('fdocs',$fdocs);
			
			$query = "SELECT A.DID, A.title FROM docs A, docs_favorited B WHERE B.USERID='".mysql_real_escape_string($USERID)."' and A.active='1' AND A.DID=B.DID ORDER BY B.FID desc limit 8";
			$executequery = $conn->execute($query);
			$fdocs =  $executequery->getarray();
			STemplate::assign('fdocs',$fdocs);
			
			$query = "SELECT A.* FROM members A, members_subscribers B WHERE B.subscriber='".mysql_real_escape_string($USERID)."' and A.status='1' AND A.USERID=B.subscribee ORDER BY B.SID desc limit 5";
			$executequery = $conn->execute($query);
			$m =  $executequery->getarray();
			STemplate::assign('m',$m);
			
			$query = "SELECT A.* FROM members A, members_subscribers B WHERE B.subscribee='".mysql_real_escape_string($USERID)."' and A.status='1' AND A.USERID=B.subscriber ORDER BY B.SID desc limit 5";
			$executequery = $conn->execute($query);
			$m2 =  $executequery->getarray();
			STemplate::assign('m2',$m2);
			
			$showtheme = "memberprofile.tpl";
		}
		else
		{
			$error = $lang['583'];
		}
	}	
	else
	{
		$error = $lang['584'];
	}
}

//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);

STemplate::display('header.tpl');
if ($error == "")
{
	STemplate::display($showtheme);
}
else
{
	STemplate::display('empty.tpl');
}
STemplate::display('footer.tpl');
//TEMPLATES END
?>