<?php
/**
 * File to handle the sitemap
 *
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		siteMapHandler
 * @author 		sridharan_08ag04
 * @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 siteMapHandler extends FormHandler
	{
		public $legal_rss_arr = array();

		/**
		 * siteMapHandler::getStaticLinks()
		 *
		 * @param mixed $activity_arr
		 * @return
		 */
		public function getStaticLinks($activity_arr)
			{
				$this->getStaticLinks_arr	=	array();
				$title = true;
				$i = 0;
				$count = 0;
				$inc=0;
				$this->getStaticLinks_arr['row']	=	array();
				foreach($activity_arr[$i] as $page=>$link)
					{
						$count++;
						if ($title)
							{
								$this->getStaticLinks_arr['row'][$inc]['link'] = $link[0];
								$title = false;
								continue;
							}
						if(($link[0]==getUrl('signup') or $link[0]==getUrl('login')) and $this->CFG['user']['user_id'])
							continue;
						$this->getStaticLinks_arr['row'][$inc]['url'] =	$link[0];
						$this->getStaticLinks_arr['row'][$inc]['page'] = $page;
						$inc++;
					}
				$this->getStaticLinks_arr['isset'] = isset($activity_arr[$i+1]);
				if (isset($activity_arr[$i+1]))
					{
						$inc=0;
						$this->getStaticLinks_arr['row1']	=	array();
						$title = true;
						foreach($activity_arr[$i+1] as $page=>$link)
							{
								if ($title)
									{
										$this->getStaticLinks_arr['row1'][$inc]['link']	=	$link[0];
										$title = false;
										continue;
									}
								$this->getStaticLinks_arr['row1'][$inc]['url']	=	$link[0];
								$this->getStaticLinks_arr['row1'][$inc]['page']	=	$page;
								$inc++;
							}
					}
				return $this->getStaticLinks_arr;
			}

		/**
		 * siteMapHandler::getCategoryWise()
		 *
		 * @return
		 */
		public function getCategoryWise()
			{
				$this->getCategoryWise_arr	=	array();
				$sql = 'SELECT cat_name, cat_id, has_child, seo_title FROM '.$this->CFG['db']['tbl']['questions_category'].
						' WHERE parent_id=0 AND status=\'1\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
			    if (!$rs)
				    trigger_db_error($this->dbObj);
				$inc=0;
				$this->getCategoryWise_arr['row']	=	array();
				while($row=$rs->FetchRow())
					{
						$this->getCategoryWise_arr['row'][$inc]['record']	=	$row;
						$this->getCategoryWise_arr['row'][$inc]['category_questions_url']	=	getAnovaUrl('questions','?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');
						$this->getCategoryWise_arr['row'][$inc]['answered_questions_url']	=	getAnovaUrl('questions','?view=search&amp;type='.$this->LANG['sitemap_type_answered'].'&amp;cat_id='.$row['cat_id'], 'search/?type='.$this->LANG['sitemap_type_answered'].'&amp;cat_id='.$row['cat_id']);
						$this->getCategoryWise_arr['row'][$inc]['unanswered_questions_url']	=	getAnovaUrl('questions','?view=search&amp;type='.$this->LANG['sitemap_type_unanswered'].'&amp;cat_id='.$row['cat_id'], 'search/?type='.$this->LANG['sitemap_type_unanswered'].'&amp;cat_id='.$row['cat_id']);
						$this->getCategoryWise_arr['row'][$inc]['best_answers_questions_url']	=	getAnovaUrl('questions','?view=search&amp;type='.$this->LANG['sitemap_type_bestanswered'].'&amp;cat_id='.$row['cat_id'], 'search/?type='.$this->LANG['sitemap_type_bestanswered'].'&amp;cat_id='.$row['cat_id']);
		        		$inc++;
					}
				return $this->getCategoryWise_arr;
			}

		/**
		 * siteMapHandler::getLegalArray()
		 *
		 * @return
		 */
		public function getLegalArray()
			{
				$sql = 'SELECT page_title FROM '.$this->CFG['db']['tbl']['static_pages'].
						' WHERE page_status=\'Yes\' AND link_in_footer=\'Yes\' AND page_title IN(\'faq\', \'privacy\', \'terms\')';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
			    	if (!$rs)
				    	trigger_db_error($this->dbObj);

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

				$legal_arr = array();
				$legal_arr['title'] = array($this->LANG['sitemap_legal']);

				while($row = $rs->FetchRow())
					{
						$sPage = strtolower($row['page_title']);
						$temp	=	getUrl('static','?pg='.$sPage, $sPage.'/');
						$legal_arr[ucwords($sPage)] = array($temp);
					}
				return $legal_arr;
			}
	}
//<<<<<-------------- Class staticPageHandler begins ---------------//
//-------------------- Code begins -------------->>>>>//
$sitemap_page = new siteMapHandler();
$legal_arr = array();
$legal_arr = $sitemap_page->getLegalArray();
$signup	=	getUrl('signup');
$login	=	getUrl('login');
$index	=	getAnovaUrl('index');
$contactUs	=	getUrl('contactus');
$staticPage	=	getUrl('static','?pg=faq','faq/');
$pointsAndLevels	=	getUrl('pointssndlevels');

$activity_arr_1 = array(array('title'=>array($LANG['sitemap_activity']),
							  $LANG['signup']=>array($signup),
							  $LANG['signin']=>array($login),
							  $LANG['common_home']=>array($index),
							  $LANG['feedback']=>array($contactUs)),

						array('title'=>array($LANG['sitemap_help']),
							  $LANG['guidelines']=> array($staticPage),
							  $LANG['contactus']=>array($contactUs),
							  $LANG['what_are_points_and_levels']=>array($pointsAndLevels))
					);
$questions_recent_url	=	getAnovaUrl('questions','?view=recent','recent/');
$questions_popular_url	=	getAnovaUrl('questions','?view=popular','popular/');
$questions_open_url	=	getAnovaUrl('questions','?view=open','open/');
$questions_best_url	=	getAnovaUrl('questions','?view=best','best/');
$categories	=	getAnovaUrl('categories');
$tags	=	getAnovaUrl('tags','?t=freq&amp;s=f','?t=freq&amp;s=f');
$tags1	=	getAnovaUrl('tags','?t=search&amp;s=f','?t=search&amp;s=f');
$activity_arr_2 = array(array('title'=>array($LANG['sitemap_recent']),
							  $LANG['common_recent_question_title']=> array($questions_recent_url),
							  $LANG['common_popular_question_title']=>array($questions_popular_url),
							  $LANG['open_questions']=>array($questions_open_url),
							  $LANG['search_type_with_best_answer']=>array($questions_best_url)),

						array('title'=>array($LANG['sitemap_browse']),
							  $LANG['browser_by_category']=> array($categories),
							  $LANG['view_top_100_tags']=>array($tags),
							  $LANG['view_top_searched_tags']=>array($tags1))
					);

$questions_adv_url	=	getAnovaUrl('questions','?so=adv&amp;view=search','search/?so=adv');
$debates_recent_url	=	getDebatesUrl('debates','?view=recent','recent/');
$debates_popular_url	=	getDebatesUrl('debates','?view=popular','popular/');
$debates_open_url	=	getDebatesUrl('debates','?view=open','open/');

$debatecategories	=	getAnovaUrl('debatecategories');
$debatetags	=	getAnovaUrl('tags','?t=freq&s=f','?t=freq&s=f');
$debatetags1	=	getAnovaUrl('tags','?t=search&s=f','?t=search&s=f');
$activity_arr_3 = array(array('title'=>array($LANG['sitemap_debate_recent']),
							  $LANG['common_recent_debate_title']=> array($debates_recent_url),
							  $LANG['common_popular_debate_title']=>array($debates_popular_url),
							  $LANG['open_debate']=>array($debates_open_url)),

						array('title'=>array($LANG['sitemap_debate_browse']),
							  $LANG['browser_by_debate_category']=> array($debatecategories),
							  $LANG['view_top_100_debates_tags']=>array($debatetags),
							  $LANG['view_top_searched_debates_tags']=>array($debatetags1))
					);
$topanalysts	=	getAnovaUrl('topanalysts','?so=adv','?so=adv');
$forumSearch	=	getForumsUrl('forumsearch','?so=adv','?so=adv');
$blogs	=	getBlogUrl('blogs','?so=adv','?so=adv');
$widgetgenerate	=	getAnovaUrl('widgetgenerate');
$search_options_arr[0] = array('title'=>array($LANG['sitemap_search']),
							  $LANG['search_questions']=>array($questions_adv_url),
							  $LANG['search_members']=>array($topanalysts));
if ($CFG['admin']['module']['forums'])
	$search_options_arr[0][$LANG['search_forums']] = array($forumSearch);
if ($CFG['admin']['module']['blog'])
	$search_options_arr[0][$LANG['search_blogs']] = array($blogs);

$search_options_arr[1] = array('title'=>array($LANG['sitemap_widget']),
							  $LANG['widget_generator']=>array($widgetgenerate));
$rss_recentquestions	=	getUrl('rss','?act=recentquestions','recentquestions/', 'root');
$rss_popularquestions	=	getUrl('rss','?act=popularquestions','popularquestions/', 'root');
$rss_recentforums	=	getUrl('rss','?act=recentforums','recentforums/', 'root');
$rss_recentblogs	=	getUrl('rss','?act=recentblogs','recentblogs/', 'root');
$legal_rss_arr[0] = array('title'=>array($LANG['sitemap_rss']),
							  $LANG['common_recent_question_title']=> array($rss_recentquestions),
							  $LANG['common_popular_question_title']=>array($rss_popularquestions));
if ($CFG['admin']['module']['forums'])
	$legal_rss_arr[0][$LANG['common_recent_forum_title']] = array($rss_recentforums);
if ($CFG['admin']['module']['blog'])
	$legal_rss_arr[0][$LANG['common_recent_blog_title']] = array($rss_recentblogs);
$legal_rss_arr[1] = $legal_arr;

$sitemap_page->siteMapCommon['title']	=	$title = str_ireplace('VAR_SITENAME', $CFG['site']['name'], $LANG['sitemap_title']);
if($activity_arr_1)
	{
		$sitemap_page->getStaticLinks['activity_arr_1']	=	$sitemap_page->getStaticLinks($activity_arr_1);
	}
if($activity_arr_2)
	{
		$sitemap_page->getStaticLinks['activity_arr_2']	=	$sitemap_page->getStaticLinks($activity_arr_2);
	}
if($search_options_arr)
	{
		$sitemap_page->getStaticLinks['search_options_arr']	=	$sitemap_page->getStaticLinks($search_options_arr);
	}

$sitemap_page->getCategoryWise['category']	=	$sitemap_page->getCategoryWise();

if($legal_rss_arr)
	{
		$sitemap_page->getStaticLinks['legal_rss_arr']	=	$sitemap_page->getStaticLinks($legal_rss_arr);
	}
//<<<<<-------------------- Code ends----------------------//
//-------------------- Page block templates begins -------------------->>>>>//
//include the header file
$sitemap_page->includeHeader();
//include the content of the page
setTemplateFolder('general/');
$smartyObj->display('siteMap.tpl');
//includ the footer of the page
//<<<<<-------------------- Page block templates ends --------------------//
$sitemap_page->includeFooter();
?>