aboutsummaryrefslogtreecommitdiff
path: root/include/discounts-edit.php
diff options
context:
space:
mode:
authorCamil Staps2016-07-20 10:54:07 +0200
committerCamil Staps2016-07-20 10:54:07 +0200
commit0b60b0ccc66cbcc26619ac762b8881f52fa85bf7 (patch)
treeb3575a335585250b300f4eafa2e0f250d8c41a2a /include/discounts-edit.php
parentNo minimum string length for assignment descriptions (diff)
Discounts
Diffstat (limited to 'include/discounts-edit.php')
-rw-r--r--include/discounts-edit.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/include/discounts-edit.php b/include/discounts-edit.php
new file mode 100644
index 0000000..e6859a1
--- /dev/null
+++ b/include/discounts-edit.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * BusinessAdmin: administrative software for small companies
+ * Copyright (C) 2015 Camil Staps (ViviSoft)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('./conf.php');
+
+$response = new response();
+
+try {
+ $discount = new discount($_pdo, $_REQUEST['pk']);
+
+ $name = explode('-', $_REQUEST['name']);
+ $what_to_edit = $name[count($name) - 1];
+ switch ($what_to_edit) {
+ case 'title':
+ $response->success = $discount->setTitle($_REQUEST['value']);
+ break;
+ case 'value':
+ $response->success = $discount->setValue($_REQUEST['value']);
+ break;
+ case 'vat':
+ $response->success = $discount->setVAT($_REQUEST['value']);
+ break;
+ case 'description':
+ $response->success = $discount->setDescription($_REQUEST['value']);
+ break;
+ default:
+ $response->http_response_code(404);
+ $response->success = false;
+ }
+ if (!$response->success && $response->http_response_code() == 200) {
+ $response->http_response_code(500);
+ $response->message = "The discount could not be edited due to an error.";
+ }
+} catch (PDOException $e) {
+ $response->http_response_code(500);
+ $response->success = false;
+ $response->message = "The discount could not be edited due to a PDO error ({$e->getMessage()}).";
+} catch (Exception $e) {
+ $response->http_response_code(404);
+ $response->success = false;
+ $response->message = "The discount could not be edited due to an exception.";
+}
+echo $response->message;