{ if (emptyAsNull($newValue) != $oldValue) { return $newValue; } else { return null; } } //Did the user just submit changes to the crisis? $id = null; $error = ""; if (!is_null($_POST) && count($_POST) > 0) { $newCode = stripString2($_POST["crisisCode"]); if ($newCode == '') { die("A crisis must have a (unique) code"); } $newName = stripString2($_POST["crisisName"]); if ($newName == '') { die("A crisis must have a name"); } $newTypeID = intval($_POST["crisisType"]); //Create or update the crisis itself $isNewCrisis = is_null($_REQUEST) || !array_key_exists("id", $_REQUEST) || $_REQUEST["id"] == ''; if ($isNewCrisis) { $result = createCrisis($newCode, $newName, $newTypeID); $id = $result[0]; $error = $result[1]; } else { $id = intval($_REQUEST["id"]); if ($newCode != $_POST["oldCrisisCode"] || $newName != $_POST["oldCrisisName"] || $newTypeID != intval($_POST["oldCrisisTypeID"])) { $error = updateCrisis($id, $newCode, $newName, $newTypeID); }
<?php include "header_start.php"; printTitle("Manage Crisis Types"); include "header_end.php"; include_once "api.php"; //Did the user just submit changes? if (!is_null($_POST) && key_exists('newName', $_POST)) { $name = stripString2($_POST["newName"]); createCrisisType($name); } elseif (!is_null($_GET) && key_exists('delete', $_GET)) { $deleteID = intval($_GET["delete"]); deleteCrisisType($deleteID); } ?> <h1><a href="overview.php">Overview</a> > Crisis Types</h1> <form method="post" action="crisistypes.php"> <div> New crisis type: <input type="text" name="newName" /> <input type="submit" value="Create" /> </div> </form> <br/> <br/> <div class="table"> <div class="table-row table-header"> <div class="table-column">Name</div> <div class="table-column">#crises</div>
$nameChange = $code != null && $_POST["oldLabelName"][$i] == '' || $_POST["labelName"][$i] != $_POST["oldLabelName"][$i]; $descChange = $_POST["labelDescription"][$i] != $_POST["oldLabelDescription"][$i]; $delete = checkDelete($code); if ($code == null || !($nameChange || $descChange || $delete)) { continue; } $labelID = intval($_POST["labelID"][$i]); $change = new LabelUpdate(); $change->id = $labelID; $change->attributeID = $attributeID; $change->code = $code; $change->newName = stripString2($_POST["labelName"][$i]); if ($change->newName == '') { $change->newName = $change->code; } $change->newDescription = stripString2($_POST["labelDescription"][$i]); $change->delete = $delete; $labelChanges[] = $change; } if (count($labelChanges) > 0) { saveLabelChanges($labelChanges); } } else { if (!is_null($_GET) && array_key_exists("id", $_GET) && $_GET["id"] != '') { $attributeID = intval($_GET["id"]); } } if (strpos($error, "Duplicate entry") !== FALSE) { $error = "Another attribute already exists with code [" . $_POST["attributeCode"] . "]. Codes must be unique."; } $attribute = null;
function updateCrisis($crisisID, $code, $name, $crisisTypeID) { $crisisID = intval($crisisID); $code = stripString1($code); $name = stripString2($name); $crisisTypeID = intval($crisisTypeID); $con = getMySqlConnection(); $con->query("update crisis set code='{$code}', name='{$name}', crisisTypeID={$crisisTypeID}\n where crisisID={$crisisID} limit 1"); $error = $con->error; $con->close(); return $error; }