<?php 

class ControllerAccountLoginReview extends Controller {

	var $error = array();

	

  	function index() {

		$customer =& $this->locator->get('customer');

		$language =& $this->locator->get('language');

		$module   =& $this->locator->get('module');

		$request  =& $this->locator->get('request');

		$response =& $this->locator->get('response');

		$session  =& $this->locator->get('session');

		$template =& $this->locator->get('template');

		$url      =& $this->locator->get('url');

				

		if ($customer->isLogged()) {  

  //   		$response->redirect($url->ssl('account'));

    	}

	

    	$language->load('controller/account_login.php');



    	$template->set('title', $language->get('heading_title'));

			

		if (($request->isPost()) && ($this->validate())) {			

      		if ($request->has('redirect', 'post')) {

				$response->redirect($request->get('redirect', 'post'));

      		} else {

				$response->redirect($url->ssl('review_write'));

      		} 

    	}  

    	$view = $this->locator->create('template');

    	$view->set('heading_title', $language->get('heading_title'));



    	$view->set('text_new_customer', $language->get('text_new_customer'));

    	$view->set('text_i_am_new_customer', $language->get('text_i_am_new_customer'));

    	$view->set('text_returning_customer', $language->get('text_returning_customer'));

    	$view->set('text_i_am_returning_customer', $language->get('text_i_am_returning_customer'));

    	$view->set('text_create_account', $language->get('text_create_account'));

    	$view->set('text_forgotten_password', $language->get('text_forgotten_password'));

    	$view->set('text_forgotten_password', $language->get('text_forgotten_password'));



    	$view->set('entry_email', $language->get('entry_email_address'));

    	$view->set('entry_password', $language->get('entry_password'));



    	$view->set('button_continue', $language->get('button_continue'));

    	$view->set('button_login', $language->get('button_login'));



		$view->set('error', @$this->error['message']);

    

		$view->set('action', $url->ssl('account_login_review'));

    	if ($request->get('redirect','post')) {
			$view->set('redirect', $request->get('redirect', 'post'));

		} else {
      		$view->set('redirect', $session->get('redirect'));

	  		$session->delete('redirect');		  	

    	}

    	$view->set('message', $session->get('message'));

    

		$session->delete('message');



    	$view->set('continue', $url->ssl('account_create'));



    	$view->set('forgotten', $url->ssl('account_forgotten'));



		$template->set('content', $view->fetch('content/account_login_review.tpl'));

	

		$template->set($module->fetchAccount());

	

		$response->set($template->fetch('layout.tpl'));

  	}

  

  	function validate() {

		$customer =& $this->locator->get('customer');

		$language =& $this->locator->get('language');

		$request  =& $this->locator->get('request');

					
		if (!$request->get('email', 'post'))
		{
			$this->error['message'] = "please login!";	
		}else
		{
			$input_password=str_replace(' ','',$request->get('password', 'post'));
                    $md5_inputpassword=md5($input_password);
					
    		if (!$customer->login($request->get('email', 'post'), $md5_inputpassword)) {

      			$this->error['message'] = $language->get('error_login');
    		}
		}
	

    	if (!$this->error) {

      		return TRUE;

    	} else {

      		return FALSE;

    	}  	

  	}

}

?>