<?php require_once('../auth/auth.php'); ?>
<section class="content">
   <div class="container-fluid">
      <div class="row">
         <div class="col-md-2">
            <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
               <div class="card-header" style="padding: 3px 8px;">
                  <h3 class="card-title"><?php echo language(2);?></h3>
                  <div class="card-tools">
                     <!-- <span title="3 New Messages" class="badge bg-primary">3</span> -->
                     <button type="button" class="btn btn-tool" data-card-widget="remove">
                     <i class="fas fa-times"></i>
                     </button>
                  </div>
               </div>
               <ul class="treee cscroll">
                  <?php
                  $accat= mysqli_query($conn,"SELECT ac_catid FROM ac_category WHERE ac_catid") or die(mysqli_error($conn));
                  while($acat= mysqli_fetch_assoc($accat)){
                  $ac_catid    = $acat['ac_catid'];
                  ?>
                  <dt class="text-success" style="font-size:15px;margin-left: -18px;">
                     <?php 
                        if($ac_catid==1) {
                          echo language(226); 
                        } elseif ($ac_catid==2) {
                          echo language(227); 
                       } elseif ($ac_catid==3) {
                          echo language(228); 
                       } elseif ($ac_catid==4) {
                          echo language(229); 
                       } elseif ($ac_catid==5) {
                          echo language(230); 
                       }
                     ?> 
                  </dt>
                  <hr style="margin-top: 0;margin-bottom: 4px;margin-left: -18px;">
                  <?php
                  $scat= mysqli_query($conn,"SELECT ac_s_cat_name,ac_g_catid,ac_g_cat_name,g_type FROM ac_sub_g_category LEFT JOIN ac_sub_category ON (ac_sub_category.ac_s_catid=ac_sub_g_category.ac_s_catid) WHERE ac_sub_category.ac_catid='$ac_catid' AND ac_sub_g_category.coid='$coid' AND ac_sub_g_category.g_type NOT IN('su-deb','su-cre') GROUP BY ac_g_catid") or die(mysqli_error($conn));
                  while($asat= mysqli_fetch_assoc($scat)){
                  $ac_g_catid    = $asat['ac_g_catid'];
                  $ac_g_cat_name = $asat['ac_g_cat_name'];
                  $g_type        = $asat['g_type'];
                  
                  $ac_s_cat_name = $asat['ac_s_cat_name'];
                  
                  $cacc = mysqli_num_rows(mysqli_query($conn,"SELECT acid FROM accounts LEFT JOIN ac_sub_g_category ON (accounts.gcatid = ac_sub_g_category.ac_g_catid) WHERE g_type='$g_type' AND (g_type='mcash' || g_type='invtr' || g_type='prls' || g_type='sl-inc' || g_type='cs-gds' || g_type='pu-exp') AND accounts.coid='$coid' AND bid ='$bid' AND brid='$brid' LIMIT 1"));
                  ?>
                  <li>
                     <a href='#' title="<?php echo $ac_s_cat_name;?>"><?php echo $ac_g_cat_name; if($cacc<1 && per('ac_add')==1) {?>
                        <i style='float:right;margin-left:5px;font-size: 15px;' class='fa fa-plus-square cshover'
                        onclick="pagecall('../accounts/add_accounts.php?gcatid=<?php echo $ac_g_catid;?>','#ac_view');"></i>
                        <?php } ?>
                       <i style='float:right;font-size: 15px;' class='fa fa-bar-chart fa-fw'></i></a>
                     <?php
                     $acc= mysqli_query($conn,"SELECT acid,ac_name,balance FROM accounts WHERE gcatid='$ac_g_catid' AND coid='$coid' AND bid ='$bid' AND brid='$brid' AND ac_type NOT IN('opening')") or die(mysqli_error($conn));
                     while($ac= mysqli_fetch_assoc($acc)){
                     $acid       = $ac['acid'];
                     $ac_name    = $ac['ac_name'];
                     $balance    = $ac['balance'];
                     ?>
                     <ul style="padding-left: 0;">
                        <hr style="margin:0;">
                        <li title="<?php echo $balance;?>">
                           <i class="fa-solid fa-folder-open"></i>
                           <a class="acid btn-raised ink-reaction" href="#" onclick="pagecall('../accounts/ac_profile.php?acid=<?php echo $acid;?>','#ac_view');">
                              <?php echo $ac_name;?>
                           </a>
                        </li>
                     </ul>
                     <?php } ?>
                  </li>
                  <hr style="margin-top: 1px;margin-bottom: 3px;">
                  <?php } }?>
               </ul>
            </div>
         </div>
         <div class="col-md-10" id="ac_view"></div>
      </div>
   </div>
</section>
<script type="text/javascript">
var tree = document.querySelectorAll('ul.treee a:not(:last-child)');
for(var i = 0; i < tree.length; i++){
tree[i].addEventListener('click', function(e) {
var parent = e.target.parentElement;
var classList = parent.classList;
if(classList.contains("open")) {
classList.remove('open');
var opensubs = parent.querySelectorAll(':scope .open');
for(var i = 0; i < opensubs.length; i++){
opensubs[i].classList.remove('open');
}
} else {
classList.add('open');
}
});
}
</script>
<style type="text/css">
ul.treee li {
list-style-type: none;
position: relative;
}
ul.treee li ul {
display: none;
}
ul.treee li.open > ul {
display: block;
}
ul.treee li a {
color: black;
text-decoration: none;
}
ul.treee li a:before {
height: 1em;
padding: 0px 0px 0px 0px;
font-size: 15px;
display: block;
position: absolute;
left: -18px;
top: -4px;
font-weight: bold;
}
ul.treee li > a:not(:last-child):before {
content: "\f07b";
font-family: FontAwesome;
text-decoration: inherit;
}
ul.treee li.open > a:not(:last-child):before {
content: "\f115";
font-family: FontAwesome;
text-decoration: inherit;
}
ul.treee {
max-height: 450px;
padding-left: 23px;
padding-right: 5px;
font-size: 12px;
overflow-y: hidden;
}
</style>