<?php
  if( !hasPermission($_SESSION['user_detail']['role_id'], 'account_edit') ) {
    echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
  }
    
  $voucher_no          = vendorCode($conn);
  $g_act_codes         = accountCode($conn);
  function get_menu_tree($parent_id){
    global $conn;
    $menu = "";
    $sqlquery = "SELECT * FROM account_group where status='0' and parent_id='".$parent_id."'";
    $res=mysqli_query($conn,$sqlquery);
    while($row=mysqli_fetch_array($res,MYSQLI_ASSOC)){
      $menu .="<li><a style='color:#000; text-decoration:none;' data-toggle='collapse' href='#Web' aria-expanded='true' aria-controls='Web'><i class='fa fa-folder-open-o' aria-hidden='true'></i> ".$row['name']."</a>";
      $menu .= "<ul>".get_menu_tree($row['id'])."</ul>"; //call  recursively
      $menu .= "</li>";
    }
      return $menu;
  }
  $role = "SELECT * FROM `account_group` WHERE status ='0'";
  $role_result = mysqli_query($conn,$role);
  if (isset($_REQUEST['eid']) && !empty($_REQUEST['eid']) && $_REQUEST['eid']!=0){
    $select_update      ="SELECT * FROM account_group WHERE id='".$_REQUEST['eid']."'";
    $select_update_res  = mysqli_query($conn,$select_update);
    $update_row         = mysqli_fetch_array($select_update_res,MYSQLI_BOTH);
  }
?>
<section class="content-header">
  <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
        <h3 class="capital font15 padding5 bold">UPDATE ACCOUNT GROUP</h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
        <h3>
          <?php if( hasPermission($_SESSION['user_detail']['role_id'], 'account_list') ) { ?>
          <a href="index.php?page=account_group/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW ACCOUNT GROUP DETAILS</a>
          <?php } ?>
        </h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="hitz-top-header">
   <div class="row bottom40">
      <div class="col-xs-8">
         <div class="box box-success">
            <div class="box-body">
              <form action="account_group/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                
                <div class="row">
                  <div class="col-md-11">
                    <div class="col-md-12">
                      <div class="form-group">
                        <label class="capital">name</label><span style="color: red">*</span>
                        <input type="text" size="35" id="name" name="name" class="form-control required" placeholder="ACCOUNT GROUP NAME" autocomplete="off" value="<?php echo $update_row['name'];?>" />
                      </div>
                    </div>
                    <div class="col-md-12">
                      <div class="form-group">
                        <label class="capital">parent</label>
                        <select id="parent_id" name="parent_id" class="form-control select2">
                          <option></option>
                          <?php while ($rows = mysqli_fetch_array($role_result,MYSQLI_BOTH)) { ?>
                          <option  <?php if($rows['id'] == $update_row['parent_id']) { echo "selected='selected'"; } ?>  value="<?php echo $rows['id'] ?>"><?php echo $rows['name'] ?></option>
                          <?php } ?>
                        </select>
                      </div>
                    </div>
                    <div class="col-md-12">
                      <div class="form-group">
                        <label class="capital">Status</label><span style="color: red">*</span><br>
                        <label class="radio-inline fontradiobuttion">
                        <input type="radio" name="status" value="0" <?php if($update_row['status']=='0'){echo "checked";}?>> <span class="label-text">ACTIVE</span>
                        </label>
                        <label class="radio-inline fontradiobuttion">
                        <input type="radio" name="status" value="1" <?php if($update_row['status']=='1'){echo "checked";}?>> <span class="label-text">IN-ACTIVE</span>
                        </label>
                      </div>
                    </div>
                  </div>
                </div>
                
                <input type="hidden" value="<?php echo $_GET['eid'];?>" name="id" id="id">
                <hr>
                <div class="row" align="center">
                  <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> Update & Save</button>
                  <a href="index.php?page=account_group/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
              </form>
              
            </div>
         </div>
      </div>
      <div class="col-xs-4">
         <div class="box box-success">
            <div class="box-body">
              <div class="tree ">
                <ul>
                  <?php echo get_menu_tree(0);?>
                </ul>
              </div>
            </div>
         </div>
      </div>

   </div>
</section>
<script type="text/javascript">
   $(document).ready(function(){
    $('input').iCheck({
       checkboxClass: 'icheckbox_flat',
       radioClass: 'iradio_flat'
     });
    $('#parent_id').select2();
   });
</script>
<style type="text/css">
  .tree li {
    list-style-type:none;
    margin:0;
    padding:10px 5px 0 5px;
    position:relative
  }
  .tree li::before, 
  .tree li::after {
    content:'';
    left:-20px;
    position:absolute;
    right:auto
  }
  .tree li::before {
    border-left:2px solid #000;
    bottom:50px;
    height:100%;
    top:0;
    width:1px
  }
  .tree li::after {
    border-top:2px solid #000;
    height:20px;
    top:25px;
    width:25px
  }
  .tree li span {
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    border:2px solid #000;
    border-radius:3px;
    display:inline-block;
    padding:3px 8px;
    text-decoration:none;
    cursor:pointer;
  }
  .tree>ul>li::before,
  .tree>ul>li::after {
    border:0
  }
  .tree li:last-child::before {
    height:27px
  }
  .tree li span:hover {
    background: hotpink;
    border:2px solid #94a0b4;
    }

  [aria-expanded="false"] > .expanded,
  [aria-expanded="true"] > .collapsed {
  display: none;
  }
</style>