<?php

//controller for page
class SiteController extends PController
{
    public $layout = 'column1';

   
    // function to render home page
    public function actionIndex()
    {
		if (Yii::app()->site->model->isExpired()) {
            $this->render('/site/expired');

            return;
        }
        $page = BPages::getHomePage();
		
        if ($page !== false) {
            $this->__runPage($page);
        }
    }

    protected function __runPage($page)
    {
		define("_BBC_PAGE_NAME", $page->name);
		define("_BBCLONE_DIR",Yii::getPathofAlias('bbclone_app').'/');
		define("_BBC_CACHE_PATH",Yii::getPathofAlias('application_site').'/stats/');
		define("COUNTER", _BBCLONE_DIR."mark_page.php");
		@include_once(COUNTER);
        Yii::app()->context->page = $page;
        $this->pageTitle = $page->title;
        Yii::app()->clientScript->registerMetaTag($page->keywords, 'keywords');
        Yii::app()->clientScript->registerMetaTag($page->description, 'description');

        require_once Yii::getPathofAlias('application_admin.classes').'/general.php';
        $this->render('view', array('page' => $page));
    }
    protected function runPage($pageName)
    {
        $page = BPages::model()->find('name=:name', array(':name' => $pageName));
        if (isset($page)) {
            $this->__runPage($page);
        } else {
            $page = new BPages();
            $page->name = $pageName;
            $page->file_name = $pageName;
            $this->__runPage($page);
        }
    }
    // render html structure for inline iframe in site builder
    public function actionView($page)
    {
		
        if (isset($page) && $page != false) {
            $this->runPage($page);
        }
    }
    public function actionUpgrade()
    {
		header('Location:http://'.(Yii::app()->mainSiteConfig['mainsite_url'].'/index.php/profile/page/upgrade/id/'.Yii::app()->site->model->id));
       // $this->layout = 'column_checkout';
       // $this->render('upgrade');
    }
    public function actionCheckout()
    {
        $planId = $_REQUEST['plan_id'];
        $plan = Plan::model()->findByPk($planId);
        $amount_monthly = $plan->monthly_amount;
        $amount_annually = $plan->yearly_amount;
        $this->layout = 'column_checkout';
        $this->render('checkout', array('plan' => $plan, 'amount_annually' => $amount_annually, 'amount_monthly' => $amount_monthly));
    }
}
