<?php  include_once('config/db.php'); include_once('config/check.php');  


 
if (filter_has_var(INPUT_POST, "submit")) 
try{
      $name =       htmlspecialchars ( $_POST['name']);
      $url =         $_POST['url'];
      $icon =      '<i class="fa fa-circle-o"></i>' ;   //$_POST['icon'];
      $module =       htmlspecialchars ( strtoupper($_POST['module']));
      $submodule =       htmlspecialchars ( strtoupper($_POST['submodule']));
      $submodulechild =       htmlspecialchars ( strtoupper($_POST['submodulechild']));
     
      $display =     0; //  htmlspecialchars ( strtoupper($_POST['display']));
      $active=1 ;
     

$sql = 'INSERT INTO sys_page (module,submodule,submodulechild,name,url,icon,active) VALUES(:module,:submodule,:submodulechild,:name,:url,:icon,:active )';
$conn->prepare($sql)->execute(['module' => $module,'submodule'=>$submodule,'submodulechild'=>$submodulechild , 'name' => $name,'url' => $url ,'icon'=>$icon , 'active'=>$active  ]);
header("location:syspage.php");

  } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}
                  
?>

<!DOCTYPE html>
<html>
<head>
<?php include_once('inc/link.php');   ?>

</head>
<body <?php include_once('inc/nav.php');  ?>>
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
    <?php include_once('inc/brand.php');   ?>


    <!-- Header Navbar -->
       <?php include_once('inc/navbar.php');   ?>

   
  </header>
 
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
     <?php include_once('inc/menu.php');   ?>
     
    <!-- /.sidebar -->
  </aside>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">

<!-- Main content -->


 <section class="content container-fluid"> 
        <div class="box box-success box-xs">
            <div class="box-body">
                <div class="row">
                    <form class="form-horizontal"  action="" method="post" >
                  <!----../ BANK NAME --->
                        
                               
                                <div class="col-md-12 ">
                                    <div class="col-md-12"><legend> <i class="fa fa-laptop"></i> Add System page </legend></div>
                                    <div class="col-sm-4">
                                        <label> Module  </label>
                                          <select class="form-control js-example-basic-single   "  required="" id="country" name="module" style="width:100%" >
                                            <option > Select your option </option>
                                            <?php $stmt = $conn->prepare("SELECT * FROM sys_module  where active=1 ");
                                              $stmt->execute(); foreach ($stmt as $row) {?>
                                                      
                                                    <option value="<?php echo $row['id']; ?>"><?php
                                                        echo $row['name']; ?></option> <?php } ?>
                                          </select> 
                                       
                                    </div>  
                                    <div class="col-sm-4">
                                        <label> subModule  </label>
                                        <select  class="form-control js-example-basic-single" id="state" name="submodule">
                                            <option value="">Select state</option>
                                         </select>
                                    </div>  
                                    <div class="col-sm-4">
                                        <label> Sub module  Child  </label>
                                        <select   class="form-control js-example-basic-single " id="city" name="submodulechild">
                                            <option value="">Select city</option>
                                        </select>                                        
                                    </div>  

                                    <div class="col-sm-4">
                                        <label> PAGE NAME  </label>
                                        <input type="text" class="form-control " name="name"   autocomplete="off">
                                    </div>                    
                                    <div class="col-sm-4">
                                        <label>  PAGE URL </label>
                                        <input type="text" class="form-control " name="url"  autocomplete="off">   
                                    </div>
                                </div>
                                                     
                <!-- submit button -->
                        <div class="form-group">                              
                              <div class="col-sm-offset-4 col-sm-10" style="padding:2rem;">
                                    <button type="submit"  name="submit" class="btn btn-success col-md-3">  <i class="fa fa-plus"></i>  Add system page  </button> </div>
                        </div> 
                </form>
                
                   
                </div>
            </div>
        </div>
                                
    </section>

    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Main Footer -->
  <footer class="main-footer">
    <?php  include_once('inc/footer.php'); ?>
  </footer>
  
</div>



<!-- REQUIRED JS SCRIPTS -->
<?php include_once('inc/linkjs.php') ?>
 
<script>
$(document).ready(function(){
    $('#country').on('change', function(){
        var countryID = $(this).val();
        
        if(countryID){
            $.ajax({
                type:'POST',
                url:'ajax.syspage.php',
                data:'country_id='+countryID,
                success:function(html){
                    $('#state').html(html);
                    $('#city').html('<option value="">Select state first</option>'); 
                }
            }); 
        }else{
            $('#state').html('<option value="">Select country first</option>');
            $('#city').html('<option value="">Select state first</option>'); 
        }
    });
    
    $('#state').on('change', function(){
        var stateID = $(this).val();
        if(stateID){
            $.ajax({
                type:'POST',
                url:'ajax.syspage.php',
                data:'state_id='+stateID,
                success:function(html){
                    $('#city').html(html);
                }
            }); 
        }else{
            $('#city').html('<option value="">Select Submodule  first</option>'); 
        }
    });
});
</script>

 
</body>
</html>