cfgReadChar("database.host")); //phpinfo(); $endpoints = array( 'createuser' => array('POST'), 'login' => array('POST'), 'userlogin' => array('POST'), 'getprofile' => array('POST'), 'userstask' => array('POST') ); 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'); $endpoint = strtolower(str_replace('/api/users/', '', strtok($_SERVER['REQUEST_URI'], '?'))); 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") { if ($endpoint == "uploadfile") { upload_file_call(); exit(); } else { $raw_json = file_get_contents("php://input"); $raw_array = json_decode($raw_json, true); $in = flatten($raw_array); } } // $in["action"] = MERMS_USER_CREATEACCOUNT; $in["loc"] = $_SERVER["REMOTE_ADDR"]; switch ($endpoint) { case 'userlogin': case 'login': $in["action"] = MERMS_USER_LOGIN; //$in["account_no"] = "7702222222"; //$in["password"] = "1234"; break; case 'createuser': $in["action"] = MERMS_USER_CREATEACCOUNT; //$in["action_recieved"] = MERMS_USER_CREATEACCOUNT; break; case 'userstask': $in["action"] = MERMS_USER_REMINDERS; break; } $out = $in; switch ( $in["action"] ) { case 100: $out["return"] = "REACH AND BACK"; $out["retrun_number"] = rand(1000,9999); $out["endpoint"] = $endpoint; break; case MERMS_USER_BEFORESESSION: break; case MERMS_USER_CREATEACCOUNT: // start account // complete account $out["return"] = "REACH AND BACK CREATE ACCOUNT"; $out["retrun_number"] = rand(1000,9999); $out["endpoint"] = $endpoint; break; case MERMS_USER_RESETPASSWORD: // start reset // complete reset // resend reset break; case MERMS_USER_LOGIN: break; case MERMS_USER_DASHLOAD: break; case MERMS_USER_LOADPROFILE: break; case MERMS_USER_UPDATEPROFILE: break; case MERMS_USER_REMINDERS: // configure // update // delete/stop break; } // calling the backend $out["internal_return"]= $mermsemr->mermsemr_api($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 processOutJson($in, $out) { switch ($in["action"]) { case 1000: break; default: return $out; } return $res; } ?>