<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Description of login_observer
 *
 * @author Igor Ratsun
 */
class login_observer implements SplObserver {

    public function update(SplSubject $subject) {
        $CI = & get_instance();
        $CI->load->helper('ciext/observer');
        $CI->lang->load('ciext/observers/login_observer');
        
        $action = ($subject->user_name == $CI->config->item('system_login')) ? 'edit_role' : 'edit_user';
        
        $save = new saveObserver();
        $save->set_access('acl', $action);
        
        $text = $CI->lang->line('login fail');
        
        if ($subject->is_logged) {
            $text = $CI->lang->line('login success');
        }
        
        $save->set_text(sprintf($text, $subject->user_name));
        
        $save->save();
    }

}
