<repo_name>itma96/cpanel<file_sep>/connect.inc.php
<?php

if(!mysql_connect('localhost','root','') || !mysql_select_db('mydatabase')) {
	die(mysql_error());
}

?><file_sep>/showusers.php
<?php
require 'connect.inc.php';
require 'core.inc.php';
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style>

body {
	 background: #0ca3d2;
}

table {
	width: 100%
}

table, th, td {
	border: 1px solid black;
	border-collapse: collapse;
}

th, td {
	padding: 5px;
	text-align: center;
}

table#t01 tr:nth-child(even) {
	background-color: #FFFFFF;
}

table#t01 tr:nth-child(odd) {
	background-color: #A69F9F;
}

table#t01 th {
	background-color: gray;
	color: black;
}

a#DeleteButton {
  background-color: red;
  -moz-border-radius: 2px;
  border-radius: 2px;
  cursor: pointer;
  border: 3px solid red;
  font-weight: bold;
  text-decoration: none;
}

a:link {
    color: #000000 ;
}

/* visited link */
a:visited {
    color: #000000 ;
}

/* mouse over link */
a:hover {
    color: #000000 ;
}

/* selected link */
a:active {
    color: #000000 ;
}

</style>
</head>
<body>
<div style=" margin:0 auto; width: 300px; font-size: 130%; background: white; border-radius: 5px;">
<h1><center>Lista Angajati</center></h1>
</div>
</body>
<form action="http://localhost/www/index.html" method="get">
<table id="t01" class="table-box">
<tr>
<th style="width: 120px; "><center>ID</center></th>
<th style="width: 120px; "><center>Nume</center></th>
<th style="width: 120px; "><center>Prenume</center></th>
<th style="width: 120px; "><center>Data nasterii</center></th>
<th style="width: 120px; "><center>Data angajarii</center></th>
<th style="width: 120px; "><center>Salariu</center></th>
<th style="width: 100px; "><center></center></th>
</tr>
<?php
	$query = "SELECT `id`, `nume`, `prenume`, `data_nastere`, `data_angajare`, `salariu` FROM `employees`";
	$query_result = mysql_query($query);
	//$query_result = mysql_result($query_run);
		
		while($row = mysql_fetch_array($query_result)) {
			
			echo '<tr>';
			echo '<td style = \'width: 120px;\'><center>'.$row['id'].'</center></th>';
			echo '<td style = \'width: 120px;\'><center>'.$row['nume'].'</center></th>';
			echo '<td style = \'width: 120px;\'><center>'.$row['prenume'].'</center></th>';
			echo '<td style = \'width: 120px;\'><center>'.$row['data_nastere'].'</center></th>';
			echo '<td style = \'width: 120px;\'><center>'.$row['data_angajare'].'</center></th>';
			echo '<td style = \'width: 120px;\'><center>'.$row['salariu'].'</center></th>';
			echo '<td><a id="DeleteButton" href=\'deleterow.php?row_id='.$row['id'].'\'>Delete</a></td>';
			echo '</tr>';
			
		}
		
?>
</table>
</form>
</body>
</html>
<file_sep>/adduser.php
<?php 

require 'connect.inc.php';
require 'core.inc.php';

echo $lastname = $_SESSION['post_data']['nume'];
echo $firstname = $_SESSION['post_data']['prenume'];
echo $password = $_SESSION['post_data']['parola'];
$data_nasterii = $_SESSION['post_data']['data nasterii'];
$data_angajarii = $_SESSION['post_data']['data angajarii'];
$salariu = $_SESSION['post_data']['salariu'];
	
$username = $firstname .'.'. $lastname;
	
$query_run = mysql_query("SELECT `username` FROM `employees` WHERE `username`='$username'");
	
if(mysql_num_rows($query_run)>=1)
{
	header("Location: index.php?message=User already exists!");
	exit;
} 
else 
{
	if(empty($firstname) || empty($lastname)) {
		header("Location: index.php?message=Please provide a proper name!");
		exit;
	}
	
	if(empty($password)) {
		header("Location: index.php?message=Please provide a proper password!");
		exit;
	}
	
	$query = "INSERT INTO `employees` VALUES ('','".mysql_real_escape_string($username)."',
	'".mysql_real_escape_string($password)."','".mysql_real_escape_string($lastname)."',
	'".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($data_nasterii)."',
	'".mysql_real_escape_string($data_angajarii)."','".mysql_real_escape_string($salariu)."')";
	
	if($query_run = mysql_query($query)) {
		header("Location: index.php?message=User has been added!");
	}
	
}

?><file_sep>/core.inc.php
<?php
ob_start();
session_start();
$current_page = $_SERVER['SCRIPT_NAME'];
?><file_sep>/controller.php
<?php

require 'connect.inc.php';
require 'core.inc.php';

$_SESSION['post_data'] = $_POST;

if(!empty($_POST['AddButton'])) {
	header('Location: adduser.php');
	exit;
}
if(!empty($_POST['ShowButton'])) {
	header('Location: showusers.php');
	exit;
}
if(!empty($_POST['LogoutButton'])) {
	header('Location: logout.php');
	exit;
}
?><file_sep>/deleterow.php
<?php

require 'connect.inc.php';
require 'core.inc.php';

 $id = $_GET['row_id'];
 
 $query = "DELETE FROM `employees` WHERE `id`='$id'";
 
 if($query_run = mysql_query($query)) {
		mysql_query("ALTER TABLE `employees` AUTO_INCREMENT=1");
		header("Location: showusers.php");
	}
 
 
?><file_sep>/index.php
<?php

require 'connect.inc.php';
require 'core.inc.php';

if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
	
	$user_id = $_SESSION['user_id'];
	$query_run = mysql_query("SELECT `username` FROM `employees` WHERE `id`='$user_id'");
	$username = mysql_result($query_run,0);
} else {
	include 'loginform.inc.php';
}

?>

<!html>
<head>
<meta charset="UTF-8">
<title>index page</title>
<link href="index_menu.css" rel="stylesheet"/>
</head>
<body>
<form action="controller.php" method="POST">

<div class="form-box">
<br>
<?php
if(!empty($_GET['message'])) {
	$message = $_GET['message'];
    echo '<font color=\'red\'>'.$message.'</font>';	
}
?>
<br>
<br>
Nume angajat:<br>
<input type="text" name="nume">
<br>
<br>
Prenume angajat:<br>
<input type="text" name="prenume">
<br>
<br>
Parola:<br>
<input type="password" name="<PASSWORD>">
<br>
<br>
Data nasterii:<br>
<input type="date" name="data nasterii">
<br>
<br>
Data angajarii:<br>
<input type="date" name="data angajarii">
<br>
<br>
Salariu:<br>
<input type="text" name="salariu">
<br>
<br>
</div>

<div class="info-panel">
<?php 
	if(isset($username) && !empty($username)) {
		echo '<center><bold><font size=\'5\'>'.$username.'</font></bold></center>';
	} else {
		include 'logout.php';
	}
?>
<img src="default_profile_pic.jpg" alt="Profile" style="width:150px;height:150px;border:2px solid #021a40;border-radius:5px">
<br>
<br>
<input type="submit" name="AddButton" value="Adauga angajat" style="width: 150px; height: 53px; ">
<br>
<br>
<input type="submit" name="ShowButton" value="Afiseaza angajati" style="width: 150px; height: 53px; ">
<br>
<br>
<input type="submit" name="LogoutButton" value="Logout" style="width: 150px; height: 53px; ">
</div>

</form>
</body>
</html>
<file_sep>/loginform.inc.php
<?php

if(isset($_POST['username']) && isset($_POST['password'])) {
	
	$username = $_POST['username'];
	$password = $_POST['<PASSWORD>'];
	
	if(!empty($username) && !empty($password)) {
		
		$query = "SELECT `id` FROM `employees` WHERE `username`='$username' AND `password`='$password'";
		
		if($query_run = mysql_query($query)) {
			
			if(mysql_num_rows($query_run)==0) {
				
				echo 'Invalid username/password!';
				
			} else if(mysql_num_rows($query_run)==1) {
				
				$user_id = mysql_result($query_run,0,'id');
				$_SESSION['user_id'] = $user_id;
				header('Location: index.php');
				
			}		
			
		}
		
	} else {
		echo 'You must provide a username and a password!';
	}
}

?>

<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Login Form</title>
  <link rel="stylesheet" href="login_form.css">
  <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
  
    <div class="login">
      <h1>Login</h1>
      <form method="POST" action="<?php echo $current_file; ?>" >
        <p><input type="text" name="username" value="" placeholder="Username"></p>
        <p><input type="password" name="password" value="" placeholder="<PASSWORD>"></p>
        <p class="submit"><input type="submit" name="commit" value="Login"></p>
      </form>
    </div>   
	
</body>
</html>