<?php include("../secure.php"); ?>
<?php include("../Function/salf_from_smak.php"); ?>
<?php 
include("dbConfig.php");
$a=array();
$sql_comv="SELECT * FROM waseet_company_user_tbl where system_id='2222' AND deleted='0'AND user_id='".$_SESSION['user_id']."' GROUP BY company_id ";
$result_comv = $conn->query($sql_comv);
if ($result_comv->num_rows > 0) {
while($row_comv = $result_comv->fetch_assoc()) {
$company_id_all=$row_comv['company_id']; //echo $company_id_all.'<br>';
array_push($a,$company_id_all);
  // echo $_SESSION['user_id'].'<br>';
  }} 
  // print_r($a);
  ?>
<?php //echo  $company_id;
//echo $urow['user_type'];
$ids = join("','",$a);
$lang = $_POST["lang"]; 
$id = $_POST["id"];
$id_level = $_POST["id_level"];
$id_company = $_POST["id_company"];
$id_type = $_POST["id_type"];
$id_emp = $_POST["id_emp"];
$f_type = $_POST["f_type"];
$account_number = coonect_employ_with_auhdacount_tn($id_emp,$id_company);
$raseed_auhd = reaseedSALFsmak($account_number,$id_company);
?>

<?php if($f_type=="qid"){ ?>
  <input type="hidden" name="f_type" id="f_type" value="<?php echo $f_type;?>">
<div style="width:40px;hieght10px;" class="btn btn-success add_cp" id="<?php echo $id;?>">+</div>
<div class="col-lg-3 col-sm-6 col-12">  
                         <div class="form-group row"> 
                          <select class="form-select form-select-sm company_qid" name="company_qid<?php echo $id?>0" id="company_qid<?php echo $id?>0" data-id="<?php echo $id?>" data-idd="0" style="width: 200px;"><?php
                         
                         if($urow['user_type']=="System_Manager"){
                       $sql_com="SELECT * FROM waseet_company_user_tbl GROUP BY company_id ";
                         }else{
                        $sql_com="SELECT * FROM waseet_company_user_tbl where deleted='0' AND company_id IN ('$ids') GROUP BY company_id ";
                            }
                        $result_com = $conn->query($sql_com);
                        if ($result_com->num_rows > 0) {
                        while($row_com = $result_com->fetch_assoc()) {
                            
                        $sql_com1="SELECT * FROM main_company_tbl where deleted='0'AND  company_id='".$row_com['company_id']."' ";
                        $result_com1 = $conn->query($sql_com1);
                        if ($result_com1->num_rows > 0) {
                        while($row_com1 = $result_com1->fetch_assoc()) {
                          //  echo $row_com1['company_name_ar'];
                          
                        if($lang=='ar'){ 
                          $com_title2= $row_com1['company_name_ar'];
                        }else{
                       $com_title2= $row_com1['company_name_en'];     
                        }
                        ?>
                        <option value="<?php echo $row_com["company_id"]?>" <?php if($row_com["company_id"]==$row_connect_form["company_id"]){ echo "selected";} ?>><?php echo $com_title2;?></option>
                    <?php  }}}} 
                          ?></select>
                           </div></div>
                           
                          <div class="col-lg-3 col-sm-6 col-12"> 
                          <div class="form-group row"> 
                          <input type="text" style="height:31px;" class="form-control Constraint" name="Constraint<?php echo $id;?>0" id="Constraint<?php echo $id;?>0" data-id="<?php echo $id;?>" data-idd="0" style="width: 200px;" placeholder="العملية" value="" required>
                        </div>
                        </div>
                        
                        <div class="col-lg-3 col-sm-6 col-12"> 
                          <div class="form-group row"> 
                          <input type="text" style="height:31px;" class="form-control proccess" name="proccess<?php echo $id;?>0" id="proccess<?php echo $id;?>0" data-id="<?php echo $id;?>" data-idd="0" style="width: 200px;" placeholder="التسلسل" value="" required></br>
                          </div>
                           </div>
                          
                           <div class="col-lg-3 col-sm-6 col-12"> 
                          <div class="form-group row"> 
                          <div clas="user-add-shedule-list"  clas="card-header bg-inverse-info" id="show_process<?php echo $id;?>0" style="font-size:12px;"></div>
                          </div>
                          
                           </div>
                            </div>
                          
                          </div> 
                          
                          <input type="text" name="count_connect" id="count_connect<?php echo $id;?>" value="<?php echo 0;?>">
                          <div class="show_cp" id="show_cp<?php echo $id;?>">

                          <script>
         $(document).on('click', '.add_cp', function() { 
          var i = 0;
   var att_id = '<?php echo $id;?>';
   //alert(att_id);
   var i = parseFloat($("#count_connect"+att_id).val());
   i++;
   $("#count_connect"+att_id).val(i);
   //alert(i);
   //$('#show_cp'+att_id).append('<div style="width: 600px;" class="cp" id="cp'+att_id+''+i+'"><select class="company_qid" id="company_qid'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;"><?php if($urow['user_type']=="System_Manager"){$sql_com="SELECT * FROM waseet_company_user_tbl GROUP BY company_id ";}else{ $sql_com="SELECT * FROM waseet_company_user_tbl where deleted='0' AND company_id IN ('$ids') GROUP BY company_id ";} $result_com = $conn->query($sql_com); if($result_com->num_rows > 0) { while($row_com = $result_com->fetch_assoc()) { $sql_com1="SELECT * FROM main_company_tbl where deleted='0'AND  company_id='".$row_com['company_id']."' "; $result_com1 = $conn->query($sql_com1); if ($result_com1->num_rows > 0) { while($row_com1 = $result_com1->fetch_assoc()) { if($lang=='ar'){ $com_title2= $row_com1['company_name_ar']; }else{ $com_title2= $row_com1['company_name_en']; }?><option value="<?php echo $row_com["company_id"]?>"><?php echo $com_title2; ?></option><?php  }}}} ?></select><input type="text" class="Constraint" id="Constraint'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;" placeholder="العملية" value="<?php if($row_fil['constraint_num']>0){ echo $row_fil['constraint_num']; }?>"><input type="text" class="proccess" id="proccess'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;" placeholder="العملية" value="<?php if($row_fil['proccess']>0){ echo $row_fil['proccess']; }?>"><button class="delete_qid" id="'+att_id+'" data-id="'+i+'" data-stat="1">x</button></br><div id="show_process'+att_id+''+i+'"></div></div>');
   
    $('#show_cp'+att_id).append('<div style="width: 600px;" class="cp" id="cp'+att_id+''+i+'"><div class="row"><div class="col-lg-3 col-sm-6 col-12"><div class="form-group row"><select style="hieght31px;"  class="form-select form-select-sm company_qid" name="company_qid'+att_id+''+i+'" id="company_qid'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;"><?php if($urow['user_type']=="System_Manager"){$sql_com="SELECT * FROM waseet_company_user_tbl GROUP BY company_id ";}else{ $sql_com="SELECT * FROM waseet_company_user_tbl where deleted='0' AND company_id IN ('$ids') GROUP BY company_id ";} $result_com = $conn->query($sql_com); if($result_com->num_rows > 0) { while($row_com = $result_com->fetch_assoc()) { $sql_com1="SELECT * FROM main_company_tbl where deleted='0'AND  company_id='".$row_com['company_id']."' "; $result_com1 = $conn->query($sql_com1); if ($result_com1->num_rows > 0) { while($row_com1 = $result_com1->fetch_assoc()) { if($lang=='ar'){ $com_title2= $row_com1['company_name_ar']; }else{ $com_title2= $row_com1['company_name_en']; }?><option value="<?php echo $row_com["company_id"]?>"><?php echo $com_title2; ?></option><?php }}}} ?></select></div></div><div class="col-lg-3 col-sm-6 col-12"><div class="form-group row"><input type="text" style="max-height:31px;" class="form-control Constraint" name="Constraint'+att_id+''+i+'" id="Constraint'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;" placeholder="العملية" value="<?php if($row_fil['constraint_num']>0){ echo $row_fil['constraint_num']; }?>"></div></div><div class="col-lg-3 col-sm-6 col-12"><div class="form-group row"><input type="text" style="max-height:31px;" class="form-control proccess" name="proccess'+att_id+''+i+'" id="proccess'+att_id+''+i+'" data-id="'+att_id+'" data-idd="'+i+'" style="width: 200px;" placeholder="التسلسل" value="<?php if($row_fil['proccess']>0){ echo $row_fil['proccess']; }?>"></div></div><div class="col-lg-3 col-sm-6 col-12"><div class="form-group row"><button style="width:40px;hieght10px;"  class="btn btn-danger delete_qid" id="'+att_id+'" data-id="'+i+'" data-stat="1">x</button>  </div></div> <div id="show_process'+att_id+''+i+'"></div></div></div></div></div>');
   
         
     });
     $(document).on('click', '.delete_qid', function(){
      var id = $(this).attr("id"); 
    var data = $(this).attr("data-id"); 
    var stat = $(this).attr("data-stat");
    $('#cp'+id+data).remove();
    });
      </script>
        <script>
    //$(".Constraint").keyup(function(){
      $(document).on('keyup', '.Constraint', function() {
    
      var at_id = $(this).attr('data-id');
      var at_idd = $(this).attr('data-idd');
      var Constraint = $("#Constraint"+at_id+at_idd).val();
      var proccess = $("#proccess"+at_id+at_idd).val();
      //var company_id = $("#company_qid"+at_id+at_idd).val();
      var company_id = $("#company_qid"+at_id+at_idd).find(":selected").val();
      
      if(proccess=="" && Constraint==""){
        $("#show_process"+at_id+at_idd).html('');
      }else{
      $.ajax({
    type: "POST",
    url: "Check_Forms_Constraintt.php",
    data: {
      at_id:at_id,at_idd:at_idd,Constraint:Constraint,proccess:proccess,company_id:company_id			
    },
    success: function(data) {
      //alert(data);
       $("#show_process"+at_id+at_idd).html(data);
      
    },
    error:function(data){
        
       //alert(data); //===Show Error Message====
    }
    });
  }
    });
  </script>
   <script>
    //$(".Constraint").keyup(function(){
      $(document).on('keyup', '.proccess', function() {
    
      var at_id = $(this).attr('data-id');
      var at_idd = $(this).attr('data-idd');
      var Constraint = $("#Constraint"+at_id+at_idd).val();
      var proccess = $("#proccess"+at_id+at_idd).val();
      //var company_id = $("#company_qid"+at_id+at_idd).val();
      var company_id = $("#company_qid"+at_id+at_idd).find(":selected").val();
      
      if(proccess=="" && Constraint==""){
        $("#show_process"+at_id+at_idd).html('');
      }else{
      $.ajax({
    type: "POST",
    url: "Check_Forms_Constraintt.php",
    data: {
      at_id:at_id,at_idd:at_idd,Constraint:Constraint,proccess:proccess,company_id:company_id			
    },
    success: function(data) {
      //alert(data);
       $("#show_process"+at_id+at_idd).html(data);
      
    },
    error:function(data){
        
       //alert(data); //===Show Error Message====
    }
    });
  }
    });
  </script>
  <script>
    //$(".Constraint").keyup(function(){
      $(document).on('change', '.company_qid', function() {
    
      var at_id = $(this).attr('data-id');
      var at_idd = $(this).attr('data-idd');
      var Constraint = $("#Constraint"+at_id+at_idd).val();
      var proccess = $("#proccess"+at_id+at_idd).val();
      //var company_id = $("#company_qid"+at_id+at_idd).val();
      var company_id = $("#company_qid"+at_id+at_idd).find(":selected").val();
      
      if(proccess=="" && Constraint==""){
        $("#show_process"+at_id+at_idd).html('');
      }else{
      $.ajax({
    type: "POST",
    url: "Check_Forms_Constraintt.php",
    data: {
      at_id:at_id,at_idd:at_idd,Constraint:Constraint,proccess:proccess,company_id:company_id			
    },
    success: function(data) {
      //alert(data);
       $("#show_process"+at_id+at_idd).html(data);
      
    },
    error:function(data){
        
       //alert(data); //===Show Error Message====
    }
    });
  }
    });
  </script>
<?php }else if($f_type=="Zeroing_financial_covenant"){ echo $raseed_auhd;?>
  
<?php }else if($f_type=="Auditing_options"){ ?>
  <input type="hidden" name="f_type" id="f_type" value="<?php echo $f_type;?>">
<?php $sql_level_audit_option = "SELECT * FROM level_audit_options where company_id='$id_company' and request_type='$id_type' and level='$id_level'";
     $result_level_audit_option = $conn->query($sql_level_audit_option);
      if ($result_level_audit_option->num_rows > 0) {
          while($row_level_audit_option = $result_level_audit_option->fetch_assoc()) { ?>
           <?php $attachments_type_id = $row_level_audit_option["attachments_type_id"]; ?>
<?php 
$sql_em1="SELECT * FROM hr_audit_options_tbl where audit_options_id='".$row_level_audit_option["audit_options_id"]."' and audit_types='1' and deleted='0'";
       $result_em1 = $conn->query($sql_em1);
       if ($result_em1->num_rows > 0) {
        while($row_em1 = $result_em1->fetch_assoc()) {?>
<input type="hidden" name="audit_options_id[]" value="<?php echo $row_em1["audit_options_id"];?>">
 <div class="row">    
                           	<div class="col-md-6">
                           	     <div class="form-group"> 
                               <label>
                                <?php echo $file_name; ?>
                                </label>
                            <input type="text" name="att_name<?php echo $row_em1["audit_options_id"];?>" id="att_name<?php echo $row_em1["audit_options_id"];?>" value="<?php echo $row_em1["audit_details_ar"];?>" class="form-control form-control-sm" placeholder="Enter File Name" required="" readonly>
                            </div>
                            </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group"> 
                                        <label>
                                         <?php echo $file; ?>
                                        </label>
                                        <input id="imageFile<?php echo $row_em1["audit_options_id"];?>" name="imageFile<?php echo $row_em1["audit_options_id"];?>" type="file"class="form-control form-control-sm"/>
                                         </div>
                                         </div>
</div>
       <?php }}else{ ?>
       <input type="text" name="audit_options_id[]" value="">
      <?php } ?>
      <?php }} ?>
      
      
      <?php }elseif($f_type=="only_accept"){ ?>
        <input type="text" name="f_type" id="f_type" value="<?php echo $f_type;?>">
      <?php }else{ } ?>
      