Example #1
0
function reserve_confirm($user, $pass, $refrence_id)
{
    $sess = UsernameToken($user, $pass);
    $user_id = (int) $sess['user_id'];
    $customer_id = (int) $sess['customer_id'];
    if ($customer_id <= 0) {
        $out['err']['code'] = 2;
        $out['err']['msg'] = 'AUTH ERROR';
        return json_encode($out);
    }
    $out['err']['code'] = 5;
    $out['err']['msg'] = 'DB ERROR';
    $conf = new conf();
    //    $my = new mysqli($conf->local_host, $conf->local_user, $conf->local_pass, $conf->local_db);
    $my = new db_flight();
    if ($my->connect_errno !== FALSE) {
        $my->set_charset("utf8");
        $res = $my->query("select * from reserve_tmp where refrence_id = {$refrence_id} and state = 2 AND source_id=1 ");
        if ($res->num_rows == 0) {
            $out['err']['code'] = 15;
            $out['err']['msg'] = 'CONFIRM CODE IS FAIL';
        } else {
            while ($r = $res->fetch_assoc()) {
                $source_id = (int) $r['source_id'];
                $gres = trim($r['second_out']) != '' ? json_decode(trim($r['second_out'])) : NULL;
                $out['err']['code'] = 3;
                $out['err']['msg'] = 'SOURCE UNDFINED';
                if ($source_id == 1) {
                    if ($gres != NULL && $gres->status == 1) {
                        $client = new nusoap_client('http://164.138.22.33/AAA/server.php?wsdl', true);
                        $voucher_id = $gres->voucher_id;
                        $params = array('voucher_id' => $voucher_id);
                        $my->log_request($refrence_id, $r['id'], 1, 1, 1, json_encode($params), $user_id);
                        $result = $client->call('Confirm', array('param' => json_encode($params)));
                        $my->log_request($refrence_id, $r['id'], 1, 1, 2, $result, $user_id);
                        if ($client->fault) {
                            $out['err']['code'] = 4;
                            $out['err']['msg'] = 'GOHAR CONNECTION ERROR';
                            return json_encode($out);
                        } else {
                            $err = $client->getError();
                            if ($err) {
                                $out['err']['code'] = 4;
                                $out['err']['msg'] = 'GOHAR CONNECTION ERROR';
                                return json_encode($out);
                            } else {
                                if ($out['err']['code'] != 0) {
                                    $out['err']['code'] = 0;
                                    $out['err']['msg'] = '';
                                }
                                $pdata = trim($r['first_out']) != '' ? json_decode(trim($r['first_out'])) : NULL;
                                if ($pdata != NULL) {
                                    $my->query("update reserve_tmp set state = 3 , third_out = '{$result}',third_time='" . date("Y-m-d H:i:s") . "' where id = " . $r['id']);
                                    //                                $out['gres'] = $result;
                                    $gres = json_decode($result);
                                    if (isset($gres->status) && $gres->status == 1) {
                                        $out['voucher_id'] = $gres->voucher_id;
                                        //                                    $out['voucher_id'][] = $gres->voucher_id;
                                        //                                        $w_ghimat = getWGhimat($r['source_id'], $pdata->total_price);
                                        $out['s_ghimat'] = $pdata->total_price;
                                        $out['w_ghimat'] = getWGhimat($r['source_id'], $pdata->total_price);
                                        //                                        $my->query("insert into kharid (refrence_id,s_ghimat,w_ghimat,user_id) values ($refrence_id," . $pdata->total_price . ",$w_ghimat,$user_id)");
                                        $query = "SELECT ticket_number from ticket where refrence_id='{$refrence_id}' ";
                                        //                                    echo $query;
                                        $query = $my->query($query);
                                        $tn = 0;
                                        $ticket_number = array();
                                        while ($row = $query->fetch_assoc()) {
                                            $ticket_number[] = $row['ticket_number'];
                                            $tn++;
                                        }
                                        $out['ticket_number'] = $ticket_number;
                                        $pricing = "SELECT first_out FROM reserve_tmp WHERE id= {$r['id']} LIMIT 1";
                                        $pricing = $my->query($pricing);
                                        $pricing = $pricing->fetch_assoc();
                                        $extra = $pricing['first_out'];
                                        $pricing = json_decode($extra, TRUE);
                                        $pc = $my->query("SELECT currency FROM flight_reserve WHERE tflight='{$r['tflight']}' LIMIT 1 ");
                                        $pc = $pc->fetch_assoc();
                                        $pc = $pc['currency'];
                                        $reserve_total = array('reserve_tmp_id' => $r['id'], 'total' => $pricing['total_price'], 'fare' => $pricing['adult_price'], 'tax' => $pricing['total_tax'], 'fees' => '', 'chd' => $pricing['child_price'], 'inf' => $pricing['inf_price'], 'currency' => $pc, 'b_fare' => $pricing['badult_price'], 'b_tax' => $pricing['btotal_tax'], 'b_fees' => '', 'b_chd' => $pricing['bchild_price'], 'b_inf' => $pricing['binf_price'], 'b_currency' => '', 'extra' => $extra);
                                        //            if ($bflight_id != 0) {
                                        //                $reserve_total = array(
                                        //                    'b_fare' =>$info['specific_fields'][0]['BaseFare'] ,
                                        //                    'b_tax' => $info['flight_extras'][0]['tax'],
                                        //                    'b_fees' => '',
                                        //                    'b_chd' => '',
                                        //                    'b_inf' => '',
                                        //                    'b_currency' => $info['total']['CurrencyCode']
                                        //                );
                                        //            }
                                        $my->add_reserve_total($reserve_total);
                                        $my->refrence_status_update($refrence_id, 1);
                                    } else {
                                        $out['err']['code'] = 1013;
                                        $out['err']['msg'] = "CHANGE STATUS FLIGHT";
                                        $out['err']['source_code'] = $gres->error->error_code;
                                        $out['err']['source_msg'] = $gres->error->error_msg;
                                    }
                                } else {
                                    $out['err']['code'] = 10;
                                    $out['err']['msg'] = "NOT A VALID RESERVE";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return json_encode($out);
}