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

/** 
*	RegistAction.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/Student.class.php');
require_once(OPT_DIR.'u-learning/data/Admin.class.php');

/** 
*	RegistAction
*/
class RegistAction extends StudentAction {
    function execute (&$controller, &$request, &$user) {

		// ブラウザの判別
		$type = $this->getUserAgentType();
		$request->setAttribute('type', $type);
		
		// 本登録処理
		$DB = $request->getAttribute('DB');
				
		$aid = $request->getParameter('aid');
		$uid = $request->getParameter('uid');
		// 教員情報取得
		$request->setAttribute('admin', new Admin($aid, $DB));

		// DB登録(ユーザ情報)
		$error = "";
   		$student = new Student( $aid, $uid, $DB );
		if($student->regist == '1'){
			$error .= "このユーザは本登録済みです。";
			
			$request->setAttribute('aid',  $aid);
			$request->setAttribute('error',  $error);
			return VIEW_ERROR;
		}
		if($student->uid == ''){
			$error .= "このユーザは存在しません。<br>\nユーザ登録を行ってください。";
			
			$request->setAttribute('aid',  $aid);
			$request->setAttribute('error',  $error);
			return VIEW_ERROR;
		}
		
		
		$student->regist = '1';
		$student->update($DB);

		// 登録成功
        $user->setAuthenticated(true);
        // 管理者IDをセット
        $user->setAttribute('aid', $aid);
        // ユーザIDをセット
        $user->setAttribute('uid', $uid);
        $request->setAttribute('pass',  $request->getParameter('pass'));

		return VIEW_SUCCESS;
    }
}

?>