<?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;

        }


        .form-control[type=file]:not(:disabled):not([readonly]) {
    cursor: pointer;
    width: 600px;
}
          


    </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 Equipment</h3>

                            <ul class="breadcrumb">

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

                                <li class="breadcrumb-item active">Edit Equipment</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_equipment">

                                                      <input required="required" type="hidden" id="id" name="id"
                                                    value="<?php echo $getEditEqData['equipment_id']?>">


                                                     <div class="form-group row">

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

                                                        <div class="col-md-9">
                                                             <select class="form-control" style="width: 100%;" name="etype" id="etype">
                                                                <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($getEditEqData['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-3">Equipment Number</label>

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

                            <input type="text" class="form-control"  placeholder="Enter equipment number" name="fno" id="fno" value="<?php echo $getEditEqData['folder_no']?>">

                        </div>

                    </div>

                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-3">Equipment Name</label>

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

                                                            <input type="text" class="form-control" placeholder="Enter Equipment Name" name="name" id="name" value="<?php echo $getEditEqData['equipment_name']?>">

                                                        </div>

                                                    </div>

                                                


                                                    <div class="form-group row">

                                                        <label class="col-form-label col-md-3">Equipment Descripion</label>

                                                        <div class="col-md-9">
                                                            <textarea rows="5" cols="10" class="form-control" name="desp"><?php echo $getEditEqData['description']?></textarea>

                                                          
                                                        </div>

                                                    </div>

                                                        <div class="form-group  row">

                        <label class="col-form-label col-md-3">Equipment History</label>

                        <div class="col-md-9">
                            <textarea rows="5" cols="10" class="form-control" name="ehistory"><?php echo $getEditEqData['equipment_history']?></textarea>

                            
                        </div>

                    </div>

                     <div class="form-group row">

                        <label class="col-form-label col-md-3">Component</label>

                        <div class="col-md-9">
   <input type="text" class="form-control" placeholder="Enter component" name="cmp" id="cmp" value="<?php echo $getEditEqData['components']?>">

                        </div>

                    </div>

                      

                      <div class="form-group row">

                        <label class="col-form-label col-md-3">Inspection Finding</label>

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

                            <textarea rows="5" cols="5"  name ="inspfind"  id="inspfind" class="form-control" placeholder="Enter inspection finding"><?php echo $getEditEqData['inspection_finding']?>  </textarea>
<!-- 
                            <input type="text" class="form-control" value="" placeholder="Enter components number" name="cmp" id="cmp"> -->

                        </div>

                    </div>

                     <div class="form-group row">

                        <label class="col-form-label col-md-3">Inspection Date</label>

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

                            <input type="date" class="form-control"  placeholder="Enter previous inspection date" name="prevDate" id="prevDate" value="<?php echo $getEditEqData['previous_inspection_date']?>">

                        </div>

                    </div>

                    <div class="form-group row">

                        <label class="col-form-label col-md-3"> Inspection Due Date</label>

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

                            <input type="date" class="form-control"  placeholder="Enter  inspection due date" name="dueDate" id="dueDate" value="<?php echo $getEditEqData['inspection_due_date']?>">

                        </div>

                    </div>

                    <?php if($getEditEqData['getAttachment'] != 'NA'){?>

                     <div class="form-group row">

                                                        
                                                        <?php foreach ($getEditEqData['getAttachment']     as $key => $value) { ?>
                                                          
                                                      

                                                        <div class="col-sm-3 my-3">
                                                         
                                                          <img class="" alt="User Image" src=""  onerror="this.src='assets/images/uploadfile.png';" width="50px" height="50px">
                                                          <br>
                                                          <a href="<?php echo $img_url_user_main.$value['attachment']?>" target='_blank'><?php echo $value['attachment']?></a>

                                                          
                                                        </div>
                                                         <?php }?>

                                                    </div>
                                                <?php } ?>



                     <div class="form-group row">

                        <label class="col-form-label col-md-3">Summary</label>

                        <div class="col-md-9">
                            <textarea rows="5" cols="10" class="form-control" name="summary"><?php echo $getEditEqData['summary']?></textarea>

                            
                        </div>

                    </div>



                                                <div class="field_wrapper1">
                                                            <div class="row">  
                              <label class="col-form-label col-md-3">Attachment</label>
    <div class="col-sm-3 col-md-3"> <div class="form-group mt-3">
          <a href="javascript:void(0);" class="add_button1" title="Add field">&nbsp;&nbsp;+ Add More</a>
       
      </div>
  </div>

                                </div>
                         </div>




                                                   


                                                  



                                                     



                                                     


                                                  

                                                   








                                                    <div class="form-group row">

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

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

                                                            <button class="btn btn-primary "  type="submit">Edit Equipment</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>

     var addButton = $('.add_button'); // Add more button selector
      var wrapper = $('.field_wrapper');
            

            var fieldHTML = `<div class="form-elements d-flex ml-3">
                    <div class="form-group">
                            <label for="product_name"></label>
                    <input type="text" class="form-control" placeholder="Enter component" name="cmp[]">
                    </div>
                    
                    <div class="form-group mt-5">
                    <a href="javascript:void(0);" class="remove_button" title="Add field">Remove</a>
                    </div>
                </div>`; //New input field html 

            var x = 1; //Initial field counter is 1

            $(addButton).click(function () {
                //Check maximum number of input fields
                if (x < 100) {
                    x++; //Increment field counter
                    $(wrapper).append(fieldHTML);
                }
            });

            //Once remove button is clicked
            $(wrapper).on('click', '.remove_button', function (e) {
                e.preventDefault();
                $(this).parent().closest(".form-elements").remove();
                x--; //Decrement field counter
            });



             var addButton1 = $('.add_button1'); // Add more button selector
      var wrapper1 = $('.field_wrapper1');
            

            var fieldHTML1 = ` <div class="field_wrapper1"><div class="row form-elements">  
                              <label class="col-form-label col-md-3"></label>
    <div class="col-sm-9 col-md-9"> <div class="form-group mt-3">
          <div class="form-group mt-5 d-flex justify-content-between">
            <input type="file" class="form-control attachment_field" value="" placeholder="Enter previous inspection date" name="attachment[]" id="attachment">
             
                    <a href="javascript:void(0);" class="remove_button1" title="Add field">&nbsp;&nbsp;Remove</a>
                    </div>
       
      </div>
  </div>

                                </div>
                         </div>
                         </div>
`; //New input field html 

            var x = 1; //Initial field counter is 1

            $(addButton1).click(function () {
                //Check maximum number of input fields
                if (x < 100) {
                    x++; //Increment field counter
                    $(wrapper1).append(fieldHTML1);
                }
            });

            //Once remove button is clicked
            $(wrapper1).on('click', '.remove_button1', function (e) {
                e.preventDefault();
                $(this).parent().closest(".form-elements").remove();
                x--; //Decrement field counter
            });
        
    
        
    


     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: {
                       

                     name: {
                      required: true,
                         
                            maxlength:150,
                            noSpace: true,
                      
            //           remote: {

            //         url: URLAPI+'user_controller.php',

            //         type: 'get',

            //         data: {

            //             'action': 'equipment_check_edit',

            //             'name': function() {

            //                 return $("#name").val();

            //             },
            //             'etype': function() {

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

            //             },
            //                'eq_no': function() {

            //     return $("#fno").val();

            // },

            //             'id': function() {

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

            //             },

                        

            //         }

            //     },
               

                  },

                   desp:
                    {
                        required:true,
                    },

                    fno:{
    required:true,

},
 ehistory:
    {
        required:true,
    },

    cmp:{
    required:true,
    noSpace:true,
    maxlength:150,
},

inspfind:{
    required:true,
    noSpace:true,
},

prevDate:{
    required:true,
},
dueDate:{
    required:true,
},

                          
                    

                     etype:{
                        required:true,
                    },

                   

                 

                    },
                    messages: {
                       
                        name: {
                            required: "Please enter equipment name",
                           
                            maxlength: " Maximum 150  characters  allowed in equipment name ",
                            //remote: "Equipment name already exists! ",
                        },
                       

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

                    fno:{
    required:"Please choose equipment number",

},

 ehistory:
    {
        required:'Please enter equipment history',
    },
                        
                        

                   

                    desp:
                    {
                        required:'Please enter description',
                    },

                    fno:{
    required:"Please enter folder number",
    
},

cmp:{
    required:"Please enter components",
    
    maxlength:"Maximum 150 characters allowed in components",
},

inspfind:{
    required:"Please enter inspection finding",
   
},

prevDate:{
    required:"Please enter previous inspection  date",
},
dueDate:{
    required:"Please enter inspection  due date",
},

                    

                    


                    },
                  

                    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,"manage_equipment.php","success");
        // $('#add_driver').modal('hide');
        // $('#image-holder').attr('src','');
        // getUserTable('first', 'all');
        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 RemoveAnswer(event){
            var cmp_id =$(event).attr('data-id');;
            swal({
              title: '',
              text: 'Are you sure you want to delete components?',
              icon: "warning", //error, success, info
              buttons:  ["Cancel", "Ok"],
              //dangerMode: true,
            })
            .then((willDelete) => {
              if (willDelete) {
                btnUserDeleteContinue(event, cmp_id);
              } else {
                //swal("Your imaginary file is safe!");
              }
            });
        }
     function btnUserDeleteContinue(event, cmp_id){
    
        var link = URLAPI+'manage_all_controller.php';
        var data = {
            action:'delete_components',
            cmp_id:cmp_id,
        }
    
        var messsage = msgLoading.blankMessage[language];
        console.log('messsage',messsage);
        
        apiRequest.get(link, data, messsage).then(function(obj){
            console.log('obj',obj);
            if(obj.success === true) { 
            var title = '';
          
            var messsage = obj.msg[language];
            swal_alert(title,messsage,"edit_equipment.php?id=<?php echo $_GET['id']?>","success");
            //getUserTable('first', 'all');
            //-------------- DataTable Row Action end ---------
            return false;
                
    
            } 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>