first commit

This commit is contained in:
2019-05-25 23:11:05 -04:00
commit 16f48376bc
6139 changed files with 990356 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /agent/
#RewriteBase /
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
+604
View File
@@ -0,0 +1,604 @@
<?php
/*
* THIS IS AGENT INDEX FILE - THE CALL CAME FROM -
* https://{SERVER_NAME}/agent/agentlogin
*/
include '../config.php';
include '../constants.php';
$endpoints = array(
'createagent' => array('POST'),
'agentlogin' => array('POST'),
'updateprofile' => array('PUT'),
'createtransportrequest' => array('POST'),
'gettransportrequest' => array('GET'),
'gettransportlist' => array('POST'),
'verifysession' => array('POST'),
'listtransport' => array('POST'),
'addinterpreter' => array('POST'),
'listinterpreters' => array('POST'),
'listtransportlocation' => array('POST'),
'addtransportlocation' => array('POST'),
'editinterpreter' => array('POST'),
'getinterpreter' => array('POST'),
'editlocation' => array('POST'),
'getlocation' => array('POST'),
'getsupportedlanguage' => array('POST'),
'uploadfile' => array('POST'),
'download' => array('POST'),
'interpreterlang' => array('POST'),
'getinterpreterlanguage' => array('POST'),
'getagentlanguage' => array('POST'),
'createdriver' => array('POST'),
'getdriverslist' => array('POST'),
'updatedriver' => array('POST'),
'updatedriverstatus' => array('POST'),
'getdevicelist' => array('POST'),
'transportstatus' => array('POST'),
'getinvoice' => array('POST'),
'getreason' => array('POST'),
'gettranslationlist' => array('POST'),
'translationstatus' => array('POST'),
'getprofile' => array('POST')
);
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header('Content-type: application/json');
$endpoint = strtolower(str_replace('/agent/', '', strtok($_SERVER['REQUEST_URI'], '?')));
$id = 0; // update, get & delete actions require ID
if (substr($endpoint, 0, 19) == 'gettransportrequest' || substr($endpoint, 0, 13) == 'updateprofile') {
$endpoint = strtok($endpoint, '/');
$id = strtok('/');
}
if (!isset($endpoints[$endpoint])) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Invalid endpoint url\"}";
exit();
}
$methods = $endpoints[$endpoint];
if (array_search($_SERVER['REQUEST_METHOD'], $methods) === false) {
header('HTTP/1.1 405 Method Not Allowed');
header('Status: 405 Method Not Allowed');
echo "{\"status\":\"Invalid request method\"}";
exit();
}
include '../rest_api.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($endpoint == "uploadfile") {
upload_file_call();
exit();
} else if ($endpoint == "download") {
download_file_call();
exit();
} else {
$in = flatten(json_decode(file_get_contents('php://input'), true));
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$in = flatten(json_decode(file_get_contents('php://input'), true));
}
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
parse_str(file_get_contents('php://input'), $in);
}
switch ($endpoint) {
case 'createagent': $in["action"] = MOBIDELIV_TRANSP_CREATE;
$in["street1"] = $in["streetaddress"];
$in["country"] = "US";
$in['login'] = 1; // login forced
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'agentlogin': $in["action"] = MOBIDELIV_TRANSP_LOGIN;
break;
case 'updateprofile': $in["action"] = MOBIDELIV_USER_PROFILE;
$in["member_id"] = $id;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'getprofile': $in["action"] = MOBIDELIV_TRANSP_AGENTPROFILE;
break;
case 'createtransportrequest': $in["action"] = MOBIDELIV_USER_REQUEST_TRAN;
break;
case 'gettransportrequest': $in["action"] = 0;
$in["id"] = $id;
break;
case 'gettransportlist': $in["action"] = MOBIDELIV_TRANSP_GET_TRANSLIST;
break;
case 'verifysession': $in["action"] = MOBIDELIV_TRANSP_VERIFYSESSION;
break;
case 'addinterpreter': $in["action"] = MOBIDELIV_TRANSP_ADD_TRANSLATOR;
break;
case 'listinterpreters': $in["action"] = MOBIDELIV_TRANSP_LIST_TRANSLATOR;
break;
case 'getinterpreter': $in["action"] = MOBIDELIV_TRANSP_GET_TRANSLATOR;
break;
case 'editinterpreter': $in["action"] = MOBIDELIV_TRANSP_EDIT_TRANSLATOR;
break;
case 'addtransportlocation': $in["action"] = MOBIDELIV_TRANSP_ADDLOCATION;
break;
case 'listtransportlocation': $in["action"] = MOBIDELIV_TRANSP_LISTLOCATION;
break;
case 'editlocation': $in["action"] = MOBIDELIV_TRANSP_EDITLOCATION;
break;
case 'getlocation': $in['action'] = MOBIDELIV_TRANSP_GET_TRANSPORTER;
break;
case 'getsupportedlanguage': $in['action'] = MOBIDELIV_USER_GET_LANGUAGE;
break;
case 'interpreterlang': $in['action'] = MOBIDELIV_TRANSP_MANAGELANGUAGE;
break;
case 'getinterpreterlanguage': $in['action'] = MOBIDELIV_TRANSP_LANGUAGELIST;
break;
case 'getagentlanguage': $in['action'] = MOBIDELIV_TRANSP_AGENTLANGUAGE;
break;
case 'createdriver': $in["action"] = MOBIDELIV_TRANSP_DRIVERSCALL;
$in['mode'] = MODE_ADD;
break;
case 'getdriverslist': $in["action"] = MOBIDELIV_TRANSP_DRIVERSCALL;
$in['mode'] = MODE_LIST;
break;
case 'updatedriver': $in["action"] = MOBIDELIV_TRANSP_DRIVERSCALL;
$in['mode'] = MODE_UPDATE;
break;
case 'updatedriverstatus': $in["action"] = MOBIDELIV_TRANSP_DRIVERSCALL;
$in['mode'] = MODE_LIST;
break;
case 'getdevicelist': $in["action"] = MOBIDELIV_TRANSP_DEVICELIST;
break;
case 'transportstatus': $in["action"] = MOBIDELIV_TRANSP_SET_TRANSSTATUS;
break;
case 'getreason': $in["action"] = MOBIDELIV_TRANSP_GETREASON;
break;
case 'getinvoice': $in["action"] = MOBIDELIV_TRANSP_GETINVOICE;
break;
case 'gettranslationlist':$in["action"] = MOBIDELIV_TRANSP_GET_TRANSLATORLIST;
break;
case 'translationstatus':
$in["action"] = MOBIDELIV_TRANSL_SET_TRANSSTATUS;
break;
}
$in["pid"] = 100;
//file_put_contents("in_debug.log", $in); // DEBUG
$out = array();
external_internal_call($in, $out);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
//$out = array_merge($in, $out); // DEBUG
//echo json_encode($out);
echo json_encode(processAgentOutJson($in, $out));
exit();
function flatten($data, $parentkey = "") {
$result = array();
foreach ($data as $key => $val) {
if (is_array($val)) {
$result = array_merge($result, flatten($val, $parentkey . $key . "_"));
} else {
$result[$parentkey . $key] = $val;
}
}
return $result;
}
function download_file_call() {
global $target_url;
$data = $_POST;
$url = $target_url . "/../internal_agentdownload.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$output = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);
if ($status != 200) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Failed to download file\"}";
exit();
}
$header = substr($output, 0, $header_size);
$body = substr($output, $header_size);
$headers = array();
$data = explode("\r\n", $header);
//$headers['status'] = $data[0];
//array_shift($data);
foreach ($data as $part) {
if (strpos($part, ":") !== false) {
$middle = explode(":", $part);
$headers[trim($middle[0])] = trim($middle[1]);
}
}
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($headers["X-File-Name"]) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($body));
header("X-File-Name: " . $headers["X-File-Name"]);
echo $body;
}
function upload_file_call() {
global $target_url;
$data = $_POST;
$url = $target_url . "/../internal_agentupload.php";
$uploaddir = realpath('./') . '/files/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
if (!move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
$in["uploadfile"] = $uploadfile;
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Failed to upload file\"}";
exit();
}
//-----------------------------------------------------------
$file_name_with_full_path = realpath($uploadfile);
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$data['file_contents'] = '@' . $file_name_with_full_path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl) . "\"}";
}
curl_close($curl);
unlink($file_name_with_full_path);
//$response = json_decode($json_response, true);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
echo $json_response;
}
function processAgentOutJson($in, $out) {
if ($in["action"] != MOBIDELIV_TRANSP_GET_TRANSLIST) {
//return $out;
}
switch ($in["action"]) {
case MOBIDELIV_TRANSP_GET_TRANSLATORLIST:
$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(
"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}"],
"dt_completed" => $out["dt_completed_${key}"],
"language" => $out["language_${key}"],
"interpreter_id" => $out["interpreter_id_${key}"],
"status_description" => $out["status_description_${key}"],
"pstatus_date" => $out["pstatus_date_${key}"],
"flags" => $out["flags_${key}"]
);
}
break;
case MOBIDELIV_TRANSP_GET_TRANSLIST:
$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(
"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}"],
"dt_completed" => $out["dt_completed_${key}"],
"language" => $out["language_${key}"],
"driver" => $out["driver_${key}"],
"status_description" => $out["status_description_${key}"],
"pstatus_date" => $out["pstatus_date_${key}"],
"flags" => $out["flags_${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_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;
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}"],
"loc_name" => $out["loc_name_${key}"]
);
}
break;
case MOBIDELIV_TRANSP_LIST_TRANSLATOR:
$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}"],
"firstname" => $out["firstname_${key}"],
"lastname" => $out["lastname_${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}"],
"mobile_key" => $out["mobile_key_${key}"],
"mobile_pin" => $out["mobile_pin_${key}"]
);
}
break;
case MOBIDELIV_TRANSP_LANGUAGELIST:
$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}"],
"interpreter_id" => $out["interpreter_id_${key}"],
"language_id" => $out["language_id_${key}"],
"lang_code" => $out["lang_code_${key}"],
"language" => $out["language_${key}"],
"flags" => $out["flags_${key}"],
"status" => $out["status_${key}"],
"document" => $out["document_${key}"],
"document_id" => $out["document_id_${key}"],
"weekend" => $out["weekend_${key}"]
);
}
break;
case MOBIDELIV_TRANSP_AGENTLANGUAGE:
$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}"],
"firstname" => $out["firstname_${key}"],
"lastname" => $out["lastname_${key}"],
"street" => $out["street_${key}"],
"city" => $out["city_${key}"],
"state" => $out["state_${key}"],
"zipcode" => $out["zipcode_${key}"],
"language_id" => $out["language_id_${key}"],
"lang_code" => $out["lang_code_${key}"],
"language" => $out["language_${key}"],
"flags" => $out["flags_${key}"],
"weekend" => $out["weekend_${key}"],
"phone" => $out["phone_${key}"],
"interpreter_id" => $out["interpreter_id_${key}"],
);
}
break;
case MOBIDELIV_TRANSP_DRIVERSCALL:
if ($out['mode'] == MODE_LIST) {
$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}"],
"firstname" => $out["firstname_${key}"],
"lastname" => $out["lastname_${key}"],
"street" => $out["street_${key}"],
"city" => $out["city_${key}"],
"state" => $out["state_${key}"],
"zipcode" => $out["zipcode_${key}"],
"lic_state" => $out["lic_state_${key}"],
"email" => $out["email_${key}"],
"expr_month" => $out["expr_month_${key}"],
"expr_year" => $out["expr_year_${key}"],
"lic_number" => $out["lic_number_${key}"],
"phone" => $out["phone_${key}"],
"driver_id" => $out["driver_id_${key}"],
"mobile_key" => $out["mobile_key_${key}"],
"mobile_pin" => $out["mobile_pin_${key}"],
);
}
}
break;
default:
return $out;
}
return $res;
}
// vi:ts=2
+5
View File
@@ -0,0 +1,5 @@
<?php
$base_url = 'https://'.str_replace("extlayer","svrlayer",$_SERVER["SERVER_NAME"]);
$local_url = 'https://'.$_SERVER["SERVER_NAME"];
$target_url = $base_url."/internal.php";
?>
+98
View File
@@ -0,0 +1,98 @@
<?php
$target_url = $base_url."/internal.php";
define('SITE_NAME','medTrans');
define('SITE_EMAIL','info@medtrans.com');
define('SITE_PHONE','+1 911 9110');
define('SITE_FAX','+1 9FX 9110');
define('PHP_API_OK', 0);
define('MAX_ADMIN_SESSION',1200);
define('MOBIDELIV_UPLOADS', 4505);
define('MOBIDELIV_DOWNLOAD',4506);
// MEDTRANS BACK OFFICE FUNCTION*****************
define('MOBIDELIV_BKO_START', 100000);
define('MOBIDELIV_BKO_LOGIN', 100005);
define('MOBIDELIV_BKO_CREATEUSER', 100010);
define('MODE_ADD',100);
define('MODE_UPDATE',200);
define('MODE_DELETE',300);
define('MODE_LIST',400);
define('MOBIDELIV_BKO_END', 199999);
// MEDTRANS USER FUNCTIONS***********************
define('MOBIDELIV_USER_START', 200000);
define('MOBIDELIV_USER_DRYCLIST', 200002);
define('MOBIDELIV_USER_LOGIN', 200005);
define('MOBIDELIV_USER_VERIFYSESSION', 200007);
define('MOBIDELIV_USER_CREATE', 200010); //
define('MOBIDELIV_USER_COMPLETEPROFILE', 200013);
define('MOBIDELIV_USER_PROFILE', 200020); //
define('MOBIDELIV_USER_SAVECARDPAYMENT', 200021);
define('MOBIDELIV_USER_GETCCLIST', 200022);
define('MOBIDELIV_USER_NEWLUNDRYPICK', 200025); // REQUEST TRANSPORT
define('MOBIDELIV_USER_GET_TRAN_BYID', 200030); // REQUEST TRANSPORT
//define('MOBIDELIV_USER_GET_TRANSLIST', 200037); // REQUEST TRANSPORT
define('MOBIDELIV_USER_GETSERVICELIST', 200035); // REQUEST TRANSPORT
define('MOBIDELIV_USER_LUNDRYLOCATION', 200040);
define('MOBIDELIV_USER_CONFIRMPICKUP', 200064);
define('MOBIDELIV_USER_GETSERVICEITEM', 200065);
define('MOBIDELIV_USER_GETCCLIST', 200066);
define('MOBIDELIV_USER_START_PASSRESET', 200067);
define('MOBIDELIV_USER_CONFIRM_RESET', 200068);
define('MOBIDELIV_USER_COMPLETE_PASSRESET', 200069);
define('MOBIDELIV_USER_DELETECARD', 200075);
define('MOBIDELIV_USER_END', 299999);
// MEDTRANS INTERPRETERS ***************************
define('MOBIDELIV_INTERP_START', 300000);
define('MOBIDELIV_INTERP_END', 399999);
// MEDTRANS TRANLATORS ***************************
define('MOBIDELIV_TRANSP_START', 400000);
define('MOBIDELIV_TRANSP_LOGIN', 400005);
define('MOBIDELIV_TRANSP_VERIFYSESSION', 400007);
define('MOBIDELIV_TRANSP_CREATE', 400010); // MOBIDELIV_AGENT_CREATE
define('MOBIDELIV_TRANSP_ADDLOCATION', 400020); //
define('MOBIDELIV_TRANSP_LISTLOCATION', 400021);
define('MOBIDELIV_TRANSP_EDITLOCATION', 400022);
define('MOBIDELIV_TRANSP_GET_TRANSLIST', 400040);
define('MOBIDELIV_TRANSP_GET_TRANSPORTER', 400041);
define('MOBIDELIV_TRANSP_GET_TRANSLATOR', 400044);
define('MOBIDELIV_TRANSP_ADD_TRANSLATOR', 400045);
define('MOBIDELIV_TRANSP_LIST_TRANSLATOR', 400046);
define('MOBIDELIV_TRANSP_EDIT_TRANSLATOR', 400047);
define('MOBIDELIV_TRANSP_MANAGELANGUAGE', 400049);
define('MOBIDELIV_TRANSP_LANGUAGELIST', 400050);
define('MOBIDELIV_TRANSP_AGENTLANGUAGE', 400051); // LANGUAGE SUPPORTED BY AGENT
define('MOBIDELIV_TRANSP_DRIVERSCALL', 400060);
define('MOBIDELIV_TRANSP_DEVICELIST', 405000);
define('MOBIDELIV_TRANSP_END', 499999);
//***********************************************
+53
View File
@@ -0,0 +1,53 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$in = $_POST;
$out = array();
external_internal_call($in, $out);
//NOTE
//$out['internal_return'] = $ret;
// this is reserved array parameter - to be caprured and reoved before you use the out array()
foreach ($out as $key => $value) {
echo $key . "=" . base64_encode($value) . "\n";
}
} else {
echo "status=" . base64_encode("Invalid request method") . "\n";
}
/*
THIS IS AN EXTERNAL LAYER OF TOTAL SEPARATION
*/
function external_internal_call($in, &$out) {
global $target_url; // "svrlayer/internal.php";
$fields_string = "";
//url-ify the data for the POST
foreach ($in as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, count($in));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
// Parse result
foreach (explode("\n", $result) as $line) {
if ($line == "" || strpos($line, "=") === false)
continue;
$key = trim(strtok($line, "="));
if ($key != "") {
$out[$key] = base64_decode(substr($line, 1 + strlen($key)));
}
}
}
+347
View File
@@ -0,0 +1,347 @@
<?php
/* Extract 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 MOBIDELIV_USER_DRYCLIST:
$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}"],
"code" => $out["code_${key}"],
"price" => $out["price_${key}"],
"description" => $out["description_${key}"]
);
} // "request_id" => 324,
break;
case MOBIDELIV_USER_LUNDRYLOCATION:
$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(
"agent_id" => $out["agent_id_${key}"],
"agent_name" => $out["agent_name_${key}"],
"status" => $out["status_${key}"],
"city" => $out["city_${key}"],
"street" => $out["street_${key}"],
"zipcode" => $out["zipcode_${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;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

+22
View File
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /provider/
#RewriteBase /
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
+199
View File
@@ -0,0 +1,199 @@
<?php
include '../config.php';
include '../constants.php';
include '../formerter.php';
$endpoints = array(
'createuser' => array('POST'),
'userlogin' => array('POST'),
'getprofile' => array('POST'),
'updateprofile' => array('POST'),
'provision' => array('POST'),
'gettranslationlist' => array('POST'),
'gettransportrequest' => array('GET'),
'gettransportlist' => array('POST'),
'getsupportedlanguage' => array('POST'),
'verifysession' => array('POST'),
'getreason' => array('POST'),
'setrequeststatus' => array('POST'),
'verifysession' => array('POST')
);
/*
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
//header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
die();
}
*/
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
exit();
}
$endpoint = strtolower(str_replace('/provider/', '', strtok($_SERVER['REQUEST_URI'],'?')));
$id = 0; // update, get & delete actions require ID
if (substr($endpoint,0,19)=='gettransportrequest'
|| substr($endpoint,0,13)=='updateprofile') {
$endpoint = strtok($endpoint,'/');
$id = strtok('/');
}
if (!isset($endpoints[$endpoint])) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Invalid endpoint url\"}";
exit();
}
$methods = $endpoints[$endpoint];
if (array_search($_SERVER['REQUEST_METHOD'], $methods)===false) {
header('HTTP/1.1 405 Method Not Allowed');
header('Status: 405 Method Not Allowed');
echo "{\"status\":\"Invalid request method\"}";
exit();
}
include '../rest_api.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($endpoint == "uploadfile") {
upload_file_call();
exit();
} else {
$in = flatten(json_decode(file_get_contents('php://input'), true));
}
}
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
parse_str(file_get_contents('php://input'), $in);
}
switch ($endpoint) {
case 'createuser': $in["action"] = MOBIDELIV_PROVIDER_CREATE;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'userlogin': $in["action"] = MOBIDELIV_PROVIDER_LOGIN;
break;
case 'provision': $in["action"] = MOBIDELIV_PROVIDER_PROVISION;
break;
case 'gettranslationlist': $in["action"] = MOBIDELIV_PROVIDER_TRANSLATEIST;
break;
case 'gettransportlist': $in["action"] = MOBIDELIV_PROVIDER_TANSPORTLIST;
break;
case 'setrequeststatus': $in["action"] = MOBIDELIV_PROVIDER_SETSTATUS;
break;
case 'verifysession': $in['action'] = MOBIDELIV_PROVIDER_VERIFYSESSION;
break;
case 'getprofile' : $in['action'] = MOBIDELIV_PROVIDER_PROFILE;
break;
case 'updateprofile': $in["action"] = MOBIDELIV_PROVIDER_UPDATEPROFILE;
break;
case 'gettransportrequest': $in["action"] = MOBIDELIV_USER_GET_TRAN_BYID;
$in["transport_id"] = $id;
break;
case 'getsupportedlanguage': $in['action'] = MOBIDELIV_USER_GET_LANGUAGE;
break;
}
$in["pid"] = 100;
//file_put_contents("in_debug.log", $in); // DEBUG
$out = array();
external_internal_call($in, $out);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
//$out = array_merge($in, $out); // DEBUG
echo json_encode(processOutJson($in, $out));
exit();
function flatten($data, $parentkey="") {
$result = array();
foreach ($data as $key=>$val) {
if (is_array($val)) {
$result = array_merge($result, flatten($val, $parentkey.$key."_"));
} else {
$result[$parentkey.$key] = $val;
}
}
return $result;
}
function upload_file_call()
{
global $target_url;
$data = $_POST;
$url = $target_url."/../internal_upload.php";
$uploaddir = realpath('./') . '/files/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
if (!move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
$in["uploadfile"] = $uploadfile;
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Failed to upload file\"}";
exit();
}
//-----------------------------------------------------------
$file_name_with_full_path = realpath($uploadfile);
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$data['file_contents'] = '@'.$file_name_with_full_path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST,1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)."\"}";
}
curl_close($curl);
unlink($file_name_with_full_path);
//$response = json_decode($json_response, true);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
echo $json_response;
}
// vi:ts=2
+36
View File
@@ -0,0 +1,36 @@
<?php
include 'config.php';
include 'constants.php';
function external_internal_call($in, &$out) {
global $target_url; // = svrlayer/internal.php";
$fields_string = "";
//url-ify the data for the POST
foreach ($in as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, count($in));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
// Parse result
foreach (explode("\n", $result) as $line) {
if ($line == "" || strpos($line, "=") === false)
continue;
$key = trim(strtok($line, "="));
if ($key != "") {
$out[$key] = base64_decode(substr($line, 1 + strlen($key)));
}
}
}
+22
View File
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /user/
#RewriteBase /
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
+221
View File
@@ -0,0 +1,221 @@
<?php
include '../config.php';
include '../constants.php';
include '../formerter.php';
$endpoints = array(
'getdrycleanservicelist' => array('POST'),
'createuser' => array('POST'),
'userlogin' => array('POST'),
'updateprofile' => array('POST'),
'updsprofile' => array('POST'),
'newlundrypickup' => array('POST'),
'newdrycleanpickup' => array('POST'),
'confirmlundrypickup' => array('POST'),
'savecardpayment' => array('POST'),
'getlundrylocation' => array('POST'),
'getcardpaymentlist' => array('POST'),
'getmyservicelist' => array('POST'),
'getoneserviceitem' => array('POST'),
'loadprofile' => array('POST'),
'deletecard' => array('POST')
);
/*
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
//header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
die();
}
*/
header("Access-Control-Allow-Origin: *");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
header('Content-type: application/json');
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
exit();
}
$endpoint = strtolower(str_replace('/user/', '', strtok($_SERVER['REQUEST_URI'],'?')));
$id = 0; // update, get & delete actions require ID
if (substr($endpoint,0,19)=='gettransportrequest'
|| substr($endpoint,0,13)=='updateprofile') {
$endpoint = strtok($endpoint,'/');
$id = strtok('/');
}
if (!isset($endpoints[$endpoint])) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Invalid endpoint url\"}";
exit();
}
$methods = $endpoints[$endpoint];
if (array_search($_SERVER['REQUEST_METHOD'], $methods)===false) {
header('HTTP/1.1 405 Method Not Allowed');
header('Status: 405 Method Not Allowed');
echo "{\"status\":\"Invalid request method\"}";
exit();
}
include '../rest_api.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($endpoint == "uploadfile") {
upload_file_call();
exit();
} else {
$in = flatten(json_decode(file_get_contents('php://input'), true));
}
}
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
parse_str(file_get_contents('php://input'), $in);
}
$in["loc"] = $_SERVER["REMOTE_ADDR"]; // get who is connecting IP
$in["pid"] = 100;
switch ($endpoint) {
case 'getdrycleanservicelist': $in["action"] = MOBIDELIV_USER_DRYCLIST;
break;
case 'createuser': $in["action"] = MOBIDELIV_USER_CREATE;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'userlogin': $in["action"] = MOBIDELIV_USER_LOGIN;
break;
case 'updateprofile': $in["action"] = MOBIDELIV_USER_PROFILE;
$in["street1"] = $in["streetaddress"];
$in["zipcode"] = $in["zip"];
$in["country"] = "US";
$in["loc"] = $_SERVER["REMOTE_ADDR"];
break;
case 'updsprofile': $in["action"] = MOBIDELIV_USER_COMPLETEPROFILE;
break;
case 'getcardpaymentlist': $in["action"] = MOBIDELIV_USER_GETCCLIST;
break;
case 'newlundrypickup': $in["action"] = MOBIDELIV_USER_NEWLUNDRYPICK;
$in["service_type"] = 1;
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
break;
case 'newdrycleanpickup': $in["action"] = MOBIDELIV_USER_NEWLUNDRYPICK;
$in["service_type"] = 2;
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
break;
case 'confirmlundrypickup': $in["action"] = MOBIDELIV_USER_CONFIRMPICKUP;
break;
case 'savecardpayment': $in["action"] = MOBIDELIV_USER_SAVECARDPAYMENT;
break;
case 'getlundrylocation': $in["action"] = MOBIDELIV_USER_LUNDRYLOCATION;
$in["limit"] = 100;
break;
case 'getmyservicelist': $in["action"] = MOBIDELIV_USER_GETSERVICELIST;
break;
case 'getoneserviceitem': $in["action"] = MOBIDELIV_USER_GETSERVICEITEM;
break;
case 'loadprofile': $in["action"] = MOBIDELIV_USER_PROFILE;
break;
case 'deletecard': $in["action"] = MOBIDELIV_USER_DELETECARD;
break;
}
$in["pid"] = 100;
//file_put_contents("in_debug.log", $in); // DEBUG
$out = array();
external_internal_call($in, $out);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
//$out = array_merge($in, $out); // DEBUG
echo json_encode(processOutJson($in, $out));
exit();
function flatten($data, $parentkey="") {
$result = array();
foreach ($data as $key=>$val) {
if (is_array($val)) {
$result = array_merge($result, flatten($val, $parentkey.$key."_"));
} else {
$result[$parentkey.$key] = $val;
}
}
return $result;
}
function upload_file_call()
{
global $target_url;
$data = $_POST;
$url = $target_url."/../internal_upload.php";
$uploaddir = realpath('./') . '/files/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
if (!move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
$in["uploadfile"] = $uploadfile;
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Failed to upload file\"}";
exit();
}
//-----------------------------------------------------------
$file_name_with_full_path = realpath($uploadfile);
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$data['file_contents'] = '@'.$file_name_with_full_path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST,1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
header('HTTP/1.1 400 Bad Request');
header('Status: 400 Bad Request');
echo "{\"status\":\"Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)."\"}";
}
curl_close($curl);
unlink($file_name_with_full_path);
//$response = json_decode($json_response, true);
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
echo $json_response;
}
// vi:ts=2
+60
View File
@@ -0,0 +1,60 @@
<?php
require_once '../config.php';
$url = $local_url . "/user/createuser";
$username = urlencode("ses66181+" . rand(1000, 9999) . "@gmail.com");
$phone = (rand(1, 2) > 1) ? "770222" . rand(2222, 9999) : '';
include '../sample_data.php'; // just for sample data
$firstname = random_name(); //
$lastname = random_name(); //
$company_name = '';
if (rand(0, 1) == 1) {
$company_name = "Company name which is optional " . rand(1000, 9999);
}
$data = array(
"username" => $username,
"password" => "kleenuser",
"email" => $username,
"firstname" => $firstname,
"lastname" => $lastname,
"phone" => $phone,
"company_name" => $company_name
);
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
//echo "<pre>";var_dump($json_response);echo "</pre>";
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo ("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
var_dump($response);
echo "<hr/>";
var_dump($data);
echo "<hr/>";
echo highlight_string(file_get_contents(__FILE__));
?>