Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Last active January 22, 2020 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorotkiewicz/7ef893c86c464d614c331595ee03d5d0 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/7ef893c86c464d614c331595ee03d5d0 to your computer and use it in GitHub Desktop.
Abfallentsorgungsplan grafischer Kalender Generator in PHP

Abfallentsorgungsplan grafischer Kalender Generator in PHP

Ein einfaches und sehr bequemes Skript, um einen fertigen grafischer Kalender mit Abfallentsorgungsplan zu generieren und ausdrucken.

Jedes Jahr habe ich immer einen solchen Plan erstellt, was ziemlich eintönig und zeitraubend ist. Deshalb habe ich dieses Skript erstellt.

Einfach alle Termine eingeben im Format: TT.MM TT.MM usw.

$dates = array(
    'papier' => '27.01 24.02 23.03',                   // Papierabfuhr
    'dsd'    => '28.01 25.02 24.03 21.04',             // Gelber Sack
    'rest'   => '14.01 28.01 11.02 25.02 10.03',       // Restmüll
    'bio'    => '13.01 27.01 10.02 24.02 09.03 23.03 ' // Biotonne
);

Das Skript erfordert http- und php(-fpm) Server.

<link rel="stylesheet" type="text/css" href="styles.css"><?php
$name = array('Papierabfuhr', 'Gelber Sack', 'Restmüll', 'Biotonne');
$monthsName = array( '','Januar','Februar','März', 'April','Mai','Juni', 'Juli','August','September', 'Oktober','November','Dezember');
$dates = array(
'papier' => '27.01 24.02 23.03 20.04 18.05 15.06 13.07 10.08 07.09 05.10 02.11 30.11 28.12',
'dsd' => '28.01 25.02 24.03 21.04 19.05 16.06 14.07 11.08 08.09 06.10 03.11 01.12 29.12',
'rest' => '14.01 28.01 11.02 25.02 10.03 24.03 06.04 21.04 05.05 19.05 03.06 16.06 30.06 14.07 28.07 10.08 25.08 08.09 22.09 06.10 20.10 03.11 17.11 01.12 15.12 29.12',
'bio' => '13.01 27.01 10.02 24.02 09.03 23.03 04.04 20.04 04.05 18.05 02.06 15.06 29.06 13.07 27.07 10.08 24.08 07.09 21.09 05.10 19.10 02.11 16.11 30.11 14.12 28.12'
);
function expl($list) {
return explode(" ", $list);
}
$calendar = array();
$cal0 = array(); // papier
$cal1 = array(); // dsd
$cal2 = array(); // rest
$cal3 = array(); // bio
function generate($material, $typ) {
$cal = array();
foreach ( expl($material) as $a) {
$s = explode(".", $a);
$d = $s[0]; // day
$m = '_' . $s[1]; // month
$cal [$m] [ $typ ] [] = $d;
}
return $cal;
}
$cal0 = generate ($dates['papier'], $name[0]);
$cal1 = generate ($dates['dsd'], $name[1]);
$cal2 = generate ($dates['rest'], $name[2]);
$cal3 = generate ($dates['bio'], $name[3]);
$calendar = array_merge_recursive($cal0, $cal1, $cal2, $cal3);
//print_r( $calendar );
echo '<div class="calendar">';
echo '<h1 style="text-align: center;">Abfallentsorgungsplan für <span style="font-size: 36px;">2020</span></h1>';
foreach ($calendar as $key => $values) {
$monthNum = (int)str_replace('_', '', $key);
$monthName = $monthsName[$monthNum];
$sort = array();
echo '<div class="events">';
echo '<div class="month">' . $monthName . '</div>';
for ($i=0; $i <= 3; $i++) {
foreach ($values[ $name[$i] ] as $v) {
$sort[+$v][] = $name[$i];
}
}
ksort($sort);
foreach ($sort as $k => $d) {
foreach ($d as $c) {
echo '<p><strong>' . $k . '</strong><span>' . $c . "<span></p>";
}
}
echo '</div>';
}
echo '</div>';
?>
body {
width: 1000px;
-webkit-transform: scale(0.99);
-moz-transform: scale(0.99);
}
.calendar {
position: absolute;
left: 0;
top: 0;
}
.events {
width: 200px;
height: 400px;
border: 2px solid #ccc;
margin: 5px;
padding: 5px;
background-color: #bbb;
float: left;
font-size: 18px;
}
.month {
font-size: 22px;
color: #fff;
padding: 10px;
background-color: #333;
margin-bottom: 10px;
}
strong {
font-size: 20px;
margin-right: 5px;
}
p {
padding: 14px;
margin-bottom: -10px;
margin-top: -10px;
background-color: #ddd;
}
p:nth-child(odd) {
background-color: #ccc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment