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

    filename:    burnbotlocs.php
    description: BurnBot Lines of Code
    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: right;
            }
.center {
    margin: auto;
    width: 60%;
    padding: 10px;
}
        </style>
    </head>
    <body>
        <?php include 'navigationmanageswdocs.html' ?>
        <h3>BURNBOT LOCs</h3>
        <div class=center>
        <?php
            $nfiles = 0;
            $nphpfiles = 0;
            $nhtmlfiles = 0;
            $ncssfiles = 0;
            $npyfiles = 0;
            $nprocessfiles = 0;
            $lots= 0;
            $locs = 0;
            echo "<table>";
            echo "<tr>";
            echo "<th>FILE</th>";
            echo "<th>Lines of Text</th>";
            echo "<th>Lines of Code</th>";
            echo "</tr>";
            $dir = getcwd();
            if (is_dir($dir)){
               if ($pdir= opendir($dir)){
                   $files = array();
                   while (($file = readdir($pdir)) !== false) {
                       array_push($files, $file);
                   }
                   sort($files);
                   foreach($files as $file) {
                       $php = strpos($file, "php");
                       $process= strpos($file, "process");
                       $html = strpos($file, "html");
                       $css = strpos($file, "css");
                       $js = strpos($file, "js");
                       $py = strpos($file, “py”);
                       $json = strpos($file, "json");
                       $x = strpos($file, "x");
                       if (($php !== false or $html !== false or $css !== false or $js !== false or $py !== false) and $json === false) {
                           $nfiles++;
                           if ($php !== false) {
                               $nphpfiles++;
                           }
                           if ($process !== false) {
                               $nprocessfiles++;
                           }
                           if ($html !== false) {
                               $nhtmlfiles++;
                           }
                           if ($css !== false) {
                               $ncssfiles++;
                           }
                           if ($py !== false) {
                               $npyfile++;
                           }
                           $lines = file($dir . "/" . $file);
                           $PHPComment = false;
                           $HTMLComment = false;
                           $filelocs = 0;
                           $filelots = 0;
                           foreach($lines as $line) {
                               $lots++;
                               $filelots++;
                               $startHTMLComment = strpos($line, "<!--");
                               $endHTMLComment = strpos($line, "-->");
                               $linePHPComment= strpos($line, "//");
                               $startPHPComment= strpos($line, "/*");
                               $endPHPComment= strpos($line, "*/");
                               if ($startPHPComment!== false) {
                                   $PHPComment= true;
                               } elseif ($endPHPComment!== false) {
                                   $PHPComment= false;
                               }
                               if ($startHTMLComment!== false) {
                                   $HTMLComment= true;
                               } elseif ($endHTMLComment!== false) {
                                   $HTMLComment= false;
                               }
                               if ($linePHPComment === false and $PHPComment === false and $HTMLComment === false and $endPHPComment === false and $endHTMLComment === false and strlen($line) > 0) {
                                   $locs++;
                                   $filelocs++;
                               }
                           }
                           echo "<tr>";
                           echo "<th>" . $file . "</th>";
                           echo "<th>" . $filelots . "</th>";
                           echo "<th>" . $filelocs . "</th>";
                           echo "</tr>";
                       }
                  }
           }
           $nscreenfiles = $nfiles - $nprocessfiles;
           echo "<tr>";
           echo "<th>" . $nfiles . " files<br>" . $nscreenfiles . " screens<br>" . $nphpfiles . " php files<br>" . $nhtmlfiles . " html files<br>" . $ncssfiles . " css files</th>";
           echo "<th>" . $lots. "</th>";
           echo "<th>" . $locs. "</th>";
           echo "</tr>";
           echo "</table>";
           }
?>
    </body>
</html>