<?php
/**
 * HeaderFormHandler
 *
 * @package
 * @author Senthil
 * @copyright Copyright (c) 2010
 * @version $Id$
 * @access public
 */
class HeaderFormHandler extends HeaderHandler
	{
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getHeaderQuestionDetails($question_table, $cat_table)
		    {
				if (!$this->fields_arr['title'])
					return ;
				//Query to display recent and popular questions
				$sql = 'SELECT q.ques_id, q.pcat_id, q.cat_id FROM '.$question_table.' AS q'.
						' WHERE q.status IN (\'Open\', \'Resolved\') AND q.seo_title='.$this->dbObj->Param('title');

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

				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						$this->fields_arr['cat_id'] = $row['cat_id'];
						$this->fields_arr['parent_id'] = $row['pcat_id'];
					}
		    }

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getCategoryDetails($cat_table)
		    {
				$sql = 'SELECT cat_id, cat_name, parent_id FROM '.$cat_table.
						' WHERE seo_title='.$this->dbObj->Param('cat').
						' AND status=\'1\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['cat']));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						$this->fields_arr['parent_id'] = 0;
						$this->fields_arr['cat_id'] = $row['cat_id'];
						if ($row['parent_id'] > 0)
							$this->fields_arr['parent_id'] = $row['parent_id'];
					}
		    }

		/**
		 * HeaderFormHandler::chooseLang()
		 *
		 * @param mixed $lang
		 * @return
		 */
		public function chooseLang($lang)
			{
			   $url = getCurrentUrl().'?lang='.$lang;
			   return $url;
			}

		/**
		 * HeaderFormHandler::chooseStyle()
		 *
		 * @param mixed $style
		 * @return
		 */
		public function chooseStyle($style)
			{
				//Have fixed querystring issue while changing the style
				$url = getCurrentUrl(true);
				if(strstr($url, 'template'))
					{
						$request_arr = $_REQUEST;
						$url_no_par = getCurrentUrl();

						foreach($request_arr as $key => $value)
							{
								if(strstr($url, $key))
									{
										if($key == 'template')
											{
												if(strstr($url_no_par, '?'))
													$url_no_par .= '&template='.$style;
												else
													$url_no_par .= '?template='.$style;
											}
										else
											{
												if(strstr($url_no_par, '?'))
													$url_no_par .= '&'.$key.'='.$value;
												else
													$url_no_par .= '?'.$key.'='.$value;
											}
									}
							}
						if($url_no_par != getCurrentUrl())
							return $url_no_par;

					}
				if(strstr($url, '?'))
					$url .= '&template='.$style;
				else
					$url .= '?template='.$style;
				return $url;
			}

		/**
		 * To get the user details from the DB
		 *
		 * @param 		string $table_name table name
		 * @param 		array $fields_arr Array of fields
		 * @param 		integer $user_id user id
		 * @return 		array has array with field values
		 * @access 		public
		 */
		public function getUserDetailsArrFromDB($table_name, $fields_arr=array(), $user_id)
			{
				$sql = 'SELECT ';
				foreach($fields_arr as $field_name)
						$sql .= $field_name . ', ';
				$sql = substr($sql, 0, strrpos($sql, ','));
				$sql .= ' FROM '.$table_name.
						' WHERE user_id='.$this->dbObj->Param($user_id);

				// prepare sql
				$stmt = $this->dbObj->Prepare($sql);
				// execute sql
				$rs = $this->dbObj->Execute($stmt, array($user_id));
				//raise user error... fatal
				if (!$rs)
						trigger_db_error($this->dbObj);

				$row = array();
				if ($rs->PO_RecordCount())
						$row = $rs->FetchRow();
				$ret_fields_arr = array();
				foreach($fields_arr as $field_name)
					$ret_fields_arr[$field_name] = isset($row[$field_name]) ? $row[$field_name] : '';
				return $ret_fields_arr;
			}

		/**
		 * HeaderFormHandler::populateTopMenu()
		 *
		 * @return
		 */
		public function populateTopMenu()
			{
				global $smartyObj;
				$populateTopMenu_arr = array();
				$currentPage = $this->CFG['html']['current_script_name'];
				$cssClassToMainLink = 'clsActiveHeaderMainLink';
				$cssClassToHighlightMainLink = 'clsActiveLink clsHighlightHeaderLink';
				$populateTopMenu_arr['forums']['class'] = $populateTopMenu_arr['blogs']['class'] = $populateTopMenu_arr['debate']['class'] = $populateTopMenu_arr['mail']['class'] = $populateTopMenu_arr['login']['class'] = $populateTopMenu_arr['payment']['class'] = $populateTopMenu_arr['logout']['class'] = $cssClassToMainLink;
				$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
				$$currentPage = $cssClassToHighlightMainLink;

				$ans_page_arr = array('questions', 'answer', 'categories', 'tags');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('forums', 'forumsAddTitle', 'forumsTopics', 'forumsTopicCreate', 'forumsResponses', 'forumsResponseCreate', 'forumSearch');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['forums']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('blogs', 'blogCategory', 'blogComment', 'manageBlog');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['blogs']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('mail', 'mailCompose', 'mailRead');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['mail']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('login', 'devLogin');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['login']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('debates', 'debatesResponse','debateCategories','debateTags');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['debate']['class'] = $cssClassToHighlightMainLink;
					}

				$ans_page_arr = array('paymentUpgrade');
				if(in_array($currentPage, $ans_page_arr))
					{
						$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
						$populateTopMenu_arr['payment']['class'] = $cssClassToHighlightMainLink;
					}

				$populateTopMenu_arr['questions']['url'] = getAnovaUrl('questions');
				$populateTopMenu_arr['forums']['url'] = getForumsUrl('forums');
				$populateTopMenu_arr['blogs']['url'] = getBlogUrl('blogs');
				$populateTopMenu_arr['debate']['url'] = getDebatesUrl('debates','?view=open&sort=date&order=d','?sort=date&order=d');
				$populateTopMenu_arr['mail']['url'] = getUrl('mail', '?folder=inbox', 'inbox/', 'members');
				$populateTopMenu_arr['login']['url'] = getUrl('login', '', '', 'root');
				$populateTopMenu_arr['logout']['url'] = getUrl('logout', '', '', 'root');
				$populateTopMenu_arr['payment']['url'] = getAnovaUrl('paymentupgrade', '', '', 'members');

				if ($this->CFG['user']['user_id'])
					{
						$populateTopMenu_arr['profile']['url'] = getAnovaUrl('forums');
						$populateTopMenu_arr['settings']['url'] = getAnovaUrl('forums');
						$populateTopMenu_arr['userLog'] = $this->getUserLog($this->CFG['user']['user_id']);
						$populateTopMenu_arr['userLevelNumber'] = '';
						if($this->CFG['admin']['user_levels']['allowed'])
							$populateTopMenu_arr['userLevelNumber'] = getUserLevelNumber($populateTopMenu_arr['userLog']['total_points']);
					}

				$smartyObj->assign('populateTopMenu_arr', $populateTopMenu_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('populateTopMenu.tpl');
			}

		/**
		 * HeaderFormHandler::rightBarSettings()
		 *
		 * @param mixed $pagingarr
		 * @return
		 */
		public function rightBarSettings($pagingarr)
		  	{

		  		if($this->CFG['admin']['index']['right_bar_anova'])
		  			$this->getAnovaModuleRightMenu();

				if(chkIsAllowedModule(array('debate')))
					$allowed_pages_array = array('debates.php', 'debatesResponse.php', 'debateCategories.php','debateTags.php');
				else
					$allowed_pages_array =array();

				if(displayBlock($allowed_pages_array))
					$sql = ' SELECT * from '.$this->CFG['db']['tbl']['rightbar_settings'].' WHERE type=\'Debate\' OR type=\'Common\' ORDER BY debate_order_value ASC';
				else
					$sql = ' SELECT * from '.$this->CFG['db']['tbl']['rightbar_settings'].' WHERE type=\'Answer\' OR type=\'Common\' ORDER BY order_value ASC';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
				        trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow()) {
							if($row['title'] == 'unanswered_question' AND $this->CFG['admin']['rightbar']['unanswered_question'])
								{
									$this->getUnansweredQuestion($this->CFG['db']['tbl']['questions'], $this->CFG['admin']['index']['question_limit']);
								}
							elseif($row['title'] == 'question_library' AND $this->CFG['admin']['rightbar']['library'])
							 	{
									 $this->populateAlphabetPagingList($pagingarr);
								}
							elseif($row['title'] == 'categories' AND $this->CFG['admin']['rightbar']['categories'])
							 	{
									$this->getAllCategories($this->CFG['db']['tbl']['questions_category'], $this->CFG['admin']['index']['category_limit'], 'total_questions');
								}
							elseif($row['title'] == 'top_tags' AND $this->CFG['admin']['rightbar']['top_tags'])
							 	{
									$this->showTopTags();
								}
							elseif($row['title'] == 'debates_categories')
							 	{
									if($this->CFG['admin']['rightbar']['debates_categories'] )
										$this->getAllCategories($this->CFG['db']['tbl']['questions_category'], $this->CFG['admin']['index']['category_limit'], 'total_debates');
								}
							elseif($row['title'] == 'top_tags')
							 	{
									if($this->CFG['admin']['rightbar']['top_tags'])
			 							$this->showTopTags();
								}
							elseif($row['title'] == 'top_searched_tags')
							 	{
									 if($this->CFG['admin']['rightbar']['top_searched_tags'])
										$this->showTopSearchedTags();
								}
							elseif($row['title'] == 'featured_debates')
							 	{
									if($this->CFG['admin']['rightbar']['featured_debates'])
			 							$this->showFeaturedDebates($this->CFG['db']['tbl']['users'],$this->CFG['db']['tbl']['debates'],$this->CFG['admin']['index']['featured_debates_limit'], $this->LANG['featured_debates']);
								}
							elseif($row['title'] == 'debates_top_tags')
							 	{
									if($this->CFG['admin']['rightbar']['debates_top_tags'])
			 							$this->showTopDebateTags();
								}

							elseif($row['title'] == 'debates_top_searched_tags')
							 	{
									 if($this->CFG['admin']['rightbar']['debates_top_searched_tags'])
										$this->showTopSearchedDebateTags();
								}
						}
					}
			}

		/**
		 * HeaderFormHandler::chkRightBarSettings()
		 *
		 * @return
		 */
		public function chkRightBarSettings()
			{
				if(!$this->CFG['admin']['rightbar']['top_tags'] AND
				   !$this->CFG['admin']['rightbar']['categories'] AND
				   !$this->CFG['admin']['rightbar']['library'] AND
				   !$this->CFG['admin']['rightbar']['unanswered_question'])
				   		return true;
				else
					return false;

			}

		/**
		 * To show answers search option
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showAnswerSearchOption()
			{
				$not_allowed_pages_array = array('blogCategory.php', 'blogComment.php',
				                                 'blogs.php', 'manageBlog.php', 'topAnalysts.php',
												 'forums.php', 'forumsResponses.php', 'forumsTopics.php',
												 'forumsResponseCreate.php', 'forumSearch.php', 'forumsTopicCreate.php',
												 'mySubscribedForum.php', 'forumsAddTitle.php', 'debates.php',
												 'debatesResponse.php', 'debateCategories.php', 'debateTags.php');

				if(displayBlock($not_allowed_pages_array))
					return;

				global $smartyObj;
				$showAnswerSearchOption_arr = array();

				if($this->getFormField('more_questions'))
					{
						if(isset($_SESSION['more_questions']) && $this->_currentPage == 'questions')
							$showAnswerSearchOption_arr['question_field_value'] = $_SESSION['more_questions'];
					}
				else if($this->getFormField('search_question'))
					{
						if(isset($_SESSION['search_question']) && $this->_currentPage == 'questions')
							$showAnswerSearchOption_arr['question_field_value'] = $_SESSION['search_question'];
						else
							{
								$showAnswerSearchOption_arr['question_field_value'] = $this->LANG['header_search_for_questions'];
							}
					}
				else
					$showAnswerSearchOption_arr['question_field_value'] = $this->LANG['header_search_for_questions'];

				$showAnswerSearchOption_arr['defaultText'] = $this->LANG['header_search_for_questions'];

				$showAnswerSearchOption_arr['form_action'] = getAnovaUrl('questions', '?view=search', 'search/');
				$showAnswerSearchOption_arr['advanced_search']['url'] = getAnovaUrl('questions', '?so=adv&amp;view=search', 'search/?so=adv');

				$smartyObj->assign('showAnswerSearchOption_arr', $showAnswerSearchOption_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('showAnswerSearchOption.tpl');
			}

		/**
		 * To show debate search obtion
		 * @return 		void
		 * @access 		public
		 */
		public function showDebateSearchOption()
			{
				$allowed_pages_array = array('debates.php', 'debatesResponse.php',
				                             'debateCategories.php', 'debateTags.php');
				if(!displayBlock($allowed_pages_array))
					return;

				global $smartyObj;
				$showDebateSearchOption_arr = array();

				if($this->getFormField('more_debates'))
					{
						if(isset($_SESSION['more_debates']) && $this->_currentPage == 'debates')
							$showDebateSearchOption_arr['debate_field_value'] = $_SESSION['more_debates'];
					}
				elseif($this->getFormField('search_debate'))
					{
						if(isset($_SESSION['search_debate']) && $this->_currentPage == 'debates')
							$showDebateSearchOption_arr['debate_field_value'] = $_SESSION['search_debate'];
						else
							{
								$showDebateSearchOption_arr['debate_field_value'] = $this->LANG['search_for_debates'];
							}
					}
				else
					$showDebateSearchOption_arr['debate_field_value'] = $this->LANG['search_for_debates'];
				$showDebateSearchOption_arr['defaultText'] = strtolower($this->LANG['search_for_debates']);

				$showDebateSearchOption_arr['form_action'] = getDebatesUrl('debates', '?view=search', 'search/');
				$showDebateSearchOption_arr['advanced_search']['url']= getDebatesUrl('debates', '?so=adv&view=search', 'search/?so=adv');

				$smartyObj->assign('showDebateSearchOption_arr', $showDebateSearchOption_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('showDebateSearchOption.tpl');

			}
		/**
		 * To show forums search option
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showForumsSearchOption()
			{
				$allowed_pages_array = array('forums.php', 'forumsResponses.php', 'forumsResponseCreate.php', 'forumsAddTitle.php',
											 'forumSearch.php', 'forumsTopics.php', 'forumsTopicCreate.php', 'mySubscribedForum.php');

				if(!displayBlock($allowed_pages_array))
					return;

				global $smartyObj;
				$showForumsSearchOption_arr = array();

				if($this->getFormField('forum_topic'))
					{
						if(isset($_SESSION['forum_topic']) && $this->_currentPage == 'forumsearch')
							$showForumsSearchOption_arr['forum_field_value'] = $_SESSION['forum_topic'];
					}
				else if($this->getFormField('search_forum_topic'))
					{
						if(isset($_SESSION['search_forum_topic']) && $this->_currentPage == 'forumsearch')
							{
								$showForumsSearchOption_arr['forum_field_value'] = $_SESSION['search_forum_topic'];
							}
						else
							{
								$showForumsSearchOption_arr['forum_field_value'] = $this->LANG['header_search_for_forum_topics'];
							}
					}
				else
					$showForumsSearchOption_arr['forum_field_value'] = $this->LANG['header_search_for_forum_topics'];

				$showForumsSearchOption_arr['defaultText'] = $this->LANG['header_search_for_forum_topics'];

				$showForumsSearchOption_arr['form_action'] = getForumsUrl('forumsearch');
				$showForumsSearchOption_arr['advanced_search']['url'] = getForumsUrl('forumsearch', '?so=adv', '?so=adv');

				$smartyObj->assign('showForumsSearchOption_arr', $showForumsSearchOption_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['forum_module']);
				$smartyObj->display('showForumsSearchOption.tpl');
			}

		/**
		 * To show blogs search option
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showBlogsSearchOption()
			{
				$allowed_pages_array = array('blogCategory.php', 'blogComment.php',
				                             'blogs.php', 'manageBlog.php');

				if(!displayBlock($allowed_pages_array))
					return;

				global $smartyObj;
				$showBlogsSearchOption_arr = array();
				if($this->getFormField('subject'))
					{
						if(isset($_SESSION['subject']) && $this->_currentPage == 'blogs')
							$showBlogsSearchOption_arr['blog_field_value'] = $_SESSION['subject'];
					}
				else if($this->getFormField('search_blog_subject'))
					{
						if(isset($_SESSION['search_blog_subject']) && $this->_currentPage == 'blogs')
							{
								$showBlogsSearchOption_arr['blog_field_value'] = $_SESSION['search_blog_subject'];
							}
						else
							{
								$showBlogsSearchOption_arr['blog_field_value'] = $this->LANG['header_search_for_blog_subject'];
							}
					}
				else
					$showBlogsSearchOption_arr['blog_field_value'] = $this->LANG['header_search_for_blog_subject'];

				$showBlogsSearchOption_arr['defaultText'] = $this->LANG['header_search_for_blog_subject'];
				$showBlogsSearchOption_arr['form_action'] = getBlogUrl('blogs');
				$showBlogsSearchOption_arr['advanced_search']['url'] = getBlogUrl('blogs', '?so=adv', '?so=adv');

				$smartyObj->assign('showBlogsSearchOption_arr', $showBlogsSearchOption_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['blog_module']);
				$smartyObj->display('showBlogsSearchOption.tpl');
			}

		/**
		 * HeaderFormHandler::showMemberSearchOption()
		 *
		 * @return
		 */
		public function showMemberSearchOption()
			{
				$allowed_pages_array = array('topAnalysts.php');

				if(!displayBlock($allowed_pages_array))
					return;

				global $smartyObj;
				$showMemberSearchOption_arr = array();

				if($this->getFormField('search_member'))
					$showMemberSearchOption_arr['question_field_value'] = $this->getFormField('search_member');
				else
					$showMemberSearchOption_arr['question_field_value'] = $this->LANG['header_search_for_members'];

				$showMemberSearchOption_arr['defaultText'] = $this->LANG['header_search_for_members'];
				$showMemberSearchOption_arr['form_action'] = getAnovaUrl('topanalysts');
				$showMemberSearchOption_arr['advanced_search']['url'] = getAnovaUrl('topanalysts', '?so=adv', '?so=adv');

				$smartyObj->assign('showMemberSearchOption_arr', $showMemberSearchOption_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('showMemberSearchOption.tpl');
			}

		/**
		 * HeaderFormHandler::getUnansweredQuestion()
		 *
		 * @param mixed $question_table
		 * @param mixed $limit
		 * @return
		 */
		public function getUnansweredQuestion($question_table, $limit)
			{
				global $smartyObj;
				$getUnansweredQuestion_arr = array();
				$sql = 'SELECT ques_id, user_id, question, seo_title FROM '.$question_table.
					   ' WHERE total_answer = 0 '.
					   ' AND (status = \'Open\' OR status = \'Resolved\') ORDER BY RAND()';
				if ($limit)
					$sql .= ' LIMIT 0,'.($limit + 1);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$getUnansweredQuestion_arr['count'] = $rs->PO_RecordCount();
				if ($count = $rs->PO_RecordCount())
					{
						$i = $inc = 1;
						$getUnansweredQuestion_arr['row'] = array();
						while($row = $rs->FetchRow())
							{
								$getUnansweredQuestion_arr['row'][$inc]['record'] = $row;
								$getUnansweredQuestion_arr['row'][$inc]['answer']['url'] = getAnovaUrl('answer', '?title='.$row['seo_title'], $row['seo_title'].'/');
								$getUnansweredQuestion_arr['row'][$inc]['row_question_manual'] = stripString($row['question']);

								$inc++;
                      			if ($i++ >= $limit)
									break;
							}
					}
				$getUnansweredQuestion_arr['unanswered_questions']['url'] = getAnovaUrl('questions', '?view=unanswered', 'unanswered/');

				$smartyObj->assign('getUnansweredQuestion_arr', $getUnansweredQuestion_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('getUnansweredQuestion.tpl');
			}

		/**
		 * HeaderFormHandler::getAnovaModuleMenu()
		 *
		 * @param mixed $question_table
		 * @param mixed $limit
		 * @return
		 */
		public function getAnovaModuleRightMenu()
			{
				global $smartyObj;

				$populateAlphabetPagingList_arr = array();

				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['answer']['manual'] = 'Answers';
				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['answer']['url'] = getAnovaUrl('questions');

				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['forums']['manual'] = 'Forums';
				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['forums']['url'] = getForumsUrl('forums');

				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['blog']['manual'] = 'Blogs';
				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['blog']['url'] = getBlogUrl('blogs');

				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['debate']['manual'] = 'Debates';
				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['debate']['url'] = getDebatesUrl('debates','?view=open&sort=date&order=d','?sort=date&order=d');

				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['inbox']['manual'] = 'Inbox';
				$getAnovaModuleRightMenu_arr['anova_module_right_menu']['inbox']['url'] = getUrl('mail', '?folder=inbox', 'inbox/', 'members');

				$smartyObj->assign('getAnovaModuleRightMenu_arr', $getAnovaModuleRightMenu_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('rightBarAnova.tpl');
			}

		/**
		 * HeaderFormHandler::populateAlphabetPagingList()
		 *
		 * @param mixed $paging_list_arr
		 * @return
		 */
		public function populateAlphabetPagingList($paging_list_arr)
			{
				global $smartyObj;
				$populateAlphabetPagingList_arr = array();
				$inc = 1;
				foreach($paging_list_arr as $key=>$value)
					{
						$populateAlphabetPagingList_arr[$inc]['alphaUrl'] = getAnovaUrl('questions', '?view=all&amp;al='.$key, 'open/?al='.$key);
						$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = '';
						if ($this->fields_arr['al'] == $value)
							$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = ' class="clsActiveQuestionLib"';
						elseif ($this->fields_arr['al'] == 1 AND $value == '#')
							$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = ' class="clsActiveQuestionLib"';

						$populateAlphabetPagingList_arr[$inc]['value'] = $value;
						$inc++;
					}

				$smartyObj->assign('populateAlphabetPagingList_arr', $populateAlphabetPagingList_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('populateAlphabetPagingList.tpl');
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getAllCategories($cat_table, $limit, $for)
		    {
		    	global $smartyObj;
		    	$getAllCategories_arr = array();
		    	if($for == 'total_debates')
					{
						$allowed_pages_array = array('debates.php', 'debatesResponse.php', 'debateCategories.php','debateTags.php');
						if(!displayBlock($allowed_pages_array))
							return;
					}
				$sql = 'SELECT cat_id, cat_name, seo_title, has_child, '.$for.' FROM '.$cat_table.
						' WHERE status=\'1\''.
						' AND parent_id=0'.
						' ORDER BY '.$for.' DESC';
				if ($limit)
					$sql .= ' LIMIT 0,'.($limit + 1);

				$parent_id = 0;
				$cat_id = 0;
				if ($this->fields_arr['parent_id'])
					{
						$parent_id = $this->fields_arr['parent_id'];
						$cat_id = $this->fields_arr['cid'];
					}
				elseif ($this->fields_arr['cat_id'])
					{
						$parent_id = $this->fields_arr['cat_id'];
					}

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

				$getAllCategories_arr['rs_PO_RecordCount'] = $rs->PO_RecordCount();
				$getAllCategories_arr['parent_id'] = $parent_id;
				if ($count = $rs->PO_RecordCount())
					{
						$i=1;
						$inc = 1;
						$getAllCategories_arr['row'] = array();
						while($row = $rs->FetchRow())
							{
								$getAllCategories_arr['row'][$inc]['record'] = $row;
								$getAllCategories_arr['row'][$inc]['class'] = 'clsInactive';
								if ($parent_id == $row['cat_id'])
									$getAllCategories_arr['row'][$inc]['class'] = 'clsActive';

								$getAllCategories_arr['row'][$inc]['clsDropDown'] = '';
								if ($row['has_child'] == '1')
									$getAllCategories_arr['row'][$inc]['clsDropDown'] = 'class="clsDropDown"';

								if($for == 'total_questions')
					  				$getAllCategories_arr['row'][$inc]['questions_category']['url'] = getAnovaUrl('questions', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');
					  			elseif($for == 'total_debates')
									$getAllCategories_arr['row'][$inc]['questions_category']['url'] = getDebatesUrl('debates', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');

								$getAllCategories_arr['row'][$inc]['row_cat_name_manual'] = stripString($row['cat_name']);


								if ($parent_id == $row['cat_id'])
									{
										$getAllCategories_arr['row'][$inc]['getAllSubCategories_arr'] = $this->getAllSubCategories($cat_table, $parent_id, $cat_id, $for);
									}
								$inc++;
                      			if ($i++ >= $limit)
                      				break;
							}
					}
				if($for == 'total_debates')
					$getAllCategories_arr['categories']['url'] = getAnovaUrl('debatecategories');
				else
					$getAllCategories_arr['categories']['url'] = getAnovaUrl('categories');

				$smartyObj->assign('getAllCategories_arr', $getAllCategories_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				if($for == 'total_debates')
					$smartyObj->display('getAllDebateCategories.tpl');
				else
					$smartyObj->display('getAllCategories.tpl');
		    }

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showTopTags()
			{
				if ($this->CFG['admin']['index']['top_tags'])
					{
						global $smartyObj;
						$showTopTags_arr = array();
						$showTopTags_arr['displayTopTags_arr'] = $this->displayTopTags($this->CFG['admin']['index']['top_tags_count']);

						$smartyObj->assign('showTopTags_arr', $showTopTags_arr);
						setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
						$smartyObj->display('showTopTags.tpl');
					}
			}

		/**
		 * To display popular tags
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayTopTags($limit = 5)
			{
				$displayTopTags_arr = array();
				$top_tags = $this->getTags('TOP', $limit);
				$displayTopTags_arr['top_tags'] = $top_tags;

					if ($top_tags)
						{
							$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
							$tagClassArray = array();
							foreach($top_tags as $row)
								{
									$tagArray[$row['tag_name']] = $row['total_count'];
									$class = $classes[rand(0, count($classes))%count($classes)];
									$tagClassArray[$row['tag_name']] = $class;
								}
							$tagArray = $this->setFontSizeInsteadOfSearchCount($tagArray);

							$displayTopTags_arr['tag_arr'] = array();
							$inc = 1;
							foreach($tagArray as $tag=>$fontSize)
								{
									$displayTopTags_arr['tag_arr'][$inc]['questions_tag']['url'] = getAnovaUrl('questions', '?view=search&amp;tags='.$tag, 'search/?tags='.$tag);
									$displayTopTags_arr['tag_arr'][$inc]['class']	=	'clsTagStyleFont'.$fontSize;
									$displayTopTags_arr['tag_arr'][$inc]['tag'] = $tag;
									$inc++;
								}//foreach

                    		$displayTopTags_arr['tags']['url'] = getAnovaUrl('tags', '?t=freq&amp;s=f', '?t=freq&amp;s=f');
						}
				return $displayTopTags_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getTags($type, $limit)
			{
				$sql = 'SELECT tag_name, search_count, total_count FROM '.$this->CFG['db']['tbl']['tags'];
				if ($type == 'SEARCH')
					$sql .= ' WHERE search_count>0 AND total_count>0 ORDER BY search_count DESC';
				else
					$sql .= ' WHERE total_count>0 ORDER BY total_count DESC';

				$sql .= ' LIMIT 0,'.$limit;

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

				$tagArray = array();
				if ($rs->PO_RecordCount())
					{
				        while($row = $rs->FetchRow())
				            {
				            	$tagArray[] = $row;
							}
					}
				return $tagArray;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showTopDebateTags()
			{
				if ($this->CFG['admin']['index']['top_tags'])
					{
						global $smartyObj;
						$showTopDebateTags_arr = array();
						$showTopDebateTags_arr['displayTopTags_arr'] = $this->displayTopDebateTags($this->CFG['admin']['index']['top_tags_count']);
						$smartyObj->assign('displayTopDebateTags_arr',$showTopDebateTags_arr );
						setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
						$smartyObj->display('showTopDebateTags.tpl');
					}
			}

		/**
		 * To display debate tags
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getDebateTags($type, $limit)
			{
				$sql = 'SELECT tag_name, search_debate_count, total_debate_count FROM '.$this->CFG['db']['tbl']['tags'];
				if ($type == 'SEARCH')
					$sql .= ' WHERE search_debate_count>0 AND total_debate_count>0 ORDER BY search_debate_count DESC';
				else
					$sql .= ' WHERE total_debate_count>0 ORDER BY total_debate_count DESC';

				$sql .= ' LIMIT 0,'.$limit;

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

				$tagArray = array();
				if ($rs->PO_RecordCount())
					{
				        while($row = $rs->FetchRow())
				            {
				            	$tagArray[] = $row;
							}
					}
				return $tagArray;
			}

		/**
		 *
		 *
		 */
		public function displayTopDebateTags($limit = 5)
			{
				$displayTopDebateTags_arr = array();
				$top_tags = $this->getDebateTags('TOP', $limit);
				$displayTopDebateTags_arr['top_tags'] = $top_tags;
				if ($top_tags)
				{
					$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
					$tagClassArray = array();
					foreach($top_tags as $row)
					{
						$tagArray[$row['tag_name']] = $row['total_debate_count'];
						$class = $classes[rand(0, count($classes))%count($classes)];
						$tagClassArray[$row['tag_name']] = $class;
					}

					$tagArray = $this->setFontSizeInsteadOfSearchCount($tagArray);
					$inc = 0;
					foreach($tagArray as $tag=>$fontSize){
						$displayTopDebateTags_arr['tag_Array'][$inc]['debates_tag_url'] = getDebatesUrl('debates', '?view=search&tags='.$tag, 'search/?tags='.$tag);
						$displayTopDebateTags_arr['tag_Array'][$inc]['class'] = $tagClassArray[$tag];
						$displayTopDebateTags_arr['tag_Array'][$inc]['fontSizeClass'] = 'style="font-size:'.$fontSize.'px"';
						$displayTopDebateTags_arr['tag_Array'][$inc]['tag'] = $tag;
						$inc++;
					}
					$displayTopDebateTags_arr['tags']['url'] = getAnovaUrl('debateTags', '?t=freq&s=f', '?t=freq&s=f');
				}
				return $displayTopDebateTags_arr;
			}

				/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function showTopSearchedDebateTags()
			{
					if ($this->CFG['admin']['index']['top_search_tags'])
					{
						global $smartyObj;
						$showTopSearchedTags_arr = array();
						$showTopSearchedDebateTags = $this->displayTopSearchedDebateTags($this->CFG['admin']['index']['top_search_tags_count']);
						$smartyObj->assign('showTopSearchedDebateTags', $showTopSearchedDebateTags);
						setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
						$smartyObj->display('displayTopSearchedDebateTags.tpl');
					}
			}

		public function displayTopSearchedDebateTags($limit = 5)
			{
				$displayTopSearchedDebateTags_arr = array();
				$top_tags = $this->getDebateTags('SEARCH', $limit);
				$displayTopSearchedDebateTags_arr['top_tags'] = $top_tags;
				if ($top_tags)
					{
						$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
						$tagClassArray = array();
						foreach($top_tags as $row){
							$tagArray[$row['tag_name']] = $row['search_debate_count'];
							$class = $classes[rand(0, count($classes))%count($classes)];
							$tagClassArray[$row['tag_name']] = $class;
						}
						$tagArray = $this->setFontSizeInsteadOfSearchCount($tagArray);
						$inc = 1;
						foreach($tagArray as $tag=>$fontSize)
							{
								$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['debates_tag_url'] = getDebatesUrl('debates', '?view=search&tags='.$tag.'/&s=f', 'search/?tags='.$tag.'/&s=f');
								$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['class'] = $tagClassArray[$tag];
								$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['fontSizeClass'] = 'style="font-size:'.$fontSize.'px"';
								$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['tag'] = $tag;
								$inc++;
							}//foreach
						$displayTopSearchedDebateTags_arr['tags']['url'] = getAnovaUrl('debateTags', '?t=search&s=f', '?t=search&s=f');
					}
				return $displayTopSearchedDebateTags_arr;
			}
		/**
		 * HeaderFormHandler::displayStaticPageLinks()
		 *
		 * @return
		 */
		/*public function displayStaticPageLinks()
			{
				$displayStaticPageLinks_val = '';

				$sql = 'SELECT page_title, seo_title FROM '.$this->CFG['db']['tbl']['static_pages'].
						' WHERE page_status=\'Yes\' AND link_in_footer=\'Yes\'';

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

				if (!$rs->PO_RecordCount())
					return ;

				while($row = $rs->FetchRow()) {
					$sPage = $row['page_title'];
					$seoPage = $row['seo_title'];

					$displayStaticPageLinks_val .= '<li><a href="'.getUrl('static', '?pg='.$seoPage, $seoPage.'/').'"><span>'.$sPage.'</span></a></li>';
				}
				return $displayStaticPageLinks_val;
			}*/

		/**
		 * HeaderFormHandler::getDisclaimerText()
		 *
		 * @return
		 */
		public function getDisclaimerText()
			{
				$disclaimer_text = $this->LANG['header_disclaimer_text'];
				$disclaimer_text = str_ireplace('VAR_SITENAME', $this->CFG['site']['name'], $disclaimer_text);
				$disclaimer_text = str_ireplace('VAR_LINK', '<a href="'.getUrl('static', '?pg=terms', 'terms/').'">', $disclaimer_text);
				return $disclaimer_text = str_ireplace('VAR_END_LINK', '</a>', $disclaimer_text);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function solvedQuestionsCount()
			{
				global $smartyObj;
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE status NOT IN(\'Blocked\',\'ToActivate\') AND date_closed < NOW()';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($solved_question_count = $rs->PO_RecordCount() AND $solved_question_count > 1)
					{
						$smartyObj->assign('solved_question_count', ($solved_question_count - 1));
						return true;
					}
				return false;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function loginForm()
			{
				global $smartyObj;
				$loginForm_arr = array();

				$loginForm_arr['form_action'] = getUrl('login');
				$loginForm_arr['forgot_password']['url'] = getUrl('forgotpassword');
				if(chkIsAllowedModule(array('registration')))
					{
						$loginForm_arr['signup']['url'] = getUrl('signup');
					}
				if(chkIsAllowedModule(array('openid')))
					{
						$loginForm_arr['openid']['url'] = getUrl('loginopenid');
					}

				$smartyObj->assign('loginForm_arr', $loginForm_arr);
				setTemplateFolder('general/');
				$smartyObj->display('loginForm.tpl');
			}
	}
$HeaderHandler = new HeaderFormHandler();
$HeaderHandler->setPageBlockNames(array('headerBlock'));
$HeaderHandler->setFormField('search_question', $LANG['header_search_for_questions']);
$HeaderHandler->setFormField('search_debates', $LANG['search_for_debates']);
$HeaderHandler->setFormField('search_forum_topic', $LANG['header_search_for_forum_topics']);
$HeaderHandler->setFormField('search_blog_subject', $LANG['header_search_for_blog_subject']);
$HeaderHandler->setFormField('uid', '');
$HeaderHandler->LANG_LIST_ARR = $LANG_LIST_ARR;

$HeaderHandler->sanitizeFormInputs($_REQUEST);
$HeaderHandler->setAllPageBlocksHide();
$HeaderHandler->setPageBlockShow('headerBlock');

if ($HeaderHandler->isFormGETed($_GET, 'title'))
	{
		$HeaderHandler->getHeaderQuestionDetails($CFG['db']['tbl']['questions'], $CFG['db']['tbl']['questions_category']);
	}
if ($HeaderHandler->isFormGETed($_GET, 'cat'))
	{
		$HeaderHandler->getCategoryDetails($CFG['db']['tbl']['questions_category']);
	}
$popupPosition = 330;

if(isAjaxPage())
	{
	  $HeaderHandler->setAllPageBlocksHide();
	}
$HeaderHandler->ask_question_link = getAnovaUrl('questions', '?view=ask', 'ask/', 'members');

if(isMember())
	{
		$HeaderHandler->my_profile_link = getMemberUrl($this->CFG['user']['user_id'], $this->CFG['user']['name']);
	}
//assign for populate the language list in header
$HeaderHandler->populateLanguageDetails();
$HeaderHandler->populateTemplateDetails();
$smartyObj->assign('isMember', isMember());
$smartyObj->assign('isAdmin', isAdmin());
//display the header tpl file
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
if($HeaderHandler->isShowPageBlock('headerBlock'))
	{
		$HeaderHandler->headerBlock['xml_content'] = (array_search($CFG['html']['current_script_name'], $CFG['admin']['light_window_pages']) and !$CFG['remote_client']['is_ie']);
		$HeaderHandler->headerBlock['suggest_css'] = (substr($CFG['html']['page_id'],-12)=='questionsask' || substr($CFG['html']['page_id'],-10)=='debatesask');
		if(isMember())
			{
				$HeaderHandler->headerBlock['userDetails'] = $HeaderHandler->getUserDetailsFromUsersTable($CFG['db']['tbl']['users'], $CFG['user']['user_id']);
				$HeaderHandler->headerBlock['display_name'] = stripString($CFG['user']['display_name'], $CFG['username']['short_length']);
				$HeaderHandler->headerBlock['myanswers_link'] = getMemberUrl($HeaderHandler->headerBlock['userDetails']['user_id'], $HeaderHandler->headerBlock['userDetails']['name']);
				$HeaderHandler->headerBlock['editprofile_link'] = getAnovaUrl('managesettings', '', '', 'members');
				$HeaderHandler->headerBlock['managesettingsClass'] = '';
				$HeaderHandler->headerBlock['myanswersClass'] = '';
				if ($CFG['html']['current_script_name'] == 'manageSettings')
					$HeaderHandler->headerBlock['managesettingsClass'] = 'clsActiveNavigationLink';
				if ($CFG['html']['current_script_name'] == 'myanswers' AND $HeaderHandler->getFormField('uid') == $CFG['user']['name'])
					$HeaderHandler->headerBlock['myanswersClass'] = 'clsActiveNavigationLink';
			}
		$not_allowed_pages_array = array('login.php');
		$HeaderHandler->headerBlock['login_link'] = (!displayBlock($not_allowed_pages_array));

		$allowed_pages_array = array('index.php');
		$user_options = $HeaderHandler->getUserOptions();
		$HeaderHandler->headerBlock['index_popular_videos_only'] = (chkIsVideoAllowed('question') or chkIsVideoAllowed('answer'));
		$HeaderHandler->headerBlock['index_popular_videos_or_audios'] = (chkIsVideoAllowed('question') or chkIsAudioAllowed('question') or chkIsVideoAllowed('answer') or chkIsAudioAllowed('answer'));

		$HeaderHandler->headerBlock['popular_videos_audios'] = ($HeaderHandler->isShowIndexBlock($CFG['admin']['index']['popular_videos'], $user_options['popular_videos']));
		if(isMember())
			{
				$HeaderHandler->insertUsersAnswerLog();
				$HeaderHandler->insertAdvanceSearch();
				$HeaderHandler->updateUsersAnswerLog();
			}
	}
if($HeaderHandler->isShowPageBlock('headerBlock'))
	{
		$smartyObj->assign_by_ref('header', $HeaderHandler);
		$smartyObj->display('../general/html_header.tpl');
	}
if(!isMember() && chkAllowedModule(array('facebook')))
 {
?>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

<script type="text/javascript">

	FB_RequireFeatures(["XFBML"], function()
		{
		  FB.Facebook.init("<?php echo $CFG['facebook']['api_key'];?>", "<?php echo $CFG['site']['url'].'facebook/xd_receiver.htm';?>");
		  //8e1eac6825a150fe4831b9b55163e0ab

		});
	function facebook_onlogin_ready() {
			  refresh_page();
		}

		/*
		 * Do a page refresh after login state changes.
		 * This is the easiest but not the only way to pick up changes.
		 * If you have a small amount of Facebook-specific content on a large page,
		 * then you could change it in Javascript without refresh.
		 */
		function refresh_page() {
		  if ( opener && !opener.closed)
			{
				self.close();
			}

		  var a = FB.Facebook.apiClient.get_session().uid;
		  window.location = '<?php echo $CFG['site']['url'].'facebook_auth.php?hashcode=';?>'+a;
		}
</script>
<?php
 }
?>