k/.DS_Store
k/addstaff.php
/* This file has the logic to add a new staff member.
It gets the staff member details via the submission of the
form in the admin page. All that it does is to append the username
and password to the file users.txt. */
$uname = $_POST["user"];
$pass = $_POST["pass"];
$uname = trim($uname);
$pass = trim($pass);
if(strpos($pass,'staff')==false)
{
echo "The password must follow the syntax dcsstaffXY";
return;
}
// Check if a user with that name exists already
$file = fopen("includes/users.txt","r");
//Output lines until EOF is reached
while(!feof($file))
{
$line = fgets($file, 1024);
$bits = explode(',', $line);
$bits[0] = trim($bits[0]);
if($uname==$bits[0])
{
echo "A user with that username exists already. Please give a new username.";
fclose($file);
return;
}
}
fclose($file);
$fp = fopen("includes/users.txt","a");//opens file in append mode
fwrite($fp,"\n".$uname.",".$pass);
fclose($fp);
header('location:admin.php');
?>
k/admin.php
require 'includes/functions.php';
session_start();
if(!isset($_SESSION["type"]))
{
echo "You are not authorized to access this page.";
return;
}
if($_SESSION["type"]!=1) // The user is not an admin
{
echo "Only admins authorized to access this page.";
return;
}
?>
Admin - CS Dept. Birbeck
// require the menu and related code
require 'includes/menu.php';
?>
Department of Computer Science, Birkbeck University
Welcome to the admin page. You can add a new staff member by filling this form: |
if(isset($_SESSION["type"])) { ?>
} ?> |
// require the footer
include 'includes/footer.php';
?>
k/authenticate.php
/* This file has the logic to validate a login. This code
is executed when a user clicks on the Login button in the
index.php page. This page gets the username and password as
POST variables, and then checks whether a username, password
combo matches it. If yes, login is successful, the session variables are
set accordingly, and the user is redirected to the appropriate page.
If not, the user is taken back to the index.php page. */
$uname = $_POST["user"];
$pass = $_POST["pass"];
$uname = trim($uname);
$pass = trim($pass);
// Read the file that stores all usernames and passwords.
$bits = "";
$file = fopen("includes/users.txt","r");
//Output lines until EOF is reached
while(!feof($file))
{
$line = fgets($file, 1024);
$bits = explode(',', $line);
$bits[0] = trim($bits[0]);
$bits[1] = trim($bits[1]);
if(($uname==$bits[0]) && ($pass==$bits[1]))
{
session_start();
$_SESSION["fname"] = $uname;
$_SESSION["password"] = $pass;
// Find out what sort of a user this is - Admin, or staff ?
if(strpos($pass,'admin') !==false)
$_SESSION["type"] = 1;
else if(strpos($pass,'staff') !==false)
$_SESSION["type"] = 2;
echo "successful login";
echo $_SESSION["type"] ;
header('location:index.php');
}
}
fclose($file);
// No user found with that username and password. Invalid credentials.
header('location:index.php');
?>
k/css/results.css
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
}
td, th {
border: 2px solid #dddddd;
text-align: left;
padding: 5px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.tables{
margin-bottom: 30px;
}
body{
font-family: Arial, Helvetica, sans-serif;
background-color: #f2f2ef;
margin: auto;
width: 70%;
border: 2px solid darkgrey;
border-radius: 5px;
padding: 2em;
}
h1{
margin: 20px 5px 0px 10px;
color: #651c65;
}
h2{
padding: 5px;
margin: 10px;
}
h3{
color: #651c65;
padding: 5px;
margin: 10px;
}
h4{
text-align: right;
color: #651c65;
}
li{
color:#651c65;
text-align: right;
list-style-position: inside;
}
h5{
text-align: right;
color: darkgrey;
}
p{
padding: 5px;
margin: 10 15px;
}
.nav ul {
list-style-type: none;
margin: 5px;
padding: 0;
overflow: hidden;
}
.nav li {
float: left;
background-color: white;
border: 1px solid darkgrey;
}
.nav li a {
display: block;
color: black;
text-align: center;
padding: 18px 20px;
text-decoration: none;
}
.nav li a:hover {
background-color: #651c65;
}
.subnav li{
text-align: left;
}
.subnav a{
text-decoration: none;
font-size: 20px;
color:#651c65;
}
.subnav a:hover{
color: darkgrey;
}
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid darkgrey;
border-radius: 4px;
box-sizing: border-box;
}
input[type=Password]{
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid darkgrey;
border-radius: 4px;
box-sizing:...