<?php
/**
 * View users details
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###My answers###
 * @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-22
 */
class MyAnswerFormHandler extends AnovaHandler
	{
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function displayAnswerDetails()
		    {
				$this->displayAnswerDetails_arr=array();
		    		$uname = $this->user_details['display_name'];
				/*$this->displayAnswerDetails_arr['common_my'] = $display_username = $this->LANG['common_my'];
				$this->displayAnswerDetails_arr['users_answers'] = $display_username.' '.$this->LANG['answered_questions'];
				$this->displayAnswerDetails_arr['users_questions'] = $display_username.' '.$this->LANG['questions'];
				$this->displayAnswerDetails_arr['users_favorites'] = $display_username.' '.$this->LANG['myanswers_favorite_question_header'];
				$this->displayAnswerDetails_arr['users_forums'] = $display_username.' '.$this->LANG['forums'];
				$this->displayAnswerDetails_arr['users_blogs'] = $display_username.' '.$this->LANG['blogs'];*/
				$this->displayAnswerDetails_arr['display_username']	= 	$display_username = str_ireplace('VAR_USERNAME', $uname, $this->LANG['common_others']);
				//if ($this->CFG['user']['user_id'] != $this->fields_arr['uid'])
					{
						$this->displayAnswerDetails_arr['users_answers'] = $this->LANG['answers'];
						$this->displayAnswerDetails_arr['users_questions'] = $this->LANG['questions'];
						$this->displayAnswerDetails_arr['users_favorites'] = $this->LANG['myanswers_favorite_question_header'];
						$this->displayAnswerDetails_arr['users_forums'] = $this->LANG['forums'];
						$this->displayAnswerDetails_arr['users_blogs'] = $this->LANG['blogs'];
					}
				$this->displayAnswerDetails_arr['stripString_disp_name'] = stripString($display_username, $this->CFG['username']['medium_length']);
				$this->displayAnswerDetails_arr['displayAnsweredQuestions']=array();
				$this->displayAnswerDetails_arr['displayAnsweredQuestions'] = $this->displayAnsweredQuestions(3);
				$display_username = $this->LANG['common_my'];
				if($this->CFG['user']['user_id'] != $this->fields_arr['uid'])
					{
						$this->displayAnswerDetails_arr['display_username']	= 	$display_username = str_ireplace('VAR_USERNAME', $uname, $this->LANG['common_others']);
					}
				if ($this->CFG['admin']['subscribe']['tags'] OR $this->CFG['admin']['subscribe']['users'] OR $this->CFG['admin']['subscribe']['forums'])
					{
						$this->displayAnswerDetails_arr['userSubscribeStyle'] = $this->displayAnswerDetails_arr['forumSubscribeStyle'] = '';
						if(chkIsAllowedModule(array('forums')))
							{
								$this->displayAnswerDetails_arr['hide_arr'] = "'selSubscribedUsers','selSubscribedForums'";
								$this->displayAnswerDetails_arr['hide_arr1'] = "'selSubscribedTags','selSubscribedForums'";
							}
						else
							{
								$this->displayAnswerDetails_arr['hide_arr'] = "'selSubscribedUsers'";
								$this->displayAnswerDetails_arr['hide_arr1'] = "'selSubscribedTags'";
							}
						if ($this->CFG['admin']['subscribe']['tags'])
							{
								$this->displayAnswerDetails_arr['userSubscribeStyle'] = $this->displayAnswerDetails_arr['forumSubscribeStyle'] = 'style=display:none;';
							}
						if ($this->CFG['admin']['subscribe']['tags'])
							{
								$this->displayAnswerDetails_arr['displaySubscribedTags'] = $this->displaySubscribedTags(25);
							}
						if ($this->CFG['admin']['subscribe']['users'])
							{
								$this->displayAnswerDetails_arr['displaySubscribedUsers']=array();
								if (!$this->displayAnswerDetails_arr['userSubscribeStyle'])
								{
									$this->displayAnswerDetails_arr['displaySubscribedUsers'] = $this->displaySubscribedUsers(3);
								}
							}
						if (chkIsAllowedModule(array('forums')) AND $this->CFG['admin']['subscribe']['forums'])
							{	$this->displayAnswerDetails_arr['displaySubscribedForums']=array();
								if (!$this->displayAnswerDetails_arr['forumSubscribeStyle'])
								{
									$this->displayAnswerDetails_arr['displaySubscribedForums'] = $this->displaySubscribedForums(5);
								}
							}
					}
				return $this->displayAnswerDetails_arr;
		    }

		/**
		 * MyAnswerFormHandler::displayAnsweredQuestions()
		 *
		 * @param integer $limit
		 * @return
		 */
		public function displayAnsweredQuestions($limit=3)
			{
				$uname = $this->user_details['name'];
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].' as q, '.$this->CFG['db']['tbl']['users'].' as u'.
						' WHERE q.user_id=u.'.$this->CFG['users']['user_id'].' AND q.status IN (\'Open\', \'Resolved\') AND u.'.$this->CFG['users']['usr_status'].'=\'Ok\''.
						' AND EXISTS (SELECT ques_id FROM '.$this->CFG['db']['tbl']['answers'].' AS a WHERE'.
						' a.user_id='.$this->dbObj->Param('user_id').' AND q.ques_id = a.ques_id)'.
						' ORDER BY q.ques_id DESC LIMIT 0,'.($limit+1);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);
				$this->displayAnsweredQuestions_arr=array();
				if (!$rs->PO_RecordCount())
					{
						$this->displayAnsweredQuestions_arr['RecordCount'] = 0;
					}
				if ($rs->PO_RecordCount())
					{
						$this->displayAnsweredQuestions_arr['RecordCount'] = 1;
						$this->displayAnsweredQuestions_arr['displayQuestions'] = $this->displayQuestions($rs, $limit, 'Ans');
						$this->displayAnsweredQuestions_arr['limit_chk'] = 0;
						if ($rs->PO_RecordCount() > $limit)
							{
								$this->displayAnsweredQuestions_arr['limit_chk'] = 1;
								$this->displayAnsweredQuestions_arr['questions_url'] = getAnovaUrl('questions', '?view=search&amp;uname='.$uname.'&amp;opt=ans', 'search/?uname='.$uname.'&amp;opt=ans');
							}
					}
				return $this->displayAnsweredQuestions_arr;
			}

		/**
		 * MyAnswerFormHandler::displayAskedQuestions()
		 *
		 * @param integer $limit
		 * @return
		 */
		public function displayAskedQuestions($limit=3)
			{
				$this->displayAskedQuestions_arr = array();
				$uname = $this->fields_arr['name'];
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].' as q'.
						' WHERE q.user_id='.$this->dbObj->Param('user_id').
						' AND q.status IN (\'Open\', \'Resolved\')'.
						' ORDER BY q.ques_id DESC LIMIT 0,'.($limit+1);

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);
				if (!$rs->PO_RecordCount())
					{
						$this->displayAskedQuestions_arr['RecordCount'] = 0;
					}
				if ($rs->PO_RecordCount())
					{
						$this->displayAskedQuestions_arr['RecordCount'] = 1;
						$this->displayAskedQuestions_arr['displayQuestions'] = $this->displayQuestions($rs, $limit, 'Ask');
						$this->displayAskedQuestions_arr['RecordCountGTlimit'] = 0;
						if ($rs->PO_RecordCount() > $limit)
							{
								$this->displayAskedQuestions_arr['RecordCountGTlimit'] = 1;
								$this->displayAskedQuestions_arr['questions_url'] = getAnovaUrl('questions', '?view=search&amp;uname='.$uname.'&amp;opt=ques', 'search/?uname='.$uname.'&amp;opt=ques');
							}
					}
				return $this->displayAskedQuestions_arr;
			}

		/**
		 * MyAnswerFormHandler::displayFavoriteQuestions()
		 *
		 * @param integer $limit
		 * @return
		 */
		public function displayFavoriteQuestions($limit=3)
			{
				$this->displayFavoriteQuestions_arr = array();
				$uname = $this->fields_arr['name'];
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['user_bookmarked'].' AS ub, '.$this->CFG['db']['tbl']['questions'].' as q'.
						' WHERE ub.user_id='.$this->dbObj->Param('user_id').
						' AND ub.content_type=\'Question\' AND ub.content_id=q.ques_id'.
						' AND q.status IN (\'Open\', \'Resolved\')'.
						' ORDER BY ub.bookmark_id DESC LIMIT 0,'.($limit+1);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				if (!$rs)
					trigger_db_error($this->dbObj);
				if (!$rs->PO_RecordCount())
					{
						$this->displayFavoriteQuestions_arr['RecordCount'] = 0;
					}
				if ($rs->PO_RecordCount())
					{
						$this->displayFavoriteQuestions_arr['RecordCount'] = 1;
						$this->displayFavoriteQuestions_arr['displayQuestions'] = $this->displayQuestions($rs, $limit, 'Fav');
						$this->displayFavoriteQuestions_arr['RecordCountGTlimit'] = 0;
						if ($rs->PO_RecordCount() > $limit)
							{
								$this->displayFavoriteQuestions_arr['RecordCountGTlimit'] = 1;
								$this->displayFavoriteQuestions_arr['questions_url'] = getAnovaUrl('questions', '?view=search&amp;uname='.$uname.'&amp;opt=fav', 'search/?uname='.$uname.'&amp;opt=fav');
							}
					}
				return $this->displayFavoriteQuestions_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayQuestions($rs, $limit, $popext='')
			{
				$i=0;
				$this->displayQuestions_arr = array();
				$inc=0;
				while($row = $rs->FetchRow())
					{
						$this->displayQuestions_arr[$inc]['questionDetails'] = $questionDetails = $this->getQuestionDetails($row['ques_id']);
						$i++;
						$this->displayQuestions_arr[$inc]['clsOddOrEvenQuestion'] = ($i%2) ? 'clsOddQuestion' : 'clsEvenQuestion';
						$this->displayQuestions_arr[$inc]['answer_plural'] = ($questionDetails['total_answer']!= 1) ? $this->LANG['answers'] : $this->LANG['common_total_answer'];
						$this->displayQuestions_arr[$inc]['views_plural'] = ($questionDetails['total_views']!= 1) ? $this->LANG['common_total_views'] : $this->LANG['common_total_view'];
						$this->displayQuestions_arr[$inc]['questionDetails']['image_id'] = $this->displayQuestions_arr[$inc]['questionDetails']['image_id'] = $popext;
						$this->displayQuestions_arr[$inc]['getTimeDiffernceFormat'] = $this->getTimeDiffernceFormat($this->displayQuestions_arr[$inc]['questionDetails']['date_asked']);
						if ($i >= $limit)
							break;
						$inc++;
					} // while
				return $this->displayQuestions_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displaySubscribedTags($limit=25)
			{
				$this->displaySubscribedTags_arr = array();
				$dname = $this->fields_arr['nameofuser'];
				$uname = $this->fields_arr['name'];
				$uid = $this->fields_arr['uid'];

				$sql = 'SELECT subscribe_keywords FROM '.$this->CFG['db']['tbl']['users_ans_log'].
						' WHERE 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);

				$found = false;
				if ($rs->PO_RecordCount())
					{
					$this->displaySubscribedTags_arr['RecordCount']=1;
					$row = $rs->FetchRow();
					$subscribed_tags = array();
					if (trim($row['subscribe_keywords']))
						{
							$subscribed_tags = explode(' ', trim($row['subscribe_keywords']));
							$found = true;
							$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
							$tagClassArray = array();
							$tagArray = array();
							foreach($subscribed_tags as $eachTag)
								{
									$tagArray[$eachTag] = $this->getTagQuestionsCount($eachTag);
									$class = $classes[rand(0, count($classes))%count($classes)];
									$tagClassArray[$eachTag] = $class;
								} // while
							$tagArray = $this->setFontSizeInsteadOfSearchCount($tagArray);
							$cntTags = 0;
							$inc=0;
							$this->displaySubscribedTags_arr['row']=array();
							foreach($tagArray as $tag=>$fontSize)
								{
									$url  = getAnovaUrl('questions', '?view=search&amp;tags='.$tag, 'search/?tags='.$tag);
									$class 	= $tagClassArray[$tag];
									$this->displaySubscribedTags_arr['row'][$inc]['fontSizeClass'] = $fontSizeClass	= 'style="font-size:'.$fontSize.'px"';
									$cntTags++;
									$this->displaySubscribedTags_arr['row'][$inc]['class'] = $class;
									$this->displaySubscribedTags_arr['row'][$inc]['url'] = $url;
									$this->displaySubscribedTags_arr['row'][$inc]['tag'] = $tag;
									if ($cntTags > $limit)
										break;
									$inc++;
								}
							$this->displaySubscribedTags_arr['cntTagsGTlimit']=0;
							if ($cntTags >= $limit)
								{
									$this->displaySubscribedTags_arr['cntTagsGTlimit']=1;
									$this->displaySubscribedTags_arr['subscribedtags'] = getAnovaUrl('subscribedtags', '?uid='.$uname, $uname.'/');
								}
						}
					}
				if (!$found)
					{
						$this->displaySubscribedTags_arr['RecordCount'] = 0;
					}
				return $this->displaySubscribedTags_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		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 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;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displaySubscribedUsers($limit=5)
			{
				$this->displaySubscribedUsers=array();
				$dname = $this->fields_arr['nameofuser'];
				$uname = $this->fields_arr['name'];
				$uid = $this->fields_arr['uid'];

				$sql = 'SELECT content_id FROM '.$this->CFG['db']['tbl']['user_bookmarked'].
						' WHERE content_type = \'User\' AND user_id = '.$this->dbObj->Param('user_id').
						' LIMIT 0, '.$limit;

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

				if (!$rs->PO_RecordCount())
					{
						$this->displaySubscribedUsers['RecordCount'] = 0;
					}
				$this->displaySubscribedUsers['row'] = array();
				$inc=0;
				if ($rs->PO_RecordCount())
					{
						$this->displaySubscribedUsers['RecordCount'] = 1;
						$photosPerRow = 3;
						$count = 0;
						$found = false;
						$cntUsers = 0;
						$this->displaySubscribedUsers['row']=array();
						while($row = $rs->FetchRow())
							{
								$this->displaySubscribedUsers['row'][$inc]['user_details'] = $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();
								$this->displaySubscribedUsers['row'][$inc]['user_ans_log'] = $user_ans_log;
								$this->displaySubscribedUsers['row'][$inc]['userLevelNumber'] = '';
								if($this->CFG['admin']['user_levels']['allowed'])
									$this->displaySubscribedUsers['row'][$inc]['userLevelNumber'] = getUserLevelNumber($user_ans_log['total_points']);
								$this->displaySubscribedUsers['row'][$inc]['userLevelTitle'] = $this->getUserLevelTitle($this->displaySubscribedUsers['row'][$inc]['userLevelNumber']);

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

								$found = true;
								$cntUsers++;
								$this->displaySubscribedUsers['row'][$inc]['myanswers_url'] = getMemberUrl($user_details['user_id'], $user_details['name']);
								$this->displaySubscribedUsers['row'][$inc]['strip_display_name'] = stripString($user_details['display_name'], $this->CFG['username']['short_length']);
								$count++;
							    if ($cntUsers > $limit)
		                   			break;
								$inc++;
							}
						$this->displaySubscribedUsers['cntUsersGTlimit'] = 0;
						if ($cntUsers >= $limit)
							{
								$this->displaySubscribedUsers['cntUsersGTlimit'] = 1;
								$this->displaySubscribedUsers['mySubscribedUser_url'] = getAnovaUrl('mysubscribeduser', '?uid='.$uname, $uname.'/');
							}
					}
				return $this->displaySubscribedUsers;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displaySubscribedForums($limit=5)
			{
				$this->displaySubscribedForums_arr = array();
				$dname = $this->fields_arr['nameofuser'];
				$uname = $this->fields_arr['name'];
				$uid = $this->fields_arr['uid'];

				$sql = 'SELECT ub.content_id FROM '.$this->CFG['db']['tbl']['user_bookmarked'].' as ub, '.$this->CFG['db']['tbl']['forum_topics'].' as ft'.
						' WHERE ub.content_type = \'Forum\' AND ub.content_id=ft.topic_id AND ub.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);

				if (!$rs->PO_RecordCount())
					{
						$this->displaySubscribedForums_arr['RecordCount'] = 0;
					}
				if ($rs->PO_RecordCount())
					{
						$this->displaySubscribedForums_arr['RecordCount'] = 1;
						$cntForums = 1;
						$this->displaySubscribedForums_arr['row']=array();
						$inc=0;
						while($row = $rs->FetchRow())
							{
								//$this->displaySubscribedForums_arr['row'][$inc]['forumDetails'] = $forumDetails = $this->populateForumDetails($row['content_id']);
								$forumDetails = $this->getForumDetails($row['content_id']);

								$this->displaySubscribedForums_arr['row'][$inc]['forumDetails'] = $forumDetails;
								$this->displaySubscribedForums_arr['row'][$inc]['resp_plural'] = $resp_plural = $this->LANG['common_total_response'];
								$this->displaySubscribedForums_arr['row'][$inc]['view_plural'] = $view_plural = $this->LANG['common_total_view'];

								$this->displaySubscribedForums_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsEvenQuestion';
								if ($inc%2)
									$this->displaySubscribedForums_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsOddQuestion';

								if($forumDetails['total_response'] != 1)
									$this->displaySubscribedForums_arr['row'][$inc]['resp_plural'] = $resp_plural = $this->LANG['common_total_responses'];
								if($forumDetails['total_views'] != 1)
									$this->displaySubscribedForums_arr['row'][$inc]['view_plural'] = $view_plural = $this->LANG['common_total_views'];
								$cntForums++;
								$this->displaySubscribedForums_arr['row'][$inc]['forumsResponses_url'] = getForumsUrl('forumsresponses', '?title='.$forumDetails['title'].'&amp;topic_title='.$forumDetails['seo_title'], $forumDetails['title'].'/'.$forumDetails['seo_title'].'/');
								$this->displaySubscribedForums_arr['row'][$inc]['wordWrapManual'] = wordWrapManual($forumDetails['forum_topic'], $this->CFG['admin']['forum']['line_length'], $this->CFG['admin']['forum']['short_length']);
							    if ($cntForums > $limit)
				                    break;
								$inc++;
							}
						$this->displaySubscribedForums_arr['cntForumsGTlimit'] = 0;
						if ($cntForums >= $limit)
							{
								$this->displaySubscribedForums_arr['cntForumsGTlimit'] = 1;
								$this->displaySubscribedForums_arr['mySubscribedForum_url'] = getForumsUrl('mysubscribedforum', '?uid='.$uname, $uname.'/');
							}
					}
					return $this->displaySubscribedForums_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getTagQuestionsCount($tag_name)
			{
				$sql = 'SELECT total_count FROM '.$this->CFG['db']['tbl']['tags'].
						' WHERE tag_name='.$this->dbObj->Param($tag_name);

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

				$row['total_count'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['total_count'];
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function displayUserDetails()
		    {
				$this->displayUserDetails_arr=array();
				$sql = 'SELECT total_ques, total_ans, total_points, total_best_ans, total_debates, total_debate_response, total_best_debate_response'.
						', 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 = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				if (!$rs)
					trigger_db_error($this->dbObj);

				$this->user_ans_log = array('total_ques'=>'', 'total_ans'=>'', 'total_points'=>'', 'date_updated'=>'', 'profile_views'=>'');
				if ($rs->PO_RecordCount())
					$this->user_ans_log = $rs->FetchRow();
				$this->displayUserDetails_arr['user_details'] = $this->user_details = $this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $this->fields_arr['uid']);
				$mcomp = $this->user_details['name'];
				$this->user_details['display_name'] = ucwords($this->user_details['display_name']);
				$display_username = $this->user_details['display_name'];
				$bio = $this->user_details['bio'];
				$this->displayUserDetails_arr['userLevelNumber'] = '';
				if($this->CFG['admin']['user_levels']['allowed'])
					$this->displayUserDetails_arr['userLevelNumber'] = getUserLevelNumber($this->user_ans_log['total_points']);
				$this->displayUserDetails_arr['userLevelTitle'] = $this->getUserLevelTitle($this->displayUserDetails_arr['userLevelNumber']);
				$this->displayUserDetails_arr['myanswers_url'] = getMemberUrl($this->user_details['user_id'], $this->user_details['name']);
				$this->displayUserDetails_arr['toggleFavorites'] = 'toggleFavorites(\''.getAnovaUrl('favoriteanswers').'\', \'cid='.$this->fields_arr['uid'].'&amp;ctype=User\', \'selShowFavoriteText_User_'.$this->fields_arr['uid'].'\'); return false;';
				$this->displayUserDetails_arr['myanswers_mem_url'] = getMemberUrl($this->user_details['user_id'], $this->user_details['name']);
				$this->displayUserDetails_arr['toggleFavorites1'] = 'toggleFavorites(\''.getAnovaUrl('favoriteanswers').'\', \'ignore_id='.$this->fields_arr['uid'].'\', \'selShowIgnoreUser\'); return false;';
				$this->displayUserDetails_arr['members_url'] = getUrl('mailcompose', '?mcomp='.$mcomp, '?mcomp='.$mcomp, 'members');
				$this->displayUserDetails_arr['show_upgrade'] = false;
				if(($this->user_details['user_id'] == $this->CFG['user']['user_id']) AND (!isMembershipValid($this->user_details['expiry_date']) OR $this->user_details['signup_type'] < '2'))
					{
						$this->displayUserDetails_arr['show_upgrade'] = true;
						$this->displayUserDetails_arr['payment_upgrade_url'] = getAnovaUrl('paymentupgrade');
					}
				else
					{
						$this->displayUserDetails_arr['plan_details'] = $this->getTariffDetails($this->user_details['signup_type']);
					}
				if($this->CFG['admin']['best_answers']['allowed'])
					{
						$this->displayUserDetails_arr['percentage'] = $percentage = 0;
						if($this->user_ans_log['total_ans'])
							$this->displayUserDetails_arr['percentage'] = round(($this->user_ans_log['total_best_ans']/$this->user_ans_log['total_ans'])*100);
					}
				$this->displayUserDetails_arr['date'] = date('M d, Y', strtotime($this->fields_arr['doj']));
				$this->displayUserDetails_arr['nl2br_bio'] = nl2br(wordWrapManual($bio, 45));
				$this->displayUserDetails_arr['profileBadgeUrl'] = '';
				if ($this->isShowPageBlock('block_badge_embed'))
						$this->displayUserDetails_arr['profileBadgeUrl'] = getUserProfileBadgeUrl($this->CFG['user']['name']);
				$this->displayUserDetails_arr['user_ans_log'] = $this->user_ans_log;
				$this->displayUserDetails_arr['pointsAndLevels_url'] = getUrl('pointssndlevels');
				$this->displayUserDetails_arr['questions_url_ans'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=ans', 'search/?uname='.$mcomp.'&amp;opt=ans');
				$this->displayUserDetails_arr['questions_url_bestans'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=bestans', 'search/?uname='.$mcomp.'&amp;opt=bestans');
				$this->displayUserDetails_arr['questions_url_ques'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=ques', 'search/?uname='.$mcomp.'&amp;opt=ques');
				$this->displayUserDetails_arr['questions_url_resolve'] = getAnovaUrl('questions', '?view=search&amp;uname='.$mcomp.'&amp;opt=resolve', 'search/?uname='.$mcomp.'&amp;opt=resolve');
				$this->displayUserDetails_arr['questions_resolve_count'] = $this->getResolvedQuestions($this->fields_arr['uid']);
				$this->displayUserDetails_arr['questions_url_res']	=	getAnovaUrl('debates','?view=search&uname='.$mcomp.'&opt=resp', 'search/?uname='.$mcomp.'&opt=resp');
				$this->displayUserDetails_arr['questions_url_bestres']	=	getAnovaUrl('debates','?view=search&uname='.$mcomp.'&opt=bestans', 'search/?uname='.$mcomp.'&opt=bestresp');
				$this->displayUserDetails_arr['questions_url_debt']	=	getAnovaUrl('debates','?view=search&uname='.$mcomp.'&opt=debt','search/?uname='.$mcomp.'&opt=debt');
				$this->displayUserDetails_arr['questions_url_resolve_debate'] = getAnovaUrl('debates','?view=search&uname='.$mcomp.'&opt=resolve', 'search/?uname='.$mcomp.'&opt=resolve');

				if ($this->displayUserDetails_arr['profileBadgeUrl'])
				{
					$badgeUrlWithoutScript = getUserProfileBadgeUrl($this->CFG['user']['name'], false);
					$badgeUrlWithoutScript .= ($this->CFG['feature']['rewrite_mode']== 'htaccess')?('?content=2'):('&amp;content=2');
					$this->displayUserDetails_arr['str_ireplace'] = str_ireplace('VAR_SITENAME', $this->CFG['site']['name'], $this->LANG['myanswers_badge_embed_hint']);

				}
				return $this->displayUserDetails_arr;
	    	}

   		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getResolvedDebates()
		    {
				$sql = 'SELECT COUNT(debate_id) AS resolved FROM '.$this->CFG['db']['tbl']['debates'].
						' WHERE user_id='.$this->dbObj->Param('uid').' AND status NOT IN(\'Blocked\',\'ToActivate\') AND date_closed<NOW()';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['uid']));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$row = $rs->FetchRow();
				return $row['resolved'];
		    }
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function chkIsValidUser()
		    {
				$this->chkIsNotEmpty('uid', $this->LANG['err_tip_compulsory']);
				if (!$this->isValidFormInputs())
					{
						$this->setCommonErrorMsg($this->LANG['err_tip_invalid_user']);
						$this->setPageBlockShow('block_msg_form_error');
						return false;
					}

				$sql = 'SELECT '.$this->getUserTableFields(array('user_id', 'name', 'display_name', 't_height', 't_width','photo_server_url', 'photo_ext', 'doj')).', u.'.$this->getUserTableField('user_id').' as img_user_id'.
						' FROM '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE u.'.$this->getUserTableField('name').'='.$this->dbObj->Param('uid').
						' AND u.'.$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 (!$rs->PO_RecordCount())
					{
						$this->setCommonErrorMsg($this->LANG['err_tip_invalid_user']);
						$this->setPageBlockShow('block_msg_form_error');
						return false;
					}
				$row = $rs->FetchRow();

				if($this->isAnonymsUser($row['user_id']))
					{
						$this->setCommonErrorMsg($this->LANG['anonyms_account_msg']);
						$this->setPageBlockShow('block_msg_form_error');
						return false;
					}

				$this->fields_arr['nameofuser'] = $row['display_name'];
				$this->fields_arr['doj'] = $row['doj'];
				$this->fields_arr['uid'] = $row['user_id'];
				$this->fields_arr['name'] = $row['name'];
				return true;
		    }

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayForums($limit=5)
			{
				$this->displayRecentForums($limit, $this->fields_arr['uid']);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayBlogs($limit=5)
			{
				$this->displayRecentBlogs($limit,$this->fields_arr['uid']);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getBlogDetails($blog_id)
			{
				$blogDetails = array();
				$sql = 'SELECT blog_id, subject, seo_title, message, blog_category_id, total_comments, total_views, b.user_id, b.video_id, b.audio_id, b.external_video_id, b.external_audio_id, UNIX_TIMESTAMP(date_added) as date_added, u.'.$this->getUserTableField('image_path').' AS image_path, u.'.$this->getUserTableField('user_id').' AS img_user_id , u.'.$this->getUserTableField('t_height').' AS t_height'.', u.'.$this->getUserTableField('t_width').' AS t_width, u.'.$this->getUserTableField('photo_server_url').' AS photo_server_url'.
						', u.'.$this->getUserTableField('s_width').' AS s_width, u.'.$this->getUserTableField('s_height').' AS s_height'.
						', u.'.$this->getUserTableField('gender').' AS gender'.
						', u.'.$this->getUserTableField('photo_ext').' AS photo_ext, u.'.$this->getUserTableField('name').' AS name'.
						' FROM '.$this->CFG['db']['tbl']['blogs'].' AS b'.', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE status=\'Active\''.
						' AND b.user_id = u.user_id'.
						' AND u.'.$this->getUserTableField('usr_status').' = \'Ok\''.
						' AND blog_id='.$this->dbObj->Param($blog_id);

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

				if ($rs->PO_RecordCount())
					{
						$blogDetails = $rs->FetchRow();
						$blogDetails['blog_link'] = '<a href="'.getBlogUrl('blogcomment','?title='.$blogDetails['seo_title'], $blogDetails['seo_title'].'/').'">'.wordWrapManual($blogDetails['subject'], $this->CFG['admin']['blog']['line_length'], $this->CFG['admin']['blog']['short_length']).'</a>';
						$blogDetails['blog_user_name'] = '<a href="'.getMemberUrl($blogDetails['user_id'], $blogDetails['name']).'">'.stripString($blogDetails['name'], $this->CFG['username']['medium_length']).'</a>';
						$blogDetails['blogcategoryname'] =  $this->getBlogCategory($blogDetails['blog_category_id']);

						$blogDetails['separator_class'] = 'clsNoLeftBgPadngMrgn';
						if((chkVideoModuleAllowed('blog') AND $blogDetails['video_id'])
							OR (chkAudioModuleAllowed('blog') AND $blogDetails['audio_id'])
							OR (chkExternalVideoModuleAllowed('blog') AND $blogDetails['external_video_id'])
							OR (chkExternalAudioModuleAllowed('blog') AND $blogDetails['external_audio_id']))
							{
								$blogDetails['separator_class'] = '';
							}

						$blogDetails['ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$blogDetails['video_id'], '?pg=Blog_'.$blogDetails['video_id']);
						$blogDetails['ans_view_video']['on_click'] = 'blog_video_'.$blogDetails['video_id'];

						$blogDetails['ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$blogDetails['audio_id'], '?pg=Blog_'.$blogDetails['audio_id']);
						$blogDetails['ans_view_audio']['on_click'] = 'blog_audio_'.$blogDetails['audio_id'];

						$blogDetails['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$blogDetails['external_video_id'], '?pg=Blog_'.$blogDetails['external_video_id']);
		  				$blogDetails['ext_ans_view_video']['on_click'] = 'external_video_blog_'.$blogDetails['external_video_id'];

						$blogDetails['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$blogDetails['external_audio_id'], '?pg=Blog_'.$blogDetails['external_audio_id']);
						$blogDetails['ext_ans_view_audio']['on_click'] = 'external_audio_blog_'.$blogDetails['external_audio_id'];
					}

				return $blogDetails;
			}

		/**
		 * To get recent blogs
		 *
		 * @return void
		 * @access public
		 **/
		public function getRecentBlogs($limit = 5, $blog_user_id='')
			{
				$condition = '';
				if($blog_user_id)
					$condition = ' AND user_id='.$blog_user_id;

				$sql = 'SELECT blog_id FROM '.$this->CFG['db']['tbl']['blogs'].' AS b'.
						' WHERE status=\'Active\''.$condition.
						' ORDER BY blog_id DESC LIMIT 0,'.$limit;

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

				$recent_blogs = array();
				while($row = $rs->FetchRow())
					{
						$recent_blogs[] = $row['blog_id'];
					}
				return $recent_blogs;
			}

		/**
		 * To display recent blogs
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayRecentBlogs($limit = 5, $blog_user_id='',  $close = NULL)
			{
				global $smartyObj;
				$this->displayRecentBlogs_arr	=	array();
				$this->displayRecentBlogs_arr['is_user']	=	$is_user = false;
				$this->displayRecentBlogs_arr['common_recent_blog_title']	=	$this->LANG['common_recent_blog_title'];
				if($blog_user_id)
					{
						$this->displayRecentBlogs_arr['is_user']	=	$is_user = true;
						$this->displayRecentBlogs_arr['common_recent_blog_title']	=	$this->LANG['common_recent_blog_title'] = $this->LANG['blogs'];
					}
				$this->displayRecentBlogs_arr['recent_blogs']	=	$recent_blogs = $this->getRecentBlogs($limit,$blog_user_id);
				$this->displayRecentBlogs_arr['close']=$close;
				$have_blogs = false;

				if ($recent_blogs)
					{
						$this->displayRecentBlogs_arr['have_blogs']=1;
						$i = 0;
						$inc=0;
						$this->displayRecentBlogs_arr['row']=array();
						foreach($recent_blogs as $eachBlog)
						{
							$this->displayRecentBlogs_arr['row'][$inc]['blogDetails']	=	$blogDetails = $this->getBlogDetails($eachBlog);
							$this->displayRecentBlogs_arr['row'][$inc]['blogDetails']['image_id']	=	'blog';
							if (!$blogDetails)
								continue;
								$have_blogs = true;
							$i++;
							$this->displayRecentBlogs_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsEvenQuestion';
							if ($i%2)
								$this->displayRecentBlogs_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsOddQuestion';
							//$this->displayRecentBlogs_arr['row'][$inc]['displayProfileImage']	=	displayProfileImage($blogDetails, 'small');
							$this->displayRecentBlogs_arr['row'][$inc]['comment_plural']	=	$comment_plural = $this->LANG['common_total_comment'];
							$this->displayRecentBlogs_arr['row'][$inc]['view_plural']	=	$view_plural = $this->LANG['common_total_view'];

							if($blogDetails['total_comments'] != 1)
								$this->displayRecentBlogs_arr['row'][$inc]['comment_plural']	=	$comment_plural = $this->LANG['common_total_comments'];
							if($blogDetails['total_views'] != 1)
								$this->displayRecentBlogs_arr['row'][$inc]['view_plural']	=	$view_plural = $this->LANG['common_total_views'];
							$inc++;
						} //foreach

					if ($have_blogs)
						{
							$this->displayRecentBlogs_arr['blogs_url']	=	getBlogUrl('blogs');
							if($is_user)
								{
									$this->displayRecentBlogs_arr['userDetails']	=	$userDetails = $this->getUserDetails($blog_user_id);
									$uname = $userDetails['name'];
									$this->displayRecentBlogs_arr['blogs_url']	=	getBlogUrl('blogs','?uname='.$uname, '?uname='.$uname);
								}
						}
					}
				else
					{
						$this->displayRecentBlogs_arr['have_blogs']	=0;
					}
				$this->assignSmartyVariables();
				$this->displayRecentBlogs_arr['cur_url']	=	getCurrentUrl('true');

				$smartyObj->assign('displayRecentBlogs_arr', $this->displayRecentBlogs_arr);
				setTemplateFolder('root/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('recentBlogs.tpl');
			}

		/**
		 * To get recent forums
		 *
		 * @return void
		 * @access public
		 **/
		public function getRecentForums($limit = 5, $topic_user_id='')
			{
				$condition = '';
				if($topic_user_id)
					$condition = ' AND ft.user_id='.$topic_user_id;

				$sql = 'SELECT ft.topic_id FROM '.$this->CFG['db']['tbl']['forum_topics'].' AS ft'.
						' WHERE topic_status = \'Yes\''.$condition.
						' ORDER BY ft.topic_id DESC LIMIT 0,'.$limit;

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

				$recent_forums = array();
				while($row = $rs->FetchRow())
					{
						$recent_forums[] = $row['topic_id'];
					}
				return $recent_forums;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getForumDetails($forum_id)
			{
				$forumDetails = array();

				$sql = 'SELECT ft.forum_id, ft.topic_id, ft.forum_topic, ft.seo_title, ft.user_id, ft.total_response'.
						', ft.total_views, ft.last_post_user_id, ft.last_post_date, UNIX_TIMESTAMP(date_added) as date_added'.
						', u.'.$this->getUserTableField('user_id').' AS topic_user_id, u.'.$this->getUserTableField('name').' AS topic_user_name, u.'.$this->getUserTableField('display_name').' AS topic_user_display_name'.
						', u.'.$this->getUserTableField('image_path').' AS image_path, u.'.$this->getUserTableField('gender').' AS gender'.
						', u.'.$this->getUserTableField('user_id').' AS img_user_id, u.'.$this->getUserTableField('t_height').' AS t_height'.
						', u.'.$this->getUserTableField('t_width').' AS t_width, u.'.$this->getUserTableField('photo_server_url').' AS photo_server_url'.
						', u.'.$this->getUserTableField('s_width').' AS s_width, u.'.$this->getUserTableField('s_height').' AS s_height'.
						', u.'.$this->getUserTableField('photo_ext').' AS photo_ext, u.'.$this->getUserTableField('name').' AS name'.
						', u1.'.$this->getUserTableField('user_id').' AS last_user_id, u1.'.$this->getUserTableField('name').' AS last_user_name, u1.'.$this->getUserTableField('display_name').' AS last_user_display_name'.
						' FROM '.$this->CFG['db']['tbl']['forum_topics'].' AS ft'.
						' LEFT JOIN '.$this->CFG['db']['tbl']['users'].' AS u1 ON ft.last_post_user_id = u1.'.$this->getUserTableField('user_id').
						', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE ft.topic_id='.$this->dbObj->Param($forum_id).
						' AND ft.user_id = u.'.$this->getUserTableField('user_id').
						' AND u.'.$this->getUserTableField('usr_status').' = \'Ok\''.
						' AND topic_status = \'Yes\'';

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

				if ($rs->PO_RecordCount())
					{
						$forumDetails = $rs->FetchRow();
						if (!($forumDetails['title'] = $this->getForumTitle($forumDetails['forum_id'])))
							return false;
						$forumDetails['forum_link'] = '<a href="'.getForumsUrl('forumsresponses','?title='.$forumDetails['title'].'&amp;topic_title='.$forumDetails['seo_title'], $forumDetails['title'].'/'.$forumDetails['seo_title'].'/').'">'.wordWrapManual($forumDetails['forum_topic'], $this->CFG['admin']['forum']['line_length'], $this->CFG['admin']['forum']['short_length']).'</a>';
						$forumDetails['topic_user_name_link'] = '<a href="'.getMemberUrl($forumDetails['topic_user_name'], $forumDetails['topic_user_id']).'">'.stripString($forumDetails['topic_user_display_name'], $this->CFG['username']['medium_length']).'</a>';
					}
				return $forumDetails;
			}

		/**
		 * To display recent forums
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayRecentForums($limit = 5, $topic_user_id='', $close = NULL)
			{
				global $smartyObj;
				$this->displayRecentForums_arr=array();

				$this->displayRecentForums_arr['isUser']	=	$isUser = false;
				if($topic_user_id)
					{
						$this->displayRecentForums_arr['isUser']	=	$isUser = true;
						$this->LANG['common_recent_forum_title'] = $this->LANG['forums'];
					}
				$this->displayRecentForums_arr['recent_forums']	=	$recent_forums = $this->getRecentForums($limit, $topic_user_id);
				$this->displayRecentForums_arr['close']=$close;

				$have_forums = false;
  				$uname = '';
				if ($recent_forums)
					{
						$this->displayRecentForums_arr['have_forums']	=	1;
						$this->displayRecentForums_arr['row']=array();
						$i = 0;
						$inc=0;
						foreach($recent_forums as $eachForum)
							{
								$this->displayRecentForums_arr['row'][$inc]['forumDetails']	=	$forumDetails = $this->getForumDetails($eachForum);
								$this->displayRecentBlogs_arr['row'][$inc]['forumDetails']['image_id']	=	'forum';
								if (!$forumDetails)
									continue;
								$name = $forumDetails['topic_user_name'];
								$this->displayRecentForums_arr['have_forums']	=	$have_forums = true;
								$i++;

								$this->displayRecentForums_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsEvenQuestion';
								if ($i%2)
									$this->displayRecentForums_arr['row'][$inc]['clsOddOrEvenQuestion']	=	$clsOddOrEvenQuestion = 'clsOddQuestion';

								$this->displayRecentForums_arr['row'][$inc]['resp_plural']	=	$resp_plural = $this->LANG['common_total_response'];
								$this->displayRecentForums_arr['row'][$inc]['view_plural']	=	$view_plural = $this->LANG['common_total_view'];

								if($forumDetails['total_response'] != 1)
									$this->displayRecentForums_arr['row'][$inc]['resp_plural']	=	$resp_plural = $this->LANG['common_total_responses'];
								if($forumDetails['total_views'] != 1)
									$this->displayRecentForums_arr['row'][$inc]['view_plural']	=	$view_plural = $this->LANG['common_total_views'];
								$forumDetails['image_id'] = 'drf';
								$inc++;
							} //foreach
							if ($have_forums)
								{
									if($isUser)
										{
											$this->displayRecentForums_arr['forumsearch_url']	=	getForumsUrl('forumsearch','?uname='.$name, '?uname='.$name);
										}
								}

						}
					else
					{
						$this->displayRecentForums_arr['have_forums']	=	0;
					}
					$this->assignSmartyVariables();
					$smartyObj->assign('displayRecentForums_arr', $this->displayRecentForums_arr);
					setTemplateFolder('root/', $this->CFG['admin']['index']['anova_module']);
					$smartyObj->display('recentForums.tpl');
			}
		/**
		* 	 UpdateProfileViews()
		*
		*/
		public function updateProfileViews()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
						' SET profile_views=profile_views+1 WHERE user_id='.$this->dbObj->Param('uid');

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

		/**
		* @return 		void
		* @access 		public
		*/
		public function showUserStatistics()
			{
				if (!$this->isShowPageBlock('form_user_details'))
					return ;
				global $smartyObj;
				$smartyObj->assign('userDetails_arr', $this->form_user_details['displayUserDetails']);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('userStatistics.tpl');
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayDebates($debates_type, $limit=5)
			{
				$Widget = new Widget();
				return $this->form_recent_debates['displayRecentDebates']	=	$Widget->displayRecentDebates($limit, $this->fields_arr['uid'], $debates_type);
			}

		public function getAnonymousTwitterUserId()
			{
				$sql = ' SELECT  user_id  FROM '.$this->CFG['db']['tbl']['users'].''.
						' WHERE name =\''.$this->CFG['user']['not_allowed'].'\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				$row = $rs->FetchRow();
				if($row)
					return $row['user_id'];
			}
	}
//<<<<<-------------- Class MyAnswerFormHandler begins ---------------//
//-------------------- Code begins -------------->>>>>//
$myanswers = new MyAnswerFormHandler();
$myanswers->setPageBlockNames(array('form_user_details', 'form_points', 'form_answer_details', 'block_badge_embed', 'twitter_user'));
//default form fields AND values...
$myanswers->setFormField('search_question', '');
$myanswers->setFormField('msg', '');
$myanswers->setFormField('list', '');
$myanswers->setFormField('nameofuser', '');
$myanswers->setFormField('doj', '');
$myanswers->setFormField('uid', '');
$myanswers->setFormField('name', '');
$myanswers->setFormField('show', '');
if ($CFG['user']['user_id'])
	$myanswers->setFormField('uid', $CFG['user']['user_id']);
$pagename = $LANG['common_my_answered_question_header'];
$myanswers->display_bold = 3;
//$myanswers->setDBObject($db);
/*************Start navigation******/
$myanswers->numpg = $CFG['data_tbl']['numpg'];
$myanswers->setFormField('start', 0);
$myanswers->setFormField('numpg', $CFG['data_tbl']['numpg']);//$CFG['data_tbl']['numpg']
$myanswers->setMinRecordSelectLimit($CFG['data_tbl']['min_record_select_limit']);
$myanswers->setMaxRecordSelectLimit($CFG['data_tbl']['max_record_select_limit']);
$myanswers->setNumPerPageListArr($CFG['data_tbl']['numperpage_list_arr']);
//Set tables AND fields to return
$myanswers->setTableNames(array());
$myanswers->setReturnColumns(array());
//orderby field AND orderby
$myanswers->setFormField('orderby_field', '');
$myanswers->setFormField('orderby', '');
/*************End navigation******/
$myanswers->sanitizeFormInputs($_REQUEST);
// Default page block
$myanswers->setAllPageBlocksHide();
$twit_id = $myanswers->getAnonymousTwitterUserId();
$myanswers->showVideoAudio = false;
if(($CFG['admin']['module']['video_audio_blogsforum']) && (chkVideoModuleAllowed('blogcomment') || chkExternalVideoModuleAllowed('blogcomment') || chkAudioModuleAllowed('blogcomment') || chkExternalAudioModuleAllowed('blogcomment')))
	{
		$myanswers->showVideoAudio = true;
	}

$title = $LANG['common_my_answered_question_header'];
if ($myanswers->chkIsValidUser())
	{
		if ($myanswers->isFormPOSTed($_REQUEST, 'show'))
			{
				switch($myanswers->getFormField('show')){
					case 'selAskedQuestions':
						$myanswers->selAskedQuestions['displayAskedQuestions'] = $myanswers->displayAskedQuestions(3);
						break;
					case 'selFavoriteQuestions':
						$myanswers->selFavoriteQuestions['displayFavoriteQuestions'] = $myanswers->displayFavoriteQuestions(3);
						break;
					case 'selSubscribedUsers':
						$myanswers->form_answer_details['displayAnswerDetails'] = $myanswers->displaySubscribedUsers(3);
						break;
					case 'selSubscribedForums':
						$myanswers->form_answer_details['displayAnswerDetails'] = $myanswers->displaySubscribedForums(5);
						break;
					case 'selForums':
						$myanswers->displayForums(5);
						exit;
						break;
					case 'selBlogs':
						$myanswers->displayBlogs(5);
						exit;
						break;
					/*case 'selDebates':
						$myanswers->displayDebates('MyDebates',5);
						break;
					case 'selResponsedDebates':
						$myanswers->form_answer_details['displayDebates']	=	$myanswers->displayDebates('MyResponse',5);
						break;
					case 'selFavoriteDebates':
						$myanswers->form_answer_details['displayDebates']	=	$myanswers->displayDebates('MyFavorites',5);
						break;*/
				} // switch

				$myanswers->includeAjaxHeader();
				setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
				$smartyObj->display('myanswersAjax.tpl');
				$myanswers->includeAjaxFooter();
				die();
			}
		if ($myanswers->getFormField('uid') == $CFG['user']['user_id'])
			{
				$myanswers->setPageBlockShow('block_badge_embed');
			}
		else
			{
				$title = ucwords($myanswers->getFormField('nameofuser')).' '.$LANG['answers'];
			}
		if ($myanswers->getFormField('uid') != $CFG['user']['user_id']){
			$myanswers->updateProfileViews();
		}
		$myanswers->setPageBlockShow('form_answer_details');
		$myanswers->setPageBlockShow('form_points');
		$myanswers->setPageBlockShow('form_user_details');
	}
if(($myanswers->getFormField('uid')==$CFG['user']['not_allowed']) || $myanswers->getFormField('uid')==$twit_id )
	{
		$myanswers->setAllPageBlocksHide();
		$myanswers->setPageBlockShow('twitter_user');
	}	
$cfg_title = $title.' - ';
$myanswers->mtanswersCommon['title'] = $title;
//--------------------Page block templates begins-------------------->>>>>//
$CFG['site']['title'] = $cfg_title.$CFG['site']['title'];
if ($myanswers->isShowPageBlock('form_user_details'))
	{
		$myanswers->form_user_details['displayUserDetails'] = $myanswers->displayUserDetails();
	}
if ($myanswers->isShowPageBlock('form_answer_details'))
	{
		$myanswers->form_answer_details['displayAnswerDetails'] = $myanswers->displayAnswerDetails();
		$myanswers->form_answer_details['forums_arr'] = array('forums');
		$myanswers->form_answer_details['blog_arr'] = array('blog');
	}
//include the header file
$myanswers->includeHeader();
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('myanswers.tpl');
//includ the footer of the page
?>
<script type="text/javascript" language="javascript">
var ajax_url = '<?php echo getAnovaUrl('myanswers', '?uid='.$myanswers->getFormField('name'), $myanswers->getFormField('name').'/');?>';
var hideBlocks = function()
	{
		for(var i=0;i<arguments.length;i++)
			{
				var objName = arguments[i];
				var liName = objName+'LI';
				var spanName = objName+'SPAN';
				var aName = objName+'A';
				if(obj = $(objName))
					{
						obj.style.display = 'none';
						$(liName).className="clsLeftInActiveQuestionsLink";
						$(spanName).className="clsRightInActiveQuestionsLink";
						$(aName).className="clsMiddleInActiveQuestionsLink";
					}
			}
	}
var showBlocks = function()
	{
		for(var i=0;i<arguments.length;i++)
			{
				var objName = arguments[i];
				var liName = objName+'LI';
				var spanName = objName+'SPAN';
				var aName = objName+'A';
				if(obj = $(objName))
					{
						obj.style.display = '';
						$(liName).className="clsLeftActiveQuestionsLink";
						$(spanName).className="clsRightActiveQuestionsLink";
						$(aName).className="clsMiddleActiveQuestionsLink";
					}
			}
	}
var showBlockAsFirst = function()
	{
		var objName = arguments[0];
		var liName = objName+'LI';
		$(liName).className="clsFirstQuestionLink clsLeftActiveQuestionsLink";
	}
function toggleTabsShowHide()
	{
		if($('myAnswersShortList').style.display=='')
			{
				$('myAnswersShortList').style.display='none';
			}
		else
			{
				$('myAnswersShortList').style.display='';
			}
		return false;
	}
</script>
<?php
//<<<<<<--------------------Page block templates Ends--------------------//
$myanswers->includeFooter();
?>