<?php
include_once('../database_connection.php');

?>

<link rel="stylesheet" href="./dist/listree.min.css"/>
<script src="./dist/listree.umd.min.js"></script>
<body style="background: white;">
<ul class="listree" >
<?php
$data="";
if(isset($_GET['Under']) && $_GET['Under']!="" && $_GET['Under']!="undefined")
{
  $Under=$_GET['Under'];
  $sql="select * from Accounts where active=1 and Under=$Under order by under";
}
else
{
$sql="select * from Accounts where active=1 and degree=1 order by under";
}
$result=odbc_exec($connection,$sql) or die(odbc_error().$sql);
while($row=odbc_fetch_array($result))
{
  $COAID=$row['COAID'];
  $Under=$row['Under'];
  $COAName=$row['COAName'];

$data=$data.'<li><div class="listree-submenu-heading" style="display:block !important;">'.$COAName.'</div>';
$data=getTree($COAID,$connection,$data);
$data=$data.'</li>';
}
echo $data;
?>
  <!-- <li>
    <div class="listree-submenu-heading">Item 1</div> -->
    <!-- <ul class="listree-submenu-items">
      <li>
        <div class="listree-submenu-heading">Item 1-1</div>
          <ul class="listree-submenu-items">
            <li>
              <div class="listree-submenu-heading">Item 1-1-1</div>
                <ul class="listree-submenu-items">
                  <li>
                    <div class="listree-submenu-heading">Item 1-1-1-1</div>
                      <ul class="listree-submenu-items">
                      <li>
                        <a href="">Item 1-1-1-1-1</a>
                      </li>
                      <li>
                        <a href="">Item 1-1-1-1-2</a>
                      </li>
                      </ul>
                  </li>
                </ul>
            </li>
          </ul>
      </li>
    </ul> -->
  <!-- </li> -->
  
</ul>
<script src="../assets/js/jquery-3.2.1.min.js"></script>
<script>
listree();
$(document).ready(function(){
  $(".listree-submenu-items").each(function(){
    $(this).css('display','block');
   // $(this).addClass('expanded');
    //$(this).before('-');
    //$("div.listree-submenu-heading.expanded:before").css('content',);
  //margin-right:4px}
  });
  //$("div.listree-submenu-heading.collapsed")
  //$("div.listree-submenu-heading").before(''); 
  //$("div.listree-submenu-heading").before('-'); 
})
</script>
<?php
function getTree($COAID,$connection,$data)
{
  $data=$data.'<ul class="listree-submenu-items">';
$sql="select * from accounts where active=1 and under=$COAID";
$result1=odbc_exec($connection,$sql) or die(odbc_error().$sql);


while($row1=odbc_fetch_array($result1))
{
  $COAID=$row1['COAID'];
  $Under=$row1['Under'];
  $COAName=$row1['COAName'];

$data=$data.'<li><div class="listree-submenu-heading ">'.$COAName.'</div>';
$data=getTree($COAID,$connection,$data);
$data=$data.'</li>';
}
$data=$data.'</ul>';
return $data;
}
?>
</body>