<?php
/**
 * File handling open static Pages WriteMode
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		StaticPage
 * @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:
 * @since 		2008-12-22
 */
class StaticPage extends FormHandler
	{

		/**
		 * StaticPage::getStaticContent()
		 *
		 * @param mixed $title
		 * @return
		 */
		public function getStaticContent($title)
			{
				$sql = 'SELECT * FROM '.$this->CFG['db']['tbl']['static_pages'].
						' WHERE seo_title = '.$this->dbObj->Param($title).' AND page_status=\'Yes\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($title));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$static_details = array('page_display_title'=>'', 'page_content'=>'Add content from admin/manageStaticPages.php');

				if($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						if (isset($row['page_display_title']))
							$static_details['page_display_title'] = $row['page_display_title'];

						if (isset($row['page_content']))
							$static_details['page_content'] = html_entity_decode($row['page_content']);
					}
				return $static_details;
			}

		/**
		 * StaticPage::chkValidStaticPage()
		 *
		 * @param mixed $title
		 * @return
		 */
		public function chkValidStaticPage($title)
			{
					$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['static_pages'].
							' WHERE seo_title = '.$this->dbObj->Param($title).' AND page_status=\'Yes\'';
					$stmt = $this->dbObj->Prepare($sql);
					$rs = $this->dbObj->Execute($stmt, array($title));
					if (!$rs)
						    trigger_db_error($this->dbObj);

					if ($rs->PO_RecordCount())
						return $title;
					return false;
			}

		public function overWritePageTitle($title)
			{
				global $LANG, $CFG;

				if(isset($LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_title']))
					$LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_title'] = $title;

			}
	}
//<<<<<-------------- Class StaticPage begins ---------------//
//-------------------- Code begins -------------->>>>>//
$StaticPage = new StaticPage();
$StaticPage->setPageBlockNames(array('block_staticPage'));
$StaticPage->setFormField('pg', '');
$StaticPage->setPageBlockShow('block_staticPage');

$StaticPage->setFormField('pg', '');
$StaticPage->sanitizeFormInputs($_REQUEST);
$title = $StaticPage->getFormField('pg');
$title = $StaticPage->chkValidStaticPage($title);
$title = ($title)?$title: 'terms';
//<<<<<-------------------- Code ends----------------------//

//-------------------- Page block templates begins -------------------->>>>>//
//include the header file
$StaticPage->overWritePageTitle($title);
$StaticPage->includeHeader();
if($StaticPage->isShowPageBlock('block_staticPage'))
	{
		$StaticPage->getStaticContent = $StaticPage->getStaticContent($title);
	}
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('staticPage.tpl');
/**
 * File to include the footer file and show benchmarking for developer
 */
$StaticPage->includeFooter();
?>