<!DOCTYPE html>
<!--
********************************************************************************

    filename:    docfiles.php
    description: BurnBot Module Documentation
    inputs:       none
    outputs:      none
    actions:      none
    redirections: none 

********************************************************************************
-->
<html>
    <head>
        <?php include 'head.html' ?>
        <script src = "navigation.js"></script>
        <style>
            table {
                border-collapse: collapse;
            }

            table, td, th {
                border: 1px solid black;
                text-align: left;
            }
.center {
    margin: auto;
    width: 60%;
    padding: 10px;
}
        </style>
    </head>
    <body>
        <?php include 'navigationmanageswdocs.html' ?>
        <h3>BURNBOT MODULE DOCUMENTATION</h3>
        <div class=center>
        <?php
            $dir = getcwd();
            if (is_dir($dir)){
               if ($pdir= opendir($dir)){
                   $files = array();
                   while (($file = readdir($pdir)) !== false) {
                       array_push($files, $file);
                   }
                   sort($files);
                   $nmodules = 0;
                   echo "<table>";
                   echo "<tr>";
                   echo "<th>MODULE</th>";
                   echo "<th>DOCUMENTATION</th>";
                   echo "</tr>";
                   foreach($files as $file) {
                       $php = strpos($file, "php");
                       $html = strpos($file, "html");
                       $css = strpos($file, "css");
                       $js = strpos($file, "js");
                       $json = strpos($file, "json");
                       $x = strpos($file, "x");
                       if (($php !== false or $html !== false or $css !== false or $js !== false) and $file != "docmodules.php" and $json === false) {
                           $nmodules++;
                           echo "<tr>";
                           echo "<th>" . $file . "</th>";
                           echo "<th>";
                           $docsection = false;
                           $lines = file($dir . "/" . $file);
                            foreach($lines as $line) {
                                $stars = strpos($line, "********");
                                if ($stars !== false) {
                                    if ($docsection == false) {
                                        $docsection = true;
                                    } else {
                                        $docsection = false; 
                                    }
                                } elseif ($docsection == true and strlen($line) > 1) {
                                    echo $line . "<br>";
                                }
                           }
                           echo "</th>";
                           echo "</tr>";
                       }
                  }
           }
           echo "</table>";
//           echo "number of modules=" . $nmodules;
           }
?>
    </body>
</html>