<!DOCTYPE html>
<html>
<head>
<title>PE1RXF APRS server</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/popup.css">
<link rel="stylesheet" href="css/font-awesome.min.css">

</head>
<body>

<?php 

    // Prevents a repost when the user refreshes the page.
    // Also it handles the post itself.
    session_start();

    if(count($_POST) > 0) {
        // figure out which form was entered   
        if ($_POST['ax0_message_text']) {
            $_SESSION['ax0_message_text'] = $_POST['ax0_message_text'];
            $_SESSION['ax0_message_path'] = $_POST['ax0_message_path'];
            $_SESSION['ax0_message_destination'] = $_POST['ax0_message_destination'];
            
        }
        if ($_POST['ax1_message_text']) {
            $_SESSION['ax1_message_text'] = $_POST['ax1_message_text'];
            $_SESSION['ax1_message_path'] = $_POST['ax1_message_path'];
            $_SESSION['ax1_message_destination'] = $_POST['ax1_message_destination'];
            
        }

        header("HTTP/1.1 303 See Other");
        header("Location: http://$_SERVER[HTTP_HOST]/send_message.php");
        die();
    }
    else { 

        if (isset($_SESSION['ax0_message_text'])){
            $ax0_message_text = $_SESSION['ax0_message_text'];
            $ax0_message_path = $_SESSION['ax0_message_path'];
            $ax0_message_destination = $_SESSION['ax0_message_destination'];
            
            //echo "Send ax0: $ax0_message_text, $ax0_message_path, $ax0_message_destination";
            //$ax0_message_destination = str_pad($ax0_message_destination, 9, " ");
            //echo "PE1RXF-1>APRX29,$ax0_message_path::$ax0_message_destination:$ax0_message_text";
            
            # Send message. NOTE: send_message.sh should be executable by www-data. Also, the ax0 transmit directory should be writable by www-data
            if ($ax0_message_path == "none")
                $execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax0 -c \"%s\" -m \"%s\"", $ax0_message_destination, $ax0_message_text);
            else
                $execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax0 -c \"%s\" -p \"%s\" -m \"%s\"", $ax0_message_destination, $ax0_message_path, $ax0_message_text);
            //$execuatable_string = sprintf("%'.9d\n", 123);
            //echo $execuatable_string;
            exec("$execuatable_string");
            
            # Wait for the changes to take effect
            sleep(1);
        }
        
        else if (isset($_SESSION['ax1_message_text'])){
            $ax1_message_text = $_SESSION['ax1_message_text'];
            $ax1_message_path = $_SESSION['ax1_message_path'];
            $ax1_message_destination = $_SESSION['ax1_message_destination'];

            //echo "Send ax1: $ax1_message_text, $ax1_message_path, $ax1_message_destination";
            # Send message. NOTE: send_message.sh should be executable by www-data. Also, the ax0 transmit directory should be writable by www-data
            if ($ax1_message_path == "none")
                $execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_text);
            else
                $execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -p \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_path, $ax1_message_text);
                
            //$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -p \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_path, $ax1_message_text);
            //echo exec("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c $ax1_message_destination -p $ax1_message_path -m $ax1_message_text");
            exec("$execuatable_string");
            
            # Wait for the changes to take effect
            sleep(1);
        }

        session_unset();
        session_destroy();

    }
    // END: Prevents a repost when the user refreshes the page.
 
    # Reads configuration file from pe1rxf-aprs-server directory, makes changes if necesary
    # and writes the newly constructed file to a temporary config-file. It does not overwrite
    # the original file, because user www-data can only read the program directory, not write to it.
    # It's a safety thing...
    # The main loop of pe1rxf-aprs-server than copies it to the program directory and removes the temporary file.
    function change_parameter_value($parameter, $value)
    {
        $config_file = '/var/www/html/config/test.cfg';
        $tmp_config_file = '/var/www/html/config/test.cfg.tmp';
        $reading = fopen($config_file, 'r');
        $writing = fopen($tmp_config_file, 'w');

        $replaced = false;
        while (!feof($reading)) {

            $line = fgets($reading);
            if (stristr($line,$parameter)) {
                $line = "$parameter=$value\n";
                //echo "New value: ", "$line";
                $replaced = true;
            }
            fputs($writing, $line);
        }
        fclose($reading); fclose($writing);
        
        // might as well not overwrite the file if we didn't replace anything
        if ($replaced) 
        {
            shell_exec("mv $tmp_config_file $config_file");
        } else {
            shell_exec("rm $tmp_config_file");
        }
    }
    
    # Saves setting for given form: ax0 or ax1
    # $a = beacon_time
    # $b = beacon_destination
    # $c = beacon_path
    # $d = beacon_position
    # $e = beacon_comment
    # $f = beacon_file
    # $g = transmit_directory
    function save_settings($form, $a, $b=0, $c=0, $d=0, $e=0, $f=0, $g=0)
    {
        # Copy original config file to temporary place on web server.
        # From here we can change the values
        $original_config_file = '/home/marcel/ham/aprs_utils/pe1rxf-aprs-server.cfg';
        $destination_config_file = '/var/www/html/config/test.cfg';
        $newly_made_config_file =  '/var/www/html/config/pe1rxf-aprs-server.cfg';

        $fileCopied = copy("$original_config_file", "$destination_config_file");
        if($fileCopied) {
        //echo "# $a, $b, $c, $d, $e, $f, $g";
            if ($form == "ax0" ) {
                change_parameter_value("ax0_beacon_time", $a);
                if ($c) change_parameter_value("ax0_beacon_path", $c);
                if ($e) change_parameter_value("ax0_beacon_comment", $e);
            }
            else if ($form == "ax1" ) {
                change_parameter_value("ax1_beacon_time", $a);
                if ($c) change_parameter_value("ax1_beacon_path", $c);
                if ($e) change_parameter_value("ax1_beacon_comment", $e);                
            }

            # now make new file with new configuration for the main loop to find.
            shell_exec("cp $destination_config_file $newly_made_config_file");
            # and remove working file:
            shell_exec("rm $destination_config_file");

        } else{
            #echo "Error";
        }
    }
    
    # Reads configuration file from pe1rxf-aprs-server directory.
    # Search this file for given paramter and returns its value.
    function search_parameter_in_config_file($parameter)
    {
        $config_file = '/home/marcel/ham/aprs_utils/pe1rxf-aprs-server.cfg';
        $reading = fopen($config_file, 'r');
        while (!feof($reading)) {
        
            $line = fgets($reading);
            if ( strstr($line,$parameter) ) {

                $line = substr( $line, strlen($parameter)+1 );
                
                # Found match. Stop further search.
                fclose($reading);
                return rtrim($line);
            }
        }
        
    }

    $ax0_name = search_parameter_in_config_file("ax0_name");
    $ax0_frequency = search_parameter_in_config_file("ax0_frequency");
    
    $ax0_message1_id =  search_parameter_in_config_file("ax0_message1_id");
    $ax0_message2_id =  search_parameter_in_config_file("ax0_message2_id");
    $ax0_message3_id =  search_parameter_in_config_file("ax0_message3_id");
    $ax0_message4_id =  search_parameter_in_config_file("ax0_message4_id");    
    
    $ax0_message1_text =  search_parameter_in_config_file("ax0_message1_text");
    $ax0_message2_text =  search_parameter_in_config_file("ax0_message2_text");
    $ax0_message3_text =  search_parameter_in_config_file("ax0_message3_text");
    $ax0_message4_text =  search_parameter_in_config_file("ax0_message4_text");
    
    $ax0_message1_destination =  search_parameter_in_config_file("ax0_message1_destination");
    $ax0_message2_destination =  search_parameter_in_config_file("ax0_message2_destination");
    $ax0_message3_destination =  search_parameter_in_config_file("ax0_message3_destination");
    $ax0_message4_destination =  search_parameter_in_config_file("ax0_message4_destination");

    $ax0_message1_path =  search_parameter_in_config_file("ax0_message1_path");
    $ax0_message2_path =  search_parameter_in_config_file("ax0_message2_path");
    $ax0_message3_path =  search_parameter_in_config_file("ax0_message3_path");
    $ax0_message4_path =  search_parameter_in_config_file("ax0_message4_path");

    $ax1_name = search_parameter_in_config_file("ax1_name");
    $ax1_frequency = search_parameter_in_config_file("ax1_frequency");
    
    $ax1_message1_id =  search_parameter_in_config_file("ax1_message1_id");
    $ax1_message2_id =  search_parameter_in_config_file("ax1_message2_id");
    $ax1_message3_id =  search_parameter_in_config_file("ax1_message3_id");
    $ax1_message4_id =  search_parameter_in_config_file("ax1_message4_id");
    
    $ax1_message1_text =  search_parameter_in_config_file("ax1_message1_text");
    $ax1_message2_text =  search_parameter_in_config_file("ax1_message2_text");
    $ax1_message3_text =  search_parameter_in_config_file("ax1_message3_text");
    $ax1_message4_text =  search_parameter_in_config_file("ax1_message4_text");
    
    $ax1_message1_destination =  search_parameter_in_config_file("ax1_message1_destination");
    $ax1_message2_destination =  search_parameter_in_config_file("ax1_message2_destination");
    $ax1_message3_destination =  search_parameter_in_config_file("ax1_message3_destination");
    $ax1_message4_destination =  search_parameter_in_config_file("ax1_message4_destination");

    $ax1_message1_path =  search_parameter_in_config_file("ax1_message1_path");
    $ax1_message2_path =  search_parameter_in_config_file("ax1_message2_path");
    $ax1_message3_path =  search_parameter_in_config_file("ax1_message3_path");
    $ax1_message4_path =  search_parameter_in_config_file("ax1_message4_path");

?>

<div class="header">
  <a href="index.php" >
    <h1><i class="fa fa-home" aria-hidden="true"></i>&nbsp; PE1RXF APRS server</h1>
  </a>
</div>

<div class="row">
  <div class="col-3 col-s-3 menu">
    <ul>
      <li><h3><?php echo $ax0_name ?> (<?php echo $ax0_frequency ?>)</h3></li>
      <li onclick="openForm_ax0_message0()">Send new message</li>
      <li><b>Predefined messages:</b></li>
      <li onclick="openForm_ax0_message1()"><b><?php echo $ax0_message1_id; ?></b></li>
      <li onclick="openForm_ax0_message2()"><b><?php echo $ax0_message2_id; ?></b></li>
      <li onclick="openForm_ax0_message3()"><b><?php echo $ax0_message3_id; ?></b></li>
      <li onclick="openForm_ax0_message4()"><b><?php echo $ax0_message4_id; ?></b></li>
    </ul>
  </div>

  <div class="col-6 col-s-9"  id="main_page">

    <div class="col-6 col-s-12">
     <img src="images/mail-out.svg" style="cursor:pointer;" onclick="show_send_messages()"/></a>
     <h1>Send messages</h1>
    </div>
    
    <div class="col-6 col-s-12"> 
     <img src="images/mail-in.svg" style="cursor:pointer;" onclick="show_received_messages()" />
     <h1>Received messages</h1>
    </div>
  
  </div>
  
  <div class="col-6 col-s-9" id="send_messages" style="display:none">
  
    <h1>Send messages</h1>

     <h2 align="left"><?php echo $ax0_name ?> (<?php echo $ax0_frequency ?>)</h2>
     <h3 align="left">
        <?php
        $csv = array_map('str_getcsv', file("/home/marcel/ham/aprs_utils/aprs_log/aprs_send_messages.log"));

        for ($i = 0; $i < count($csv); $i++) {
            if ($csv[$i][1] == "ax0") {
                echo $csv[$i][2];
                echo ": ";
                echo $csv[$i][4];
                echo "<br>";
            }
        }
        
        ?> 
    </h3>

     <h2 align="left"><?php echo $ax1_name ?> (<?php echo $ax1_frequency ?>)</h2>
     <h3 align="left">
        <?php
        $csv = array_map('str_getcsv', file("/home/marcel/ham/aprs_utils/aprs_log/aprs_send_messages.log"));

        for ($i = 0; $i < count($csv); $i++) {
            if ($csv[$i][1] == "ax1") {
                echo $csv[$i][2];
                echo ": ";
                echo $csv[$i][4];
                echo "<br>";
            }
        }
        
        ?> 
    </h3>

       <a href=""><h1 style="color:Black;" onclick="show_main_page()"><i class="fa fa-arrow-left" aria-hidden="true"></i>&nbsp; Back</h1></a>
  </div>
  
  <div class="col-6 col-s-9" id="received_messages" style="display:none">
  
    <h1>Received messages</h1>

     <h2 align="left"><?php echo $ax0_name ?> (<?php echo $ax0_frequency ?>)</h2>
     <h3 align="left">
        <?php
        $csv = array_map('str_getcsv', file("/home/marcel/ham/aprs_utils/aprs_log/aprs_received_messages.log"));

        for ($i = 0; $i < count($csv); $i++) {
            if ($csv[$i][1] == "ax0") {
                echo $csv[$i][2];
                echo ": ";
                echo $csv[$i][4];
                echo "<br>";
            }
        }
        
        ?> 
    </h3>

     <h2 align="left"><?php echo $ax1_name ?> (<?php echo $ax1_frequency ?>)</h2>
     <h3 align="left">
        <?php
        $csv = array_map('str_getcsv', file("/home/marcel/ham/aprs_utils/aprs_log/aprs_received_messages.log"));

        for ($i = 0; $i < count($csv); $i++) {
            if ($csv[$i][1] == "ax1") {
                echo $csv[$i][2];
                echo ": ";
                echo $csv[$i][4];
                echo "<br>";
            }
        }
        
        ?> 
    </h3>

       <a href=""><h1 style="color:Black;" onclick="show_main_page()"><i class="fa fa-arrow-left" aria-hidden="true"></i>&nbsp; Back</h1></a>
  </div>

  <div class="col-3 col-s-12 menu">
      <ul>
      <li><h3><?php echo $ax1_name ?> (<?php echo $ax1_frequency ?>)</h3></li>
      <li onclick="openForm_ax1_message0()">Send new message</li>
      <li><b>Predefined messages:</b></li>
      <li onclick="openForm_ax1_message1()"><b><?php echo $ax1_message1_id; ?></b></li>
      <li onclick="openForm_ax1_message2()"><b><?php echo $ax1_message2_id; ?></b></li>
      <li onclick="openForm_ax1_message3()"><b><?php echo $ax1_message3_id; ?></b></li>
      <li onclick="openForm_ax1_message4()"><b><?php echo $ax1_message4_id; ?></b></li>
    </ul>
  </div>
</div>

<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax0_message0">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax0_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax0_message_text" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="pwd" placeholder="Destination" name="ax0_message_destination" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax0_message_path" value="none" checked>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax0_message_path" value="WIDE2-1" <?php if ($ax0_message0_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax0_message_path" value="WIDE2-2" <?php if ($ax0_message0_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax0_message_path" value="WIDE3-3" <?php if ($ax0_message0_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax0_message0"><button type="submit" class="btn" onclick="SubmitClicked_ax0_message0()">Submit</button></div>
          <div id="submit_done_ax0_message0" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax0_message0"><button type="button" class="btn cancel" onclick="closeForm_ax0_message0()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax0_message1">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax0_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax0_message_text" value="<?php echo $ax0_message1_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax0_message_destination" value="<?php echo $ax0_message1_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax0_message_path" value="none" <?php if ($ax0_message1_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax0_message_path" value="WIDE2-1" <?php if ($ax0_message1_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax0_message_path" value="WIDE2-2" <?php if ($ax0_message1_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax0_message_path" value="WIDE3-3" <?php if ($ax0_message1_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax0_message1"><button type="submit" class="btn" onclick="SubmitClicked_ax0_message1()">Submit</button></div>
          <div id="submit_done_ax0_message1" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax0_message1"><button type="button" class="btn cancel" onclick="closeForm_ax0_message1()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax0_message2">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax0_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax0_message_text" value="<?php echo $ax0_message2_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax0_message_destination" value="<?php echo $ax0_message2_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax0_message_path" value="none" <?php if ($ax0_message2_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax0_message_path" value="WIDE2-1" <?php if ($ax0_message2_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax0_message_path" value="WIDE2-2" <?php if ($ax0_message2_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax0_message_path" value="WIDE3-3" <?php if ($ax0_message2_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax0_message2"><button type="submit" class="btn" onclick="SubmitClicked_ax0_message2()">Submit</button></div>
          <div id="submit_done_ax0_message2" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax0_message2"><button type="button" class="btn cancel" onclick="closeForm_ax0_message2()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax0_message3">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax0_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax0_message_text" value="<?php echo $ax0_message3_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax0_message_destination" value="<?php echo $ax0_message3_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax0_message_path" value="none" <?php if ($ax0_message3_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax0_message_path" value="WIDE2-1" <?php if ($ax0_message3_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax0_message_path" value="WIDE2-2" <?php if ($ax0_message3_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax0_message_path" value="WIDE3-3" <?php if ($ax0_message3_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax0_message3"><button type="submit" class="btn" onclick="SubmitClicked_ax0_message3()">Submit</button></div>
          <div id="submit_done_ax0_message3" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax0_message3"><button type="button" class="btn cancel" onclick="closeForm_ax0_message3()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax0_message4">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax0_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax0_message_text" value="<?php echo $ax0_message4_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax0_message_destination" value="<?php echo $ax0_message4_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax0_message_path" value="none" <?php if ($ax0_message4_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax0_message_path" value="WIDE2-1" <?php if ($ax0_message4_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax0_message_path" value="WIDE2-2" <?php if ($ax0_message4_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax0_message_path" value="WIDE3-3" <?php if ($ax0_message4_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax0_message4"><button type="submit" class="btn" onclick="SubmitClicked_ax0_message4()">Submit</button></div>
          <div id="submit_done_ax0_message4" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax0_message4"><button type="button" class="btn cancel" onclick="closeForm_ax0_message4()">Cancel</button>
        </form>
      </div>
    </div>
</div>

<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax1_message0">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax1_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax1_message_text" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax1_message_destination" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax1_message_path" value="none" checked>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax1_message_path" value="WIDE2-1" <?php if ($ax1_message0_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax1_message_path" value="WIDE2-2" <?php if ($ax1_message0_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax1_message_path" value="WIDE3-3" <?php if ($ax1_message0_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax1_message0"><button type="submit" class="btn" onclick="SubmitClicked_ax1_message0()">Submit</button></div>
          <div id="submit_done_ax1_message0" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax1_message0"><button type="button" class="btn cancel" onclick="closeForm_ax1_message0()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax1_message1">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax1_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax1_message_text" value="<?php echo $ax1_message1_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax1_message_destination" value="<?php echo $ax1_message1_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax1_message_path" value="none" <?php if ($ax1_message1_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax1_message_path" value="WIDE2-1" <?php if ($ax1_message1_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax1_message_path" value="WIDE2-2" <?php if ($ax1_message1_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax1_message_path" value="WIDE3-3" <?php if ($ax1_message1_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax1_message1"><button type="submit" class="btn" onclick="SubmitClicked_ax1_message1()">Submit</button></div>
          <div id="submit_done_ax1_message1" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax1_message1"><button type="button" class="btn cancel" onclick="closeForm_ax1_message1()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax1_message2">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax1_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax1_message_text" value="<?php echo $ax1_message2_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax1_message_destination" value="<?php echo $ax1_message2_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax1_message_path" value="none" <?php if ($ax1_message2_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax1_message_path" value="WIDE2-1" <?php if ($ax1_message2_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax1_message_path" value="WIDE2-2" <?php if ($ax1_message2_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax1_message_path" value="WIDE3-3" <?php if ($ax1_message2_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax1"><button type="submit" class="btn" onclick="SubmitClicked_ax1_message2()">Submit</button></div>
          <div id="submit_done_ax1" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax1"><button type="button" class="btn cancel" onclick="closeForm_ax1_message2()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax1_message3">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax1_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax1_message_text" value="<?php echo $ax1_message3_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax1_message_destination" value="<?php echo $ax1_message3_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax1_message_path" value="none" <?php if ($ax1_message3_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax1_message_path" value="WIDE2-1" <?php if ($ax1_message3_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax1_message_path" value="WIDE2-2" <?php if ($ax1_message3_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax1_message_path" value="WIDE3-3" <?php if ($ax1_message3_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax1"><button type="submit" class="btn" onclick="SubmitClicked_ax1_message3()">Submit</button></div>
          <div id="submit_done_ax1" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax1"><button type="button" class="btn cancel" onclick="closeForm_ax1_message3()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="loginPopup">
      <div class="formPopup" id="popupForm_ax1_message4">
        <form action="" class="formContainer" method="post">
          <h2>Message <?php echo $ax1_frequency ?></h2>
          
          <label for="email">
            <strong>Message</strong>
          </label>
          <input type="text" id="email" placeholder="Message" name="ax1_message_text" value="<?php echo $ax1_message4_text; ?>" required>
          <label for="psw">
            <strong>Destination</strong>
          </label>
          <input type="text" id="email" placeholder="Destination" name="ax1_message_destination" value="<?php echo $ax1_message4_destination; ?>" required>
          
          <label for="path">
            <strong>Path<br></strong>
          </label>
          <div class="radioLeft">
            <input type="radio" class="formContainer radio" id="path_none" name="ax1_message_path" value="none" <?php if ($ax1_message4_path == "none") echo "checked"; ?>>
            <label for="path_none">none</label><br>
            <input type="radio" class="formContainer radio" id="path_wide21" name="ax1_message_path" value="WIDE2-1" <?php if ($ax1_message4_path == "WIDE2-1") echo "checked"; ?> >
            <label for="path_wide21">WIDE2-1</label><br>  
            <input type="radio" class="formContainer radio" id="path_wide22" name="ax1_message_path" value="WIDE2-2" <?php if ($ax1_message4_path == "WIDE2-2") echo "checked"; ?> >
            <label for="path_wide22">WIDE2-2</label><br>
            <input type="radio" class="formContainer radio" id="path_wide33" name="ax1_message_path" value="WIDE3-3" <?php if ($ax1_message4_path == "WIDE3-3") echo "checked"; ?> >
            <label for="path_wide33">WIDE3-3</label><br>
          </div>


          <div id="submit_ax1"><button type="submit" class="btn" onclick="SubmitClicked_ax1_message4()">Submit</button></div>
          <div id="submit_done_ax1" style="display:none;"><button type="button" class="btn wait"><img src="images/preload.gif">Please wait...</button></div>
          <div id="cancel_ax1"><button type="button" class="btn cancel" onclick="closeForm_ax1_message4()">Cancel</button>
        </form>
      </div>
    </div>
</div>
<div class="footer">
  <p>Open source hardware and software. Visit https://www.meezenest.nl/mees for more information.</p>
</div>

<script>
      function openForm_ax0_message0() {
        document.getElementById("popupForm_ax0_message0").style.display = "block";
      }
      function closeForm_ax0_message0() {
        document.getElementById("popupForm_ax0_message0").style.display = "none";
      }
      function openForm_ax0_message1() {
        document.getElementById("popupForm_ax0_message1").style.display = "block";
      }
      function closeForm_ax0_message1() {
        document.getElementById("popupForm_ax0_message1").style.display = "none";
      }
      function openForm_ax0_message2() {
        document.getElementById("popupForm_ax0_message2").style.display = "block";
      }
      function closeForm_ax0_message2() {
        document.getElementById("popupForm_ax0_message2").style.display = "none";
      }
      function openForm_ax0_message3() {
        document.getElementById("popupForm_ax0_message3").style.display = "block";
      }
      function closeForm_ax0_message3() {
        document.getElementById("popupForm_ax0_message3").style.display = "none";
      }
      function openForm_ax0_message4() {
        document.getElementById("popupForm_ax0_message4").style.display = "block";
      }
      function closeForm_ax0_message4() {
        document.getElementById("popupForm_ax0_message4").style.display = "none";
      }
      
      function openForm_ax1_message0() {
        document.getElementById("popupForm_ax1_message0").style.display = "block";
      }
      function closeForm_ax1_message0() {
        document.getElementById("popupForm_ax1_message0").style.display = "none";
      }
      function openForm_ax1_message1() {
        document.getElementById("popupForm_ax1_message1").style.display = "block";
      }
      function closeForm_ax1_message1() {
        document.getElementById("popupForm_ax1_message1").style.display = "none";
      }
      function openForm_ax1_message2() {
        document.getElementById("popupForm_ax1_message2").style.display = "block";
      }
      function closeForm_ax1_message2() {
        document.getElementById("popupForm_ax1_message2").style.display = "none";
      }
      function openForm_ax1_message3() {
        document.getElementById("popupForm_ax1_message3").style.display = "block";
      }
      function closeForm_ax1_message3() {
        document.getElementById("popupForm_ax1_message3").style.display = "none";
      }
      function openForm_ax1_message4() {
        document.getElementById("popupForm_ax1_message4").style.display = "block";
      }
      function closeForm_ax1_message4() {
        document.getElementById("popupForm_ax1_message4").style.display = "none";
      }
      
      function show_send_messages() {
        document.getElementById("main_page").style.display = "none";
        document.getElementById("received_messages").style.display = "none";
        document.getElementById("send_messages").style.display = "block";
      }
      function show_received_messages() {
        document.getElementById("main_page").style.display = "none";
        document.getElementById("received_messages").style.display = "block";
        document.getElementById("send_messages").style.display = "none";
      }
      
      function show_main_page() {
        document.getElementById("main_page").style.display = "block";
        document.getElementById("received_messages").style.display = "none";
        document.getElementById("send_messages").style.display = "none";
      }
      
      
        /*
        Replacing Submit Button with 'Loading' Image
        Version 2.0
        December 18, 2012

        Will Bontrager Software, LLC
        https://www.willmaster.com/
        Copyright 2012 Will Bontrager Software, LLC

        This software is provided "AS IS," without 
        any warranty of any kind, without even any 
        implied warranty such as merchantability 
        or fitness for a particular purpose.
        Will Bontrager Software, LLC grants 
        you a royalty free license to use or 
        modify this software provided this 
        notice appears on all copies. 
        */
        function SubmitClicked_ax1_message0()
        {
            document.getElementById("submit_ax1_message0").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax1_message0").style.display = "block"; // to display
            document.getElementById("cancel_ax1_message0").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax1_message1()
        {
            document.getElementById("submit_ax1_message1").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax1_message1").style.display = "block"; // to display
            document.getElementById("cancel_ax1_message1").style.display = "none"; // to display            
            return true;
        }function SubmitClicked_ax1_message2()
        {
            document.getElementById("submit_ax1_message2").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax1_message2").style.display = "block"; // to display
            document.getElementById("cancel_ax1_message2").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax1_message3()
        {
            document.getElementById("submit_ax1_message3").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax1_message3").style.display = "block"; // to display
            document.getElementById("cancel_ax1_message3").style.display = "none"; // to display            
            return true;
        }
         function SubmitClicked_ax1_message4()
        {
            document.getElementById("submit_ax1_message4").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax1_message4").style.display = "block"; // to display
            document.getElementById("cancel_ax1_message4").style.display = "none"; // to display            
            return true;
        }
        
        function SubmitClicked_ax0_message0()
        {
            document.getElementById("submit_ax0_message0").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax0_message0").style.display = "block"; // to display
            document.getElementById("cancel_ax0_message0").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax0_message1()
        {
            document.getElementById("submit_ax0_message1").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax0_message1").style.display = "block"; // to display
            document.getElementById("cancel_ax0_message1").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax0_message2()
        {
            document.getElementById("submit_ax0_message2").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax0_message2").style.display = "block"; // to display
            document.getElementById("cancel_ax0_message2").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax0_message3()
        {
            document.getElementById("submit_ax0_message3").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax0_message3").style.display = "block"; // to display
            document.getElementById("cancel_ax0_message3").style.display = "none"; // to display            
            return true;
        }
        function SubmitClicked_ax0_message4()
        {
            document.getElementById("submit_ax0_message4").style.display = "none"; // to undisplay
            document.getElementById("submit_done_ax0_message4").style.display = "block"; // to display
            document.getElementById("cancel_ax0_message4").style.display = "none"; // to display            
            return true;
        }
    </script>
</body>
</html>


