diff --git a/fhem/FHEM/98_DSBMobile.pm b/fhem/FHEM/98_DSBMobile.pm index 5b8531fe7..a6e3acfd4 100644 --- a/fhem/FHEM/98_DSBMobile.pm +++ b/fhem/FHEM/98_DSBMobile.pm @@ -635,6 +635,106 @@ sub DSBMobile_simpleHTML($;$) { $ret .= ""; return $ret; +} +################################### +sub DSBMobile_tableHTML($;$) { + my ( $name, $infoDay ) = @_; + my $dat = ReadingsVal( $name, ".lastResult", "" ); + my $idat = ReadingsVal( $name, ".lastIResult", "" ); + my @cn = split( ",", ReadingsVal( $name, "columnNames", "" ) ); + my $classr = ReadingsVal( $name, "dsb_classReading", "Klasse_n_" ); + my $ret = ""; + + $dat = decode_json($dat); + $idat = decode_json($idat); + + my @data = @$dat; + my @idata = @$idat; + return "no data found" if ( @data == 0 && ( @idata == 0 || !$infoDay ) ); + + if ( @data > 0 ) { + @data = sort { $a->{sdate} cmp $b->{sdate} or $a->{$classr} cmp $b->{$classr} } @data; + } + + # get today + my ( $sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst ) + = localtime( gettimeofday() ); + $month++; + $year += 1900; + my $today = sprintf( '%04d-%02d-%02d', $year, $month, $mday ); + + # build a sorted array of valid dates + my %hash = (); + foreach my $d (@data) { + $hash{ $d->{sdate} } = 1 if $d->{sdate} ge $today; + } + if ($infoDay) { + foreach my $d (@idata) { + $hash{ $d->{sdate} } = 1 if $d->{sdate} ge $today; + } + } + my @days = keys %hash; + @days = sort { $a cmp $b } @days; + + my $date = ""; + my $class; + my $out = AttrVal( $name, "dsb_outputFormat", undef ); + + foreach my $day (@days) { + my $row = 0; + my $class = "even"; + $ret .= "
"; + $row++; + if ($infoDay) { + foreach my $iline (@idata) { + if ( $row % 2 == 0 ) { + $class = "even"; + } + else { + $class = "odd"; + } + $row++; + + if ( $iline->{sdate} eq $day ) { + $ret + .= ""; + } + } + } + $ret .= ""; + foreach my $c (@cn) { + $ret .= ""; + } + $ret .= ""; + + foreach my $line (@data) { + if ( $line->{sdate} eq $day ) { + if ( $row % 2 == 0 ) { + $class = "even"; + } + else { + $class = "odd"; + } + $row++; + + $ret .= ""; + + foreach my $c (@cn) { + $ret .= ""; + + } + $ret .= ""; + + } + } + } + + $ret .= "
" . $day . "
" + . $iline->{topic} . ": " + . $iline->{text} + . "
" . $c . "
" . $line->{$c} . "
"; + return $ret; + } ################################### sub DSBMobile_infoHTML($) { @@ -745,11 +845,15 @@ sub DSBMobileUUID() {
  • dsb_outputFormat: can be used to format the output of the weblink. Takes the readingnames enclosed in % as variables, e.g. %Klasse_n_%
  • - DSBMobile additionally provides two functions to display the information in weblinks: + DSBMobile additionally provides three functions to display the information in weblinks: - DSBMobile bietet zusätzlich zwei Funktionen, um die Informationen in weblinks darzustellen: + DSBMobile bietet zusätzlich drei Funktionen, um die Informationen in weblinks darzustellen: