School Commit Init
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user