School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,94 @@
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: ../Users/login.php');
}
if (isset($_POST['returnButton'])) {
header('Location: ../Users/admin.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title>Add a news</title>
</head>
<body>
<div class="container" id="addFormDiv">
<div class="row">
<div class="col-sm">
<div class="container text-left">
<form id="addForm">
<h3>Add a news:</h3>
<div class="mb-1"><label for="titleField" class="form-label">Title: </label><input type="text"
id="titleField" class="form-control" required pattern="[0-9A-Za-z-.\:;]{5,30}"></div>
<div class="mb-1"><label for="contentField" class="form-label">Content: </label><input
type="text" id="contentField" class="form-control" required
pattern="[0-9A-Za-z-.\:;]{10,256}"></div>
<div class="mb-1"><label for="dateField" class="form-label">Date: </label><input type="date"
id="dateField" class="form-control" required></div>
<div class="mb-1"><label for="producerField" class="form-label">Producer: </label><input
type="text" id="producerField" class="form-control" required
pattern="[0-9A-Za-z-]{5,30}"></div>
<div class="mb-1"><label for="categoryField" class="form-label">Category: </label><input
type="text" id="categoryField" class="form-control" required
pattern="[0-9A-Za-z-]{5,30}"></div>
<button id="insertNewsButton" type="submit" class="btn btn-success mb-1">Add
News</button>
</form>
<form method="post">
<input type="submit" class="btn btn-secondary mb-1" name="returnButton"
value="Return to profile">
</form>
</div>
</div>
</div>
</div>
<script>
const insertNews = (e) => {
e.preventDefault();
const title = $('#titleField').val();
const content = $('#contentField').val();
const date = $('#dateField').val();
const producer = $('#producerField').val();
const category = $('#categoryField').val();
$.ajax({
url: 'http://localhost/web/Lab 7/Repositories/Repository.php',
type: 'POST',
data: {
title: title,
news_text: content,
date: date,
producer: producer,
category: category,
action: 'insertNews'
},
success: function (response) {
alert('Log added successfully!');
},
error: function (response) {
alert('Error adding log!');
}
});
}
$('#addForm').submit(insertNews);
</script>
</body>
</html>
@@ -0,0 +1,106 @@
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: ../Users/login.php');
}
if (isset($_POST['returnButton'])) {
header('Location: ../Users/admin.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title>Edit a news report</title>
</head>
<body>
<div class="container" id="addFormDiv">
<div class="row">
<div class="col-sm">
<div class="container text-left">
<form id="editForm">
<h3>Edit a news:</h3>
<?php
require_once '../../Repositories/Repository.php';
$connection = new DBConnection();
if (!isset($_GET['id'])) {
header('Location: ../Users/admin.php');
}
$id = $_GET['id'];
$result = $connection->getNewsById($id);
if (!isset($result) || empty($result)) {
header('Location: ../Users/admin.php');
}
echo '<input type="hidden" id="idField" value="' . $result['id'] . '">';
echo '<div class="mb-1"><label for="titleField" class="form-label">Title: </label><input type="text" id="titleField" class="form-control" required pattern="[0-9A-Za-z-.\:;]{5,30}" value="' . $result['title'] . '"></div>';
echo '<div class="mb-1"><label for="contentField" class="form-label">Content: </label><input
type="text" id="contentField" class="form-control" required
pattern="[0-9A-Za-z-.\:;]{10,256}" value="' . $result['news_text'] . '"></div>';
echo '<div class="mb-1"><label for="dateField" class="form-label">Date: </label><input type="date"
id="dateField" class="form-control" required value=' . $result["date"] . '></div>';
echo '<div class="mb-1"><label for="producerField" class="form-label">Producer: </label><input
type="text" id="producerField" class="form-control" required
pattern="[0-9A-Za-z-]{5,30}" value="' . $result['producer'] . '"></div>';
echo '<div class="mb-1"><label for="categoryField" class="form-label">Category: </label><input
type="text" id="categoryField" class="form-control" required
pattern="[0-9A-Za-z-]{5,30}" value="' . $result['category'] . '"></div>';
?>
<button id="updateNewsButton" type="submit" class="btn btn-success mb-1">Update
News</button>
</form>
<form method="post">
<input type="submit" class="btn btn-secondary mb-1" name="returnButton"
value="Return to profile">
</form>
</div>
</div>
</div>
</div>
<script>
const updateNews = (e) => {
e.preventDefault();
const id = $('#idField').val();
const title = $('#titleField').val();
const content = $('#contentField').val();
const date = $('#dateField').val();
const producer = $('#producerField').val();
const category = $('#categoryField').val();
$.ajax({
url: 'http://localhost/web/Lab 7/Repositories/Repository.php',
type: 'POST',
data: {
id: id,
title: title,
news_text: content,
date: date,
producer: producer,
category: category,
action: 'updateNews'
},
success: function (response) {
alert('Log added successfully!');
},
error: function (response) {
alert('Error adding log!');
}
});
}
$('#editForm').submit(updateNews);
</script>
</body>
</html>
@@ -0,0 +1,99 @@
<?php
if (isset($_POST['backButton'])) {
header('Location: ../../main.html');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<title>News</title>
</head>
<body>
<div class="container text-center">
<h3>Welcome</h3>
<div class='dropdown'>
<button class='btn btn-secondary dropdown-toggle' type='button' id='dropdownMenuButton'
data-bs-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>
Filter
</button>
<div class='dropdown-menu' aria-labelledby='dropdownMenuButton'>
<input class='dropdown-item' type="date" id="dateField" class="form-control" required>
<input class='dropdown-item' placeholder="Category" type="text" id="categoryField" class="form-control"
required>
<input class='dropdown-item' type="button" class="btn btn-primary" id="filterButton" value="Filter">
</div>
</div>
<table class="container" id="newsTable"
style="margin: 30px; border: 1px solid;border-color: black; border-collapse: collapse;">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Date</th>
<th>Producer</th>
</tr>
</thead>
<tbody id='tableBody'>
<?php
require_once '../../Repositories/Repository.php';
$connection = new DBConnection();
$result = $connection->getAllNews();
foreach ($result as $key => $value) {
echo "<tr>";
echo "<td>" . $value['title'] . "</td>";
echo "<td>" . $value['news_text'] . "</td>";
echo "<td>" . $value['category'] . "</td>";
echo "<td>" . $value['date'] . "</td>";
echo "<td>" . $value['producer'] . "</td>";
echo "</tr>";
}
?>
</tbody>
<form method="post">
<input type="submit" class="btn btn-dark" name="backButton" value="Back" style=" margin: 30px">
</form>
</div>
<script>
$(document).ready(function () {
$('#filterButton').click(function () {
var date = $('#dateField').val();
var category = $('#categoryField').val();
$.ajax({
url: '../../Repositories/Repository.php',
type: 'GET',
data: {
date: date,
category: category,
action: 'getAllNewsByCategoryAndDate'
},
success: function (response) {
response = JSON.parse(response);
$('#tableBody').empty();
for (var i = 0; i < response.length; i++) {
var newRow = "<tr><td>" + response[i].title + "</td><td>" + response[i].news_text +
"</td><td>" + response[i].category + "</td><td>" + response[i].date +
"</td><td>" + response[i].producer + "</td></tr>";
$('#tableBody').append(newRow);
}
}
});
});
});
</script>
</body>
</html>
@@ -0,0 +1,78 @@
<?php
session_start();
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
} else {
header('Location: login.php');
die();
}
if (isset($_POST['logoutButton'])) {
session_unset();
session_destroy();
header('Location: login.php');
}
if (isset($_POST['addNewsButton'])) {
header('Location: ../News/addNews.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title>Admin page</title>
</head>
<body>
<div class="container text-center">
<h3>Welcome, <?php echo $username; ?>!</h3>
<table class="container" id="newsTable"
style="margin: 30px; border: 1px solid;border-color: black; border-collapse: collapse;">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Date</th>
<th>Producer</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
require_once '../../Repositories/Repository.php';
$connection = new DBConnection();
$result = $connection->getAllNews();
foreach ($result as $key => $value) {
echo "<tr>";
echo "<td>" . $value['title'] . "</td>";
echo "<td>" . $value['news_text'] . "</td>";
echo "<td>" . $value['category'] . "</td>";
echo "<td>" . $value['date'] . "</td>";
echo "<td>" . $value['producer'] . "</td>";
echo "<td><a href='../News/editNews.php?id=" . $value['id'] . "'>Edit</a></td>";
echo "</tr>";
}
?>
</tbody>
<form method="post">
<input type="submit" class="btn btn-primary" name="addNewsButton" value="Add news" style="margin: 30px">
<input type="submit" class="btn btn-dark" name="logoutButton" value="Log out" style="margin: 30px">
</form>
</div>
</body>
</html>
@@ -0,0 +1,92 @@
<?php
header('Cache-Control: no-cache, must-revalidate');
require_once '../../Repositories/Repository.php';
session_start();
if (isset($_SESSION['username'])) {
unset($_SESSION['username']);
}
function checkValidUser(string $username, string $password): bool
{
$connection = new DBConnection();
$result = $connection->validateUser($username, $password);
return !(count($result) == 0);
}
if (isset($_POST['loginButton'])) {
$errors = 0;
$fields = array("username", "password");
foreach ($fields as $key => $field) {
if (!isset($_POST[$field]) || empty($_POST[$field])) {
$errors++;
break;
}
}
if ($errors <= 0) {
$username = $_POST['username'];
$password = $_POST['password'];
if (checkValidUser($username, $password)) {
$_SESSION['username'] = $username;
header('Location: admin.php');
} else {
$_SESSION['login-error'] = "Invalid username and/or password! Try again!";
}
} else {
$_SESSION['login-error'] = "Invalid username and/or password! Try again!";
}
}
if (isset($_POST['indexPage'])) {
header('Location: ../../main.html');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<title>Login</title>
</head>
<body>
<div class="container">
<h2>Login</h2>
<form id="login-form" method="post" action="login.php">
<div class="mb-3 mt-3">
<label for="username" class="form-label">Username:</label>
<input type="text" class="form-control" id="username" placeholder="Enter username" name="username">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password:</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password">
</div>
<input type="submit" class="btn btn-primary" name="loginButton" value="Login">
<input type="submit" class="btn btn-secondary" name="indexPage" value="Cancel">
<?php
if (isset($_SESSION['login-error'])) {
$error = $_SESSION['login-error'];
echo '<script type="text/javascript">';
echo 'window.alert("Invalid username and/or password")';
echo '</script>';
}
?>
</form>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</html>
<?php
unset($_SESSION['login-error']);
?>