Example #1
0
 * This is caught on any request to the api and serves to hand off all requests to the appropriate functions.
 *
 */
include "functions.php";
//Gets Request Parameters
$request = "{$_SERVER['REQUEST_URI']}";
$request = substr($request, 1);
$parameters = explode("/", $request);
//Only look for post data if there is any.
if (isset($_POST["data"])) {
    $input = $_POST["data"];
}
//Hand off based on the paragmeters.
switch ($parameters[1]) {
    case "setupEnvironment":
        echo setupEnvironment($input);
        break;
    case "newCommands":
        echo newCommands($input);
        break;
    case "clearCommands":
        echo clearCommands();
        break;
    case "getCommands":
        echo getCommands();
        break;
    case "getLastModifiedTime":
        echo getLastModifiedTime();
        break;
    case "getPhysicalGridSize":
        echo getPhysicalGridSize();
Example #2
0
<?php

$startTime = microtime(true);
require 'ledgerManager.php';
// Credit to https://github.com/adamtomecek/Template
require 'templateManager/Template.php';
$pathArray = pathinfo(__FILE__);
$path = preg_replace('/\\/var\\/www\\//', '', $pathArray['dirname']) . "/";
$thisScript = $pathArray['basename'];
$host = $_SERVER['HTTP_HOST'];
list($user, $password, $database, $table) = setupEnvironment();
$ledgerManager = new LedgerManager($user, $password, $database, $table);
$verb = getRequestParam('verb', 'transactions');
$id = (int) getRequestParam('id');
$description = getRequestParam('description');
$amount = getRequestParam('amount');
$credit = getRequestParam('credit');
$cleared = getRequestParam('cleared', 0);
$duration = getRequestParam('duration', 30);
$windowStartDate = date('Y-m-d', strtotime("-" . $duration . " days"));
if (isset($verb)) {
    if ($verb == 'update' && $ledgerManager->validateUpdate($id, $description, $amount, $cleared)) {
        $ledgerManager->updateTransaction($id, $description, $amount, $cleared);
        error_log('updated transaction: ' . $id);
        redirectTo("{$host}/{$path}{$thisScript}");
    } elseif ($verb == 'create' && $ledgerManager->validateCreate($description, $amount, $credit)) {
        $ledgerManager->insertTransaction($description, $amount, $credit);
        error_log('inserted transaction');
        redirectTo("{$host}/{$path}{$thisScript}");
    } elseif ($verb == 'delete' && $ledgerManager->validateDelete($id)) {
        $ledgerManager->deleteTransaction($id);