/*
 * Copyright 2015 Mario Richter, Peter Stephan
 * This file is part of NeMo.
 *
 * NeMo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NeMo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NeMo.  If not, see <http://www.gnu.org/licenses/>.
 */

/*!
 * \file http_pages.c
 * \ingroup http
 * \brief Webseiten für den Webserver.
 */


#include "main.h"

// ---------------------------------------------
// HTTP-Header

// Standard-HTML-Header
PROGMEM const uint8_t httpHtmlHeader[] = {
    "HTTP/1.1 200 OK\r\n"
    "Server: NeMo Webserver\r\n"
    "Content-Type: text/html\r\n\r\n"
    "###"
};

// Standard-JPEG-Header
PROGMEM const uint8_t httpJpegHeader[] = {
    "HTTP/1.1 200 OK\r\n"
    "Server: NeMo Webserver\r\n"
    "Content-Type: image/jpeg\r\n\r\n"
    "###"
};

// Standard-GIF-Header
PROGMEM const uint8_t httpGifHeader[] = {
    "HTTP/1.1 200 OK\r\n"
    "Server: NeMo Webserver\r\n"
    "Content-Type: image/gif\r\n\r\n"
    "###"
};

// Authorisierungsanforderung (401 Unauthorized)
PROGMEM const uint8_t httpAuthHeader[] = {
    "HTTP/1.1 401 Unauthorized\r\n"
    "Server: NeMo Webserver\r\n"
    "WWW-Authenticate: Basic realm=\"Authorisierung\"\r\n"
    "Content-Type: text/html\r\n\r\n"
    "###"
};

// Datei nicht gefunden (404 Not Found)
PROGMEM const uint8_t httpNotFoundHeader[] = {
    "HTTP/1.1 404 Not Found\r\n"
    "Server: NeMo Webserver\r\n"
    "Content-Type: text/html\r\n\r\n"
    "###"
};


// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Wichtig: Für jede darzustellende Seite die Endekennung "###" ans Ende einfügen.
// Die Seite wird nur bis zum Erkennen dieser Endekennung übertragen.
// --------------------------------------------------------------------------------
// Stringvariablen innerhalb der Seitenbeschreibung werden mit der Kennung "@@@"
// eingeleitet, gefolgt von der zweistelligen Nummer des Strings.
// --------------------------------------------------------------------------------
// Im Formular muss jeder Button den Namen "cmd" haben, die Unterscheidung der
// Befehle erfolgt anhand des Wertes, welcher mit "*" abgeschlossen werden muss.
// Dies ist notwendig, um die Abarbeitung anzutriggern, da kein finales \r\n vom
// Client übertragen wird.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// ---------------------------------------------
// Die Hauptseite des Webservers (mainPage)
// Spezielle Stringvariablen:
// 61..76: Namen der 16 Lichtprogramme, bzw. "kein Programm"
// 81..96: Status der Buttons (" disabled" wenn kein Programm, sonst "")
// 99: Einsatzort

PROGMEM const uint8_t mainPage[] = {
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n"
    "<html>\r\n"
    "<head>\r\n"
      "<title>NeLiS @@@99</title>\r\n"
      "<meta name=\"author\" content=\"mario001.de\">\r\n"
      "<meta name=\"editor\" content=\"gedit\">\r\n"
      "<style type=\"text/css\">\r\n"
        "<!--\r\n"
        "body {font-family: Verdana, Arial; font-size:14px; background-color: #222222; color:#DDDDDD; text-align:center;}\r\n"
        "#mainframe {width: 80%; margin: 5px auto; text-align: center; background-color: #333388; border:1px solid #EEEEEE;}\r\n"
        "a { color: #FFFF00; }\r\n"
        "a:link { color: #FFFF00; }\r\n"
        "a:visited { color: #CCAA00; }\r\n"
        "-->\r\n"
      "</style>\r\n"
    "</head>\r\n"
    "<body>\r\n"
      "<div id=\"mainframe\">\r\n"
      "<h1>NeLiS V@@@01</h1>\r\n"
      "<h3>-- @@@99 --</h3>\r\n"
      "<form action=\"\" method=\"post\" autocomplete=\"off\">\r\n"
        "<table style=\"margin-left:auto; margin-right:auto; border-spacing:15px; border:0\">\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"off*\">AUS</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"brk*\"@@@02>@@@03</button></td>\r\n"
          "</tr>\r\n"
        "</table>\r\n"
        "<hr style=\"width:60%\">\r\n"
        "<table style=\"margin-left:auto; margin-right:auto; border-spacing:15px; border:0\">\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p01*\"@@@81>01: @@@61</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p02*\"@@@82>02: @@@62</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p03*\"@@@83>03: @@@63</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p04*\"@@@84>04: @@@64</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p05*\"@@@85>05: @@@65</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p06*\"@@@86>06: @@@66</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p07*\"@@@87>07: @@@67</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p08*\"@@@88>08: @@@68</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p09*\"@@@89>09: @@@69</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p10*\"@@@90>10: @@@70</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p11*\"@@@91>11: @@@71</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p12*\"@@@92>12: @@@72</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p13*\"@@@93>13: @@@73</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p14*\"@@@94>14: @@@74</button></td>\r\n"
          "</tr>\r\n"
          "<tr>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p15*\"@@@95>15: @@@75</button></td>\r\n"
            "<td><button type=\"submit\" name=\"cmd\" value=\"p16*\"@@@96>16: @@@76</button></td>\r\n"
          "</tr>\r\n"
        "</table>\r\n"
        "<hr style=\"width:60%\">\r\n"
        "<table style=\"margin-left:auto; margin-right:auto; border-spacing:15px; border:0\">\r\n"
          "<tr>\r\n"
            "<td colspan=\"2\"><button type=\"submit\" name=\"cmd\" value=\"ato*\">Autostart @@@05</button></td>"
          "</tr>\r\n"
        "</table>\r\n"
      "</form><br />\r\n"
      "Temperatur: @@@04<br />\r\n"
      "Betriebsspannung: @@@06<br />\r\n"
      "&nbsp;<br />\r\n"
      "(c) 2013-2016 <a href=\"http://www.mario001.de/\">mario001.de</a><br />\r\n"
      "&nbsp;<br />\r\n"
      "</div>\r\n"
    "</body>\r\n"
    "</html>\r\n\r\n"
    "###"
};


// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Wichtig: Liste mit Eintrag {NULL,NULL} abschließen. Der erste Eintrag
// ist die Standardseite, die auch bei fehlendem Dateinamen angezeigt wird.
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// ---------------------------------------------
// Liste der Dateien

httpPageType httpPages[] = {
    { "index.htm",  mainPage },
    { NULL,         NULL }
};

// ---------------------------------------------
// Stringvariablen:
// 01: Softwareversion
// 02: Status des Pause-Buttons ("" wenn aktiv oder pausiert, " disabled" wenn inaktiv)
// 03: Beschriftung des Pause-Buttons ("Pause" oder "Fortsetzen")
// 04: Temperatur
// 05: Autostart-Button ("ausschalten" oder "aktivieren")
// 06: Betriebsspannung

httpStringType httpString[HTTP_STRING_VARS];

