Add customer editing and creation
parent
477b7c1868
commit
9f639727a7
@ -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>
|
@ -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…
Reference in New Issue