<?php

class DefaultController extends Controller
{
	public $layout='common';
	public function actionIndex()
	{
		$data=Exammanage::model()->findAll();
		//echo count($data);exit;
		$this->render('index',array(
			'data'=>$data,
		));
	}
	public function actionError()
	{
		//$this->layout='common';		
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}
	public function actionLogin()
	{
		$this->layout='denglu';
		$model=new assistantLoginForm;

		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		if(isset($_POST['assistantLoginForm']))
		{
			$model->attributes=$_POST['assistantLoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				$this->redirect('index');
		}
		// display the login form
		$this->render('login',array('model'=>$model));
	}
	public function actionLogout()
	{
		Yii::app()->assistant->logout(false);
		$this->redirect(Yii::app()->assistant->loginUrl);
	}
}