You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?
|
|
include_once("../php/include-request.php");
|
|
|
|
verifyAuthorized();
|
|
|
|
$action = getMandatoryRequestValue("action");
|
|
|
|
initDatabaseConnection();
|
|
if($action == "save-group") {
|
|
$id = getOptionalRequestValue("id", null);
|
|
$name = getMandatoryRequestValue("name", "Name cannot be empty");
|
|
$expense = (getMandatoryRequestValue("expense") == "true" ? 1 : 0);
|
|
$exclude = (getMandatoryRequestValue("exclude") == "true" ? 1 : 0);
|
|
|
|
if($id == null) { // new group
|
|
$rowCount = dbUpdate("INSERT INTO category_group(name, expense, exclude, household_id) VALUES (?, ?, ?, ?)", $name, $expense, $exclude, getHouseholdId());
|
|
if($rowCount) {
|
|
requestOk("$rowCount group created");
|
|
}
|
|
} else { // save category
|
|
$rowCount = dbUpdate("
|
|
UPDATE category_group
|
|
SET name = ?,
|
|
expense = ?,
|
|
exclude = ?
|
|
WHERE id = ?
|
|
AND household_id = ?
|
|
",
|
|
$name,
|
|
$expense,
|
|
$exclude,
|
|
$id,
|
|
getHouseholdId()
|
|
);
|
|
if($rowCount) {
|
|
requestOk("$rowCount group updated");
|
|
}
|
|
}
|
|
} else if($action == "delete-group") {
|
|
$id = getMandatoryRequestValue("id");
|
|
$rowCount = dbUpdate("DELETE FROM category_group WHERE id = ? AND household_id = ?", $id, getHouseHoldId());
|
|
if($rowCount) {
|
|
requestOk("Deleted $rowCount group");
|
|
}
|
|
} else if($action == "save-category") {
|
|
$id = getOptionalRequestValue("id", null);
|
|
$name = getMandatoryRequestValue("name", "Name cannot be empty");
|
|
$categoryGroupId = getMandatoryRequestValue("categoryGroupId");
|
|
|
|
if($id == null) { // new category
|
|
$rowCount = dbUpdate("
|
|
INSERT INTO category(
|
|
category_group_id,
|
|
name
|
|
) VALUES (
|
|
?,
|
|
?
|
|
)",
|
|
$categoryGroupId,
|
|
$name
|
|
);
|
|
if($rowCount) {
|
|
requestOk("$rowCount category created");
|
|
}
|
|
} else { // save category
|
|
$rowCount = dbUpdate("
|
|
UPDATE category
|
|
SET name = ?
|
|
WHERE id = ?
|
|
",
|
|
$name,
|
|
$id
|
|
);
|
|
if($rowCount) {
|
|
requestOk("$rowCount category updated");
|
|
}
|
|
}
|
|
} else if($action == "delete-category") {
|
|
$id = getMandatoryRequestValue("id");
|
|
$rowCount = dbUpdate("DELETE FROM category WHERE id = ?", $id);
|
|
if($rowCount) {
|
|
requestOk("Deleted $rowCount category");
|
|
}
|
|
} else {
|
|
requestFail("Unknown request action \"$action\"");
|
|
}
|
|
closeDatabaseConnection();
|
|
?>
|