<?php

function formatCreateTranspData($in) {
    $in["member_id"] = $in["session_member_id"];
    $in['firstname'] = $in['patientinfo_firstname'];
    $in['lastname'] = $in['patientinfo_lastname'];
    $in['from_phone'] = $in['patientinfo_phone'];  //

    $in['from_street'] = $in['pickupaddress_streetaddress'];  //
    //$in['from_aptno'] = $in['pickupaddress_aptno'];  //
    $in['from_zipcode'] = $in['pickupaddress_zip'];  //

    $in['from_city'] = $in['pickupaddress_city'];  //
    $in['from_state'] = $in['pickupaddress_state'];  //
    $in['to_street'] = $in['dropoffaddress_streetaddress'];  //
    //$in['to_aptno'] = $in['dropoffaddress_aptno'];  //
    $in['to_zipcode'] = $in['dropoffaddress_zip'];  //
    $in['to_city'] = $in['dropoffaddress_city'];  //
    $in['to_state'] = $in['dropoffaddress_state'];  //
    $in['facilityname'] = $in['dropoffaddress_facilityname'];  //
    $in['transport_date'] = $in['datetime_currentdate'] . " " . $in['datetime_currentTime'];

// payment information 
    $in['paymenttype'] = $in['paymentinfo_paymenttype'];  //
    $in['paymentid'] = $in['paymentinfo_paymentid'];  //
    $in['cardname'] = $in['paymentinfo_fullname'];  //
    $in['cardnumber'] = $in['paymentinfo_cardnumber'];  //
    $in['exp_month'] = $in['paymentinfo_exp_month'];  //
    $in['exp_year'] = $in['paymentinfo_exp_year'];  //
    $in['cvc'] = $in['paymentinfo_cvc'];  //


    return $in;
}

function processOutJson($in, $out) {
    if ($in["action"] != MEDTRANS_USER_GET_TRANSLIST) {
        //     return $out;
    }


    switch ($in["action"]) {
        case WRENCHBOARD_START_JOBLIST:

            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total - 1),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "title" => $out["title_${key}"],
                    "description" => $out["description_${key}"],
                    "id" => $out["id_${key}"]             
                );
            }

            break;
        case MEDTRANS_USER_GET_LANGUAGE:
            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total - 1),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "language" => $out["language_${key}"],
                    "code" => $out["code_${key}"]
                );
            }
            break;

        case MEDTRANS_TRANSP_LISTLOCATION:

            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total - 1),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "agent_id" => $out["agent_id_${key}"],
                    "street" => $out["street_${key}"],
                    "city" => $out["city_${key}"],
                    "id" => $out["id_${key}"],
                    "state" => $out["state_${key}"],
                    "zipcode" => $out["zipcode_${key}"],
                    "state" => $out["state_${key}"]
                );
            }

            break;

        case MEDTRANS_TRANSP_GETREASON:

            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total - 1),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "key" => $out["lkey_${key}"],
                    "name" => $out["name_${key}"],
                    "lorder" => $out["lorder_${key}"]
                );
            }


            break;

        default:
            return $out;
    }

    return $res;
}
