Exemplo n.º 1
0
function login( $uacc, $upwd ){
    $login = (array)json_decode(
        file_get_contents_curl(
            'http://apit.cedric.testapi-1.stu.edu.tw/acc/auth/uacc/'.$uacc.'/?upwd='.$upwd),true);
    # Authentication fail.
    if ( $login['status'] )
        print_response_msg(3);

    # Analyze data.
    $ou_group;
    $start_tag = "ou=";
    $close_tag = ",";
    preg_match_all("($start_tag(.*)$close_tag)siU", $login['dn'], $ou_group);

    # If login user not is student, this column value set 0.
    if ( !preg_match('/\d{2,3}/', $ou_group[1][0]) )
        $ou_group[1][0] = 0;

    # Get record data.
    $sql = "SELECT record_id FROM record WHERE account=? ";
    $record_id = sql_q( $sql, array($login['uacc']) );

    # If this account not have play record in database, insert new row to database.
    if ( !count($record_id) ) {
        $addRecord = add_record(
            $login['uacc'],
            $ou_group[1][1]
        );
        if ( $addRecord )
            $record_id = sql_q( $sql, array($login['uacc']) );
        else
            print_response_msg(5);
    }

    # Session content
    $profile = array(
        'record_id' => $record_id[0]['record_id'],
        'account'   => $login['uacc'],
        'name'      => $login['uname'],
        'dep'       => $ou_group[1][1]
    );

    # Define session
    $_SESSION[ session_id() ] = $profile;

    # Print login success message and session data.
    print_response_msg( 2, $profile );
}
Exemplo n.º 2
0
        $result = get_sessionData();
        print_response_msg(
            ( is_array($result) ? 4 : 5 ),
            ( is_array($result) ? $result : null )
        );
    break;

    case 'get_record':
        $result = get_record();
        print_response_msg(
            ( is_array($result) ? 4 : 5 ),
            ( is_array($result) ? $result : null )
        );
    break;
    
    case 'update_record':
        $result = update_record($_POST['column'] );
        print_response_msg(
            ( $result ? 4 : 5 )
        );
    break;

    case 'logout':
        logout();
        print_response_msg(4);
    break;

    default:
        print_response_msg(0);
    break;
}
Exemplo n.º 3
0
function error_handler( $error_level, $error_message, $error_file, $error_line, $error_context ) {
    $err_msg = $error_message." in ".$error_file." Line ".$error_line;
    print_response_msg( 9, $err_msg );

    if ( $error_level > 8 )
        die();
}