Guten Abend,
noch schnell vor den Ferien ein Script zum visualisieren der Stundenpläne der Kinder. Kann man bestimmt auch für andere Sachen missbraucen :eek:
WICHTIG: Folgende Schritte unbedingt vor dem ersten Start des Scriptes ausführen:
[ul]
[li]Script igendwo anlegen
[/li][li]Script öffnen und Arrays an eigene Situation anpassen
[/li][li]Im Array childs die Kinder fortlaufend hinterlegen
[/li][li]Die Schulfächer im Array subjects anpassen/erweitern
[/li][li]Das Array persons entsprechend dem Array childs anpassen und die richtigen Zeiten hinterlegen
[/li][li]Einmal das Script in der Konsole starten
[/li][li]Dannach die Variablen im Webfront verlinken (siehe Bilder)
[/li][li]Button Speichern schreibt das gewählte Fach in die gewählte Zelle
[/li][li]Button Update erzeugt nach getaner Arbeit den „schönen“ Stundenplan
[/li][/ul]
VORSICHT: ein wiederholtes Ausführen des Scripts auf der Konsole löscht alle bisher konfigurierten Daten!!!
Und hier das Script:
<?php
################################################################################
# Script: Other.Timetable.ips.php
# Version: 1.0.20180402
# Author: Heiko Wilknitz (@pitti)
#
# Anlegen und Verwalten von Stundenplänen
#
# ------------------------------ Profile ---------------------------------------
#
# Kinder, muss in Reihenfolge und Anzahl mit dem "persons"-Array übereinstimmen
#
$childs =array(
array(0, 'Kind1', '', 0x800080),
array(1, 'Kind2', '', 0x00FFFF)
);
#
# Tage, die der Stundenplan abbilden soll (5 ist Standard)
#
$cols = array(
array(5, 'Mo - Fr', '', 0x80FF80),
array(6, 'Mo - Fr, Sa', '', 0xFFFF80),
array(7, 'Mo - Fr, Sa, So', '', 0xFF8080)
);
#
# Schultag
#
$days = array(
array(0, 'Montag', '', 0x80FF80),
array(1, 'Dienstag', '', 0x80FF80),
array(2, 'Mittwoch', '', 0x80FF80),
array(3, 'Donnerstag', '', 0x80FF80),
array(4, 'Freitag', '', 0x80FF80),
array(5, 'Samstag', '', 0xFFFF80),
array(6, 'Sonntag', '', 0xFF8080)
);
#
# Fächer
#
$subjects = array(
array(0, 'Chemie', '', -1),
array(1, 'Deutsch', '', -1),
array(2, 'Engl.-Conv.', '', -1),
array(3, 'Englisch', '', -1),
array(4, 'Ethik', '', -1),
array(5, 'Geschichte', '', -1),
array(6, 'Informatik', '', -1),
array(7, 'Kunst', '', -1),
array(8, 'Mathematik', '', -1),
array(9, 'Physik', '', -1),
array(10,'P-Seminar', '', -1),
array(11, 'Sozialkunde', '', -1),
array(12, 'Sport', '', -1),
array(13, 'Technologie', '', -1),
array(14, 'Wirt.-Englisch', '', -1),
array(15, 'Wirtschaft', '', -1),
array(16, 'W-Seminar', '', -1)
);
#
# Speichern
#
$save = array(
array(0, '>', '', -1),
array(1, 'Speichern', '', 0xFF8000)
);
#
# Generieren
#
$write = array(
array(0, '>', '', -1),
array(1, 'Update', '', 0x008000)
);
#
# ----------------------------- Konfiguration ----------------------------------
#
# Namen der Kinder und Schulzeiten, kann pro Kind unterschiedlich sein
#
$persons = array (
"Kind1" => array (
1 => "08:00 - 08:45",
2 => "08:45 - 09:30",
3 => "09:45 - 10:30",
4 => "10:30 - 11:15",
5 => "11:30 - 12:15",
6 => "12:15 - 13:00",
7 => "13:00 - 13:45",
8 => "13:45 - 14:30",
9 => "14:30 - 15:15",
10 => "15:15 - 16:00"),
"Kind2" => array (
1 => "08:15 - 09:00",
2 => "08:00 - 09:45",
3 => "10:00 - 10:45",
4 => "10:45 - 11:30",
5 => "11:45 - 12:25",
6 => "12:25 - 13:10",
7 => "13:10 - 13:55",
8 => "13:55 - 14:40",
9 => "14:40 - 15:25",
10 => "15:30 - 16:15"),
);
#
# Benennung der Spalten
#
$header = array (
"Zeit",
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag",
"Sonntag"
);
#
################################################################################
// INSTALLATION
if ($_IPS['SENDER']=='Execute') {
$pos = -1;
// Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
SetValue($did, InitData($persons, $header));
IPS_SetPosition($did, $pos++);
// Kinder
$vid = CreateVariableByName($_IPS['SELF'], "Kinder", 1);
CreateProfileInteger('Timetable.Childs', 'Robot', '', '', 0, 0, 0, 0, $childs);
IPS_SetVariableCustomProfile($vid, 'Timetable.Childs');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Spalten
$vid = CreateVariableByName($_IPS['SELF'], "Spalten", 1);
CreateProfileInteger('Timetable.Cols', 'Distance', '', '', 0, 0, 0, 0, $cols);
IPS_SetVariableCustomProfile($vid, 'Timetable.Cols');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 5);
// Zeilen
$vid = CreateVariableByName($_IPS['SELF'], "Stunden", 1);
CreateProfileInteger('Timetable.Rows', 'Database', '', '', 1, 10, 1, 0);
IPS_SetVariableCustomProfile($vid, 'Timetable.Rows');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 10);
// Tag
$vid = CreateVariableByName($_IPS['SELF'], "Tag", 1);
CreateProfileInteger('Timetable.Days', 'Calendar', '', '', 0, 0, 0, 0, $days);
IPS_SetVariableCustomProfile($vid, 'Timetable.Days');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Stunde
$vid = CreateVariableByName($_IPS['SELF'], "Stunde", 1);
CreateProfileInteger('Timetable.Lesson', 'Clock', '', '. Stunde', 1, 10, 1, 0);
IPS_SetVariableCustomProfile($vid, 'Timetable.Lesson');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 1);
// Fach
$vid = CreateVariableByName($_IPS['SELF'], "Fach", 1);
CreateProfileInteger('Timetable.Subjects', 'ErlenmeyerFlask', '', '', 0, 0, 0, 0, $subjects);
IPS_SetVariableCustomProfile($vid, 'Timetable.Subjects');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Speichern
$vid = CreateVariableByName($_IPS['SELF'], "Speichern", 1);
CreateProfileInteger('Timetable.Save', 'Repeat', '', '', 0, 0, 0, 0, $save);
IPS_SetVariableCustomProfile($vid, 'Timetable.Save');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// Vorschau
$vid = CreateVariableByName($_IPS['SELF'], "Vorschau", 3);
IPS_SetVariableCustomProfile($vid, '~HTMLBox');
IPS_SetIcon($vid, "Edit");
IPS_SetPosition($vid, $pos++);
$json = json_decode(GetValue($did), true);
SetValue($vid, GeneratePreview(key($persons), $json));
// Update Table
$vid = CreateVariableByName($_IPS['SELF'], "Update", 1);
CreateProfileInteger('Timetable.Update', 'Script', '', '', 0, 0, 0, 0, $write);
IPS_SetVariableCustomProfile($vid, 'Timetable.Update');
IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
IPS_SetPosition($vid, $pos++);
SetValue($vid, 0);
// HTML Stundenpläne für Kinder
foreach($persons as $key => $value) {
$vid = CreateVariableByName($_IPS['SELF'], "Stundenplan ".$key, 3);
IPS_SetVariableCustomProfile($vid, '~HTMLBox');
IPS_SetIcon($vid, "Robot");
IPS_SetPosition($vid, $pos++);
}
}
// AKTION VIA WEBFRONT
else if($_IPS['SENDER'] == "WebFront") {
// Speichern
SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
$name = IPS_GetName($_IPS['VARIABLE']);
// viel zu tun
switch ($name) {
case 'Kinder':
// Kind
$cid = GetValueFormatted($_IPS['VARIABLE']);
// Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
$dat = GetValue($did);
$json = json_decode($dat, true);
$col = $json[$cid]['days'];
$row = $json[$cid]['lessons'];
// Spalten korrekt setzen
$vid = CreateVariableByName($_IPS['SELF'], "Spalten", 1);
SetValue($vid, $col);
// Stunden korrekt setzen
$vid = CreateVariableByName($_IPS['SELF'], "Stunden", 1);
SetValue($vid, $row);
// Tag zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Tag", 1);
SetValue($vid, 0);
// Stunde zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Stunde", 1);
SetValue($vid, 1);
// Preview neu rendern
$vid = CreateVariableByName($_IPS['SELF'], "Vorschau", 3);
SetValue($vid, GeneratePreview($cid, $json));
break;
case 'Spalten':
// Kind
$vid = CreateVariableByName($_IPS['SELF'], "Kinder", 1);
$cid = GetValueFormatted($vid);
// Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
$dat = GetValue($did);
$json = json_decode($dat, true);
$json[$cid]['days'] = $_IPS['VALUE'];
SetValue($did, json_encode($json));
// Tag zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Tag", 1);
SetValue($vid, 0);
// Stunde zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Stunde", 1);
SetValue($vid, 1);
// Preview neu rendern
$vid = CreateVariableByName($_IPS['SELF'], "Vorschau", 3);
SetValue($vid, GeneratePreview($cid, $json));
break;
case 'Stunden':
// Kind
$vid = CreateVariableByName($_IPS['SELF'], "Kinder", 1);
$cid = GetValueFormatted($vid);
// Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
$dat = GetValue($did);
$json = json_decode($dat, true);
$json[$cid]['lessons'] = $_IPS['VALUE'];
SetValue($did, json_encode($json));
// Tag zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Tag", 1);
SetValue($vid, 0);
// Stunde zurücksetzen
$vid = CreateVariableByName($_IPS['SELF'], "Stunde", 1);
SetValue($vid, 1);
// Preview neu rendern
$vid = CreateVariableByName($_IPS['SELF'], "Vorschau", 3);
SetValue($vid, GeneratePreview($cid, $json));
break;
case 'Tag':
// Check ob Tag erlaubt
$vid = CreateVariableByName($_IPS['SELF'], "Spalten", 1);
$col = GetValue($vid);
if($_IPS['VALUE'] >= $col) {
SetValue($_IPS['VARIABLE'],$col-1);
}
break;
case 'Stunde':
// Check ob Stunde erlaubt
$vid = CreateVariableByName($_IPS['SELF'], "Stunden", 1);
$hours = GetValue($vid);
if($_IPS['VALUE'] > $hours) {
SetValue($_IPS['VARIABLE'],$hours);
}
break;
case 'Fach':
// nix zu tun
break;
case 'Speichern':
// Kind,Spalte, Zeile, Fach & Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
$dat = GetValue($did);
$vid = CreateVariableByName($_IPS['SELF'], "Kinder", 1);
$cid = GetValueFormatted($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Tag", 1);
$col = GetValue($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Stunde", 1);
$row = GetValue($vid);
$vid = CreateVariableByName($_IPS['SELF'], "Fach", 1);
$sub = GetValueFormatted($vid);
// Fach Speichern
$json = json_decode($dat, true);
$lesson = sprintf('%02d.', $row);
$json[$cid][$lesson][$col+1] = $sub;
SetValue($did, json_encode($json));
// Preview neu rendern
$vid = CreateVariableByName($_IPS['SELF'], "Vorschau", 3);
SetValue($vid, GeneratePreview($cid, $json));
// Speichern Button zurückstellen
SetValue($_IPS['VARIABLE'], 0);
break;
case 'Update':
// Kind & Daten
$did = CreateVariableByName($_IPS['SELF'], "Daten", 3);
$dat = GetValue($did);
$vid = CreateVariableByName($_IPS['SELF'], "Kinder", 1);
$cid = GetValueFormatted($vid);
// Json
$json = json_decode($dat, true);
// HTML neu rendern
$vid = CreateVariableByName($_IPS['SELF'], "Stundenplan ".$cid, 3);
SetValue($vid, GenerateTimetable($cid, $json));
// Update Button zurückstellen
SetValue($_IPS['VARIABLE'], 0);
break;
}
}
# ------------------------------ Funktionen ------------------------------------
// Erzeugt initial die Json Struktur
function InitData($persons, $header)
{
$json = array();
foreach ($persons as $key => $value) {
$json[$key]['days'] = 5;
$json[$key]['lessons'] = 10;
$json[$key]['header'] = $header;
for($l = 1; $l <= count($value); $l++) {
$lesson = sprintf('%02d.', $l);
$json[$key][$lesson] = array($value[$l], '', '', '', '', '', '', '');
}
}
// var_dump($json);
return json_encode($json);
}
// Erzeugt aus den JSON Daten eine "unformatierte " HTML Tabelle
function GeneratePreview($person, $json)
{
$arr = $json[$person];
$html = '<style>table{width:100%;border: 1px solid rgba(255, 255, 255, 0.2);border-collapse:collapse;} th,td{border:1px solid rgba(255, 255, 255, 0.2); text-align:center;}</style>';
$html = $html.'<table>';
$html = $html.'<tr>';
for ($h = 0; $h <= $arr['days']; $h++) {
$html = $html.'<th>'.$arr['header'][$h].'</th>';
}
$html = $html.'</tr>';
for ($z = 1; $z <= $arr['lessons']; $z++) {
$lesson = sprintf('%02d.', $z);
$html = $html.'<tr>';
for ($s = 0; $s <= $arr['days']; $s++) {
if($s == 0) {
$html = $html.'<td>'.$lesson.' Stunde ('.$arr[$lesson][$s].')</td>';
}
else {
$html = $html.'<td>'.$arr[$lesson][$s].'</td>';
}
}
$html = $html.'</tr>';
}
$html = $html.'</table>';
return $html;
}
// Erzeugt aus den JSON Daten eine HTML Tabelle
function GenerateTimetable($person, $json)
{
// Kind wählen
$arr = $json[$person];
// styles definieren
$style = "";
$style = $style.'<style type="text/css">';
$style = $style.'table {border-collapse: collapse; font-size: 14px; width: 100%; }';
$style = $style.'td.fst {vertical-align: middle; text-align: center; width: 120px; padding: 5px; border-left: 1px solid rgba(255, 255, 255, 0.2); border-right: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'td.mid {vertical-align: middle; text-align: center; line-height: 20px; padding: 5px; border-right: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'td.lst {vertical-align: middle; text-align: center; line-height: 20px; padding: 5px; border-right: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
$style = $style.'tr:last-child {border-bottom: 1px solid rgba(255, 255, 255, 0.2); }';
$style = $style.'tr:nth-child(even) { background-color: rgba(0, 0, 0, 0.2); }';
$style = $style.'.th { color: rgb(255, 255, 255); background-color: rgb(0, 160, 255); font-weight:bold; background-image: linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -o-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -moz-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -webkit-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -ms-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); }';
$style = $style.'.num { font-size: 32px; font-weight:bold; color: rgb(0,160,255); float:left; }';
$style = $style.'.ttt { font-size: 11px; width:30px; float:right;}';
$style = $style.'.les { font-size: 1.5em; }';
$style = $style.'</style>';
// html table erzeugen
$html = $style;
$html = $html.'<table>';
$html = $html.'<tr>';
// table head
for ($h = 0; $h <= $arr['days']; $h++) {
// first
if ($h == 0) {
$html = $html.'<td class="fst th">'.$arr['header'][$h].'</td>';
}
// middle
else if ($h < $arr['days']) {
$html = $html.'<td class="mid th">'.$arr['header'][$h].'</td>';
}
// last
else {
$html = $html.'<td class="lst th">'.$arr['header'][$h].'</td>';
}
}
$html = $html.'</tr>';
// table rows
for ($z = 1; $z <= $arr['lessons']; $z++) {
$lesson = sprintf('%02d.', $z);
$html = $html.'<tr>';
for ($s = 0; $s <= $arr['days']; $s++) {
// first
if($s == 0) {
$col ='<div class="num">'.$lesson.'</div><div class="ttt">'.$arr[$lesson][$s].'</div>';
$html = $html.'<td class="fst">'.$col.'</td>';
}
// middle
else if ($s < $arr['days']) {
$html = $html.'<td class="mid les">'.$arr[$lesson][$s].'</td>';
}
// last
else {
$html = $html.'<td class="lst les">'.$arr[$lesson][$s].'</td>';
}
}
$html = $html.'</tr>';
}
$html = $html.'</table>';
return $html;
}
// Erzeugt eine Variable unterhalb {id} mit dem Namen {name} vom Typ [type}
// Existiert die Variable schon wird diese zurückgeliefert.
// Types: 0 = Boolean, 1 = Integer, 2 = Float, 3 = String
function CreateVariableByName($id, $name, $type)
{
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid===false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
}
return $vid;
}
// Erzeugt ein Variablenprofil vom Typ {type} mit Name n{name}
function CreateProfile($name, $type)
{
if(!IPS_VariableProfileExists($name)) {
IPS_CreateVariableProfile($name, $type);
}
else {
$profile = IPS_GetVariableProfile($name);
if($profile['ProfileType'] != $type)
throw new Exception("Variable profile type does not match for profile ".$name);
}
}
// Erzeugt ein Integer-Variablenprofil
function CreateProfileInteger($name, $icon, $prefix, $suffix, $minvalue, $maxvalue, $step, $digits, $asso = NULL)
{
CreateProfile($name, 1);
IPS_SetVariableProfileIcon($name, $icon);
IPS_SetVariableProfileText($name, $prefix, $suffix);
IPS_SetVariableProfileDigits($name, $digits);
if(sizeof($asso) !== 0){
$minvalue = 0;
$maxvalue = 0;
}
IPS_SetVariableProfileValues($name, $minvalue, $maxvalue, $step);
if(sizeof($asso) !== 0){
foreach($asso as $ass) {
IPS_SetVariableProfileAssociation($name, $ass[0], $ass[1], $ass[2], $ass[3]);
}
}
}
?>
Viel Spaß beim Klicken
Ciao Pitti