예제 #1
0
function hot_reserve($user, $pass, $param)
{
    //var_dump($param);
    $rooms_id = isset($param->rooms_id) ? $param->rooms_id : 0;
    //    $hotel_id = isset($param->hotel_id) ? $param->hotel_id : 0;
    $check_in = isset($param->check_in) ? $param->check_in : NULL;
    $check_out = isset($param->check_out) ? $param->check_out : NULL;
    $adult = isset($param->adult) ? $param->adult : 2;
    $child = isset($param->child) ? $param->child : 0;
    $inf = isset($param->inf) ? $param->inf : 0;
    $passengers = isset($param->passengers) ? $param->passengers : NULL;
    $mobile = isset($param->mobile) ? $param->mobile : '';
    $email = isset($param->email) ? $param->email : '';
    $address = isset($param->address) ? $param->address : '';
    //
    //    if ($room_id == 0 || $check_in == NULL ) {
    //        $return['err']['code'] = 2001;
    //        $return['err']['ecode'] = 21011;
    //        $return['err']['msg'] = "CHECK INPUT VALUES";
    //        return json_encode($return);
    //    }
    global $db_hotel;
    $passengers = json_decode($passengers, TRUE);
    //var_dump($passengers);
    $rooms = json_decode($rooms_id, TRUE);
    $reserve_room_data = $db_hotel->reserve_room_data($rooms);
    //    print_r($reserve_room_data);
    if (count($reserve_room_data) != count($rooms)) {
        $return['err']['code'] = 2001;
        $return['err']['ecode'] = "C21012";
        $return['err']['msg'] = "CHECK INPUT VALUES";
        return json_encode($return);
    }
    if (count($passengers) != count($rooms)) {
        $return['err']['code'] = 2001;
        $return['err']['ecode'] = "C21013";
        $return['err']['msg'] = "CHECK INPUT VALUES";
        return json_encode($return);
    }
    if (count($rooms) > 1) {
        if ($reserve_room_data[1]['source_id'] != $reserve_room_data[1]['source_id'] || $reserve_room_data[1]['hotels_id'] != $reserve_room_data[1]['hotels_id']) {
            $return['err']['code'] = 2001;
            $return['err']['ecode'] = "C21014";
            $return['err']['msg'] = "CHECK INPUT VALUES";
            return json_encode($return);
        }
    }
    $source_id = $reserve_room_data[1]['source_id'];
    $sess = UsernameToken($user, $pass);
    $user_id = (int) $sess['user_id'];
    $refrence_id = $db_hotel->refrence_generator($user_id, 2);
    $today = new DateTime();
    foreach ($rooms as $room_number => $room_id) {
        $adult = 0;
        $child = 0;
        $inf = 0;
        foreach ($passengers[$room_number] as $pid => $passenger) {
            //            $passengers[$room_number]['room_id']=$room_id;
            if (!isset($passenger['prefix'])) {
                //                if($passenger['gender']=='M') $passengers[$room_id][]
            }
            try {
                $birth = new DateTime($passenger['birthday']);
                // three days difference!
            } catch (Exception $ex) {
                $return['err']['code'] = 2001;
                $return['err']['ecode'] = "C21014.1";
                $return['err']['msg'] = "CHECK passenger_birth";
                return json_encode($return);
            }
            $diff = $birth->diff($today);
            $age = $diff->format('%y') + 1;
            $passengers[$room_number][$pid]['age'] = $age;
            if ($passengers[$room_number][$pid]['passenger_type'] == 'CHD') {
                $child++;
            } elseif ($passengers[$room_number][$pid]['passenger_type'] == 'ADT') {
                $adult++;
            } else {
                $return['err']['code'] = 2001;
                $return['err']['ecode'] = "C21014.1";
                $return['err']['msg'] = "CHECK passenger_type";
                return json_encode($return);
            }
            //_______________________
            $reserve_room_data[$room_number]['room_id'] = $room_id;
            $reserve_room_data[$room_number]['adult'] = $adult;
            $reserve_room_data[$room_number]['child'] = $child;
            $reserve_room_data[$room_number]['inf'] = $inf;
        }
        $db_hotel->insert_passenger($refrence_id, '', $passengers[$room_number], $mobile, $email, $address, $room_id, $room_number);
    }
    $source_hotel_id = $reserve_room_data[1]['id_source_hotel'];
    //var_dump($reserve_room_data);
    /* Reserve_room_data Parameter
        $return[$rooms_id[$i]]['id_room_source']=$row['id_room_source'];
        $return[$rooms_id[$i]]['source_id']=$row['source_id'];
        $return[$rooms_id[$i]]['hotels_id']=$row['hotels_id'];
        $return[$rooms_id[$i]]['id_source_hotel']=$row['id_source_hotel'];
        $return[$rooms_id[$i]]['extra_data']=$row['extra_data'];
       */
    //$id_reserve_tmp = $db_hotel->hot_reserve_temp($refrence_id, $user_id, $source_id, $reserve_room_data, $check_in, $check_out);
    $id_reserve_tmp = $db_hotel->hot_reserve_temp($refrence_id, $user_id, $source_id, $reserve_room_data, $check_in, $check_out);
    $fn_reserve = hot_reserve_fn_finder($source_id);
    if ($fn_reserve == FALSE) {
        $return['err']['code'] = 2001;
        $return['err']['ecode'] = "C21015";
        $return['err']['msg'] = "CHECK INPUT VALUES";
        return json_encode($return);
    }
    $out = call_user_func($fn_reserve, $refrence_id, $reserve_room_data, $check_in, $check_out, $passengers, $mobile, $email, $address);
    //    if(isset($out['err'])){
    //        return json_encode($out);
    //    }
    $db_hotel->close();
    return json_encode($out);
}
예제 #2
0
function search2($user, $pass, $aztarikh, $tatarikh, $from_city, $to_city, $extra, $airlines, $sort, $way)
{
    if (trim($airlines) == '') {
        $airlines = array();
    } else {
        $airlines = explode(",", $airlines);
    }
    $out = array("err" => array("code" => "1", "msg" => "Unknown ERROR"), "data" => array());
    $param = array();
    $sess = UsernameToken($user, $pass);
    $user_id = (int) $sess['user_id'];
    $customer_id = (int) $sess['customer_id'];
    $out['data'] = array();
    if ($customer_id <= 0) {
        $out['err']['code'] = 2;
        $out['err']['msg'] = 'AUTH ERROR';
        return json_encode($out);
    }
    $source = new source_class();
    $wer = $source->createWhere($customer_id);
    $aztarikh = trim($aztarikh);
    $tatarikh = trim($tatarikh);
    $extra = trim($extra);
    $from_city = trim($from_city);
    $to_city = trim($to_city);
    if ($aztarikh != '') {
        $param['aztarikh'] = $aztarikh;
    }
    if ($tatarikh != '') {
        $param['tatarikh'] = $tatarikh;
    }
    if ($extra != '') {
        $param['extra'] = $extra;
    }
    if (strlen($from_city) == 3 && strlen($to_city) == 3) {
        $param['from_city'] = $from_city;
        $param['to_city'] = $to_city;
    }
    if (count($airlines) > 0) {
        $param['extra'] = 'extra';
        $airs = array();
        foreach ($airlines as $airline) {
            $tmp = explode("|", $airline);
            foreach ($tmp as $tt) {
                $airs[] = $tt;
            }
        }
        $param['airline'] = $airs;
    }
    $param['sort'] = $sort;
    $param['way'] = $way;
    /*
     else
     {
     $out['err']['code'] = 2;
     $out['err']['msg'] = 'From or To CITY IATA code is not right.';
     }
    * 
    */
    $flight = new flight_class(TRUE, $param, $wer);
    $out['data'] = $flight->data;
    $out['err']['code'] = 0;
    $out['err']['msg'] = '';
    //    $out['query'] = $flight->query;
    $conf = new conf();
    $my = new mysqli($conf->local_host, $conf->local_user, $conf->local_pass, $conf->local_db);
    if ($my->connect_errno !== FALSE) {
        $my->set_charset("utf8");
        $my->query("insert into search_log (user_id,func,query,param) values ({$user_id},'search2','" . $my->real_escape_string($flight->query) . "','" . json_encode($param) . "')");
    }
    return json_encode($out);
}