summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--categories.php32
-rw-r--r--contact.php (renamed from contact.html)14
-rw-r--r--index.php (renamed from index.html)16
-rw-r--r--login.php (renamed from login.html)33
-rw-r--r--productdetails.php14
-rw-r--r--products.php15
6 files changed, 109 insertions, 15 deletions
diff --git a/categories.php b/categories.php
index 2ef44df..f141e3e 100644
--- a/categories.php
+++ b/categories.php
@@ -1,3 +1,6 @@
+<?php
+session_start();
+?>
<!DOCTYPE html>
<html>
<head>
@@ -9,25 +12,42 @@
<header><h1>Categories</h1></header>
<nav>
<dl>
-<dt><a href="contact.html">Contact us</a></dt>
+<dt><a href="contact.php">Contact us</a></dt>
<dt><a href=".">Home</a></dt>
-<dt><a href="login.html">Login</a></dt>
+<?php
+if(isset($_SESSION['username']))
+{
+ echo "<dt><a href=\"login.php?logout\">Logout</a></dt>";
+ $username = $_SESSION['username'];
+}
+else
+{
+ echo "<dt><a href=\"login.html\">Login</a></dt>";
+}
+?>
</dl>
</nav>
<div id="content">
-<dl>
+<table>
<?php
require_once('vendor.inc.php');
$categories = CategoryQuery::create()->find();
foreach( $categories as $category ){
- echo "<dt><a href=\"products.php?id={$category->getId()}\">{$category->getName()}</a></dt>";
- echo "<dd>{$category->getDescription()}</dd>";
+ echo "<tr>";
+ echo "<td><a href=\"products.php?id={$category->getId()}\">{$category->getName()}</a></td>";
+ echo "<td>{$category->getDescription()}</td>";
+ if(isset($username))
+ {
+ echo "<td><a href=\"categoryedit.php?modify={$category->getId()}\">Edit</a></td>";
+ echo "<td><a href=\"categoryedit.php?delete={$category->getId()}\">Delete</a></td>";
+ }
+ echo "</tr>";
}
?>
-</dl>
+</table>
<div class="spacer"></div>
</div>
<footer>Copyright by SomeCompany Ltd.</footer>
diff --git a/contact.html b/contact.php
index 89b609f..85fc9dc 100644
--- a/contact.html
+++ b/contact.php
@@ -1,3 +1,6 @@
+<?php
+session_start();
+?>
<!DOCTYPE html>
<html>
<head>
@@ -11,7 +14,16 @@
<dl>
<dt><a href=".">Home</a></dt>
<dt><a href="categories.php">Categories</a></dt>
- <dt><a href="login.html">Login</a></dt>
+ <?php
+ if(isset($_SESSION['username']))
+ {
+ echo "<dt><a href=\"login.php?logout\">Logout</a></dt>";
+ }
+ else
+ {
+ echo "<dt><a href=\"login.php\">Login</a></dt>";
+ }
+ ?>
</dl>
</nav>
<div id="content">
diff --git a/index.html b/index.php
index 205eeb2..c7eb711 100644
--- a/index.html
+++ b/index.php
@@ -1,3 +1,6 @@
+<?php
+session_start();
+?>
<!DOCTYPE html>
<html>
<head>
@@ -9,9 +12,18 @@
<header><h1>Home</h1></header>
<nav>
<dl>
- <dt><a href="contact.html">Contact us</a></dt>
+ <dt><a href="contact.php">Contact us</a></dt>
<dt><a href="categories.php">Categories</a></dt>
- <dt><a href="login.html">Login</a></dt>
+ <?php
+ if(isset($_SESSION['username']))
+ {
+ echo "<dt><a href=\"login.php?logout\">Logout</a></dt>";
+ }
+ else
+ {
+ echo "<dt><a href=\"login.php\">Login</a></dt>";
+ }
+ ?>
</dl>
</nav>
<div id="content">
diff --git a/login.html b/login.php
index 4455b0e..bbe1897 100644
--- a/login.html
+++ b/login.php
@@ -1,3 +1,32 @@
+<?php
+ session_start();
+ if(isset($_GET['logout']))
+ {
+ session_destroy();
+ header('Location: login.php');
+ }
+ if(isset($_SESSION['username']))
+ {
+ header('Location: .');
+ }
+ if(isset($_POST['username']) && isset($_POST['password']))
+ {
+ $username = $_POST['username'];
+ $password = $_POST['password'];
+ require_once('vendor.inc.php');
+
+ $user = UserQuery::create()->findOneByUsername($username);
+ if ( !is_object($user) )
+ {
+ header('Location: login.php');
+ }
+ if($user->checkPassword($password))
+ {
+ $_SESSION['username'] = $username;
+ }
+ header('Location: .');
+ }
+?>
<!DOCTYPE html>
<html>
<head>
@@ -9,13 +38,13 @@
<header><h1>Customer login</h1></header>
<nav>
<dl>
- <dt><a href="contact.html">Contact us</a></dt>
+ <dt><a href="contact.php">Contact us</a></dt>
<dt><a href="categories.php">Categories</a></dt>
<dt><a href=".">Home</a></dt>
</dl>
</nav>
<div id="content">
- <form action="http://www-in.fh-swf.de/fbp-cgi/showenv.pl" method="post">
+ <form action="login.php" method="post">
<h1>User</h1>
<div class="row">
<label for="username"><u>U</u>sername:</label><input class="formw" type="text"
diff --git a/productdetails.php b/productdetails.php
index 63ba451..44f3e04 100644
--- a/productdetails.php
+++ b/productdetails.php
@@ -1,4 +1,5 @@
<?php
+session_start();
if(isset($_GET['id']))
{
$id = $_GET['id'];
@@ -31,11 +32,20 @@ if ( !is_object($product) )
<header><h1><?php echo $product->getName(); ?></h1></header>
<nav>
<dl>
- <dt><a href="contact.html">Contact us</a></dt>
+ <dt><a href="contact.php">Contact us</a></dt>
<dt><a href=".">Home</a></dt>
<dt><a href="categories.php">Categories</a></dt>
<dt><a href="products.php?id=<?php echo $catid; ?>">Back to Category</a></dt>
- <dt><a href="login.html">Login</a></dt>
+ <?php
+ if(isset($_SESSION['username']))
+ {
+ echo "<dt><a href=\"login.php?logout\">Logout</a></dt>";
+ }
+ else
+ {
+ echo "<dt><a href=\"login.php\">Login</a></dt>";
+ }
+ ?>
</dl>
</nav>
<div id="content">
diff --git a/products.php b/products.php
index 1591799..5827254 100644
--- a/products.php
+++ b/products.php
@@ -1,4 +1,5 @@
<?php
+session_start();
if(isset($_GET['id']))
{
$id = $_GET['id'];
@@ -27,10 +28,20 @@ $products = $category->getProducts();
<header><h1><?php echo $category->getName(); ?></h1></header>
<nav>
<dl>
-<dt><a href="contact.html">Contact us</a></dt>
+<dt><a href="contact.php">Contact us</a></dt>
<dt><a href=".">Home</a></dt>
<dt><a href="categories.php">Categories</a></dt>
-<dt><a href="login.html">Login</a></dt>
+<?php
+if(isset($_SESSION['username']))
+{
+ echo "<dt><a href=\"login.php?logout\">Logout</a></dt>";
+ $username = $_SESSION['username'];
+}
+else
+{
+ echo "<dt><a href=\"login.php\">Login</a></dt>";
+}
+?>
</dl>
</nav>
<div id="content">