Jums jāizstrādā kāda lielāk projekta prototips. Izstrādājot prototipu, paturiet prātā, ka projektam attīstoties, šo prototipu varētu vajadzēt pilnveidot.
<?php
require("header.php");
$errors = array();
$app_manager = new ApplicationManager();
if (isset($_GET["id"]))
$app_id = $_GET["id"];
else
$app_id = 0;
?>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="./">Home</a></li>
<li class="breadcrumb-item"><a href="./applications.php">Applications List</a></li>
<li class="breadcrumb-item active" aria-current="page">Application Info</li>
</ol>
</nav>
<?php
$form_valid = true;
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (isset($_POST["btnSave"]))
{
$id = $_POST["hdnID"];
$email = $_POST["txtEmail"];
$amount = $_POST["txtCreditAmount"];
$status = $_POST["cbxStatus"];
if (empty($email))
{
$form_valid = false;
$errors["email"] = "Please enter email.";
}
if (empty($amount))
{
$form_valid = false;
$errors["amount"] = "Please enter amount.";
}
else if ($amount <= 0)
{
$form_valid = false;
$errors["amount"] = "Amount cannot be less than 0.";
}
if ($form_valid)
{
$app_manager->updateApplication($id, $email, $amount, $status);
header("Location: applications.php");
die();
}
}
if (isset($_POST["btnCancel"]))
{
header("Location: applications.php");
die();
}
}
if (!$app_manager->isApplicationExists($app_id))
{
?>
<div class="alert alert-danger" role="alert">
Application with ID <strong><?php echo $app_id ?></strong> is not exists.
</div>
<?php
if (count($errors) > 0)
{
?>
<ul style="color: #f00">
<?php
foreach ($errors as $key => $value)
{
echo "<li>".$value."</li>";
}
?>
</ul>
<?php
}
?>
<?php
}
else
{
$app_item = $app_manager->getApplicationById($app_id);
?>
<div class="col col-sm-8 col-md-8 col-lg-8 col-xl-8">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $app_id ?>" method="POST" class="needs-validation" novalidate>
<input type="hidden" name="hdnID" value="<?php echo $app_id; ?>">
<div class="form-group row">
<label class="col-sm-3 col-form-label">ID</label>
<label class="col-sm-4 col-form-label"><?php echo $app_item->id ?></label>
</div>
<div class="form-group row">
<label for="txtEmail" class="col-sm-3 col-form-label">Email</label>
<div class="col-sm-9">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">@</div>
</div>
<input type="email" class="form-control" id="txtEmail" name="txtEmail" value="<?php echo $app_item->email ?>" />
<div class="invalid-feedback">
Please enter email.
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="txtCreditAmount" class="col-sm-3 col-form-label">Amount</label>
<div class="col-sm-9">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">€</div>
</div>
<input type="number" class="form-control" id="txtCreditAmount" name="txtCreditAmount" value="<?php echo $app_item->amount ?>" />
<div class="invalid-feedback">
Please enter amount.
</div>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Partner</label>
<div class="col-sm-9">
<input type="text" class="form-control" disabled value="<?php echo $app_item->partner ?>" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Status</label>
<div class="col-sm-9">
<select class="custom-select mr-sm-2 form-control" name="cbxStatus">
<option value="ask" <?php if ($app_item->status == "ask") echo "selected" ?>>Ask</option>
<option value="offer" <?php if ($app_item->status == "offer") echo "selected" ?>>Offer</option>
<option value="rejection" <?php if ($app_item->status == "rejection") echo "selected" ?>>Rejection</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Date Created</label>
<label class="col-sm-4 col-form-label"><?php echo $app_item->date_created ?></label>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Date Modified</label>
<label class="col-sm-4 col-form-label"><?php echo $app_item->date_modified ?></label>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary" name="btnSave">Save</button>
<button type="submit" class="btn btn-light" name="btnCancel">Cancel</button>
</div>
</div>
</form>
</div>
<?php
}
require("footer.php");
?>
<script>
(function() {
'use strict';
window.addEventListener('load', function() {
var forms = document.getElementsByClassName('needs-validation');
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>