#!/bin/bash

echo "Content-type: text/html"
echo 

export RRD_OKRES=$(echo "$QUERY_STRING" | grep -oE "(^|[?&])RRD_OKRES=[0-9a-z-]+" | cut -f 2 -d "=" | head -n1)

cat <<EOF
<HTML>
 <HEAD>
 <TITLE>Wiatrówka - Archiwum odczytów parametrów wiatru dla regionu Zielona Góra</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<META HTTP-EQUIV="Refresh" CONTENT="300">
<meta http-equiv="expires" content="-1">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
</HEAD>
<BODY>
EOF

cat <<EOF
 <A href="wiatrowka.cgi?RRD_OKRES=-12hours">12h,</A>&nbsp;&nbsp;
 <A href="wiatrowka.cgi?RRD_OKRES=-1day">1d,</A>&nbsp;&nbsp;
 <A href="wiatrowka.cgi?RRD_OKRES=-3days">3d,</A>&nbsp;&nbsp;
 <A href="wiatrowka.cgi?RRD_OKRES=-1week">1w,</A>&nbsp;&nbsp;
 <H3><H3>
EOF

# wielkosc obrazkow
export RRD_X="400"
export RRD_Y="160"

################# pierwsze wygenerowanie blanka
rrdtool graph ./img/blank.png --start $RRD_OKRES --end -4min -w $RRD_X -h 27 -y none -L 6 -v "kierunek" -l 0 -u 0 -r -c MGRID#000000 -c GRID#B0B0B0  --font DEFAULT:0:/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf DEF:dir=/var/www/wiatrowka/rrd/stelmet-pellet.rrd:DIR:AVERAGE LINE1:dir#FFFFFF: > /dev/null
################# pierwsze wygenerowanie blanka

################# START TABELKI #################
echo "<table>"

################# START WIERSZ  #################
echo "<tr>"

####################################################################################################
export RRD_NAME="urzad-miasta"

cat <<EOF
<td><pre>METAR - EPZG</pre>
EOF
export RRD_NAME="metar-epzg"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'
echo "<BR><BR></td>"

####################################################################################################
cat <<EOF
<td><pre>METEO Stelmet</pre>
EOF
export RRD_NAME="stelmet-pellet"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'

echo "<BR><BR></td>"

####################################################################################################

################# KONIEC WIERSZ  #################
echo "</tr>"

#################      HR        #################
echo "<tr><td colspan=\"2\"><hr width=\"90%\"></td></tr>"

################# START WIERSZ  #################
echo "<tr>"

####################################################################################################
cat <<EOF
<td><pre>Pogodynka.pl Zielona Góra</pre>
EOF
export RRD_NAME="pogpl-zie"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'

echo "<BR><BR></td>"

####################################################################################################
cat <<EOF
<td><pre>Pogodynka.pl Gorzów Wlkp.</pre>
EOF
export RRD_NAME="pogpl-gorz"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'

echo "<BR><BR></td>"

####################################################################################################

################# KONIEC WIERSZ  #################
echo "</tr>"

#################      HR        #################
echo "<tr><td colspan=\"2\"><hr width=\"90%\"></td></tr>"

################# START WIERSZ  #################
echo "<tr>"

####################################################################################################
cat <<EOF
<td><pre>METAR - EPWR</pre>
EOF
export RRD_NAME="metar-epwr"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'

echo "<BR><BR></td>"

####################################################################################################
cat <<EOF
<td><pre>METAR - EPPO</pre>
EOF
export RRD_NAME="metar-eppo"
./graph_wind.cgi | grep -Ev "Content|text/html"
php -f /var/www/wiatrowka/rot-arrow/rotatingarrow.php > img/$RRD_NAME-w.png
echo '<img src="img/'$RRD_NAME'-w.png"></img>'

echo "<BR><BR></td>"

####################################################################################################

################# KONIEC WIERSZ  #################
echo "</tr>"

################# KONIEC TABELKI #################
echo "</table>"

cat <<EOF
</BODY>
</HTML>
EOF
