<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  03/01/11, 17:28
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
  @file
  @brief base functions and class fro login by methode
  
  Cette fonction assure l'identification par la methode intégres a oscss. 
*/

class oscss {
	
  function __construct(){
  	
  }
  
  /**
   * \fn draw()
   * \brief call html 
   */
  public function draw(){
    return tep_get_include_contents('login.'.__CLASS__);
  }
  
  /**
   * \fn check()
   * \brief call check exe 
   */
  public function check(){
  	return $this->check_exe();
  }
  
  /**
   * \fn check()
   * \brief test and retrun bool
   * \return boolean
   * @param $_POST['email_address'] string
   * @param $_POST['password'] string
  */
	protected function check_exe(){
	    $DB=Database::getInstance();
	    
	    include(DIR_WS_FUNCTIONS . 'password_funcs.php');
	    
	    $email_address = tep_db_prepare_input($_POST['email_address']);
	    $password = tep_db_prepare_input($_POST['password']);
	
	    // Check if email exists
	    $check_admin_query = $DB->query("select admin_id as login_id, admin_password as login_password  from " . TABLE_ADMIN . " where admin_email_address = '" . tep_db_input($email_address) . "'");
	    if (!$check_admin_query->__get('numRows')) {
	      return false;
	    } else {
	    	
	      $check_admin = $check_admin_query->fetchAssoc();
			  // Check that password is good
			  if (!tep_validate_password($password, $check_admin['login_password'])) return false;
			  else {
			    login_ident::$lID=$check_admin['login_id'];
			
			    if (tep_session_is_registered('password_forgotten')) {
			      tep_session_unregister('password_forgotten');
			    }
			    return true;
			  }
	
	      }
	    return false;
	}
}
?>