<?php
/**
 * File handling the My Subscribed Uesr
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###My subscribed user###
 * @author 		karthiselvam_75ag08
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2008-12-19
 */
class subscribedUser extends AnovaHandler
	{
		public $user_details = array();

		/**
		 * subscribedUser::populateUserDetails()
		 *
		 * @param mixed $user_id
		 * @return
		 */
		public function populateUserDetails($user_id)
			{
				$fields_arr = array('user_id', 'name', 'display_name', 'email', 'image_path', 'gender', 'usr_status', 'user_access', 't_height', 't_width', 's_height', 's_width', 'photo_server_url', 'photo_ext');
				$sql = 'SELECT '. $this->getUserTableFields($fields_arr).' ,'.$this->getUserTableField('user_id').' as img_user_id FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('user_id').' = '.$this->dbObj->Param('user_id');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($user_id));
				if (!$rs)
					trigger_db_error($this->dbObj);

				if($row = $rs->FetchRow())
					return $row;
				return false;
			}

		/**
		 * subscribedUser::populateUserList()
		 *
		 * @return
		 */
		public function populateUserList()
			{
				$sql = 'SELECT content_id FROM '.$this->CFG['db']['tbl']['user_bookmarked'].
						' WHERE content_type = \'User\' AND user_id = '.$this->dbObj->Param('user_id');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				if (!$rs)
					trigger_db_error($this->dbObj);

				$populateUserList_arr=array();
				$inc=1;
				while($row = $rs->FetchRow())
					{
						$populateUserList_arr[$inc]['record'] = $user_details = $this->populateUserDetails($row['content_id']);

						$sql_log = 'SELECT total_ques, total_ans, total_points, total_best_ans'.
									', DATE_FORMAT(date_updated,\'%D %b %Y\') as date_updated, profile_views'.
									' FROM '.$this->CFG['db']['tbl']['users_ans_log'].
									' WHERE user_id='.$this->dbObj->Param('uid');

						$stmt_log = $this->dbObj->Prepare($sql_log);
						$rs_log = $this->dbObj->Execute($stmt_log, array($user_details['user_id']));
						if (!$rs_log)
							trigger_db_error($this->dbObj);

						$user_ans_log = array('total_ques'=>'', 'total_ans'=>'', 'total_points'=>'', 'date_updated'=>'', 'profile_views'=>'');
						if ($rs_log->PO_RecordCount())
							$user_ans_log = $rs_log->FetchRow();

						$populateUserList_arr[$inc]['user_ans_log'] = $user_ans_log;
						$populateUserList_arr[$inc]['userLevelNumber'] = '';
						if($this->CFG['admin']['user_levels']['allowed'])
							$populateUserList_arr[$inc]['userLevelNumber'] = getUserLevelNumber($user_ans_log['total_points']);
						$populateUserList_arr[$inc]['userLevelTitle'] = $this->getUserLevelTitle($populateUserList_arr[$inc]['userLevelNumber']);

						$mcomp = $user_details['name'];
						$populateUserList_arr[$inc]['questions_url_ans'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=ans', 'search/?uname='.$mcomp.'&amp;opt=ans');
						$populateUserList_arr[$inc]['questions_url_bestans'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=bestans', 'search/?uname='.$mcomp.'&amp;opt=bestans');
						$populateUserList_arr[$inc]['questions_url_ques'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=ques', 'search/?uname='.$mcomp.'&amp;opt=ques');
						$populateUserList_arr[$inc]['questions_url_resolve'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=resolve', 'search/?uname='.$mcomp.'&amp;opt=resolve');
						$populateUserList_arr[$inc]['questions_resolve_count'] = $this->getResolvedQuestions($user_details['user_id']);

						$populateUserList_arr[$inc]['myanswers_url'] = getMemberUrl($user_details['user_id'], $user_details['name']);
						$populateUserList_arr[$inc]['strip_display_name'] = stripString($user_details['display_name'], $this->CFG['username']['short_length']);

						$inc++;
					}
				return 	$populateUserList_arr;
			}
		/**
		 * subscribedUser::populateUserDetailsArr()
		 *
		 * @return
		 */
		public function populateUserDetailsArr()
			{
				$sql = 'SELECT '.$this->getUserTableFields(array('name', 'user_id', 'display_name')).
						' FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('name').' = '.$this->dbObj->Param('name').
						' AND '.$this->getUserTableField('usr_status').'=\'OK\'';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				if (!$rs)
					trigger_db_error($this->dbObj);

				if($row = $rs->FetchRow())
					{
						$this->user_details = $row;
						$this->setFormField('uid', $row['user_id']);
						return true;
					}
				return false;
			}
	}
//--------------------Code begins-------------->>>>>//
$subscribedUser = new subscribedUser();
//set blocks
$subscribedUser->setPageBlockNames(array('user_list_block'));
//show default pages
$subscribedUser->setFormField('uid', '');
$subscribedUser->sanitizeFormInputs($_REQUEST);
if(!$subscribedUser->getFormField('uid'))
	$subscribedUser->setFormField('uid', $CFG['user']['user_id']);
if($subscribedUser->populateUserDetailsArr())
	{
		$subscribedUser->setPageBlockShow('user_list_block');
		$LANG['mysubscribeduser_back_to_user_profile_user'] = str_ireplace('VAR_USERNAME', $subscribedUser->user_details['display_name'], $LANG['mysubscribeduser_back_to_user_profile_user']);
		$LANG['mysubscribeduser_back_to_user_profile'] = ($CFG['user']['user_id']==$subscribedUser->getFormField('uid'))?$LANG['mysubscribeduser_back_to_user_profile']:$LANG['mysubscribeduser_back_to_user_profile_user'];
		$LANG['mysubscribeduser_page_title_user_name'] = str_ireplace('VAR_USERNAME', $subscribedUser->user_details['display_name'], $LANG['mysubscribeduser_page_title_user_name']);
		$LANG['mysubscribeduser_title'] = ($subscribedUser->getFormField('uid')==$CFG['user']['user_id'])?$LANG['mysubscribeduser_title']:$LANG['mysubscribeduser_page_title_user_name'];
		$back_link = getMemberUrl($subscribedUser->user_details['user_id'], $subscribedUser->user_details['name']);
		$profile_name = $LANG['back_to_profile'];
		$subscribedUser->populateUserDetailsArr['back_link']=$back_link;
		$subscribedUser->populateUserDetailsArr['profile_name']=$profile_name;
		$subscribedUser->populateUserDetailsArr['profile_tooltip']=$LANG['mysubscribeduser_back_to_user_profile'];
	}
else
	{
		$subscribedUser->setPageBlockShow('block_msg_form_error');
		$subscribedUser->setCommonErrorMsg($LANG['err_tip_invalid_user']);
	}
//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
if ($subscribedUser->isShowPageBlock('user_list_block'))
	{
		$display_username = $LANG['common_subscribed'];
		$uid = $subscribedUser->getFormField('uid');
		$dname = $subscribedUser->user_details['display_name'];
		$uname = $subscribedUser->user_details['name'];
		if($CFG['user']['user_id'] != $uid)
			{
				$display_username = str_ireplace('VAR_USERNAME', ucwords($dname), $LANG['common_subscribed_others']);
			}
		$subscribedUser->user_list_block['display_username'] = $display_username;
		$subscribedUser->user_list_block['tag_url'] = getAnovaUrl('mysubscribedtag', '?uid='.$uname, $uname.'/');
		$subscribedUser->user_list_block['user_url'] = getAnovaUrl('mysubscribeduser', '?uid='.$uname, $uname.'/');
		$subscribedUser->user_list_block['forum_url'] = getForumsUrl('mysubscribedforum', '?uid='.$uname, $uname.'/');
		$subscribedUser->user_list_block['populateUserList'] = $subscribedUser->populateUserList();
	}
//include the header file
$subscribedUser->includeHeader();
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('mySubscribedUser.tpl');
//includ the footer of the page
?>
<script language="javascript" type="text/javascript">
	var block_arr= new Array('selMsgConfirm');
</script>
<?php
//<<<<<<--------------------Page block templates Ends--------------------//
$subscribedUser->includeFooter();
?>