Ejemplo n.º 1
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);
Ejemplo n.º 2
0
function checkDataValid(&$database, $post, $table, $column, &$json_return)
{
    if (!checkInputExists($post, $column, $json_return)) {
        return;
    }
    $sql = 'SELECT * FROM ' . $table . ' WHERE ' . $column . '=:data';
    $statement = $database->prepare($sql);
    $statement->bindParam(':data', htmlspecialchars($post[$column]));
    $statement->execute();
    $query_result = $statement->fetch(PDO::FETCH_ASSOC);
    // item must be unique
    if (!empty($query_result)) {
        if ($json_return['status'] === "NA") {
            $json_return['status'] = "OK";
        }
    } else {
        $json_return['status'] = "FAILED";
        $json_return['error'][$column] = "Must be an item from the dropdown";
    }
}
Ejemplo n.º 3
0
 $table = 'item';
 $unique_id = 'name';
 $original_unique_id = 'original_' . $unique_id;
 // all values in the main table that are not in the sub-tables
 // ex) what columns are in items that are not in armor
 $exceptions = array($original_unique_id, 'weight', 'value', 'primaryType', 'secondaryType', 'description');
 $primary_key = array($unique_id, 'rpg');
 checkDataUnique($database, $_POST, $table, $unique_id, $json_return);
 checkDataValid($database, $_POST, 'itemType', 'primaryType', $json_return);
 //checkCombinedDataValid($database, $_POST, 'itemType', 'secondaryType', 'primaryType', $json_return, $exceptions);
 checkInputExists($_POST, 'description', $json_return);
 $_POST['rpg'] = 'dales';
 // now check individual item types
 if ($_POST['primaryType'] === 'Ammunition') {
     checkInputExists($_POST, 'quantityForValue', $json_return);
     checkInputExists($_POST, 'type', $json_return);
     if ($json_return['status'] === "OK") {
         insertInto('ammunition', $_POST, $exceptions, $primary_key, $database, $json_return);
     }
 } else {
     if ($_POST['primaryType'] === 'Arcane') {
         checkDataValid($database, $_POST, 'rarity', 'rarity', $json_return);
         if ($json_return['status'] === "OK") {
             insertInto('arcane', $_POST, $exceptions, $primary_key, $database, $json_return);
         }
     } else {
         if ($_POST['primaryType'] === 'Valuable') {
             checkDataValid($database, $_POST, 'rarity', 'rarity', $json_return);
             if ($json_return['status'] === "OK") {
                 insertInto('valuable', $_POST, $exceptions, $primary_key, $database, $json_return);
             }
Ejemplo n.º 4
0
         insertInto('armor', $_POST, $exceptions, $primary_key, $database, $json_return);
     }
 } else {
     if ($_POST['primaryType'] === 'Consumable') {
         checkDataValid($database, $_POST, 'rarity', 'rarity', $json_return);
         // if locality exists, it must be because it is an ingredient
         if (inputExists($_POST, 'locality') && $_POST['secondaryType'] !== 'Ingredient') {
             $json_return['status'] = "FAILED";
             $json_return['error']['locality'] = "Only Ingredients have locality.";
         }
         if ($json_return['status'] === "OK") {
             insertInto('consumable', $_POST, $exceptions, $primary_key, $database, $json_return);
         }
     } else {
         if ($_POST['primaryType'] === 'Melee Weapon' || $_POST['primaryType'] === 'Ranged Weapon') {
             checkInputExists($_POST, 'damage', $json_return);
             checkDataValid($database, $_POST, 'damageType', 'damageType', $json_return);
             if (inputExists($_POST, 'secondaryDamageType')) {
                 // TODO: doesn't actually check secondaryDamageType
                 checkDataValid($database, $_POST, 'damageType', 'damageType', $json_return);
             }
             if ($json_return['status'] === "OK") {
                 insertInto('weapon', $_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.';
             }