Add customer editing and creation
This commit is contained in:
parent
477b7c1868
commit
9f639727a7
30
action.php
30
action.php
@ -289,6 +289,36 @@ END;
|
|||||||
$cards = $database->select('certificates', ['certid (id)', 'certcode (code)', 'amount (balance)', 'start_amount (amount)'], ['certcode' => $code]);
|
$cards = $database->select('certificates', ['certid (id)', 'certcode (code)', 'amount (balance)', 'start_amount (amount)'], ['certcode' => $code]);
|
||||||
exit(json_encode(["status" => "OK", "cards" => $cards]));
|
exit(json_encode(["status" => "OK", "cards" => $cards]));
|
||||||
break;
|
break;
|
||||||
|
case "editcustomer":
|
||||||
|
$insert = true;
|
||||||
|
if (is_empty($VARS['id'])) {
|
||||||
|
$insert = true;
|
||||||
|
} else {
|
||||||
|
if ($database->has('customers', ['customerid' => $VARS['id']])) {
|
||||||
|
$insert = false;
|
||||||
|
} else {
|
||||||
|
returnToSender("invalid_customerid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_empty($VARS['name'])) {
|
||||||
|
returnToSender('invalid_parameters');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $VARS['name'],
|
||||||
|
'email' => $VARS['email'],
|
||||||
|
'phone' => $VARS['phone'],
|
||||||
|
'address' => $VARS['address'],
|
||||||
|
'notes' => $VARS['notes']
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($insert) {
|
||||||
|
$database->insert('customers', $data);
|
||||||
|
} else {
|
||||||
|
$database->update('customers', $data, ['customerid' => $VARS['id']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
returnToSender("customer_saved");
|
||||||
case "session_keepalive":
|
case "session_keepalive":
|
||||||
header("Content-Type: application/json");
|
header("Content-Type: application/json");
|
||||||
exit(json_encode(["status" => "OK"]));
|
exit(json_encode(["status" => "OK"]));
|
||||||
|
@ -54,5 +54,12 @@ define("STRINGS", [
|
|||||||
"phone" => "Phone",
|
"phone" => "Phone",
|
||||||
"email" => "Email",
|
"email" => "Email",
|
||||||
"address" => "Address",
|
"address" => "Address",
|
||||||
"notes" => "Notes"
|
"notes" => "Notes",
|
||||||
|
"edit" => "Edit",
|
||||||
|
"new customer" => "New Customer",
|
||||||
|
"adding customer" => "Adding Customer",
|
||||||
|
"editing customer" => "Editing {name}",
|
||||||
|
"save" => "Save",
|
||||||
|
"customer saved" => "Customer saved.",
|
||||||
|
"invalid customer id" => "Invalid customer ID",
|
||||||
]);
|
]);
|
@ -16,5 +16,13 @@ define("MESSAGES", [
|
|||||||
"404_error" => [
|
"404_error" => [
|
||||||
"string" => "page not found",
|
"string" => "page not found",
|
||||||
"type" => "info"
|
"type" => "info"
|
||||||
]
|
],
|
||||||
|
"customer_saved" => [
|
||||||
|
"string" => "customer saved",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"invalid_customerid" => [
|
||||||
|
"string" => "invalid customer id",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
@ -40,6 +40,13 @@ define("PAGES", [
|
|||||||
"static/js/customers.js"
|
"static/js/customers.js"
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
"editcustomer" => [
|
||||||
|
"title" => "edit customer",
|
||||||
|
"navbar" => false,
|
||||||
|
"scripts" => [
|
||||||
|
"static/js/editcustomer.js"
|
||||||
|
]
|
||||||
|
],
|
||||||
"404" => [
|
"404" => [
|
||||||
"title" => "404 error"
|
"title" => "404 error"
|
||||||
]
|
]
|
||||||
|
@ -12,6 +12,10 @@ redirectIfNotLoggedIn();
|
|||||||
$customers = $database->select('customers', ['customerid (id)', 'name', 'email', 'phone', 'address', 'notes']);
|
$customers = $database->select('customers', ['customerid (id)', 'name', 'email', 'phone', 'address', 'notes']);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<div class="btn-toolbar">
|
||||||
|
<a href="app.php?page=editcustomer" class="btn btn-success"><i class="fas fa-user-plus"></i> <?php lang("new customer"); ?></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table id="customertable" class="table table-bordered table-hover table-sm">
|
<table id="customertable" class="table table-bordered table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -30,7 +34,9 @@ $customers = $database->select('customers', ['customerid (id)', 'name', 'email',
|
|||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="app.php?page=editcustomer&id=<?php echo $c['id']; ?>"><i class="fas fa-edit"></i> <?php lang("edit"); ?></a>
|
||||||
|
</td>
|
||||||
<td><?php echo $c['name']; ?></td>
|
<td><?php echo $c['name']; ?></td>
|
||||||
<td><?php echo $c['phone']; ?></td>
|
<td><?php echo $c['phone']; ?></td>
|
||||||
<td><?php echo $c['email']; ?></td>
|
<td><?php echo $c['email']; ?></td>
|
||||||
|
89
pages/editcustomer.php
Normal file
89
pages/editcustomer.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
$custdata = [
|
||||||
|
'id' => '',
|
||||||
|
'name' => '',
|
||||||
|
'email' => '',
|
||||||
|
'phone' => '',
|
||||||
|
'address' => '',
|
||||||
|
'notes' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$editing = false;
|
||||||
|
|
||||||
|
if (!empty($VARS['id']) && !is_empty($VARS['id'])) {
|
||||||
|
if ($database->has('customers', ['customerid' => $VARS['id']])) {
|
||||||
|
$editing = true;
|
||||||
|
$custdata = $database->get(
|
||||||
|
'customers', [
|
||||||
|
'customerid (id)',
|
||||||
|
'name',
|
||||||
|
'email',
|
||||||
|
'phone',
|
||||||
|
'address',
|
||||||
|
'notes'
|
||||||
|
], [
|
||||||
|
'customerid' => $VARS['id']
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// customer id is invalid, redirect to a version of the page that won't
|
||||||
|
// cause an error when pressing Save
|
||||||
|
header('Location: app.php?page=editcustomer');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="card border-green">
|
||||||
|
<h3 class="card-header text-green">
|
||||||
|
<?php
|
||||||
|
if ($editing) {
|
||||||
|
?>
|
||||||
|
<i class="fas fa-edit"></i> <?php lang2("editing customer", ['name' => "<span id=\"name_title\">" . htmlspecialchars($custdata['name']) . "</span>"]); ?>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
<i class="fas fa-edit"></i> <?php lang("adding customer"); ?>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h3>
|
||||||
|
<div class="card-body row">
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label for="name"><i class="fas fa-user"></i> <?php lang("name"); ?></label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" placeholder="Foo Bar" required="required" value="<?php echo htmlspecialchars($custdata['name']); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="email"><i class="fas fa-at"></i> <?php lang("email"); ?></label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" placeholder="user@example.com" value="<?php echo htmlspecialchars($custdata['email']); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="phone"><i class="fas fa-phone"></i> <?php lang("phone"); ?></label>
|
||||||
|
<input type="phone" class="form-control" id="phone" name="phone" placeholder="" value="<?php echo htmlspecialchars($custdata['phone']); ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="address"><i class="fas fa-map-marker"></i> <?php lang("address"); ?></label>
|
||||||
|
<textarea rows="3" class="form-control" id="address" name="address" placeholder=""><?php echo htmlspecialchars($custdata['address']); ?></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="notes"><i class="fas fa-sticky-note"></i> <?php lang("notes"); ?></label>
|
||||||
|
<textarea rows="3" class="form-control" id="notes" name="notes" placeholder=""><?php echo htmlspecialchars($custdata['notes']); ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="id" value="<?php echo htmlspecialchars($custdata['id']); ?>" />
|
||||||
|
<input type="hidden" name="action" value="editcustomer" />
|
||||||
|
<input type="hidden" name="source" value="customers" />
|
||||||
|
|
||||||
|
<div class="card-footer d-flex">
|
||||||
|
<button type="submit" class="btn btn-success mr-auto"><i class="fas fa-save"></i> <?php lang("save"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
10
static/js/editcustomer.js
Normal file
10
static/js/editcustomer.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
$('#name').on('input propertychange paste', function () {
|
||||||
|
$('#name_title').text($('#name').val());
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user