<?php
// auto-generated by sfPropelCrud
// date: 2007/06/10 17:54:03
?>
<?php

/**
 * authenticate actions.
 *
 * @package    tvtl
 * @subpackage authenticate
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 3335 2007-01-23 16:19:56Z fabien $
 */
class authenticateActions extends sfActions
{
  public function executeIndex()
  {
    return $this->forward('authenticate', 'list');
  }

  /*
  * Manhtl
  */
	public  function executeLogin()
	{
		if ($this->getRequest()->getMethod() != sfRequest::POST)
		{
			// display the form
			$this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer());
		}
		else
		{
			// handle the form submission
			// redirect to last page
			return $this->redirect('document');
		}
	}
	
	public function executeLogout()
	{
		$this->getUser()->setAuthenticated(false);
		$this->getUser()->clearCredentials();
		$this->getUser()->getAttributeHolder()->removeNamespace('subscriber');
		$this->redirect('@homepage');
	}
	
	public function handleError()
{
return sfView::ERROR;
}

public function handleErrorLogin()
{
	return sfView::SUCCESS;
}
  /*
  * End Manhtl
  */
  public function executeList()
  {
  }

  public function executeShow()
  {
    $this->tbluser = TbluserPeer::retrieveByPk($this->getRequestParameter('us_id'));
    $this->forward404Unless($this->tbluser);
  }

  public function executeCreate()
  {
    $this->tbluser = new Tbluser();

    $this->setTemplate('edit');
  }

  public function executeEdit()
  {
    $this->tbluser = TbluserPeer::retrieveByPk($this->getRequestParameter('us_id'));
    $this->forward404Unless($this->tbluser);
  }

  public function executeUpdate()
  {
    if (!$this->getRequestParameter('us_id'))
    {
      $tbluser = new Tbluser();
    }
    else
    {
      $tbluser = TbluserPeer::retrieveByPk($this->getRequestParameter('us_id'));
      $this->forward404Unless($tbluser);
    }

    $tbluser->setUsId($this->getRequestParameter('us_id'));
    $tbluser->setUsUsername($this->getRequestParameter('us_username'));
    $tbluser->setUsPassword($this->getRequestParameter('us_password'));
    $tbluser->setUsFirstname($this->getRequestParameter('us_firstname'));
    $tbluser->setUsLastname($this->getRequestParameter('us_lastname'));
    $tbluser->setUsEmail($this->getRequestParameter('us_email'));
    $tbluser->setUsAclgroup($this->getRequestParameter('us_aclgroup'));
    $tbluser->setUsSchool($this->getRequestParameter('us_school'));
    $tbluser->setUsProvince($this->getRequestParameter('us_province'));
    if ($this->getRequestParameter('us_lastvisited'))
    {
      list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('us_lastvisited'), $this->getUser()->getCulture());
      $tbluser->setUsLastvisited("$y-$m-$d");
    }
    $tbluser->setUsRating($this->getRequestParameter('us_rating'));
    $tbluser->setUsAvatar($this->getRequestParameter('us_avatar'));

    $tbluser->save();

    return $this->redirect('authenticate/show?us_id='.$tbluser->getUsId());
  }

  public function executeDelete()
  {
    $tbluser = TbluserPeer::retrieveByPk($this->getRequestParameter('us_id'));

    $this->forward404Unless($tbluser);

    $tbluser->delete();

    return $this->redirect('authenticate/list');
  }
}
