192 lines
5.8 KiB
PHP
192 lines
5.8 KiB
PHP
<?php
|
|
|
|
include '../../backend.php';
|
|
include 'constants.php';
|
|
include 'formarter.php';
|
|
|
|
$endpoints = array(
|
|
'createuser' => array('POST'),
|
|
'createmobileuser' => array('POST'),
|
|
'completemobileuser' => array('POST'),
|
|
'startresetpasword' => array('POST'),
|
|
'userlogin' => array('POST'),
|
|
'startjoblist' => array('POST'),
|
|
'dashdata' => array('POST'),
|
|
'getjobsdata' => array('POST'),
|
|
'offerslist' => array('POST'),
|
|
'activejoblist' => array('POST'),
|
|
'loadprofile' => array('POST'),
|
|
'account' => array('POST'),
|
|
'message' => array('POST'),
|
|
'pendingjob' => array('POST'),
|
|
'paymenthx' => array('POST'),
|
|
'getjob' => array('POST'),
|
|
'mybanklist' => array('POST'),
|
|
'sendmoney' => array('POST'),
|
|
'sendinterest' => array('POST'),
|
|
'sendmoneyfee' => array('POST'),
|
|
'getpendingjobs' => array('POST'),
|
|
'taskmessage' => array('POST'),
|
|
'sendtaskmessage' => 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('/svs/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();
|
|
}
|
|
|
|
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);
|
|
}
|
|
if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
|
$in = $_GET;
|
|
}
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
switch ($endpoint) {
|
|
case 'startjoblist': $in["action"] = WRENCHBOARD_START_JOBLIST;
|
|
break;
|
|
|
|
case 'createmobileuser': $in["action"] = WRENCHBOARD_CREATE_MOBILEUSER;
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
$in["news"] = 0;
|
|
$in["terms"] = 1;
|
|
$in["mobile"] = "MOBILE";
|
|
break;
|
|
case 'completemobileuser': $in["action"] = WRENCHBOARD_COMPLETE_MOBILEUSER;
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
break;
|
|
|
|
case 'startresetpasword':
|
|
$in["action"] = WRENCHBOARD_RESET_PASSWORD;
|
|
break;
|
|
case 'createuser': $in["action"] = WRENCHBOARD_ACCOUNT_PENDING;
|
|
$in["street1"] = $in["streetaddress"];
|
|
$in["zipcode"] = $in["zip"];
|
|
$in["country"] = "US";
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
$in["mobile"] = "MOBILE";
|
|
break;
|
|
case 'activejoblist': $in["action"] = WRENCHBOARD_MOBILE_ACTIVEJOB;
|
|
break;
|
|
case 'message': $in["action"] = WRENCHBOARD_MOBILE_MESSAGE;
|
|
|
|
break;
|
|
case 'paymenthx': $in["action"] = WRENCHBOARD_MOBILE_PAYMENTHX;
|
|
|
|
break;
|
|
case 'getjobsdata': $in["action"] = WRENCHBOARD_ACCOUNT_JOBLIST;
|
|
break;
|
|
|
|
case 'userlogin': $in["action"] = WRENCHBOARD_ACCOUNT_LOGIN;
|
|
break;
|
|
|
|
case 'dashdata': $in["action"] = WRENCHBOARD_ACCOUNT_DASHDATA;
|
|
break;
|
|
case 'offerslist': $in["action"] = WRENCHBOARD_MOBILE_OFFERSLIST;
|
|
break;
|
|
|
|
case 'loadprofile': $in["action"] = WRENCHBOARD_MOBILE_LOADPROFILE;
|
|
break;
|
|
case 'account': $in["action"] = WRENCHBOARD_MOBILE_ACCOUNT;
|
|
break;
|
|
case 'getpendingjobs':
|
|
$in["action"] = WRENCHBOARD_ACCOUNT_PENDJOB;
|
|
break;
|
|
case 'pendingjob':
|
|
|
|
break;
|
|
case 'getjob':
|
|
|
|
break;
|
|
|
|
case 'mybanklist':$in["action"] = WRENCHBOARD_USER_GETBANKLIST;
|
|
break;
|
|
case 'sendmoney':$in["action"] = WRENCHBOARD_USER_SENDMONEY;
|
|
$out["internal_return"] = 0;
|
|
break;
|
|
case 'sendinterest':$in["action"] = WRENCHBOARD_USER_SENDJOBINT;
|
|
$out["internal_return"] = 0;
|
|
break;
|
|
case 'sendmoneyfee': $in["action"] = WRENCHBOARD_SMONEY_PROCFEE;
|
|
break;
|
|
case 'taskmessage': $in["action"] = WRENCHBOARD_MOBILE_TASKMESSAGE;
|
|
break;
|
|
case 'sendtaskmessage': $in["action"] = WRENCHBOARD_MOBILE_SENDTASKMESSAGE;
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
$in["pid"] = 100;
|
|
|
|
//file_put_contents("in_debug.log", $in); // DEBUG
|
|
|
|
$out = array();
|
|
$ret = $wrenchboard->wrenchboard_api($in, $out);
|
|
$out['internal_return'] = $ret; // this is reserved array parameter - to be caprured and reoved before you use the out array()
|
|
|
|
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;
|
|
}
|
|
|
|
// vi:ts=2
|