<?php if (!defined('HTTP_SERVER')) die('You can not access this file directly!');
/**
  @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  30/08/10, 17:28
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
  @class login_ident
  @brief it's class for login in backoffice panel , 
    use librairie function in includes/exts/login/
*/

class login_ident {

  public static $lID;
  /**
   * \brief array methode use
   * @var $method_array array
   */
  public static $method_array;

  public function __construct() {
  	global $conf;

    $method_array=explode(';',$conf->login);
    
    foreach($method_array as $method)
      if(!empty($method)) {
      	$method=trim($method);
      	include_once(DIR_WS_INCLUDES.'exts/login/'.$method.'.php');
      	self::$method_array[]=$method;
      }
  }

  /**
   * \brief draw from html in template login
   */
  public static function draw_form(){
  	foreach(self::$method_array as $method){
  		$obj=new $method();
  		echo $obj->draw();
  	}
  }
  
  /**
  */
  public function init_login(){
    $DB=Database::getInstance();
    $check_admin_query = $DB->query($sql="select admin_id as login_id, admin_groups_id as login_groups_id, admin_firstname as login_firstname, admin_email_address as login_email_address, admin_password as login_password, admin_modified as login_modified, admin_logdate as login_logdate, admin_lognum as login_lognum from " . TABLE_ADMIN . " where admin_id = '" . (int)self::$lID . "'");

    $check_admin = $check_admin_query->fetchAssoc();

    $_SESSION['login_id'] = self::$lID;
    $_SESSION['login_groups_id'] = $check_admin['login_groups_id'];
    $_SESSION['login_firstname'] = $check_admin['login_firstname'];
    $_SESSION['login_email_address'] = $check_admin['login_email_address'];
    $_SESSION['login_logdate'] = $check_admin['login_logdate'];
    $_SESSION['login_lognum'] = $check_admin['login_lognum'];
    $_SESSION['login_modified'] = $check_admin['login_modified'];

    $DB->query($sql="update " . TABLE_ADMIN . " SET admin_logdate = NOW(),  admin_lognum = admin_lognum + 1  where admin_id = '" . (int)self::$lID . "'");
  }

  /**
   * \fn check_user()
   * \brief Control
  */
  public function check_user(){
  	if(count(self::$method_array)==0) return false;
  	
    foreach(self::$method_array as $method){
      $obj=new $method();
      if(($res=$obj->check()) && $res !=null) return $res;
    }

    return false;
  }

}
?>