<?php

/* Extract Format Account Creation Inputs
 * 
 */

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['patient_number'] = $in['patientinfo_patient_number'];  //

    $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['service_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'];  //

    /*
     * ADD BASIC VALIDATION HERE 
     */

    return $in;
}

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

        case SAVVY_USERLOAD_SAVEDCARDS:
        case SAVVY_USERSAPP_SLIDECARD:

            $total = $out["total_record"];
            $res = array(
                "session_valid" => $out["session_valid"],
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "assign_id" => $out["assign_id_${key}"],
                    "card_id" => $out["card_id_${key}"],
                    "can_save" => $out["can_save_${key}"],
                    "name" => $out["name_${key}"],
                    "short_title" => $out["short_title_${key}"],
                    "title" => $out["title_${key}"],
                    "description" => $out["description_${key}"],
                    "background_picture" => $out["background_picture_${key}"],
                    "button1" => $out["button1_${key}"],
                    "button1_text" => $out["button1_text_${key}"],
                    "short_title" => $out["short_title_${key}"],
                    "button1_action" => $out["button1_action_${key}"],
                    "expires" => $out["expires_${key}"],
                    "template" => $out["template_${key}"],
                    "card_canexpire" => $out["card_canexpire_${key}"],
                    "card_action_type" => $out["card_action_type_${key}"],
                    "card_action_data" => $out["card_action_data_${key}"],
                    "titleshow" => $out["titleshow_${key}"],
                    "multiple_answer" => $out["multiple_answer_${key}"],
                    "use_short_title" => $out["use_short_title_${key}"],
                    "target_key" => $out["target_key_${key}"],
                    "target_text" => $out["target_text_${key}"],
                    "subscribe" => $out["subscribe_${key}"],
                    "long_description" => $out["long_description_${key}"],
                    "card_behavior" => $out["card_behavior_${key}"],
                    "card_type" => $out["card_type_${key}"],
                    "card_time" => $out["card_time_${key}"],
                    "card_country" => $out["card_country_${key}"],
                    "card_location" => $out["card_location_${key}"],
                    "latitude" => $out["latitude_${key}"],
                    "longitude" => $out["longitude_${key}"],
                    "card_order" => $out["card_order_${key}"],
                    "background_color" => $out["background_color_${key}"],
                    "blog_id" => $out["blog_id_${key}"],  
                    "expiration" => $out["expiration_${key}"]
                );
            } //  "request_id" => 324,


            break;

        case SAVVY_USERSAPP_LOADREDEEM:
            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "icon" => $out["icon_${key}"],
                    "redeem_id" => $out["redeem_id_${key}"],
                    "long_description" => $out["long_description_${key}"],
                    "points" => $out["points_${key}"],
                    "description" => $out["description_${key}"],
                    "key" => $out["key_${key}"]
                );
            } //  "request_id" => 324,


            break;
        case SAVVY_USER_GETSAVEDTRIPS:
            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "trip_id" => $out["trip_id_${key}"],
                    "trip_name" => $out["trip_name_${key}"],
                    "to" => $out["to_${key}"],
                    "from" => $out["from_${key}"],
                    "trip_date" => $out["date_${key}"],
                    "color" => $out["color_${key}"]
                );
            } //  "request_id" => 324,

            break;
        case SAVVY_USERSAPP_POINTSDEATAIL:
            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "name" => $out["name_${key}"],
                    "points" => $out["points_${key}"],
                    "added" => $out["added_${key}"],
                    "point_key" => $out["point_key_${key}"]
                );
            } //  "request_id" => 324,


            break;

        case SAVVY_USER_TRANSPORTPROFILE:

            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "id" => $out["id_${key}"],
                    "cost" => $out["cost_${key}"],
                    "name" => $out["name_${key}"]
                );
            } //  "request_id" => 324,


            break;

        case SAVVY_USER_TRANSPORTLIST:

            $total = $out["total_record"];
            $res = array(
                "status" => $out["status"],
                "total_record" => ($total),
                "internal_return" => $out["internal_return"],
                "result_list" => array(),
            );
            for ($i = 0; $i < $total; $i++) {
                $key = sprintf("%05d", $i);
                $res["result_list"][] = array(
                    "travel_date" => $out["travel_date_${key}"],
                    "location_start" => $out["location_start_${key}"],
                    "location_end" => $out["location_end_${key}"],
                    "duration" => $out["duration_${key}"],
                    "cost" => $out["cost_${key}"],
                    "distance" => $out["distance_${key}"],
                    "transport_provider" => $out["transport_provider_id_${key}"],
                    "parsedemail_item_id" => $out["parsedemail_item_id_${key}"]
                );
            } //  "request_id" => 324,
            break;
        /*
          case MOBIDELIV_USER_GETCCLIST:
          $total = $out["total_record"];
          $res = array(
          "status" => $out["status"],
          "total_record" => ($total),
          "internal_return" => $out["internal_return"],
          "result_list" => array(),
          );
          for ($i = 0; $i < $total; $i++) {
          $key = sprintf("%05d", $i);
          $res["result_list"][] = array(
          "paymentid" => $out["paymentid_${key}"],
          "digits" => $out["digits_${key}"],
          "description" => $out["description_${key}"],
          "expiration_month" => $out["expiration_month_${key}"],
          "expiration_year" => $out["expiration_year_${key}"]
          );
          } //  "request_id" => 324,

          break;

          case MOBIDELIV_PROVIDER_TANSPORTLIST:

          $total = $out["total_record"];
          $res = array(
          "status" => $out["status"],
          "total_record" => ($total),
          "internal_return" => $out["internal_return"],
          "result_list" => array(),
          );
          for ($i = 0; $i < $total; $i++) {
          $key = sprintf("%05d", $i);
          $res["result_list"][] = array(
          "transport_date" => $out["transport_date_${key}"],
          "transport_time" => $out["transport_time_${key}"],
          "firstname" => $out["firstname_${key}"],
          "lastname" => $out["lastname_${key}"],
          "from_phone" => $out["from_phone_${key}"],
          "from_street" => $out["from_street_${key}"],
          "to_street" => $out["to_street_${key}"],
          "from_city" => $out["from_city_${key}"],
          "to_city" => $out["to_city_${key}"],
          "from_state" => $out["from_state_${key}"],
          "to_state" => $out["to_state_${key}"],
          "from_zipcode" => $out["from_zipcode_${key}"],
          "to_zipcode" => $out["to_zipcode_${key}"],
          "miles" => $out["distance_${key}"],
          "id" => $out["id_${key}"],
          "request_id" => $out["id_${key}"],
          "status" => $out["status_${key}"],
          "status_description" => $out["status_description_${key}"],
          "assign_date" => $out["assign_date_${key}"],
          "dist_mode" => $out["dist_mode_${key}"],
          "needwheelchair" => $out["needwheelchair_${key}"],
          "abilitytowalk" => $out["abilitytowalk_${key}"],
          "conciergeneeded" => $out["conciergeneeded_${key}"],
          "courtappearance" => $out["courtappearance_${key}"]
          );
          } //  "request_id" => 324,
          break;
          case MOBIDELIV_PROVIDER_TRANSLATEIST:

          $total = $out["total_record"];
          $res = array(
          "status" => $out["status"],
          "total_record" => ($total),
          "internal_return" => $out["internal_return"],
          "result_list" => array(),
          );
          for ($i = 0; $i < $total; $i++) {
          $key = sprintf("%05d", $i);
          $res["result_list"][] = array(
          "transport_date" => $out["transport_date_${key}"],
          "transport_time" => $out["transport_time_${key}"],
          "firstname" => $out["firstname_${key}"],
          "lastname" => $out["lastname_${key}"],
          "from_phone" => $out["from_phone_${key}"],
          "from_street" => $out["from_street_${key}"],
          "to_street" => $out["to_street_${key}"],
          "from_city" => $out["from_city_${key}"],
          "to_city" => $out["to_city_${key}"],
          "from_state" => $out["from_state_${key}"],
          "to_state" => $out["to_state_${key}"],
          "from_zipcode" => $out["from_zipcode_${key}"],
          "to_zipcode" => $out["to_zipcode_${key}"],
          "miles" => $out["distance_${key}"],
          "id" => $out["id_${key}"],
          "request_id" => $out["id_${key}"],
          "status" => $out["status_${key}"],
          "status_description" => $out["status_description_${key}"],
          "lang_code" => $out["lang_code_${key}"],
          "language" => $out["language_${key}"],
          "status" => $out["status_${key}"],
          "assign_date" => $out["assign_date_${key}"],
          "courtappearance" => $out["courtappearance_${key}"],
          "dt_confirmed" => $out["dt_confirmed_${key}"],
          "dt_rejected" => $out["dt_rejected_${key}"],
          "language" => $out["language_${key}"],
          "flags" => $out["flags_${key}"]
          );
          }



          break;


          case MOBIDELIV_USER_GET_TRANSLLIST:

          $total = $out["total_record"];
          $res = array(
          "status" => $out["status"],
          "total_record" => ($total),
          "internal_return" => $out["internal_return"],
          "result_list" => array(),
          );
          for ($i = 0; $i < $total; $i++) {
          $key = sprintf("%05d", $i);
          $res["result_list"][] = array(
          "transport_date" => $out["transport_date_${key}"],
          "transport_time" => $out["transport_time_${key}"],
          "firstname" => $out["firstname_${key}"],
          "lastname" => $out["lastname_${key}"],
          "from_phone" => $out["from_phone_${key}"],
          "from_street" => $out["from_street_${key}"],
          "to_street" => $out["to_street_${key}"],
          "from_city" => $out["from_city_${key}"],
          "to_city" => $out["to_city_${key}"],
          "from_state" => $out["from_state_${key}"],
          "to_state" => $out["to_state_${key}"],
          "from_zipcode" => $out["from_zipcode_${key}"],
          "to_zipcode" => $out["to_zipcode_${key}"],
          "miles" => $out["distance_${key}"],
          "transport" => $out["transport_${key}"],
          "translate" => $out["translate_${key}"],
          "id" => $out["id_${key}"],
          "lang_code" => $out["lang_code_${key}"],
          "language" => $out["language_${key}"],
          "status" => $out["status_${key}"],
          "assign_date" => $out["assign_date_${key}"],
          "dist_mode" => $out["dist_mode_${key}"],
          "needwheelchair" => $out["needwheelchair_${key}"],
          "abilitytowalk" => $out["abilitytowalk_${key}"],
          "conciergeneeded" => $out["conciergeneeded_${key}"],
          "courtappearance" => $out["courtappearance_${key}"],
          "dt_confirmed" => $out["dt_confirmed_${key}"],
          "dt_rejected" => $out["dt_rejected_${key}"],
          "language" => $out["language_${key}"],
          "interpreter_id" => $out["interpreter_id_${key}"],
          "flags" => $out["flags_${key}"]
          );
          }
          break;

          case MOBIDELIV_USER_GETSERVICELIST:

          $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(
          "service_date" => $out["service_date_${key}"],
          "long_date" => $out["long_date_${key}"],
          "service_id" => $out["service_id_${key}"],
          "agent_name" => $out["agent_name_${key}"],
          "flags" => $out["flags_${key}"],
          "status" => $out["status_${key}"],
          "quantity" => $out["quantity_${key}"],
          "confirm_text" => $out["confirm_text_${key}"],
          "flag_text" => $out["flag_text_${key}"],
          "service_fee" => $out["service_fee_${key}"],
          "service_type_description" => $out["stype_desc_${key}"],
          "service_list_detail" => $out["service_list_detail_${key}"]
          );
          }

          break;
          case MOBIDELIV_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 MOBIDELIV_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 MOBIDELIV_USER_GET_INVOICE:

          break;

          case MOBIDELIV_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;
}
