Lekcja 5, planer

This commit is contained in:
Adam Łukasik committed 2026-11-02 12:42:33 +01:00
1 parent ff62de50d2
commit b83f3cba5f
7 files changed
+285

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
<?php
$user = 'root';
$pass = 'ServBay.dev';
date_default_timezone_set('Europe/Warsaw');
setlocale(LC_TIME, 'pl_PL.UTF-8');
$CALENDAR = CAL_GREGORIAN;
$weekday_letters = array();
for($i = 5; $i < 12; $i++) {
$weekday_letters[] = mb_strtoupper(mb_substr(strftime('%a', mktime(0, 0, 0, 1, $i, 2026)), 0, 1));
}
$month_names = array();
for($i = 1; $i <= 12; $i++) {
$month_names[] = strftime('%b', mktime(0, 0, 0, $i, 1, 2026));
}
?>
View File
Whitespace-only changes.
+40
View File
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Planer</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
if(!isset($_GET['date'])) {
header("Location: ./");
exit();
}
$date = $_GET['date'];
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
?>
<div class="container">
<form action="update.php" method="post">
<p>Na <?=$date?> zaplanowałem:</p>
<br>
<textarea name="plans" id="plans">
</textarea>
<br>
<button onclick="event.preventDefault(); window.location='./?year=<?=$year?>&month=<?=$month?>';">Anuluj</button>
<button formaction="delete.php">Skasuj</button>
<input type="submit" value="OK">
</form>
</div>
</body>
</html>
+128
View File
@@ -0,0 +1,128 @@
<?php include('config.php'); ?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Planer</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
$year = Date('Y');
if(isset($_GET['year'])) { $year = intval($_GET['year']); }
if ($year < 1) { $year = 1; }
$month = Date('m');
if(isset($_GET['month'])) { $month = intval($_GET['month']); }
if($month < 1) { $month = 1; }
if($month > 12) { $month = 12; }
?>
<div class="container">
<form method="get">
<select id="select_miesiac" name="month">
<?php
for($i = 0; $i < 12; $i++) {
if($i + 1 == $month) {
echo '<option value="' . $i+1 . '" selected>' . $month_names[$i] . '</option>';
} else {
echo '<option value="' . $i+1 . '">' . $month_names[$i] . '</option>';
}
}
?>
</select>
<select id="select_rok" name="year">
<?php
for($i = 2020; $i < 2030; $i++) {
if($i == $year) {
echo '<option selected>' . $i . '</option>';
} else {
echo '<option>' . $i . '</option>';
}
}
?>
</select>
<button>ok</button>
</form>
<?php
$day_table_offset = strftime('%w', mktime(0, 0, 0, $month, 1, $year)) + 6;
if($day_table_offset >= 7) { $day_table_offset -= 7; }
$day_table = [];
$ptr = 1 - $day_table_offset;
while($ptr <= cal_days_in_month($CALENDAR, $month, $year)) {
if($ptr < 1) {
$day_table[] = '';
} else {
$day_table[] = strftime('%Y-%m-%d', mktime(0, 0, 0, $month, $ptr, $year));
}
$ptr++;
}
?>
<table>
<tr>
<?php
for($i = 0; $i < 7; $i++) {
if($i > 4) {
echo "<th class='holiday'>" . $weekday_letters[$i] . "</th>";
} else {
echo "<th>" . $weekday_letters[$i] . "</th>";
}
}
?>
</tr>
</tr>
<?php
$idx = 0;
while($idx < count($day_table)) {
if($day_table[$idx] != '') {
if($idx % 7 == 5 || $idx % 7 == 6) {
if(mb_substr($day_table[$idx], 8, 1) == '0') {
echo '<td class="holiday" data-date="' . $day_table[$idx] . '">' . mb_substr($day_table[$idx], 9, 2) . '</td>';
} else {
echo '<td class="holiday" data-date="' . $day_table[$idx] . '">' . mb_substr($day_table[$idx], 8, 2) . '</td>';
}
} else {
if(mb_substr($day_table[$idx], 8, 1) == '0') {
echo '<td data-date="' . $day_table[$idx] . '">' . mb_substr($day_table[$idx], 9, 2) . '</td>';
} else {
echo '<td data-date="' . $day_table[$idx] . '">' . mb_substr($day_table[$idx], 8, 2) . '</td>';
}
}
} else {
echo '<th></th>';
}
if(++$idx % 7 == 0) {
echo '</tr><tr>';
}
}
while($idx % 7 != 0) {
echo '<th></th>';
$idx++;
}
?>
</tr>
</table>
<br>
<p>Nie masz planów na dziś</p>
</div>
<script>
function edit() {
window.location = `edit.php?date=${this.dataset.date}`;
}
const kafelki = document.querySelectorAll("td");
for(let i = 0; i < kafelki.length; i++) {
kafelki[i].onclick = edit;
}
</script>
</body>
</html>
+48
View File
@@ -0,0 +1,48 @@
-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Lis 02, 2026 at 11:41 AM
-- Wersja serwera: 12.0.2-MariaDB-log
-- Wersja PHP: 8.3.25
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+01:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `planner_al`
--
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `wydarzenia`
--
CREATE TABLE `wydarzenia` (
`date` date NOT NULL,
`value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
-- Indeksy dla zrzutów tabel
--
--
-- Indeksy dla tabeli `wydarzenia`
--
ALTER TABLE `wydarzenia`
ADD PRIMARY KEY (`date`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+51
View File
@@ -0,0 +1,51 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: fit-content;
margin: 3rem auto;
text-align: center;
}
select {
margin: .5rem;
}
button {
margin: .5rem;
}
table {
border-collapse: collapse;
margin: .5rem;
user-select: none;
}
th {
border: 1px solid black;
width: 2rem;
height: 2rem;
}
td {
border: 1px solid black;
width: 2rem;
height: 2rem;
cursor: pointer;
}
td:hover {
background-color: lightyellow;
}
.holiday {
color: red;
}
textarea {
width: 36rem;
height: 16rem;
}
View File
Whitespace-only changes.