added adminCategories
This commit is contained in:
parent
c08abe7915
commit
a50f0bbce1
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
function fetchCats() {
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
$stmt = $pdo->prepare('SELECT * FROM categories');
|
||||
$stmt->execute();
|
||||
$cats = $stmt->fetchAll();
|
||||
|
||||
return $cats;
|
||||
}
|
||||
16
layout.php
16
layout.php
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['loggedin'])) {
|
||||
$logButton = 'href="account/logout.php">Logout';
|
||||
$logButton = 'href="../account/logout.php">Logout';
|
||||
}
|
||||
else {
|
||||
$logButton = 'href="account/login.php">Login';
|
||||
$logButton = 'href="../account/login.php">Login';
|
||||
}
|
||||
|
||||
require_once 'db.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
|
@ -33,14 +34,7 @@ else {
|
|||
<nav> <!--TODO: Populate this list from the categories defined by the admins-->
|
||||
<ul>
|
||||
<?php
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
$stmt = $pdo->prepare('SELECT * FROM categories');
|
||||
$stmt->execute();
|
||||
$cats = $stmt->fetchAll();
|
||||
$cats = fetchCats();
|
||||
foreach ($cats as &$cat) {
|
||||
echo '<li><a class="categoryLink" href="../index.php?pageHeading='. urlencode($cat['category_name']) .'">'. $cat['category_name'] .'</a></li>';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
session_start();
|
||||
$pageTitle = 'iBuy - Login';
|
||||
$pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to register</a></p>
|
||||
<h1>Login</h1>
|
||||
<form action="login.php" method="POST">
|
||||
<label>Email</label> <input name="email" type="text" />
|
||||
<label>Password</label> <input name="password" type="text" />
|
||||
<label>Password</label> <input name="password" type="password" />
|
||||
<input name="submit" type="submit" value="Submit" />
|
||||
</form>';
|
||||
$stylesheet = '../assets/ibuy.css';
|
||||
|
|
@ -23,10 +24,11 @@ if (isset($_POST['submit'])) {
|
|||
$user = $stmt->fetch();
|
||||
if (password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['loggedin'] = $user['user_id'];
|
||||
echo'<script>window.location.href = "../index.php";</script>';
|
||||
if ($user['admin'] === 'y') {
|
||||
$_SESSION['loggedin'] = 'y';
|
||||
$_SESSION['admin'] = 'y';
|
||||
}
|
||||
echo'<script>window.location.href = "../index.php";</script>';
|
||||
|
||||
}
|
||||
else {
|
||||
echo '<p>Unsuccessful Login</p>';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
session_start();
|
||||
unset($_SESSION['loggedin']);
|
||||
header('Location: ../index.php');
|
||||
echo '<p>Logged Out</p>';
|
||||
unset($_SESSION['admin']);
|
||||
echo'<script>window.location.href = "../index.php";</script>';
|
||||
?>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
session_start();
|
||||
$pageTitle = 'iBuy - Admin';
|
||||
$stylesheet = '../assets/ibuy.css';
|
||||
if(isset($_SESSION['admin'])) {
|
||||
if($_SESSION['admin'] != 'y') {
|
||||
//echo'<script>window.location.href = "../index.php";</script>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
//echo'<script>window.location.href = "../index.php";</script>';
|
||||
}
|
||||
|
||||
require_once '../../db.php';
|
||||
$pageContent = '<h1>Categories <a href="addCategory.php">Add</a></h1>
|
||||
<ul>'. populateContent() .'</ul>';
|
||||
|
||||
require '../../layout.php';
|
||||
|
||||
function populateContent() {
|
||||
$output = '';
|
||||
$cats = fetchCats();
|
||||
foreach ($cats as &$cat) {
|
||||
$output .= '<li>'. $cat['category_name'] . ' <a href="editCategory.php?category_id='. urlencode($cat['category_id']) .'">edit</a> <a href="deleteCategory.php?category_id='. urlencode($cat['category_id']). '">delete</a></li>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
session_start();
|
||||
//Listing display page. Display the 10 auctions finishing soonest
|
||||
//Can be used for index, search page, and category listing
|
||||
$pageTitle = 'iBuy - Home';
|
||||
|
|
|
|||
Loading…
Reference in New Issue