Initial commit
This commit is contained in:
116
admin/shipping_process.php
Normal file
116
admin/shipping_process.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
defined('admin') or exit;
|
||||
// Default input shipping values
|
||||
$shipping = [
|
||||
'name' => '',
|
||||
'price_from' => '',
|
||||
'price_to' => '',
|
||||
'weight_from' => '',
|
||||
'weight_to' => '',
|
||||
'price' => '',
|
||||
'type' => 'Single Product',
|
||||
'countries' => ''
|
||||
];
|
||||
$types = ['Single Product', 'Entire Order'];
|
||||
if (isset($_GET['id'])) {
|
||||
// ID param exists, edit an existing shipping method
|
||||
$page = 'Edit';
|
||||
if (isset($_POST['submit'])) {
|
||||
// Update the shipping method
|
||||
$countries_list = isset($_POST['countries']) ? implode(',', $_POST['countries']) : '';
|
||||
$stmt = $pdo->prepare('UPDATE shipping SET name = ?, price_from = ?, price_to = ?, weight_from = ?, weight_to = ?, price = ?, type = ?, countries = ? WHERE id = ?');
|
||||
$stmt->execute([ $_POST['name'], $_POST['price_from'], $_POST['price_to'], $_POST['weight_from'], $_POST['weight_to'], $_POST['price'], $_POST['type'], $countries_list, $_GET['id'] ]);
|
||||
header('Location: index.php?page=shipping&success_msg=2');
|
||||
exit;
|
||||
}
|
||||
if (isset($_POST['delete'])) {
|
||||
// Delete the shipping method
|
||||
$stmt = $pdo->prepare('DELETE FROM shipping WHERE id = ?');
|
||||
$stmt->execute([ $_GET['id'] ]);
|
||||
header('Location: index.php?page=shipping&success_msg=3');
|
||||
exit;
|
||||
}
|
||||
// Get the shipping method from the database
|
||||
$stmt = $pdo->prepare('SELECT * FROM shipping WHERE id = ?');
|
||||
$stmt->execute([ $_GET['id'] ]);
|
||||
$shipping = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
// Create a new shipping method
|
||||
$page = 'Create';
|
||||
if (isset($_POST['submit'])) {
|
||||
$countries_list = isset($_POST['countries']) ? implode(',', $_POST['countries']) : '';
|
||||
$stmt = $pdo->prepare('INSERT INTO shipping (name, price_from, price_to, weight_from, weight_to, price, type, countries) VALUES (?,?,?,?,?,?,?,?)');
|
||||
$stmt->execute([ $_POST['name'], $_POST['price_from'], $_POST['price_to'], $_POST['weight_from'], $_POST['weight_to'], $_POST['price'], $_POST['type'], $countries_list ]);
|
||||
header('Location: index.php?page=shipping&success_msg=1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?=template_admin_header($page . ' Shipping Method', 'shipping', 'manage')?>
|
||||
|
||||
<form action="" method="post">
|
||||
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100"><?=$page?> Shipping Method</h2>
|
||||
<a href="index.php?page=shipping" class="btn alt mar-right-2">Cancel</a>
|
||||
<?php if ($page == 'Edit'): ?>
|
||||
<input type="submit" name="delete" value="Delete" class="btn red mar-right-2" onclick="return confirm('Are you sure you want to delete this shipping method?')">
|
||||
<?php endif; ?>
|
||||
<input type="submit" name="submit" value="Save" class="btn">
|
||||
</div>
|
||||
|
||||
<div class="content-block">
|
||||
|
||||
<div class="form responsive-width-100">
|
||||
|
||||
<label for="name"><i class="required">*</i> Name</label>
|
||||
<input type="text" name="name" placeholder="Name" value="<?=$shipping['name']?>" required>
|
||||
|
||||
<label for="type"><i class="required">*</i> Type</label>
|
||||
<select name="type" id="type" required>
|
||||
<?php foreach ($types as $type): ?>
|
||||
<option value="<?=$type?>"<?=$shipping['type'] == $type ? ' selected' : ''?>><?=$type?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<label for="countries">Countries</label>
|
||||
<div class="multiselect" data-name="countries[]">
|
||||
<?php foreach (explode(',', $shipping['countries']) as $c): ?>
|
||||
<?php if (empty($c)) continue; ?>
|
||||
<span class="item" data-value="<?=$c?>">
|
||||
<i class="remove">×</i><?=$c?>
|
||||
<input type="hidden" name="countries[]" value="<?=$c?>">
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<input type="text" class="search" id="countries" placeholder="Countries">
|
||||
<div class="list">
|
||||
<?php foreach (get_countries() as $country): ?>
|
||||
<span data-value="<?=$country?>"><?=$country?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="price"><i class="required">*</i> Product Price Range</label>
|
||||
<div style="display:flex;margin:0;">
|
||||
<input type="number" name="price_from" placeholder="From" min="0" step=".01" value="<?=$shipping['price_from']?>" required>
|
||||
<span style="padding-top:15px"> — </span>
|
||||
<input type="number" name="price_to" placeholder="To" min="0" step=".01" value="<?=$shipping['price_to']?>" required>
|
||||
</div>
|
||||
|
||||
<label for="price"><i class="required">*</i> Product Weight Range (lbs)</label>
|
||||
<div style="display:flex;margin:0;">
|
||||
<input type="number" name="weight_from" placeholder="From" min="0" step=".01" value="<?=$shipping['weight_from']?>" required>
|
||||
<span style="padding-top:15px"> — </span>
|
||||
<input type="number" name="weight_to" placeholder="To" min="0" step=".01" value="<?=$shipping['weight_to']?>" required>
|
||||
</div>
|
||||
|
||||
<label for="name"><i class="required">*</i> Total Shipping Price</label>
|
||||
<input type="number" name="price" placeholder="3.99" min="0" step=".01" value="<?=$shipping['price']?>" required>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<?=template_admin_footer()?>
|
||||
Reference in New Issue
Block a user