<?php

require '../private/config.php';
require '../private/restricted_admin.php';
require '../class/Admin.php';
$products = new CyanideSystems\OrderSystem\Admin();
include 'template/header.php';
?>

	<main role="main">

		<section>

			<h2>Products</h2>

			<table>
				<thead>
					<tr>
						<th>SKU</th><th>Name</th><th>Price</th><th>Quantity</th><th>VAT Rate</th><th class="editproduct">Edit</th><th class="editingproduct" style="display:none;">Confirm</th>
					</tr>
				</thead>
				<tbody>
					<?php 
foreach ($products->getProducts() as $product) {
    ?>
					<tr>
						<td><?php 
    echo $product->sku;
    ?>
</td><td><?php 
    echo $product->product_name;
<?php

require '../private/config.php';
require '../private/restricted_admin.php';
if (!isset($_GET['p'])) {
    header('Location: proformas.php');
}
$proforma_id = (int) $_GET['p'];
require '../class/Admin.php';
$order = new CyanideSystems\OrderSystem\Admin();
$proforma = $order->getProformaMain($proforma_id);
$proforma_lines = $order->getProformaLines($proforma_id);
?>
<!doctype html>
<html lang="en-GB">
	<head>
		<meta charset="utf-8" />
		<title>Proforma ID: <?php 
echo $proforma->proforma_id;
?>
</title>
		<link rel="stylesheet" href="template/assets/css/invoice.min.css" />
	</head>
	<body>
		<p class="return"><a href="proformas.php" target="_blank">[Return to Proformas]</a></p>
		<section class="page-break">
			<br />
			<header>
				<h1>Proforma</h1>
				<address>
					<p>Polyverse Ltd. (T/A: Bluebelles)</p>
<?php

require '../private/config.php';
require '../private/restricted_admin.php';
if (!isset($_GET['i'])) {
    header('Location: invoices.php');
}
$invoice_id = (int) $_GET['i'];
require '../class/Admin.php';
$order = new CyanideSystems\OrderSystem\Admin();
$invoice = $order->getInvoiceMain($invoice_id);
$invoice_lines = $order->getInvoiceLines($invoice_id);
?>
<!doctype html>
<html lang="en-GB">
	<head>
		<meta charset="utf-8" />
		<title>invoice ID: <?php 
echo $invoice->invoice_id;
?>
</title>
		<link rel="stylesheet" href="template/assets/css/invoice.min.css" />
	</head>
	<body>
		<p class="return"><a href="invoices.php" target="_blank">[Return to Invoices]</a></p>
		<section class="page-break">
			<br />
			<header>
				<h1>invoice</h1>
				<address>
					<p>Polyverse Ltd. (T/A: Bluebelles)</p>
<?php

require '../private/config.php';
require '../private/restricted_admin.php';
require '../class/Admin.php';
if (!isset($_GET['p'])) {
    header('Location: awaiting_payment.php');
}
$proforma_id = (int) $_GET['p'];
$admin = new CyanideSystems\OrderSystem\Admin();
if ($invoice_id = $admin->createInvoice($proforma_id)) {
    header('Location: view_invoice.php?i=' . $invoice_id);
} else {
    header('Location: proformas.php');
}
<?php

require '../private/config.php';
require '../class/Admin.php';
$email = $_POST['email'];
$password = $_POST['password'];
$signup = new CyanideSystems\OrderSystem\Admin();
if ($signup->setupDatabase()) {
    // Directs back to registration.php if there's an error
    if ($signup->registerAdminUser($email, $password)) {
        header('Location: ../admin/index.php?install=success');
    } else {
        $_SESSION['error'] = 'There was an error registering your email address and password into the database';
        header('Location: index.php');
    }
} else {
    $_SESSION['error'] = 'There was an error in creating the database tables. Please ensure you have entered the database connection settings correctly in private/config.php and that the database user has sufficient permissions to create new tables.';
    header('Location: index.php');
}
<?php

require '../../private/config.php';
require '../../private/restricted_admin.php';
require '../../class/Admin.php';
$products = new CyanideSystems\OrderSystem\Admin();
$products->newProduct($_POST['sku'], $_POST['product_name'], $_POST['price'], $_POST['vat_rate'], $_POST['stock_quantity']);
echo '<p>New product added.</p>';
<?php

require '../private/config.php';
require '../private/restricted_admin.php';
require '../class/Admin.php';
$admin = new CyanideSystems\OrderSystem\Admin();
$proformas = $admin->getProformas();
include 'template/header.php';
?>

	<main role="main">

		<section>

			<h2>Proformas</h2>

			<table>
				<thead>
					<tr>
						<th>Proforma ID</th><th>Proforma Date</th><th>Customer ID</th><th>View Proforma</th><th>Invoice Proforma (Payment Recieved)</th>
					</tr>
				</thead>
				<tbody>
					<?php 
foreach ($proformas as $proforma) {
    ?>
					<tr>
						<td><?php 
    echo $proforma->proforma_id;
    ?>
</td><td><?php 
<?php

require '../private/config.php';
require '../private/restricted_admin.php';
// Restrict to Admin. only
require '../class/Admin.php';
$admin = new CyanideSystems\OrderSystem\Admin();
$invoices = $admin->getInvoices();
include 'template/header.php';
?>

	<main role="main">

		<section>

			<h2>Proformas</h2>

			<table>
				<thead>
					<tr>
						<th>Invoice ID</th><th>Invoice Date</th><th>Customer ID</th><th>View Invoice</th>
					</tr>
				</thead>
				<tbody>
					<?php 
foreach ($invoices as $invoice) {
    ?>
					<tr>
						<td><?php 
    echo $invoice->invoice_id;
    ?>
<?php

require '../../private/config.php';
if (!isset($_POST['email']) || !isset($_POST['password'])) {
    echo '<p>Please enter your login credentials.</p>';
} else {
    require '../../class/Admin.php';
    $email = $_POST['email'];
    $password = $_POST['password'];
    $login = new CyanideSystems\OrderSystem\Admin();
    if ($login->verifyAdminLogin($email, $password)) {
        echo '<p>You are now logged in.</p>';
    } else {
        echo '<p>Login unsuccessful.</p>';
    }
}
<?php

require '../private/config.php';
require '../class/Admin.php';
$email = $_POST['email'];
$password = $_POST['password'];
$signup = new CyanideSystems\OrderSystem\Admin();
// Directs back to registration.php if there's an error
if ($signup->registerAdminUser($email, $password)) {
    header('Location: index.php');
} else {
    header('Location: register_admin.php');
}