Mini Kabibi Habibi
<?php
include 'includes/db.php'; // Make sure this connects to your database using $pdo
// Handle form submission to add new activity
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$activity = $_POST['activity'];
$location = $_POST['location'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
try {
$stmt = $pdo->prepare("INSERT INTO activities (name, activity, location, start_date, end_date, status) VALUES (?, ?, ?, ?, ?, 'pending')");
$stmt->execute([$name, $activity, $location, $start_date, $end_date]);
echo "<script>alert('Activity successfully added!'); window.location.href='index.php';</script>";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
// Handle complete activity
if (isset($_GET['complete'])) {
$activity_id = $_GET['complete'];
try {
$stmt = $pdo->prepare("UPDATE activities SET status = 'completed', mark_as_completed = NOW() WHERE id = ?");
$stmt->execute([$activity_id]);
echo "<script>alert('Activity marked as completed!'); window.location.href='index.php';</script>";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
// Handle delete activity
if (isset($_GET['delete'])) {
$activity_id = $_GET['delete'];
try {
$stmt = $pdo->prepare("DELETE FROM activities WHERE id = ?");
$stmt->execute([$activity_id]);
echo "<script>alert('Activity deleted successfully!'); window.location.href='index.php';</script>";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
// ✅ Handle inserting new leave
if (isset($_POST['insert_leave'])) {
$complete_name = $_POST['complete_name'];
$date_of_leave = $_POST['date_of_leave'];
$type_of_leave = $_POST['type_of_leave'];
try {
$stmt = $pdo->prepare("INSERT INTO leave_schedule (complete_name, date_of_leave, type_of_leave) VALUES (?, ?, ?)");
$stmt->execute([$complete_name, $date_of_leave, $type_of_leave]);
echo "<script>alert('Leave successfully added!'); window.location.href='index.php';</script>";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
// Fetch data
try {
$stmt = $pdo->prepare("SELECT * FROM leave_schedule ORDER BY date_of_leave DESC");
$stmt->execute();
$leaveRecords = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
try {
$stmt = $pdo->prepare("SELECT * FROM activities WHERE status = 'pending' ORDER BY start_date DESC");
$stmt->execute();
$ongoingActivities = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
try {
$stmt2 = $pdo->prepare("SELECT * FROM activities WHERE status = 'completed' ORDER BY start_date DESC");
$stmt2->execute();
$completedActivities = $stmt2->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ICT Unit Monitoring</title>
<link rel="stylesheet" href="css/styles.css">
<style>
/* Your original styling (unchanged) */
.sidebar {
width: 200px;
height: 100vh;
background-color: maroon;
color: white;
padding: 20px;
position: fixed;
top: 0;
left: 0;
}
.sidebar h2, .sidebar a {
color: white;
text-align: center;
}
.main-content {
margin-left: 250px;
padding: 20px;
}
table, th, td {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 10px;
}
button {
background-color: maroon;
color: white;
padding: 8px 15px;
border: none;
}
.btn-complete { background-color: green; }
.btn-delete { background-color: red; }
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<img src="image/sdologo.png" alt="logo" style="width: 100%; max-width: 100px; margin: 20px auto; display: block;">
<h2>Dashboard</h2>
<ul>
<li><a href="#monthly-calendar">Monthly Calendar</a></li>
<li><a href="#insert-activity">Insert Activity</a></li>
<li><a href="#scheduled-activities">Scheduled Activities</a></li>
<li><a href="#completed-activities">Completed Activities</a></li>
<li><a href="#leave-schedule">Leave Schedule</a></li>
</ul>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Insert Activity -->
<div id="insert-activity">
<h2>Insert Activity</h2>
<form method="POST" onsubmit="return confirm('Add this activity?');">
<input type="text" name="name" placeholder="Name" required><br>
<input type="text" name="activity" placeholder="Activity" required><br>
<input type="text" name="location" placeholder="Location" required><br>
<input type="date" name="start_date" required><br>
<input type="date" name="end_date" required><br>
<button type="submit" name="submit">Add Activity</button>
</form>
</div>
<!-- Scheduled Activities -->
<div id="scheduled-activities" style="display:none;">
<h2>Scheduled Activities</h2>
<table>
<tr>
<th>Name</th><th>Activity</th><th>Location</th><th>Start</th><th>End</th><th>Actions</th>
</tr>
<?php foreach ($ongoingActivities as $a): ?>
<tr>
<td><?= htmlspecialchars($a['name']) ?></td>
<td><?= htmlspecialchars($a['activity']) ?></td>
<td><?= htmlspecialchars($a['location']) ?></td>
<td><?= htmlspecialchars($a['start_date']) ?></td>
<td><?= htmlspecialchars($a['end_date']) ?></td>
<td>
<form method="get" style="display:inline;">
<button class="btn-complete" name="complete" value="<?= $a['id'] ?>">Complete</button>
</form>
<form method="get" style="display:inline;" onsubmit="return confirm('Delete this?');">
<button class="btn-delete" name="delete" value="<?= $a['id'] ?>">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<!-- Completed Activities -->
<!-- Completed Activities -->
<div id="completed-activities" style="display:none;">
<h2>Completed Activities</h2>
<!-- Filter Form (Month & Year based on start/end date) -->
<form method="GET" action="#completed-activities" style="margin-bottom: 15px;">
<label for="filter_month">Month:</label>
<select name="filter_month" id="filter_month">
<option value="">All</option>
<?php for ($m = 1; $m <= 12; $m++):
$selected = (isset($_GET['filter_month']) && $_GET['filter_month'] == $m) ? 'selected' : '';
?>
<option value="<?= $m ?>" <?= $selected ?>><?= date('F', mktime(0, 0, 0, $m, 10)) ?></option>
<?php endfor; ?>
</select>
<label for="filter_year">Year:</label>
<select name="filter_year" id="filter_year">
<option value="">All</option>
<?php
$currentYear = date('Y');
for ($y = $currentYear; $y >= $currentYear - 5; $y--):
$selected = (isset($_GET['filter_year']) && $_GET['filter_year'] == $y) ? 'selected' : '';
?>
<option value="<?= $y ?>" <?= $selected ?>><?= $y ?></option>
<?php endfor; ?>
</select>
<button type="submit">Filter</button>
</form>
<!-- Filtered Table -->
<table>
<tr>
<th>Name</th><th>Activity</th><th>Location</th><th>Start</th><th>End</th><th>Completed</th>
</tr>
<?php
// Filter using start or end date based on selected month/year
$filteredCompleted = array_filter($completedActivities, function ($a) {
$filterMonth = $_GET['filter_month'] ?? '';
$filterYear = $_GET['filter_year'] ?? '';
$startDate = strtotime($a['start_date']);
$monthMatch = !$filterMonth || date('n', $startDate) == $filterMonth;
$yearMatch = !$filterYear || date('Y', $startDate) == $filterYear;
return $monthMatch && $yearMatch;
});
if (empty($filteredCompleted)) {
echo "<tr><td colspan='6'>No activities found for selected month/year.</td></tr>";
} else {
foreach ($filteredCompleted as $a):
?>
<tr>
<td><?= htmlspecialchars($a['name']) ?></td>
<td><?= htmlspecialchars($a['activity']) ?></td>
<td><?= htmlspecialchars($a['location']) ?></td>
<td><?= htmlspecialchars($a['start_date']) ?></td>
<td><?= htmlspecialchars($a['end_date']) ?></td>
<td><?= htmlspecialchars($a['mark_as_completed']) ?></td>
</tr>
<?php endforeach; } ?>
</table>
</div>
<!-- Preserve #completed-activities hash on filter -->
<script>
const filterForm = document.querySelector('#completed-activities form');
if (filterForm) {
filterForm.addEventListener('submit', function () {
setTimeout(() => {
window.location.hash = 'completed-activities';
}, 0);
});
}
</script>
<!-- Monthly Calendar -->
<div id="monthly-calendar" style="display:none;">
<h2>Monthly Calendar of Activities</h2>
<!-- Tabs Navigation -->
<div class="tab-container">
<button class="tab-button" onclick="openTab(event, 'ebora')">Dandy G. Ebora</button>
<button class="tab-button" onclick="openTab(event, 'ali')">Aldin Van T. Ali</button>
<button class="tab-button" onclick="openTab(event, 'macalalad')">Ralph Kevin G. Macalalad</button>
</div>
<!-- Tab Content -->
<div id="ebora" class="tab-content" style="display:none;">
<h3>Dandy G. Ebora</h3>
<iframe
src="https://calendar.google.com/calendar/embed?src=dandy.ebora%40deped.gov.ph&ctz=Asia%2FManila"
style="border: 0"
width="1500"
height="600"
frameborder="0"
scrolling="no">
</iframe>
</div>
<div id="ali" class="tab-content" style="display:none;">
<h3>Aldin Van T. Ali</h3>
<iframe
src="https://calendar.google.com/calendar/embed?src=aldinvan.ali%40deped.gov.ph&ctz=Asia%2FManila"
style="border: 0"
width="1500"
height="600"
frameborder="0"
scrolling="no">
</iframe>
</div>
<div id="macalalad" class="tab-content" style="display:none;">
<h3>Ralph Kevin G. Macalalad</h3>
<iframe
src="https://calendar.google.com/calendar/embed?src=ralphkevin.macalalad%40deped.gov.ph&ctz=Asia%2FManila"
style="border: 0"
width="1500"
height="600"
frameborder="0"
scrolling="no">
</iframe>
</div>
</div>
<!-- Tab Functionality Script -->
<script>
function openTab(evt, tabName) {
// Hide all tab contents
var tabContent = document.getElementsByClassName("tab-content");
for (var i = 0; i < tabContent.length; i++) {
tabContent[i].style.display = "none";
}
// Remove "active" class from all buttons
var tabButtons = document.getElementsByClassName("tab-button");
for (var i = 0; i < tabButtons.length; i++) {
tabButtons[i].classList.remove("active");
}
// Show the selected tab and add active class to the button
document.getElementById(tabName).style.display = "block";
evt.currentTarget.classList.add("active");
}
</script>
<!-- Optional CSS for styling -->
<style>
.tab-container {
margin-top: 20px;
}
.tab-button {
background-color: #1E90FF;
border: none;
padding: 10px 20px;
cursor: pointer;
margin-right: 5px;
}
.tab-button.active {
background-color: #ccc;
font-weight: bold;
}
.tab-content {
border: 1px solid #ccc;
padding: 15px;
margin-top: 10px;
background-color: #fff;
}
</style>
<!-- Leave Schedule -->
<div id="leave-schedule" style="display:none;">
<h2>Leave Schedule</h2>
<form method="POST">
<input type="text" name="complete_name" placeholder="Complete Name" required><br>
<input type="date" name="date_of_leave" required><br>
<select name="type_of_leave" required>
<option value="">Select Leave Type</option>
<option value="Sick Leave">Sick Leave</option>
<option value="Special Privileged Leave">Special Privileged Leave</option>
<option value="Force Leave">Force Leave</option>
</select><br>
<button type="submit" name="insert_leave">Insert Leave</button>
</form>
<h3>Leave Records</h3>
<table>
<tr><th>Name</th><th>Date of Leave</th><th>Type</th></tr>
<?php foreach ($leaveRecords as $record): ?>
<tr>
<td><?= htmlspecialchars($record['complete_name']) ?></td>
<td><?= htmlspecialchars($record['date_of_leave']) ?></td>
<td><?= htmlspecialchars($record['type_of_leave']) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<!-- JavaScript Navigation -->
<script>
const links = document.querySelectorAll('.sidebar a');
const sections = document.querySelectorAll('.main-content > div');
links.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
sections.forEach(section => section.style.display = 'none');
const target = document.querySelector(link.getAttribute('href'));
if (target) target.style.display = 'block';
links.forEach(l => l.classList.remove('active'));
this.classList.add('active');
});
});
// Show section based on current hash or default to the first
window.addEventListener('DOMContentLoaded', () => {
const hash = window.location.hash;
const targetSection = hash ? document.querySelector(hash) : null;
// Hide all sections first
document.querySelectorAll('.main-content > div').forEach(section => {
section.style.display = 'none';
});
// Show the matching section or default to the first
if (targetSection) {
targetSection.style.display = 'block';
} else {
const firstSection = document.querySelector('.main-content > div');
if (firstSection) firstSection.style.display = 'block';
}
// Set sidebar link active state
const links = document.querySelectorAll('.sidebar a');
links.forEach(link => {
link.classList.remove('active');
if (hash && link.getAttribute('href') === hash) {
link.classList.add('active');
}
});
});
</script>
</body>
</html>