<?php
// +----------------------------------------------------------------------+
// | PHP version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Snapshot Inc.                                |
// +----------------------------------------------------------------------+
// | License                                                              |
// | GNU General Public License                                           |
// +----------------------------------------------------------------------+
// | Authors: Mai Kawasaki                                                |
// +----------------------------------------------------------------------+
//
// $Id: LoginAction.class.php,v 1.1 2005/06/20 09:31:27 snapshot Exp $
//
// Description:
// 2005/05/18
//

/** 
*	LoginAction.class.php
*	Mai Kawasaki
*	2005/05/18
*/

require_once(OPT_DIR.'u-learning/config.php');
require_once(OPT_DIR.'u-learning/action/StudentAction.class.php');
require_once(OPT_DIR.'u-learning/data/Admin.class.php');

/** 
*	LoginAction
*/
class LoginAction extends StudentAction {
    function execute (&$controller, &$request, &$user) {
		// ブラウザの判別
		$type = $this->getUserAgentType();
		$request->setAttribute('type', $type);
		
		$DB = $request->getAttribute('DB');
		
		// 教員情報を取得
		$aid = $request->getParameter('aid');
		if($aid == ""){
			$aid = "admin";
		}		
		$admin = new Admin( $aid, $DB );
				
		if($request->getParameter('login') ) {
			// ログイン処理
	
			$uid = $request->getParameter('uid');
			$pass = $request->getParameter('pass');
			
			$sql = "select * from user_info" .
					" where aid = ".$DB->qstr($aid) .
					" and uid = ".$DB->qstr($uid).
					" and pass = ".$DB->qstr($pass).
					" and regist = '1' and del <> '1'";
			
			// DB接続
	        $array = $DB->GetRow($sql);

	        if( count($array) > 0 ) {
		        $user->setAuthenticated(true);
		        $user->setAttribute('aid', $aid);
		        $user->setAttribute('uid', $uid);
				
				// リダイレクト
				$this->location('Top', 'Index', array('aid'=>$aid, 'uid'=>$uid, 'pass'=>$pass));
				return VIEW_NONE;
	        } 
	        
	        $request->setAttribute('error', 'ログインIDとパスワードが間違っています。');
	        $request->setAttribute('aid', $aid);
	        $request->setAttribute('uid', $uid);
	        $request->setAttribute('pass', $pass);
        	$request->setAttribute('admin', $admin);

	        return VIEW_ERROR;
	
		}
		

        $request->setAttribute('aid', $aid);		
       	$request->setAttribute('admin', $admin);
		return VIEW_INPUT;
    }


}



?>
