<div class="breadcrumb">
    <h1>User Permission</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li><?php echo isset($permissionDetail) ? 'Edit' : 'Add New'; ?> Permission</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3"><?php echo isset($permissionDetail) ? 'Edit' : 'Add New'; ?> Permission</div>
                <form action="" id='frm-permission' method="post">
                    <?php if(isset($permissionDetail->id)) { ?>
                       <input type="hidden" name="userPermission_id" value="<?php echo $permissionDetail->id ?>" />
                    <?php } ?>
                    <div class="row">
                        <div class="col-md-6 form-group mb-3">
                            <label for="title">Permission Name</label>
                            <input type="text" class="form-control" id="title" name="title"
                                   value="<?php echo $permissionDetail->title ?? '' ?>" required>
                        </div>

                        <div class="col-md-12">
                            <input type="submit" class="btn btn-primary" name="submit" value="Submit">
                            <input type="hidden" name="act" value="load">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
   
    $( "form" ).on( "submit", function(e) {
      e.preventDefault();
      var title = $("#title").val();
      

      if($("#title").val()=='')
       {
          $("#title").addClass('error');
          $("#title").focus();
          $("#msg_title").html('Please input name').show();
          return false;
        }
        else
        {
          if(title !='')
            {
              $("#title").removeClass('error');
              $("#msg_title").hide();
            }

          <?php if(!isset($_REQUEST['id']))
          { ?>  
              $.ajax({
                      url: "userPermissionadd.php",
                      data: { act:"load",
                            title:title },
                      method: 'POST',
                      success: function(msg){
                          if(msg!=''){
                             window.location='userPermission.php';
                              //return false;
                          }
                      }
                  });
            <?php }else{ ?>

                $.ajax({      
                    url: "userPermissionadd.php",
                    data: { act:"load",
                          title:title,id:<?php echo $_REQUEST['id']; ?> },
                    method: 'POST',
                    success: function(msg){
                        if(msg!=''){
                            window.location='userPermission.php';
                        }
                    }
                });

            <?php } ?>
      }

  });
      

</script>