database 4 assignment #2€¦ · jimmy kenny a00177486 database 4 assignment #2 year 4 2 clock in /...
TRANSCRIPT
Database 4 Assignment #2
Part 1:
Database Schema and Web Application Wireframes
Part 2:
Screenshots of Application and Code Printouts
Jimmy Kenny – A00177486 11/19/2013
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
1
Part I
Database Schema and
Web Application Wireframes
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
2
Clock In / Clock Out System
I will develop an online Clock In/Clock Out system using PHP and a MySQL database.
The system will have the following requirements:
Register Users on the System
Each user will have an ID, First Name, Surname, Department, Job Level (such as Operations,
Services, Supervisor, Manager, Senior Manager) and a Password
Form for users to clock in/clock out.
Form will require the user to enter their ID and Password and if starting/finishing
The Time, ID and In or Out is recorded in the database.
Only a manager or higher will be able to access a secure page where he/she can run reports
on the Clock In/Clock out data.
The manager must be able to choose from at least 6 predefined reports and have the date
presented in a readable format such as a table.
A number of the reports will combine data from a number of different tables.
Database Schema for Clock In/Clock Out System
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
3
Homepage
Insert Time Clock Details
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
4
Register User Details
Enter Password Details
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
5
Get Reports
Typical Report Layout
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
6
Part II
Screenshots of Application
and Code Printouts
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
7
Code and Screenshots
header.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//connect to the database
require('dbConnect.php');
//all SQL procedures stored in this php file
require('dbFunctions.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TimeClock</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"
/>
<link rel="stylesheet" type="text/css" href="./styles/main.css" />
<!-- CSS Style Sheet -->
</head>
<body>
<div id="page">
<div id="header">
<div id="links">
<table width="100%">
<tr>
<td width="37%" height="22"></td>
<td class="buttonColor" width="15.75%"
height="20"><a href="<?php echo 'index.php'; ?>">Home</a> </td>
<td class="buttonColor" width="15.75%"
height="20"><a href="<?php echo 'clockInOut.php'; ?>">Time Clock</a> </td>
<td class="buttonColor" width="15.75%"
height="20"><a href="<?php echo 'registerUser.php'; ?>">Register User</a>
</td>
<td class="buttonColor" width="15.75%"
height="20"><a href="<?php echo 'login.php'; ?>">Admin</a> </td>
</tr>
</table>
</div>
</div>
The header.php file is included in every php file that displays data on screen. It contains php require
functions to connect to the database (require('dbConnect.php');) and to access the sql
procedures to manipulate data in the database (require('dbFunctions.php');). The html
section generates the banner head and the page links.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
8
dbConnect.php
<?php
$host = "localhost"; //host name
$username = "root"; //username
$password = "admin"; //password
$databasename = "timeclock"; //db name
//connect to database
//$testCon = "Connection made";
$con = mysqli_connect("$host", "$username", "$password");
mysqli_select_db($con, "$databasename") or die("Cannot select DB");
mysqli_set_charset($con, 'utf8');
?>
PHP script to connect to the timeclock database.
dbFunctions.php <?php
//get information of all employees combining data from three different
tables
function get_employee_details() {
global $con;
$query = "SELECT employee.idEmployee as ID, employee.firstName as
FirstName, employee.lastName as LastName, joblevel.jobName as Position,
department.deptName as Department
FROM employee, joblevel, department
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
ORDER BY ID";
$employee_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $employee_details;
}
//get all details of specified employee
function get_single_employee_details($idEmployee) {
global $con;
$query = "SELECT * from employee
WHERE idEmployee = '$idEmployee'";
$employee_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $employee_details;
}
//get employee details by department using three different tables
function get_department_details($department) {
global $con;
$query = "SELECT employee.idEmployee as ID, employee.firstName as
FirstName, employee.lastName as LastName, joblevel.jobName as Position,
department.deptName as Department
FROM employee, joblevel, department
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
AND department.idDepartment = '$department'
ORDER BY ID";
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
9
$department_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $department_details;
}
//get employee details by job position using three different tables
function get_position_details($position) {
global $con;
$query = "SELECT employee.idEmployee as ID, employee.firstName as
FirstName, employee.lastName as LastName, joblevel.jobName as Position,
department.deptName as Department
FROM employee, joblevel, department
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
AND joblevel.idJobLevel = '$position'
ORDER BY ID";
$position_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $position_details;
}
//add new employee to database
function add_employee($firstName, $lastName, $password, $position,
$department){
global $con;
$query = "INSERT INTO employee (idEmployee, firstName, lastName,
password, idJobLevel, idDepartment) VALUES (NULL, '$firstName',
'$lastName', '$password', '$position', '$department')";
mysqli_query($con, $query) or die(mysqli_error($con));
}
//delete employee from database by ID
function delete_employee($identity) {
global $con;
$query = "DELETE FROM employee WHERE idEmployee = '$identity'";
mysqli_query($con, $query) or die(mysqli_error($con));
}
//validates ID and password
function check_employee_details($idEmployee, $password){
global $con;
$query = "SELECT * FROM employee WHERE idEmployee = '$idEmployee' AND
password = '$password'";
$admin_login = mysqli_query($con, $query) or die(mysqli_error($con));
return $admin_login;
}
//inserts employees time records
function record_clocktime($clockInOut, $idEmployee){
global $con;
$query = "INSERT INTO timerecord (idTimeRecord, time, clockInOut,
idEmployee) VALUES (NULL, Now(), '$clockInOut', '$idEmployee')";
mysqli_query($con, $query) or die(mysqli_error($con));
}
//retrieves individuals time records using four different tables
function get_clocking_details($idEmployee) {
global $con;
$query = "SELECT employee.firstName as FirstName, employee.lastName as
LastName, joblevel.jobName as Position, department.deptName as Department,
timerecord.time as Times, timerecord.clockInOut as ClockRecord
FROM employee, joblevel, department, timerecord
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
10
AND employee.idEmployee = timerecord.idEmployee
AND employee.idEmployee = '$idEmployee'
ORDER BY Times;";
$clocking_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $clocking_details;
}
//retrieves individuals time records over specified time frame using four
different tables
function get_clock_days_details($idEmployee, $interval) {
global $con;
$query = "SELECT employee.firstName as FirstName, employee.lastName as
LastName, joblevel.jobName as Position, department.deptName as Department,
timerecord.time as Times, timerecord.clockInOut as ClockRecord
FROM employee, joblevel, department, timerecord
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
AND employee.idEmployee = timerecord.idEmployee
AND employee.idEmployee = '$idEmployee'
AND timerecord.time >= DATE_SUB(CURDATE(), INTERVAL '$interval' DAY);";
$clock_days_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $clock_days_details;
}
//get all time records of all employees over specified timeframe using four
tables
function get_all_clock_days_details($interval) {
global $con;
$query = "SELECT employee.firstName as FirstName, employee.lastName as
LastName, joblevel.jobName as Position, department.deptName as Department,
timerecord.time as Times, timerecord.clockInOut as ClockRecord
FROM employee, joblevel, department, timerecord
WHERE employee.idJobLevel = joblevel.idJobLevel
AND employee.idDepartment = department.idDepartment
AND employee.idEmployee = timerecord.idEmployee
AND timerecord.time >= DATE_SUB(CURDATE(), INTERVAL '$interval' DAY)
ORDER BY Times;";
$all_clock_days_details = mysqli_query($con, $query) or
die(mysqli_error($con));
return $all_clock_days_details;
}
//update employee records
function
update_employee($idEmployee,$firstName,$lastName,$password,$idJobLevel,$idD
epartment){
global $con;
$query = "UPDATE employee
SET firstName ='$firstName', lastName='$lastName',
password='$password', idJobLevel='$idJobLevel',
idDepartment='$idDepartment'
WHERE idEmployee='$idEmployee';";
mysqli_query($con, $query) or die(mysqli_error($con));
}
?>
This file contains all sql procedures inside php functions to manipulate the database using sql
queries. To specify time intervals in some functions I’ve used the following: DATE_SUB(CURDATE(), INTERVAL '$interval' DAY)
The DATE_SUB function subtracts the specified interval from the current date to get the timeframe.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
11
index.php <?php
include 'header.php';
?>
<div id="innerBlockF">
<table width="100%">
<tr>
<td align="top"><h1>Employee Timeclock Application</h1></td>
</tr>
<tr>
<td align="center"><img src="images/clock3.gif"
alt="timeClock"></td>
</tr>
<tr>
<td align="center"><p>This application allows employees to
record hours worked by clocking in and clocking out.
New Employees can be registered on the system.
Users with administration rights (Managers and Senior Managers)
can generate various reports from the information stored on the database
and employee records can be deleted or updated.</p></td>
</tr>
</table>
</div>
<?php include 'footer.php'; ?>
The index.php file includes header.php and footer.php to generate the homepage of the application.
Homepage of application – index.php
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
12
clockInOut.php <?php
include 'header.php';
?>
<div id="innerBlock">
<table class="parent">
<tr>
<form name="form1" method="post" action="clockInOut.php">
<input type="hidden" name="action" value="record_clocktime"
/>
<td>
<table class="input">
<tr>
<td colspan="3"
align="center"><strong>CLOCK IN OR OUT</strong> </td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="130">Employee ID</td>
<td width="6">:</td>
<td width="294"><input name="idEmployee"
type="text" id="idEmployee"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password"
id="password" size='21'></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="clockOption" type="radio"
value="in" checked="checked" />Clock In
<input name="clockOption" type="radio"
value="out" />Clock Out
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit"
value="Enter" width="48"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<?php
if (isset($_POST['submit'])){
$clockInOut = $_POST['clockOption'];
$idEmployee = intval($_POST['idEmployee']);
$password = $_POST['password'];
$result = check_employee_details($idEmployee, $password); //function
that validates data input
$count=mysqli_num_rows($result); //returns number of records returned
from query
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
13
//if a record is returned record clock time otherwise invalid input and
try input again
if ($count==1){
record_clocktime($clockInOut, $idEmployee);
echo "<p class='error'>Time Recorded</p>";
}
else {
header("location:clockInOutAgain.php");
}
}
include 'footer.php';
?>
This php file presents the Clock In or Out view to the user to record their clock times.
Clock In or Out view
Clock In or Out view re-presented if initial input is invalid
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
14
registerUser.php <?php
include 'header.php';
?>
<div id="innerBlock">
<table class="parent">
<tr>
<form action="registerUser.php" method="post"
enctype="multipart/form-data"> <!-- action call to self -->
<input type="hidden" name="action" value="add_employee"
/>
<td>
<table class="input">
<tr >
<td colspan="3"
align="center"><strong>REGISTER EMPLOYEE </strong></td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="130"><label>First
Name</label></td>
<td width="6">:</td>
<td width="294"><input type="text"
name="firstName"/></td>
</tr>
<tr>
<td><label>Last Name</label></td>
<td>:</td>
<td><input type="text"
name="lastName"/></td>
</tr>
<tr>
<td><label>Department</label></td>
<td>:</td>
<td>
<select name="department">
<option value="1">Accounts</option>
<option value="2">Human
Resources</option>
<option
value="3">Marketing</option>
<option value="4">Sales</option>
<option
value="5">Purchasing</option>
<option
value="6">Manufacturing</option>
</select>
</td>
</tr>
<tr>
<td><label>Position</label></td>
<td>:</td>
<td>
<select name="position">
<option
value="1">Operations</option>
<option value="2">Services</option>
<option
value="3">Supervisor</option>
<option value="4">Manager</option>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
15
<option value="5">Senior
Manager</option>
</select>
</td>
</tr>
<tr>
<td><label>Password</label></td>
<td>:</td>
<td>
<input type="password" name="password"
size="21"/>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit"
value="Add Employee"/></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<?php
if (isset($_POST['submit'])){ //checks to see if submit variable has
been set
if(!get_magic_quotes_gpc()){ //if magic quotes function is disable
$firstName = addslashes($_POST['firstName']); //add back slashes to
escape a character (e.g. single or double quote)
$lastName = addslashes($_POST['lastName']);
$password = addslashes($_POST['password']);
}
else {
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$password = $_POST['password'];
}
$position = intval($_POST['position']);
$department = intval($_POST['department']);
add_employee($firstName, $lastName, $password, $position, $department);
//add new employee to database
echo "<p class='error'>Employee Registered</p>";
}
include 'footer.php'; ?>
This php file is used to register new employees inputing first name, last name, department, position
(job level) the employee id number is automatically incremented from previous entry in the
database. It makes use of the addslasehes() function to add back slashes to any character the needs
escaping from the input from the user.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
16
Register Employee view
login.php <?php
include 'header.php';
?>
<div id="innerBlock">
<table class="parent">
<tr>
<form name="form1" method="post" action="checklogin.php">
<!--calls checklogin.php to validate input-->
<td>
<table class="input">
<tr>
<td colspan="3"
align="center"><strong>ADMIN LOGIN </strong></td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="130">Employee ID</td>
<td width="6">:</td>
<td width="294"><input name="idEmployee"
type="text" id="idEmployee"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password"
id="password" size="21"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
17
</table>
</td>
</form>
</tr>
</table>
</div>
<?php include 'footer.php'; ?>
Log in to secure area of application using login.php. Only Managers and Senior Managers will be able
to access the Adminstation area of website. This gives access to various forms displaying data about
employees and also allows administrators to delete or update employee records. When user data is
submitted the checklogin.php validates the input.
Admin Login view
checkLogin.php <?php
session_start(); //starts a new session
include 'header.php';
// username and password sent from form
$idEmployee=$_POST['idEmployee'];
$password=$_POST['password'];
// To protect MySQL injection
$idEmployee = stripslashes($idEmployee); //removes backslash before
escaped characters in user input
$password = stripslashes($password);
$idEmployee = intval($idEmployee); //parses text input as an int
value
$result = check_employee_details($idEmployee, $password); //validates
data and passes returned data to $result
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
18
$count=mysqli_num_rows($result); // mysqli_num_row counts no. of table
rows
$row = mysqli_fetch_assoc($result); //returns the current row of a
fieldset as an associative array
$user_id = $row['idEmployee'];
$user_jobLevel = $row['idJobLevel'];
if ($count!=1){ //if no records found
header("location:loginAgain.php");
}
else if($count==1 && $user_jobLevel > 3){ //if user record exists and
they have admistrtion rights
$_SESSION['userlogin'] = $user_id; //store session information of
user
header("location:adminMenu.php"); //display administration menu
}
else if($count==1 && $user_jobLevel < 4){ //if user exists but does not
have administrtion rights
header("location:notAdmin.php"); //display message - no
administration rights
}
?>
The checkLogin.php scripts validate the administration login details and sets session state of user if
data is valid. If all data is valid the aministration menu is displayed, if wrong Employee ID or
password is entered an error message is displayed and user is invited to log in again. If the user has
no adminitration rights a message to that effect is displayed and they are not allowed to
administration area.
Admin Login view presented again
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
19
admin.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
?>
<div id="innerBlock">
<h1>Employee Reports</h1>
<br />
</tr>
<table class='employee_report'>
<tr>
<form name="form2" method="post"
action="adminEmpDetails.php">
<td>
<table class="input">
<tr>
<td colspan="2"
align="center"><strong>SELECT A REPORT</strong></td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="550">List all Employees</td>
<td width="200"> </td>
<td><input type="submit" name="submit1"
value="Enter"></td>
</tr>
</table>
</td>
</form>
</tr>
<tr>
<form name="form3" method="post"
action="adminDeptDetails.php">
<td>
<table class="input">
<tr>
<td width="550">List Employees by
Department</td>
<td width="200">
<select name="department">
<option value="1">Accounts</option>
<option value="2">Human
Resources</option>
<option
value="3">Marketing</option>
<option value="4">Sales</option>
<option
value="5">Purchasing</option>
<option
value="6">Manufacturing</option>
</select>
</td>
<td><input type="submit" name="submit2"
value="Enter"></td>
</tr>
</table>
</td>
</form>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
20
</tr>
<tr>
<form name="form4" method="post"
action="adminPositionDetails.php">
<td>
<table class="input">
<tr>
<td width="550">List Employees by
Position</td>
<td width="200">
<select name="position">
<option
value="1">Operations</option>
<option value="2">Services</option>
<option
value="3">Supervisor</option>
<option value="4">Manager</option>
<option value="5">Senior
Manager</option>
</select>
</td>
<td><input type="submit" name="submit3"
value="Enter"></td>
</tr>
</table>
</td>
</form>
</tr>
<tr>
<form name="form2" method="post"
action="adminClockingDetails.php">
<td>
<table class="input">
<tr>
<td width="550">List Clock Records of
Employee</td>
<td width="200"><input name="employeeID"
type="text" id="employeeID" placeholder="Enter Employee ID"
onfocus="value=''"></td>
<td><input type="submit" name="submit4"
value="Enter"></td>
</tr>
</table>
</td>
</form>
</tr>
<tr>
<form name="form2" method="post"
action="adminClockDaysDetails.php">
<td>
<table class="input">
<tr>
<td width="300">List Clock Records over
time</td>
<td width="90"><input class="report"
name="employeeID" type="text" id="employeeID" placeholder="Emp ID"
onfocus="value=''"></td>
<td width="90"><input class="report"
name="interval" type="text" id="interval" placeholder="No. Days"
onfocus="value=''"></td>
<td><input type="submit" name="submit5"
value="Enter"></td>
</tr>
</table>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
21
</td>
</form>
</tr>
<tr>
<form name="form2" method="post"
action="adminAllClockDaysDetails.php">
<td>
<table class="input">
<tr>
<td width="400">List Records for All
Employees over time </td>
<td width="90"><input class="report"
name="interval" type="text" id="interval" placeholder="No. Days"
onfocus="value=''"></td>
<td><input type="submit" name="submit6"
value="Enter"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<?php
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
If user is valid and has administrtion rights the adminMenu.php presents the Admin menu view
giving the user the ability to generate employee reports.
Administration Menu view
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
22
adminEmpDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
$employees = get_employee_details(); //gets all employee details
echo "
<div id='innerBlock'>
<h2>Employee Details</h2>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr>
<th>ID No.</td>
<th>First Name</th>
<th>Surname</th>
<th>Position</th>
<th>Department</th>
<th>Edit</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){ //returns the
fields of the current row in the result set
echo "<tr class='rowColour'>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Position'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>
<form action='editUser.php' method='post'
enctype='multipart/form-data'>
<input type='hidden' name='id' value='" .
$row['ID'] . "' />
<input type='submit' name='submitEdit'
value='Edit' />
</form>
</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin
Menu < </a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php'; ?>
This php file generates a report that displays all employee details in a form presented to user with a link to a page to update or delete an employee record.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
23
Employee Report view
editUser.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state
is valid
//session = true
if (isset($_POST['submitEdit'])){
$idEmployee = intval($_POST['id']);
$employee = get_single_employee_details($idEmployee); //get
details of specified employee
$row = mysqli_fetch_array($employee); //returns
fields of current row in result set
}
?>
<div id="innerBlock">
<h2>Edit Employee Record</h2>
<table class="parent">
<tr>
<form name="myform" action="editUser.php" method="post"
enctype="multipart/form-data" >
<input type="hidden" name="action"
value="add_employee" />
<td>
<table class="input">
<tr >
<td colspan="4"
align="center"><strong>UPDATE/DELETE EMPLOYEE DETAILS </strong></td>
</tr>
<tr><td> </td></tr>
<tr>
<td width="150"><label>Employee
ID</label></td>
<td width="6">:</td>
<td width="294"><input type="text"
name="idEmployee" value="<?php echo $row['idEmployee'];?>" readonly /></td>
</tr>
<tr>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
24
<td width="130"><label>First
Name</label></td>
<td width="6">:</td>
<td width="294"><input type="text"
name="firstName" value="<?php echo $row['firstName']; ?>"
onfocus="value=''"/></td>
</tr>
<tr>
<td><label>Last Name</label></td>
<td>:</td>
<td><input type="text" name="lastName"
value="<?php echo $row['lastName']; ?>" onfocus="value=''"/></td>
</tr>
<tr>
<td><label>Department</label></td>
<td>:</td>
<td><input type="text"
name="department" value="<?php echo $row['idDepartment']; ?>"
onfocus="value=''"/></td>
</tr>
<tr>
<td><label>Position</label></td>
<td>:</td>
<td><input type="text" name="position"
value="<?php echo $row['idJobLevel']; ?>" onfocus="value=''"/></td>
</tr>
<tr>
<td><label>Password</label></td>
<td>:</td>
<td>
<input type="text" name="password"
value="<?php echo $row['password']; ?>" onfocus="value=''"/>
</td>
</tr>
<tr>
<?php $row = "";?>
<td> </td>
<td> </td>
<td><input type="submit"
name="submitUpdate" value="Update Employee"/></td>
<td><input type="submit"
name="submitDelete" value="Delete Employee"/></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<p class="center_text"><a href="adminMenu.php"> > Admin Menu <
</a></p>
</div>
<?php
if (isset($_POST['submitUpdate'])){ //checks to see
if submit variable has been set
if(!get_magic_quotes_gpc()){ //if magic
quotes function is disable
$firstName = addslashes($_POST['firstName']); //add back
slashes to escape a character (e.g. single or double quote)
$lastName = addslashes($_POST['lastName']);
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
25
$password = addslashes($_POST['password']);
}
else {
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$password = $_POST['password'];
}
$idEmployee = intval($_POST['idEmployee']);
$idJobLevel = intval($_POST['position']);
$idDepartment = intval($_POST['department']);
update_employee($idEmployee,$firstName,$lastName,$password,$idJobLevel,$idD
epartment); //updates employee details in database
echo "<p class='error'>Record Updated</p>";
}
if (isset($_POST['submitDelete'])){ //checks to see if
submit variable has been set
$identity = intval($_POST['idEmployee']);
delete_employee($identity); //delete employee
from database
echo "<p class='error'>Record Deleted</p>";
}
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php'; ?>
This php file allows administrators to update or delete an employees record.
Update/Delete Employee Details Report view
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
26
adminDeptDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
if (isset($_POST['submit2'])){
$department = intval($_POST['department']);
$employees = get_department_details($department); //get employee
details by department
}
echo "
<div id='innerBlock'>
<h2>Employee Details by Department</h2>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr>
<th>ID No.</td>
<th>First Name</th>
<th>Surname</th>
<th>Position</th>
<th>Department</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){
echo "<tr class='rowColour'>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Position'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin Menu <
</a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
This php file generates a report that displays details of all employess by the chosen department.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
27
Employee Report by Department view
adminPositionDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
if (isset($_POST['submit3'])){
$position = intval($_POST['position']);
$employees = get_position_details($position); //function that
returns all employee details by position (job level)
}
echo "
<div id='innerBlock'>
<h2>Employee Details by Position</h2>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr>
<th>ID No.</td>
<th>First Name</th>
<th>Surname</th>
<th>Position</th>
<th>Department</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){
echo "<tr class='rowColour'>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
28
echo "<td>" . $row['Position'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin
Menu < </a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
This php file generates a report that displays details of all employess by the chosen position.
Employee Report by Position (job level) view
adminClockingDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
if (isset($_POST['submit4'])){
$employeeID = intval($_POST['employeeID']);
$employees = get_clocking_details($employeeID); //get all clock
times of individual employee
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
29
$row = mysqli_fetch_array($employees); //returns
fields of current row in result set
}
echo "
<div id='innerBlock'>
<h2>Employee Clocking Times</h2>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr><p align='center'>Employee Name: <span
style='font-weight:bold'>" . $row['FirstName'] . " " . $row['LastName'] .
"</span> Position: <span style='font-weight:bold'>"
. $row['Position'] . "</span> Department: <span
style='font-weight:bold'>" . $row['Department'] . "</span></p></tr>
<tr>
<!--
<th>First Name</th>
<th>Surname</th>
<th>Position</th>
<th>Department</th> -->
<th class='center'>Dates and Times</th>
<th class='center'>Clock In/Out</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){
echo "<tr class='rowColour'>";
//echo "<td>" . $row['FirstName'] . "</td>";
//echo "<td>" . $row['LastName'] . "</td>";
//echo "<td>" . $row['Position'] . "</td>";
//echo "<td>" . $row['Department'] . "</td>";
echo "<td class='center'>" . $row['Times'] . "</td>";
echo "<td class='center'>" . $row['ClockRecord'] . "</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin
Menu < </a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
This php file generates a report that displays details all clock times of specified employee.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
30
Employee Clocking Times Report view
adminClockDaysDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if session state is
valid
//session = true
if (isset($_POST['submit5'])){
$employeeID = intval($_POST['employeeID']);
$interval = intval($_POST['interval']);
$employees = get_clock_days_details($employeeID,$interval); //get
clock details of specified employee over a particular time interval
$row = mysqli_fetch_array($employees);
//returns fields of current row in result set
}
echo "
<div id='innerBlock'>
<h2>Employee Clocking Times by Time Period</h1>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr><p align='center'>Employee Name: <span
style='font-weight:bold'>" . $row['FirstName'] . " " . $row['LastName'] .
"</span> Position: <span style='font-weight:bold'>"
. $row['Position'] . "</span> Department: <span
style='font-weight:bold'>" . $row['Department'] . "</span></p></tr>
<tr><p align='center'>Time span of records: <span
style='font-weight:bold'>" . $interval . "</span> days</p></tr>
<tr>
<!--
<th>First Name</th>
<th>Surname</th>
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
31
<th>Position</th>
<th>Department</th> -->
<th class='center'>Dates and Times</th>
<th class='center'>Clock In/Out</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){
echo "<tr class='rowColour'>";
//echo "<td>" . $row['FirstName'] . "</td>";
//echo "<td>" . $row['LastName'] . "</td>";
//echo "<td>" . $row['Position'] . "</td>";
//echo "<td>" . $row['Department'] . "</td>";
echo "<td class='center'>" . $row['Times'] . "</td>";
echo "<td class='center'>" . $row['ClockRecord'] . "</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin
Menu < </a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
This php file generates a report that displays details clock times of specified employee over a specified time interval.
Employee Clocking Times by Time Period Report view
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
32
adminAllClockDaysDetails.php <?php
session_start();
include 'header.php';
if(isset($_SESSION['userlogin'])){ //checks to see if
session state is valid
//session = true
if (isset($_POST['submit6'])){
$interval = intval($_POST['interval']);
$employees = get_all_clock_days_details($interval); //get clock
details of all employees over specified time interval
$row = mysqli_fetch_array($employees); //returns
fields of current row in result set
}
echo "
<div id='innerBlock'>
<h2>All Employees Clocking Times by Time Period</h2>
<table class='employee_report'>
<tr>
<td>
<table class='input'>
<tr><p align='center'>Time span of records: <span
style='font-weight:bold'>" . $interval . "</span> days</p></tr>
<tr>
<th>First Name</th>
<th>Surname</th>
<th>Position</th>
<th>Department</th>
<th class='center'>Dates and Times</th>
<th class='center'>Clock In/Out</th>
</tr>";
while ($row = mysqli_fetch_array($employees)){
echo "<tr class='rowColour'>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Position'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td class='center'>" . $row['Times'] . "</td>";
echo "<td class='center'>" . $row['ClockRecord'] . "</td>";
echo "</tr>";
}
echo " </table>
</td>
</tr>
</table>
<p class='center_text'><a href='adminMenu.php'> > Admin
Menu < </a></p>
</div>";
}
else { //if session state is not valid
//if !session
header('location:login.php');
}
include 'footer.php';
?>
This php file generates a report that displays details clock times of all employees over a specified time interval.
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
33
All Employee Clocking Times by Time Period Report view
main.css
/* the styles for the body element and page division */
body { font-family: Arial, Helvetica, sans-serif;
font-size: 87.5%;
margin: 0;
background-color: #800000;
background-image: url(../images/woodTile.jpg);
}
#page { width: 840px;
background-color: white;
padding: 15px;
margin-right: auto;
margin-left: auto;
}
#innerBlockF{
display:block;
width: 90%;
height: 420px;
background-color: white;
padding: 15px;
margin-right: auto;
margin-left: auto;
overflow:auto;
}
#innerBlock { display:block;
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
34
width: 90%;
height: 420px;
background-image: url(../images/clockThumb.jpg);
background-repeat:repeat;
background-size:11.1%;
background-color: white;
padding: 15px;
margin-right: auto;
margin-left: auto;
overflow:auto;
}
#floater { float:left;
height:50%;
margin-bottom:-120px;
}
#top { float:right;
width:100%;
text-align:center;
}
#content { clear:both;
height:240px;
position:relative;
}
/* the styles for the elements */
h1, h2 { color: #FFFFCC;
}
h1 { background-color:#CC0000;
padding:5px;
font-size: 200%;
text-align:center;
margin-top: .05em;
}
h2 { background-color:#CC0000;
padding:4px;
font-size: 150%;
text-align:center;
margin-bottom: 0;
}
ul { line-height: 1.4;
margin-top: .25em;
}
select { width: 150px;
}
th.center{ text-align: center;
}
td.center{ text-align: center;
}
a.primary{
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
35
color: darkred
}
a:hover { font-weight: bold;
}
img.clockCentre{ position:relative;
top:50%;
left:50%;
margin-top:-340px;
margin-left:-225px;
}
table.parent{ width:400px;
border-style:solid;
border-color:#000000;
border-spacing:10;
background-color:#99FF66;
margin-left:auto;
margin-right:auto;
margin-top:75px;
padding:15px 10px 15px 10px;
}
table.input{ width:80%;
border:0;
border-spacing:1;
background-color:#99FF66;
margin-left:50px;
}
table.employee_report{ width:600px;
border-style:solid;
border-color:#000000;
border-spacing:10;
background-color:#99FF66;
margin-left:auto;
margin-right:auto;
margin-top:30px;
padding:15px 10px 15px 10px;
}
input.admin[type=submit] { width: 11.5em;
}
input.report[type=text]{ width: 60px;
}
p.error{ background-color:#CC0000;
text-align: center;
padding:5px;
color: white;
}
/* the styles for the header division */
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
36
#header img{ float:left;
}
#header h1{ margin-left: 3em;
}
#header h2{ margin: 0em 0em 0em 6em;
color: #00ced1;
}
#header { height: 120px;
border-bottom: 3px solid firebrick;
margin-bottom: 1.4em;
background-image: url(../images/bannerTimeClock.jpg);
}
#links td { text-align: center;
font-style: italic;
font-weight: bolder;
}
#links a { color:#fdf992;
text-decoration:none;
}
#links a:hover { color:white;
text-decoration: underline;
}
#links{
position: relative;
top: 96px;
left: 3px;
}
.buttonColor { background-image: url(../images/button.jpg);
background-size: cover;
}
/* the styles for the main division */
#main { margin-left: 165px;
}
#dbDetails { width: 750px;
height: 400px;
overflow-y: scroll;
margin-left: 45px;
background-color: #660000;
padding-top: .2em;
}
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
37
.center_text { text-align:center;
}
.center_text a{ color: #800000;
font-size: 120%;
font-style: italic;
font-weight: bold;
text-decoration:none;
}
.center_text a:hover{ color: red;
text-decoration: underline;
}
/* the styles for the header division */
#footer { clear: both;
margin-top: 1.5em;
border-top: 3px solid firebrick;
padding-top: .7em;
}
/* the styles for classes */
.copyright { color: gray;
font-size: 90%;
text-align: center;
margin: 0;
}
.dbtext { color: black;
font-size: 85%;
text-align: left;
margin: 6px;
padding: 3px;
}
.boldText{
font-weight: bold;
line-height: 180%;
}
.italicText{
font-style: italic;
}
.italicTextHeight{
font-style: italic;
line-height: 180%;
}
.center{
margin-left:130px;
}
.marginLeft{
margin-left: 155px;
margin-top: 5px;
Jimmy Kenny A00177486 Database 4 Assignment #2 Year 4
38
}
.imageWrap{
margin-right: 15px;
}
.year{
text-align: right;
font-style: italic;
color: #ffcd92;
}
textArea{ resize: none;
}
#buttons { float:right;
}
.error { color: red;
font-weight: bold;
}
/* the styles for the details division */
.rowColour { background-color: #FFFFCC;
}
#main td,th { padding: .2em .4em .2em .4em;
vertical-align: top;
text-align: left;
background-color: #fdf992;
}
root { display: block;
}
The css stylesheet for the application.