<?
  require_once('config/cfg.php');

  //apache htaccess - www authentication
  if ( ( !isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))  
       || ( $PHP_AUTH_USER != $htaccessUser ) || ( $PHP_AUTH_PW != $htaccessPassword ) ) { 
      header( 'WWW-Authenticate: Basic realm="Private"' ); 
      header( 'HTTP/1.0 401 Unauthorized' ); 
      echo "This folder is protected "; 
      exit; 
  } 

  $db->SetFetchMode(ADODB_FETCH_BOTH);
  $qry="SELECT DISTINCT filename FROM ast_config";
  $res=$db->Execute($qry);
  while ($arr=$res->FetchRow()) {
    $filename=$arr["0"];
    echo "<hr/><h1>".$filename."</h1>";

    $qry="SELECT DISTINCT category FROM ast_config WHERE filename='$filename' ORDER BY cat_metric";
    $res2=$db->Execute($qry);
    while ($arr=$res2->FetchRow()) {
      $category=$arr["0"];
      echo "<h3>[".$category."]</h3>";
      
      $qry="SELECT * FROM ast_config WHERE filename='$filename' AND category='$category' ORDER BY var_metric";
      $res3=$db->Execute($qry);
      while ($arr=$res3->FetchRow()) {
        $var_name=$arr["var_name"];
        $var_val=$arr["var_val"];
        $comment=$arr["comment"];
        $commented=$arr["commented"];
        echo "<div>";
        if ($var_name!="" and $commented!=1) echo "<strong>$var_name</strong> = $var_val ";
        if ($var_name!="" and $commented==1) echo "<strong style='color: darkgreen'>; $var_name</strong> <span style='color: darkgreen'> = $var_val </span> ";
        if ($comment!="") echo "<span style='color: darkgreen'>;$comment</span>";
        echo "</div>";
      }

      $qry="SELECT * FROM extensions_table WHERE context='$category' ORDER BY priority";
      $res3=$db->Execute($qry);
      while ($arr=$res3->FetchRow()) {
        $exten=$arr["exten"];
        $priority=$arr["priority"];
        $app=$arr["app"];
        $appdata=$arr["appdata"];
        echo "<div style='color: gray;'>";
        echo "exten => $exten,$priority,$app"."[".$appdata."]";
        echo "</div>";
      }


    }
  }
   
?>
