<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
             <?php
               echo isset($title) ? $title : NULL;
             ?>
          </h1>
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-lg-12">
                    <div class="box box-primary">
                        <div class="box-header with-border">
                          <h3 class="box-title">Edit Employee</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        
                        <?php
                        if(isset($message))
                        {
                            echo $message;
                        }
                        ?>
                        <form role="form" method="post" enctype="multipart/form-data">
                          <div class="box-body">
                            <div class="form-group">
                              <label for="exampleInputEmail1">Employee Name</label>
                              <input type="text" name="name" value="<?php echo $user['name']; ?>" class="form-control" id="" placeholder="Enter Employee Name">
                            </div>
                            
                            <div class="form-group">
                              <label for="exampleInputEmail1">Email Address</label>
                              <input type="email" name="email" value="<?php echo $user['mail']; ?>" class="form-control" id="" placeholder="Enter Employee Email Address">
                            </div>
                            <div class="form-group">
                              <label for="exampleInputEmail1">Phone</label>
                              <input type="text" name="phone" value="<?php echo $user['phone']; ?>" class="form-control" id="" placeholder="Enter Employee Phone">
                            </div>  
                            <div class="form-group">
                              <label for="">Employee Birth Date</label>
                              <input type="text" name="birth_date" value="<?php echo $employee['birth_date']; ?>" class="form-control datePickerInput" id="" placeholder="Enter Employee Birth Date">
                            </div> 
                            
                            <div class="form-group">
                              <label for="exampleInputEmail1">Address</label>
                              <input type="text" name="address" value="<?php echo $user['address']; ?>" class="form-control" id="" placeholder="Enter Employee Address">
                            </div> 
                            <div class="form-group">
                              <label for="availability" class="set-block">Gender</label>
                              <div class="radio radio-info  radio-inline">
                                 <input type="radio" id="inlineRadio3" value="1" name="gender" <?php if($user['gender']==1 ) echo "checked"; ?>>
                                 <label for="inlineRadio3"> Male </label>
                              </div>
                              <div class="radio radio-info  radio-inline">
                                 <input type="radio" id="inlineRadio4" value="2" name="gender" <?php if($user['gender']==2) echo "checked"; ?>>
                                 <label for="inlineRadio4"> Female </label>
                              </div>
                           </div> 
                            <div class="form-group">
                              <label for="exampleInputEmail1">Fixed Salary</label>
                              <input type="text" name="fixed_salary" value="<?php echo $employee['fixed_salary']; ?>" class="form-control" id="" placeholder="Enter Fixed Salary">
                            </div> 
                            <div class="form-group">
                              <label for="exampleInputEmail1">Fixed Commission</label>
                              <input type="text" name="fixed_commision" value="<?php echo $employee['fixed_commision']; ?>" class="form-control" id="exampleInputEmail1" placeholder="Enter Fixed Commission">
                            </div> 
                            
                             <div class="form-group">
                              <label for="exampleInputEmail1">Social Security Number</label>
                              <input type="text" name="ssn" value="<?php echo $employee['ssn']; ?>" class="form-control" id="" placeholder="Enter Ssn">
                            </div>
                              
                            <div class="form-group">
                              <label for="exampleInputEmail1">Snapshot</label>
                                <textarea name="snapshot" class="form-control"><?php echo $employee['snapshot']; ?></textarea>
                            </div> 
                                
                             <div class="form-group">
                              <label for="exampleInputEmail1">Admin Type</label>
                                <select name="admin_type" id="admin_type" class="form-control">
                                    <option value="0">Select Admin Type</option>
                                    <?php
                                        if (is_array($adminTypes) && count($adminTypes)>0){
                                            foreach ($adminTypes as $type):
                                                if($type['id'] == $employee['admin_type_id'])
                                                {
                                                    echo '<option selected value="'.$type['id'].'">'.$type['type'].'</option>';
                                                }else{
                                                    echo '<option value="'.$type['id'].'">'.$type['type'].'</option>';
                                                }
                                                endforeach;
                                        }else{
                                            echo '<option value="">There Is No Types</option>';
                                        }
                                    ?>
                                </select>    
                            </div>  
                              
                             
                            <div class="form-group">
                              <label for="availability" class="set-block">Status</label>
                              <div class="radio radio-info  radio-inline">
                                 <input type="radio" id="inlineRadio1" value="1" name="status" <?php if($user['status']==1 ) echo "checked"; ?>>
                                 <label for="inlineRadio1"> Active </label>
                              </div>
                              <div class="radio radio-info  radio-inline">
                                 <input type="radio" id="inlineRadio2" value="2" name="status" <?php if($user['status']==2 ) echo "checked"; ?>>
                                 <label for="inlineRadio2"> Not Active </label>
                              </div>
                           </div>  
                            <div class="form-group">
                                  <label for="password" class="set-block">Password </label>
                                    <a href="" data-toggle="modal" data-target="#changepassword" class="">Edit Employee Password</a>
                            </div>
                            
                            <div class="form-group">
                                <label for="website-logo">Ssn Image</label>
                                <img src="<?php echo UPLOAD_LINK.$employee['ssn_image'] ?>" data-id="<?php echo $user['id'] ?>" data-toggle="modal" data-target="#employee_ssn" class="img-responsive change-logo employee_ssn" />
                                <p class="help-block">Update Ssn Image</p>
                            </div>    
                              
                          </div>
                          <!-- /.box-body -->

                          <div class="box-footer">
                            <button type="submit" name="edit" class="btn btn-primary">Edit</button>
                          </div>
                        </form>
                      </div>
                      <!-- /.box -->
                </div>
            </div>
      </section><!-- /.content -->
</div><!-- /.content-wrapper -->
<!-- Start change Password  Modal -->
<div class="modal fade" id="changepassword" role="dialog">
   <div class="modal-dialog modal-md">
      <!-- Modal content-->
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Edit User Password</h4>
         </div>
         <div class="modal-body">
            <div class="row">
               <div class="col-lg-12 pull-left">
                   <div id="updatePasswordResult"></div>
                  <form id="EditPassword">
                      
                     <div class="form-group">
                        <label for="category-image">New Password</label>
                        <input type="password" class="form-control"  id="password" name="password">
                        <p class="help-block">Insert New Password.</p>
                     </div>
                      <div class="form-group">
                        <label for="category-image">Confirm New Password</label>
                        <input type="password" class="form-control" id="repassword" name="repassword">
                        <p class="help-block">Re-Type New Password.</p>
                     </div>
                      <input type="hidden" name="user_id" value="<?php echo $user['id'] ?>" />
                     <input type="submit" class="btn btn-primary" name="editPass" value="Save" />
                  </form>
               </div>
            </div>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         </div>
      </div>
   </div>
</div>
<!--End change password Modal-->



<!-- Start editssn image  Modal -->
<div class="modal fade" id="employee_ssn" role="dialog">
   <div class="modal-dialog modal-md">
      <!-- Modal content-->
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Edit Ssn Image</h4>
         </div>
         <div class="modal-body">
         <div id="updateImageResult"></div>
            <div class="row">
               <div class="col-lg-9 pull-left">
                  <form id="updateImage" method="post" enctype="multipart/form-data">
                     <div class="form-group">
                        <label for="category-image"> Image</label>
                        <input type="file" name="image_name" id="image-file">
                        <p class="help-block">Choose Image.</p>
                     </div>
                     <input type="hidden" value=""  class="field_id" name="field_id" />
                     <input type="submit" class="btn btn-primary updatebtn" name="editImage" value="Save" />
					  <span class="loadingImage">
					  	<img src="customize\backend\images\Preloader_61.gif" />
					  </span>
                  </form>
               </div>
               <div class="col-lg-3 pull-right">
                  <img src="" alt="" title="Edit Image" class="img-responsive old-image" />
               </div>
            </div>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         </div>
      </div>
   </div>
</div>
<!--End Edit ssn image Modal-->
    <script type="text/javascript">
        $(document).ready(function(){
             //start edit password
    $("#EditPassword").submit(function(){
         var formData = $(this).serialize();
         var allData  = formData + "&action=editPass";
                $.ajax({
                    url: "<?php echo BASE_URL."employee/update_password"; ?>",
                    type:"POST",
                    data: allData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                    beforeSend:function(){
                    },
                    statusCode: {
                     404: function() {
                       alert( "page not found" );
                      },
                      },
                      success:function(valdata) {
                          //alert(valdata);
                         var da = jQuery.parseJSON(valdata);
                          //alert("")
						  if(da['status'] == "success")
						  {
							$("#updatePasswordResult").html(da['message']);
							setTimeout(function(){$('#changepassword').modal('hide');}, 2000);
						  }else{
							 $("#updatePasswordResult").html(da['message']); 
						  }
                      }
                });
                return false;
             });
    //end edit password
             // start edit ssn pic
	 $(".employee_ssn").click(function () {
             $("#updateImageResult").html("");
             // get id for update
             var myId = $(this).attr("data-id");
             // get image
             var image = $(this).attr("src");
             // set image into model
             $(".old-image").attr("src",image);
             // set  id in hidden input
             $(".field_id").attr("value",myId);
             $("#updateImage").submit(function(){
                $.ajax({
                    url: "<?php echo BASE_URL."employee/update_ssn_image"; ?>",
                    type: "POST",
                    data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                    contentType: false,       // The content type used when sending data to the server.
                    processData:false,
                    beforeSend:function(){
						$(".loadingImage").show();
                    },
                    statusCode: {
                     404: function() {
                       alert( "page not found" );
                      },
                      },
                      success:function(valdata) {
						  $(".loadingImage").hide();
                         var da = jQuery.parseJSON(valdata);
                        if(da['status'] == "success")
                        {
                          $("#updateImageResult").html('<div class="alert alert-success" role="alert"><strong>Success </strong> Image Updated Successfuly </div>');
                          $('#employee_ssn').modal('hide')
                          // get image row id to change image when success
                          var filedId = $(".field_id").val();
                          $('.employee_ssn').attr("src","<?php echo UPLOAD_LINK; ?>"+da['newImage']);

                        }else{
                          $("#updateImageResult").html('<div class="alert alert-danger" role="alert"><strong> Error ! </strong> Error Update Your Image (Not Allowed Image Extension Or You Did Not Choose Image)</div>');
                        }
                      }
                });
                return false;
             });
           });
         // end edit ssn pic
            // start add  to date picker
            var queryDate = '<?php echo $employee['birth_date'] ?>',
            dateParts = queryDate.match(/(\d+)/g),
            realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);  
            $('.datePickerInput').datepicker("setDate", realDate);
            // end add to date picker
            
            // get all governate's
            $("#country").change(function(){
                // get country id
                var countryId  = $(this).val();
                $.ajax({
                    url:'<?php echo BASE_URL."governate/retreive_all_governates_by_country_id" ?>',
                    type: 'POST',
                    data:{country_id: countryId},
                    success:function(result){
                        if(result == null || result == "null" || result == false) {
                            $("#governate").html("<option value=''>there's no governates </option>");
                        }else{
                            // remove all childes 
                             $("#governate").empty();
                            var responseData = JSON.parse(result);
                            if(responseData['status'] == "success")
                            { 
                                var text = "<option value='0'>Select Governate</option>";
                                for(i = 0; i< responseData['governates'].length;i++)
                                {
                                    text += '<option value="'+responseData['governates'][i]['id']+'">'+responseData['governatesEn'][i]['name']+'</option>';	
                                }
                                $("#governate").html(text);
                            }else{
                                $("#governate").html("<option value='0'>No Data Found</option>");
                            }
                            
                        }
                    }
                });
            });
            
             // get all cites's
            $("#governate").change(function(){
                // get country id
                var governateId  = $(this).val();
                $.ajax({
                    url:'<?php echo BASE_URL."city/retreive_all_cities_by_governate_id" ?>',
                    type: 'POST',
                    data:{governate_id: governateId},
                    success:function(result){
                        if(result == null || result == "null" || result == false) {
                            $("#city").html("<option value=''>there's no Cities </option>");
                        }else{
                            // remove all childes 
                             $("#city").empty();
                            var responseData = JSON.parse(result);
                            if(responseData['status'] == "success")
                            { 
                                var text2 = "<option value='0'>Select Governate</option>";
                                for(i = 0; i< responseData['cities'].length;i++)
                                {
                                    text2 += '<option value="'+responseData['cities'][i]['id']+'">'+responseData['citiesEn'][i]['name']+'</option>';	
                                }
                                $("#city").html(text2);
                            }else{
                                $("#city").html("<option value='0'>No Data Found</option>");
                            }
                            
                        }
                    }
                });
            });
            
            
        });
    </script>
