Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Skripte zur automatischen Generierung der Daten #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@

Website for https://chaostreff-nuernberg.de


## Skriptaufbau

### appointments.inc.php

Das Skript setzt die Daten (erster Donnerstag bzw. dritter Dienstag) pro Monat, ausser es steht in der Datei `appointments.csv` ein anderes Datum.

### appointments.csv

| location | year-month | appointment |
| --- | --- | --- |
| lab | 2019-06 | 11.06.2019 |
| k4cg | 2020-01 | 09.01.2020 |

#### location

Muss entweder `lab` oder `k4cg` sein. Alle anderen Werte werden ignoriert -> die Zeile nicht beachtet

#### year-month

Das Jahr und Monat wo der Treff an einem anderen Tag stattfinden wird.

#### appointment

Das Datum das auf der Webseite statt des Regeltermins angezeigt werden soll.
7 changes: 7 additions & 0 deletions appointment.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

<tr>
<td>{{date}}</td>
<td>{{location}}</td>
<td>19:30 - 22:00</td>
</tr>

3 changes: 3 additions & 0 deletions appointments.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location,year-month,appointment
lab,2019-06,11.06.2019
k4cg,2020-01,09.01.2020
93 changes: 93 additions & 0 deletions appointments.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
$numberOfAppointments = 6;
$customAppointmentsFile = getcwd() .'/appointments.csv';
$appointmentTemplateFile = getcwd() .'/appointment.tpl';

$k4cgArr = Array();
$labArr = Array();

$year = date('Y');
$month = date('m');

$customAppointmentsK4cgArr = Array();
$customAppointmentsLabArr = Array();

$row = 1;
if(file_exists($customAppointmentsFile)) {
if (($handle = fopen($customAppointmentsFile, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {
$row++;

if($row>1) { //ignore header line
switch($data[0]) {
case 'k4cg':
$customAppointmentsK4cgArr[$data[1]] = $data[2];
break;
case 'lab':
$customAppointmentsLabArr[$data[1]] = $data[2];
break;
default:
break;
}
}
}
fclose($handle);
} else {
echo "error";
}
} else {
echo 'file not found';
}

while(count($k4cgArr)<$numberOfAppointments && count($labArr)<$numberOfAppointments) {
$yearMonth = "$year-$month";

if(count($k4cgArr)<$numberOfAppointments) {
$k4cgAppointment = strtotime("first thursday of $yearMonth");

if($k4cgAppointment>strtotime('today')) {
if(array_key_exists($yearMonth, $customAppointmentsK4cgArr)) {
$k4cgArr[] = $customAppointmentsK4cgArr[$yearMonth];
} else {
$k4cgArr[] = date('d.m.Y', $k4cgAppointment);
}
}
}

if(count($labArr)<$numberOfAppointments) {
$labAppointment = strtotime("third tuesday of $yearMonth");

if($k4cgAppointment>strtotime('today')) {
if(array_key_exists($yearMonth, $customAppointmentsLabArr)) {
$labArr[] = $customAppointmentsLabArr[$yearMonth];
} else {
$labArr[] = date('d.m.Y', $labAppointment);
}
}
}

$year = date('Y', strtotime('+1 month', strtotime($yearMonth)));
$month = date('m', strtotime('+1 month', strtotime($yearMonth)));
}

$k4cgArr = array_reverse($k4cgArr);
$labArr = array_reverse($labArr);

$template = file_get_contents($appointmentTemplateFile);

$output = '';
for($i=0;$i<$numberOfAppointments;$i++) {
$tmp = $template;
$tmp = str_replace('{{date}}', array_pop($k4cgArr), $tmp);
$tmp = str_replace('{{location}}', 'K4CG', $tmp);
$output .= $tmp;

$tmp = $template;
$tmp = str_replace('{{date}}', array_pop($labArr), $tmp);
$tmp = str_replace('{{location}}', 'Fablab Region Nürnberg', $tmp);
$output .= $tmp;
}
echo $output;

?>

125 changes: 0 additions & 125 deletions index.html

This file was deleted.

78 changes: 78 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!doctype html>
<html lang="de">

<head>
<title>Chaostreff Nürnberg</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="images/icons/favicon.ico" />

<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body>
<div class="container">

<div class="row justify-content-center container-head">
<div class="col-md-12">
<h1 class="display-4 text-center">Chaostreff Nürnberg</h1>
</div>
</div>

<div class="row justify-content-center">
<div class="col-md-9">
<p>
Der Chaostreff Nürnberg trifft sich abwechselnd im <a href="https://fablab-nuernberg.de/">Fablab
Region Nürnberg</a> und in der <a href="https://k4cg.org">K4CG</a>. Anfahrt, etc. bitte der jeweiligen Homepage entnehmen.
</p>
<p>
<ul>
<li><b>K4CG</b>: jeden ersten Donnerstag im Monat um 19:30 Uhr</li>
<li><b>Fablab Region Nürnberg</b>: jeden dritten Dienstag im Monat um 19:30 Uhr</li>
</ul>
</p>
<p>
Wir reden über internationale Netzwerke – Kommunikationsrecht – Datenrecht (Wem gehören meine Daten?) – Copyright – Informations- u. Lernsysteme – Datenbanken – Encryption – Komputerspiele – Programmiersprachen – processcontrol – Hardware – und was auch
immer. (Quelle: <a href="https://events.ccc.de/2017/11/23/34c3-tuwat/">tuwat.txt</a>)
</p>
</div>
</div>

<div class="row justify-content-center">
<div class="col-md-9">
<table class="table table-striped table-dark date-table">
<thead>
<tr>
<th scope="col">Datum</th>
<th scope="col">Ort</th>
<th scope="col">Zeit</th>
</tr>
</thead>
<tbody>
<?php include('appointments.inc.php'); ?>
</tbody>
</table>
</div>
</div>

<div class="row justify-content-center">
<div class="col-md-9">
<p>
Kontakt zur Chaostreff Nürnberg Orga:
</p>
<p>
IRC: hackint, <a href="https://webirc.hackint.org/#chaosnuernberg">#chaosnuernberg</a>
</p>
<p>
All creatures welcome!
</p>
</div>
</div>

</div>
</body>

</html>