<?php 



include('libraryPHP/site_config.php');

include('libraryPHP/session_check_url.php');





?>


<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">

    <title><?php echo $appName?> | <?php echo $pageTitle?></title>

 <?php echo $appFaviconHtml ?>

    <!-- theme css start -->

     <?php include("commoncss.php"); ?>

    <!-- theme css end -->

    <style>

        .eye {

            position: absolute;

            right: 4%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword1 {

            position: absolute;

            right: 52%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword2 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword3 {

            position: absolute;

            right: 52%;

            transform: translate(0, -176%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword4 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword5 {

            position: absolute;

            right: 52%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }



        #togglePassword6 {

            position: absolute;

            right: 154%;

            transform: translate(0, -174%);

            top: auto;

            cursor: pointer;

        }
        


    </style>




</head>



<body>



    <!-- Main Wrapper -->

    <div class="main-wrapper">



        <!-- Header start  -->

        <?php include("header.php"); ?>

        <!-- /Header end -->



        <!-- Sidebar -->

        <?php include("sidebar.php"); ?>

        <!-- /Sidebar -->



        <!-- Page Wrapper -->

        <div class="page-wrapper">



            <div class="content container-fluid">



                <!-- Page Header -->

                <div class="page-header">

                    <div class="row">

                        <div class="col">

                            <h3 class="page-title">Edit Maintainance</h3>

                            <ul class="breadcrumb">

                                <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
                                <li class="breadcrumb-item"><a href="manage_maintainance.php">Manage Maintainance</a></li>

                                <li class="breadcrumb-item active">Edit Maintainance</li>

                            </ul>

                        </div>

                    </div>

                </div>

                <!-- /Page Header -->



                <!-- start write start -->

                <div class="col-12">



                    <div class="card">



                        <div class="card-body">

                           



                           <form method="POST" id="add_subadmin_form" class="form-horizontal"
                           enctype="multipart/form-data">
                           <input required="required" type="hidden" id="action" name="action"
                           value="edit_maintainance">

                           <input type="hidden" name="id" id="id" value="<?php echo $getEditEqData1['maintainance_id']?>">




                           <div class="form-group row">

                            <label class="col-form-label col-md-2">Select Equipment Type</label>

                            <div class="col-md-10">
                             <select class="form-control" style="width: 100%;" name="etype" id="etype" onchange="findCategory(this)">
                                <option value="" selected hidden disabled="">Choose Equipment Type</option> 

                                <?php 
                                $user_id    =   0; 
                                $name           =   '';
                                if(!empty($getEditData['cat_ary'])){
                                    foreach($getEditData['cat_ary'] as $value) {
                                        $category_id    =   $value['category_id'];
                                        $category_name           =   $value['category_name'];
                                        
                                        ?>
                                        
                                        <option value="<?php echo $category_id;?>" <?php if($getEditEqData1['equipment_type_id'] == $category_id){ echo 'selected';}?>><?php echo $category_name;?></option> 

                                        <?php  
                                    }
                                } 
                                ?>  

                            </select>

                        </div>

                    </div>


                           <div class="form-group row">

                            <label class="col-form-label col-md-2">Select Equipment </label>

                            <div class="col-md-10">
                             <select class="form-control" style="width: 100%;" name="equipment" id="equipment">
                                
                            <option value="" selected hidden disabled="">Choose Equipment Type</option> 

                                <?php 
                                $user_id    =   0; 
                                $name           =   '';
                                //print_r($getEditEqData);exit;
                                if(!empty($getEditEqData1['equipment_ary'])){
                                    foreach($getEditEqData1['equipment_ary'] as $value) {
                                        $equipment_id    =   $value['equipment_id'];
                                        $equipment_name           =   $value['equipment_name'];
                                        
                                        ?>
                                        
                                        <option value="<?php echo $equipment_id;?>" <?php if($getEditEqData1['equipment_id'] == $equipment_id){ echo 'selected';}?>><?php echo $equipment_name;?></option> 

                                        <?php  
                                    }
                                } 
                                ?>  
                            </select>

                        </div>

                    </div>

                     <div class="form-group row">

                        <label class="col-form-label col-md-2">Maintainance Title</label>

                        <div class="col-md-10">

                            <input type="text" class="form-control"  placeholder="Enter Maintainance Title" name="ititle" id="ititle" value="<?php echo $getEditEqData1['maintainance_title']?>">

                        </div>

                    </div>

                    <div class="form-group row">

                        <label class="col-form-label col-md-2">Maintainance Date</label>

                        <div class="col-md-10">

                            <input type="date" class="form-control"  placeholder="Enter Maintainance Date" name="idate" id="idate" value="<?php echo $getEditEqData1['maintainance_date']?>">

                        </div>

                    </div>

                     <div class="form-group row">

                        <label class="col-form-label col-md-2">Next Maintainance Date(Optional)</label>

                        <div class="col-md-10">

                            <input type="date" class="form-control"  placeholder="Enter Next Maintainance Date" name="nidate" id="nidate" value="<?php echo $getEditEqData1['maintainace_next_date']?>">

                        </div>

                    </div>

                    


                   

                    



                    <div class="form-group row">

                        <label class="col-form-label col-md-2"></label>

                        <div class="col-md-10">

                            <button class="btn btn-primary"  type="submit">Edit Maintainance</button>

                        </div>

                    </div>





                </form>




            </div>



        </div>



    </div> <!-- end col -->



    <!-- start write end -->

</div>

</div>

<!-- /Page Wrapper -->

<!-- footer start -->

<?php include("footer.php"); ?>

<!-- footer end -->



</div>

<!-- /Main Wrapper -->



<!-- sctipt start  -->

<?php include('commonjs.php')?>

<?php include_once('extrajs.php') ?>
<!-- script end -->

<script>

 jQuery.validator.addMethod("noSpace", function(value, element) { 
  return value == '' || value.trim().length != 0;  
}, "No space please and don't leave it empty");


 $.validator.addMethod("customemail", 
    function(value, element) {
        return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value);
    }, 
    "Enter valid email"
    ); 
 $('#add_subadmin_form').validate({
    rules: {
       

     ititle: {
      required: true,
      
      maxlength:50,
      noSpace: true,
      
      remote: {

        url: URLAPI+'user_controller.php',

        type: 'get',

        data: {

            'action': 'maintainance_check_edit',

            'ititle': function() {

                return $("#ititle").val();

            },
            'etype': function() {

                return $("#etype").val();

            },
             'equipment': function() {

                return $("#equipment").val();

            },
            'id': function() {

                return $("#id").val();

            },

            

        }

    },
    

},

idate:
{
    required:true,
},






etype:{
    required:true,
},

equipment:{
    required:true,
},





},
messages: {
   
    ititle: {
        required: "Please enter Maintainance title",
        
        maxlength: " Maximum 50  characters  allowed in Maintainance title",
        remote:"Maintainance title already exists!",
    },

    idate:{
    required:"Please enter Maintainance date",
    
},
    

    etype:{
        required:"Please choose equipment type",
    },

    equipment:{
        required:"Please choose equipment ",
    },
    
    

    

  

    

    


},


submitHandler:function(form,e){

   
 
  

       //e.preventDefault();
       var link=URLAPI+'manage_all_controller.php';
       var data = new FormData($(form)[0]);
       var message = msgLoading.blankMessage[language];
       console.log('message',message);

       apiRequest.postFile(link,data,message).then(function(obj){
          if(obj.success === true){
            var title ='';
            var message = obj.msg[language];
            swal_alert(title,message,"edit_maintainance.php?id=<?php echo $_GET['id']?>","success");
        // $('#add_driver').modal('hide');
        // $('#image-holder').attr('src','');
        // getUserTable('first', 'all');
        //$('#add_subadmin_form')[0].reset();
        return false;

    }else{
        var title = msgTitleOperation.StaffNotAdded[language];
        var message = obj.msg[language];
        swal_alert(title,message,'#','error');
        return false;
    }
},function(err){

  consoleProvider.log('err',err);
  var title    = msgTitleOperation.errorOnServer[language];
  var messsage = msgOperations.errorOnServer[language];
  swal_alert(title,message,"#","warning");
  return false;

});

  }//end of submit handler
});




      function findCategory(self) {
          //alert($(self).val());
        var link = URLAPI + 'manage_all_controller.php';
        var data = {
          action: 'get_equipment_name',
          type:'all',
          sel2:$(self).val(),
        }
        apiRequest.get(link, data).then(function(obj) {
              console.log('obj', obj);
              if (obj.success === true) {
                $("#equipment").html("");
                 var sub_array = obj.data.user_arr;
              
             
                $("#equipment").html("<option value=''>Select equipment</option>");
             
              var html_subcat='';
              $.each(sub_array, function(keysub, valuesub){
            //  for(var i=0;i<sub_array.length;i++){
                html_subcat=  $("#equipment").append('<option value="'+valuesub.equipment_id+'">'+valuesub.equipment_name+'</option>');
            //  }
              });
                    }
                    else {
                      //------------ Operation Message --------------------
                      var title = msgTitleOperation.userDeleted[language];
                      var messsage = obj.msg[language];
                      msgSuccessErrorHtml.error(title, messsage, msgSuccessErrorHtmlSelector);
                      //------------ Operation Message End--------------------
                      return false;
                    }
                  },
                  function(err) {
                    console.log('err', err);
                    //alert('Server not responde');
                    //------------ Operation Message --------------------
                    var title = msgTitleOperation.errorOnServer[language];
                    var messsage = msgOperations.errorOnServer[language];
                    msgSuccessErrorHtml.warning(title, messsage, msgSuccessErrorHtmlSelector);
                    //------------ Operation Message End--------------------
                    return false;
                  });
            }



</script>




</body>



</html>