function checkInputExists($post, $input_key, &$json_return)
{
    if (inputExists($post, $input_key)) {
        return TRUE;
    }
    $json_return['status'] = "FAILED";
    $json_return['error'][$input_key] = "Input is required";
    return FALSE;
}
Example #2
0
<?php

require_once '../../php/db/connection.php';
require_once '../../php/submit_helper.php';
$json_return['status'] = "NA";
$json_return['message'] = "Could not add ability.";
try {
    // variables
    $table = 'ability';
    $unique_id = 'name';
    $original_unique_id = 'original_' . $unique_id;
    $exceptions = array($original_unique_id);
    $primary_key = array($unique_id, 'rpg');
    checkDataUnique($database, $_POST, $table, $unique_id, $json_return);
    checkDataValid($database, $_POST, 'abilityType', 'type', $json_return);
    checkDataValid($database, $_POST, 'target', 'target', $json_return);
    if (inputExists($_POST, 'radiusType')) {
        checkDataValid($database, $_POST, 'radiusType', 'radiusType', $json_return);
    }
    checkInputExists($_POST, 'description', $json_return);
    if ($json_return['status'] === "OK") {
        $_POST['rpg'] = 'dales';
        insertInto($table, $_POST, $exceptions, $primary_key, $database, $json_return);
    }
} catch (PDOException $e) {
    $json_return['status'] = "FAILED";
    $json_return['message'] = $e->getMessage();
}
// send json
header("Content-Type: application/json", true);
echo json_encode($json_return);
Example #3
0
         insertInto('consumable', $_POST, $exceptions, $primary_key, $database, $json_return);
     }
 } else {
     if ($_POST['primaryType'] === 'Melee Weapon' || $_POST['primaryType'] === 'Ranged Weapon') {
         checkDiceValid($_POST, 'damage', $json_return);
         if (inputExists($_POST, 'property')) {
             checkDiceValid($_POST, 'secondaryDamage', $json_return);
         }
         checkDataValid($database, $_POST, 'damageType', 'damageType', $json_return);
         if (inputExists($_POST, 'property')) {
             checkDataValid($database, $_POST, 'property', 'property', $json_return);
         }
         if ($_POST['primaryType'] === 'Ranged Weapon') {
             checkDataValid($database, $_POST, 'ammunition', 'ammunitionType', $json_return);
         }
         if (inputExists($_POST, 'secondaryDamageType')) {
             // TODO: doesn't actually check secondaryDamageType, just checks damageType, modify checkDataValid to include ability to rename the field
             checkDataValid($database, $_POST, 'damageType', 'damageType', $json_return);
         }
         if ($json_return['status'] === "OK") {
             insertInto('consumable', $_POST, $exceptions, $primary_key, $database, $json_return);
         }
     } else {
         if ($_POST['primaryType'] === 'Gear' || $_POST['primaryType'] === 'Miscellaneous' || $_POST['primaryType'] === 'Tool') {
             // do nothing more
         } else {
             $json_return['status'] = "FAILED";
             $json_return['message'] = 'Not a recognized type.';
         }
     }
 }
Example #4
0
<?php

require_once '../../php/db/connection.php';
require_once '../../php/submit_helper.php';
$json_return['status'] = "NA";
$json_return['message'] = "Could not edit skill.";
try {
    // variables
    $table = 'skill';
    $unique_id = 'name';
    $original_unique_id = 'original_' . $unique_id;
    $exceptions = array($original_unique_id);
    $primary_key = array($unique_id, 'rpg');
    if (inputExists($_POST, $unique_id) && $_POST[$unique_id] !== $_POST[$original_unique_id]) {
        checkDataUnique($database, $_POST, $table, $unique_id, $json_return);
    }
    checkValidEnum($_POST['attribute'], array('STR', 'DEX', 'INF', 'WIS'), $json_return);
    checkInputExists($_POST, 'type', $json_return);
    checkInputExists($_POST, 'description', $json_return);
    if ($json_return['status'] === "OK") {
        // add rpg
        $_POST['rpg'] = 'dales';
        insertAndDeleteEdit($table, $_POST, $exceptions, $primary_key, $database, $json_return, $unique_id);
    }
} catch (PDOException $e) {
    $json_return['status'] = "FAILED";
    $json_return['message'] = "ERROR: " . $e->getMessage();
}
// send json
header("Content-Type: application/json", true);
echo json_encode($json_return);