<?php
/**
 * Admin Index Page
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		IndexFormHandler
 * @author 		selvaraj_47ag04
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: index.php 736 2008-05-26 06:34:50Z selvaraj_47ag04 $
 * @since 		2008-12-23
 */
require_once('../common/configs/config.inc.php');
$CFG['lang']['include_files'][] = 'languages/%s/admin/index.php';
$CFG['lang']['include_files'][] = 'languages/%s/admin/latestNews.php';
$CFG['mods']['include_files'][] = 'common/classes/class_XmlParser.lib.php';
$CFG['html']['header'] = 'admin/html_header.php';
$CFG['html']['footer'] = 'admin/html_footer.php';

//compulsory
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header'] = false;
/**
 * To include application top file
 */
require($CFG['site']['project_path'].'common/application_top.inc.php');

//--------------class IndexFormHandler--------------->>>//
class IndexFormHandler extends FormHandler
	{
		/**
		 * IndexFormHandler::getTotalUsersCount()
		 *
		 * @return
		 */
		public function getTotalUsersCount()
			{
				$sql = 'SELECT COUNT(user_id) AS cnt FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE (usr_status=\'Ok\' OR usr_status=\'ToActivate\')';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		/**
		 * IndexFormHandler::getTotalAdminUsersCount()
		 *
		 * @return
		 */
		public function getTotalAdminUsersCount()
			{
				$sql = 'SELECT COUNT(user_id) AS cnt FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE (usr_status=\'Ok\' OR usr_status=\'ToActivate\') AND user_access=\'Admin\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		/**
		 * IndexFormHandler::getTotalLogins()
		 *
		 * @return
		 */
		public function getTotalLogins()
			{
				$sql = 'SELECT COUNT(user_id) AS cnt FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE DATEDIFF(DATE_FORMAT(last_logged, \'%Y-%m-%d\'), DATE_FORMAT(NOW(), \'%Y-%m-%d\')) = 0';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		/**
		 * IndexFormHandler::getTotalQuestions()
		 *
		 * @return
		 */
		public function getTotalQuestions()
			{
				$sql = 'SELECT COUNT(ques_id) AS cnt FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE (status=\'Open\' OR status=\'Resolved\')';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		/**
		 * IndexFormHandler::getTotalQuestionsAskedToday()
		 *
		 * @return
		 */
		public function getTotalQuestionsAskedToday()
			{
				$sql = 'SELECT COUNT(ques_id) AS cnt FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE DATEDIFF(DATE_FORMAT(date_asked, \'%Y-%m-%d\'), DATE_FORMAT(NOW(), \'%Y-%m-%d\')) = 0';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		/**
		 * IndexFormHandler::getTotalQuestionsAnsweredToday()
		 *
		 * @return
		 */
		public function getTotalQuestionsAnsweredToday()
			{
				$sql = 'SELECT COUNT(ques_id) AS cnt FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE DATEDIFF(DATE_FORMAT(date_answered, \'%Y-%m-%d\'), DATE_FORMAT(NOW(), \'%Y-%m-%d\')) = 0';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row['cnt'] = 0;
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row['cnt'];
			}

		public function populateNews()
			{
				$getContents_ar = array();
				if($content = getContents($this->CFG['members']['productnews']))
					{
						$xmlObj = new XmlParser();
						$output_arr = $xmlObj->parse($content);
						if(isset($output_arr[0]['children']) and $output_arr[0]['children'])
							{
								$output_arr = $output_arr[0]['children'];
								$inc = 0;
								foreach($output_arr as $key=>$value)
									{
										if(!$value or !is_array($value))
											{
												continue;
											}
										foreach($value as $key1=>$value1)
											{
												if(!$value1 or !is_array($value1))
													{
														continue;
													}
												$myval = 0;
												foreach($value1 as $key2=>$value2)
													{
														$myval++;
														if($myval == 1)
															$value2['tagData'] = html_entity_decode($value2['tagData']);
														if($myval == 2)
															$value2['tagData'] = wordWrapManual($value2['tagData'], $this->CFG['admin']['blog']['line_length']);
														$getContents_ar[$inc][$value2['name']] = $value2['tagData'];

													}
											}
										$inc++;
										if ($inc >= 4)
											break;
									}
							}
					}
				return $getContents_ar;
			}
	}
//<<<<<<<--------------class IndexFormHandler---------------//

//--------------------Code begins-------------->>>>>//
$indexfrm = new IndexFormHandler();
$indexfrm->setPageBlockNames(array('form_index', 'block_main_ionformation'));

$indexfrm->setAllPageBlocksHide();
$indexfrm->setPageBlockShow('form_index');
$indexfrm->setPageBlockShow('block_main_ionformation');

$indexfrm->admin_welcome_info_1 = str_ireplace('VAR_USERNAME', ucwords($CFG['user']['name']), $LANG['admin_welcome_info_1']);
$indexfrm->admin_welcome_info_2 = str_ireplace('VAR_SITENAME', $CFG['site']['name'], $LANG['admin_welcome_info_2']);

if ($indexfrm->isShowPageBlock('form_index'))
	{
		$settings_info = $LANG['settings_info'];
		$settings_info = str_ireplace('VAR_MAIN_LINK', '<a href="'.$CFG['site']['relative_url'].'editConfig.php?config_file_name=config">'.$LANG['main'].'</a>', $settings_info);
		$settings_info = str_ireplace('VAR_GENERAL_LINK', '<a href="'.$CFG['site']['relative_url'].'editConfig.php?config_folder=anova&config_file_name=config_general">'.$LANG['general'].'</a>', $settings_info);
		$settings_info = str_ireplace('VAR_MODULE_LINK', '<a href="'.$CFG['site']['relative_url'].'editConfigModule.php">'.$LANG['module'].'</a>', $settings_info);
		$settings_info = str_ireplace('VAR_ANSWERS_LINK', '<a href="'.$CFG['site']['relative_url'].'editConfig.php?config_folder=anova&config_file_name=config_answers">'.$LANG['answers'].'</a>', $settings_info);
		$indexfrm->settings_info = $settings_info;

		$answers_info = $LANG['answers_info'];
		$answers_info = str_ireplace('VAR_QUESTIONS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/manageAnswers.php">'.$LANG['questions'].'</a>', $answers_info);
		$answers_info = str_ireplace('VAR_ANSWERS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/manageAnswers.php">'.$LANG['answers'].'</a>', $answers_info);
		$answers_info = str_ireplace('VAR_QUESTION_CATEGORIES_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/questionCategory.php">'.$LANG['question_categories'].'</a>', $answers_info);
		$indexfrm->answers_info = $answers_info;

		$members_info = $LANG['members_info'];
		$members_info = str_ireplace('VAR_MEMBERS_LINK', '<a href="'.$CFG['site']['relative_url'].'manageAnswersMembers.php">'.$LANG['members'].'</a>', $members_info);
		$indexfrm->members_info = $members_info;

		$video_player_info = $LANG['video_player_info'];
		$video_player_info = str_ireplace('VAR_VIDEO_PLAYER_SETTINGS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/ansVideoPlayerSettings.php">'.$LANG['video_player_settings'].'</a>', $video_player_info);
		$video_player_info = str_ireplace('VAR_VIDEO_LOGO_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/ansVideoLogo.php">'.$LANG['video_logo'].'</a>', $video_player_info);
		$video_player_info = str_ireplace('VAR_VIDEO_ADVERTISEMENT_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['anova_module'].'/ansVideoAdvertisement.php">'.$LANG['video_advertisement'].'</a>', $video_player_info);
		$indexfrm->video_player_info = $video_player_info;

		$banners_info = $LANG['banners_info'];
		$banners_info = str_ireplace('VAR_BANNERS_LINK', '<a href="'.$CFG['site']['relative_url'].'manageBanner.php">'.$LANG['banners'].'</a>', $banners_info);
		$indexfrm->banners_info = $banners_info;

		$manage_static_info = $LANG['manage_static_info'];
		$manage_static_info = str_ireplace('VAR_NEWSLETTERS_LINK', '<a href="'.$CFG['site']['relative_url'].'addNewsLetter.php">'.$LANG['news_letter'].'</a>', $manage_static_info);
		$manage_static_info = str_ireplace('VAR_SIDEBAR_LINK', '<a href="'.$CFG['site']['relative_url'].'orderRightBar.php">'.$LANG['rightbar'].'</a>', $manage_static_info);
		$manage_static_info = str_ireplace('VAR_STATIC_PAGES_LINK', '<a href="'.$CFG['site']['relative_url'].'manageStaticPages.php">'.$LANG['static_pages'].'</a>', $manage_static_info);
		$indexfrm->manage_static_info = $manage_static_info;

		if($CFG['admin']['module']['forums'])
			{
				$forums_info = $LANG['forums_info'];
				$forums_info = str_ireplace('VAR_FORUM_TITLES_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['forum_module'].'/forums.php">'.$LANG['forum_titles'].'</a>', $forums_info);
				$forums_info = str_ireplace('VAR_TOPICS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['forum_module'].'/forums.php">'.$LANG['topics'].'</a>', $forums_info);
				$forums_info = str_ireplace('VAR_RESPONSES_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['forum_module'].'/forums.php">'.$LANG['common_total_responses'].'</a>', $forums_info);
				$indexfrm->forums_info = $forums_info;
			}
		if($CFG['admin']['module']['blog'])
			{
				$blogs_info = $LANG['blogs_info'];
				$blogs_info = str_ireplace('VAR_BLOGS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['blog_module'].'/manageBlogs.php">'.$LANG['blogs'].'</a>', $blogs_info);
				$blogs_info = str_ireplace('VAR_BLOG_COMMENTS_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['blog_module'].'/manageBlogs.php">'.$LANG['common_total_comments'].'</a>', $blogs_info);
				$blogs_info = str_ireplace('VAR_BLOG_CATEGORIES_LINK', '<a href="'.$CFG['site']['relative_url'].$CFG['admin']['index']['blog_module'].'/manageBlogCategory.php">'.$LANG['blog_categories'].'</a>', $blogs_info);
				$indexfrm->blogs_info = $blogs_info;
			}

		$indexfrm->block_main_ionformation['populateNews'] = $indexfrm->populateNews();
	}
//<<<<--------------------Code Ends----------------------//

//--------------------Page block templates begins-------------------->>>>>//
//include the header file
$indexfrm->includeHeader();
//include the content of the page
setTemplateFolder('admin/');
$smartyObj->display('index.tpl');
//includ the footer of the page
//<<<<<<--------------------Page block templates Ends--------------------//
$indexfrm->includeFooter();
?>