Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
include 'crud.php';
include 'db_config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = isset($_POST['title']) ? trim($_POST['title']) : null;
$descriptions = isset($_POST['description']) ? $_POST['description'] : [];
$image = $_FILES['image'];

if ($title && !empty($descriptions) && $image['error'] === UPLOAD_ERR_OK) {
$targetDir = "images/";
$targetFile = $targetDir . basename($image['name']);

if (move_uploaded_file($image['tmp_name'], $targetFile)) {
// Encode descriptions as JSON
$descriptionJson = json_encode($descriptions);
$result = createSection($pdo, $title, $descriptionJson, $targetFile);

if ($result) {
header('Location: index.php');
exit;
} else {
echo "Failed to create section.";
}
} else {
echo "Failed to upload image.";
}
} else {
echo "All fields are required and image upload must be successful.";
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Section</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>

<div class="container">
<h1>Add New Section</h1>
<form action="create.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<div id="description-container">
<input type="text" class="form-control mb-2" name="description[]" required placeholder="Description">
</div>
<button type="button" id="add-description" class="btn btn-secondary">Add More Descriptions</button>
</div>
<div class="form-group">
<label for="image">Image File</label>
<input type="file" class="form-control" name="image" accept="image/*" required>
</div>
<button type="submit" class="btn btn-primary">Create Section</button>
</form>
</div>

<script>
$(document).ready(function() {
$('#add-description').click(function() {
$('#description-container').append('<input type="text" class="form-control mb-2" name="description[]" placeholder="Description">');
});
});
</script>

<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions crud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

function getSections(PDO $pdo): array
{
$stmt = $pdo->query('SELECT * FROM sections');
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

function getSectionById(PDO $pdo, int $id): ?array
{
$stmt = $pdo->prepare('SELECT * FROM sections WHERE id = ?');
$stmt->execute([$id]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}

function createSection(PDO $pdo, string $title, string $description, string $image): bool
{
try {
$stmt = $pdo->prepare('INSERT INTO sections (title, description, image) VALUES (?, ?, ?)');
return $stmt->execute([$title, $description, $image]);
} catch (Exception $e) {
echo "Error while creating section: " . $e->getMessage();
return false;
}
}

function updateSection(PDO $pdo, int $id, string $title, string $description, string $image): bool
{
try {
$stmt = $pdo->prepare('UPDATE sections SET title = ?, description = ?, image = ? WHERE id = ?');
return $stmt->execute([$title, $description, $image, $id]);
} catch (Exception $e) {
echo "Error while updating section: " . $e->getMessage();
return false;
}
}

function deleteSection(PDO $pdo, int $id): bool
{
try {
$stmt = $pdo->prepare('DELETE FROM sections WHERE id = ?');
return $stmt->execute([$id]);
} catch (Exception $e) {
echo "Error while deleting section: " . $e->getMessage();
return false;
}
}
64 changes: 64 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
body {
background-color: #1b2e42;
color: white;
font-family: 'Arial', sans-serif;
}

.container-fluid {
padding: 50px 0;
}

#tabs-column {
background-color: #ffffff;
border-right: 1px solid #ccc;
padding: 20px;
}

#tabs-column .nav-link {
color: #333;
font-size: 18px;
margin-bottom: 10px;
background-color: #f7f7f7;
border-radius: 5px;
text-align: left;
}

#tabs-column .nav-link.active {
background-color: #007bff;
color: #fff;
}

#sectionContent .content-slider {
background-color: #2ca3d9;
padding: 40px;
border-radius: 5px;
}

#image-column img {
width: 100%;
border-radius: 5px;
}

/* Mobile view styles */
@media (max-width: 768px) {
#tabs-column {
background-color: transparent;
border: none;
}

#tabs-column .nav-link {
font-size: 16px;
}

#image-column {
display: none;
}

.content-slider {
background-image: url('../images/mobile-background.jpg'); /* Change the background for mobile */
background-size: cover;
background-position: center;
color: white;
}

}
14 changes: 14 additions & 0 deletions db_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$host = 'localhost';
$db = 'delphian_logic';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';

try {
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Could not connect to the database: " . $e->getMessage());
}
8 changes: 8 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
include 'crud.php';

if (isset($_GET['id'])) {
deleteSection($pdo, $_GET['id']);
header('Location: index.php');
exit;
}
58 changes: 58 additions & 0 deletions edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
include 'crud.php';

if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}

$section = getSectionById($pdo, $_GET['id']);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$description = $_POST['description'];
$image = $_POST['image'];

updateSection($pdo, $_GET['id'], $title, $description, $image);
header('Location: index.php');
exit;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Section</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>

<body>

<div class="container">
<h1>Edit Section</h1>
<form action="edit.php?id=<?php echo $section['id']; ?>" method="POST">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title" value="<?php echo htmlspecialchars($section['title']); ?>" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" name="description" required><?php echo htmlspecialchars($section['description']); ?></textarea>
</div>
<div class="form-group">
<label for="image">Image Path</label>
<input type="text" class="form-control" name="image" value="<?php echo htmlspecialchars($section['image']); ?>" required>
</div>
<button type="submit" class="btn btn-primary">Update Section</button>
</form>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>

</html>
12 changes: 12 additions & 0 deletions fetch_sections.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require 'db_config.php';

$query = "SELECT * FROM sections";
$result = $conn->query($query);

$sections = array();
while ($row = $result->fetch_assoc()) {
$sections[] = $row;
}

echo json_encode($sections);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/communication-infrastructure.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/digital-learning.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/technology-solutions.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading