<style>
.small-label {
    font-size: 15px;
}
</style>
<!----------------------------------- Cloning end for Accreditation  --------------------------------------------->

        <section class="content">
			<!-- general form elements -->
                <form class="" method="post" name="FeasbilityForm" id="FeasbilityForm" action="index?page=view_quotation_progress&action=insert_feasibility" onsubmit="return validateForm(this)" enctype="multipart/form-data">
					  <div class="row">
							<div class="col-6">
								<div>
						            <label class="control-label p-2" for="Company Name">Feasibility Type</label>
				                      <?= $gsi->getFeasibilityTypeList("fsb_type", "$fsb_type", "100%", false, "form-control"); ?>
								</div>
						    </div>
							<div class="col-6">
								<div>
						            <label class="control-label p-2" for="Company Name">Issue and Concern</label>
									<textarea id="issue_concern" name="issue_concern" class="form-control" value="" rows="1" placeholder="Issue and Concern"oninput="this.value=this.value.toUpperCase();"><?php echo $row_fasb['issue_concern']; ?></textarea>
								</div>
						    </div>
						 </div>
						 <br>
						 <h5 class="" style="margin-top: 0; margin-bottom: 0;color:#9c4893;">RISK ASSESSMENT</h5>
						 <hr style="background-color: #9c4893; height:1px; margin-top: 0; margin-bottom: 1;">
						 <div class="row">
							<div class="col-6">
								<label for="risk_assessment_images">Select Files</label>
								<div>
									<input type="file" name="risk_assessment_images[]" id="risk_assessment_images" class="form-control" multiple accept=".pdf,.jpg,.jpeg,.png">						
								</div>
							</div>
							<div class="col-6">
								<div>
						            <label class="control-label" for="RISK ASSESSMENT COMMENTS">RISK ASSESSMENT COMMENTS</label>
									<textarea id="risk_assessment_comments" name="risk_assessment_comments" class="form-control" value="" rows="1" placeholder="RISK ASSESSMENT COMMENTS"oninput="this.value=this.value.toUpperCase();"><?php echo $row_fasb['risk_assessment_comments']; ?></textarea>
								</div>
						    </div>
						 </div>
						
						 <div class="">
							<div style="">
								
								<?php
								$dir = "../feasibility_images/";
								$result = mysqli_query($conn, "SELECT id, file_name FROM quot_feasibility_files WHERE quot_id='$qot_id' AND file_for=1");

								echo '<div style="display: flex; flex-wrap: wrap; gap: 15px;">'; // Start a flex container

								while ($row = mysqli_fetch_assoc($result)) {
									$row = utility::validate_crypt_data($row);
									$product_images = $row['file_name'];

									if (is_file($dir . $product_images)) {
										$ext = pathinfo($product_images, PATHINFO_EXTENSION);
										$file_nameee = basename($product_images);
										if ($ext == "jpg" || $ext == "jpeg" || $ext == "png") {
											$image_path = '<a href="../' . $dir . $product_images . '" target="_blank" class="primary text-primary">' . $file_nameee . '</a>';
										} else if ($ext == "pdf") {
											$image_path = '<a href="../' . $dir . $product_images . '" target="_blank">
												<span class="primary text-primary" title="' . $product_images . '">' . utility::ellipsis($file_nameee, 100) . '</span>
											</a>';
										}

										$delete_sign = '<span class="feasibility_files" alt="' . $row['id'] . '" data-product_image="' . $product_images . '" style="cursor: pointer; color: red; font-size: 20px;">&times;</span>'. '<i class="fas fa-sync-alt fa-spin" style="display:none;" id="delete_image_load_' . $row['id'] . '"></i>' . '<i class="fa fa-check" id="delete_image_done_' . $row['id'] . '" style="color:#bad23a;font-size: 20px;display:none;"></i>';

									} else {
										$image_path = '<img style="width:100px;border:1px solid #777" src="../' . $dir . 'no-image.gif">';
										$delete_sign = ''; 
									}

									
									echo '<div id="image_record_no_' . $row['id'] . '">' . $image_path . $delete_sign . '</div>';
								}

								echo '</div>'; 
								?>				
							</div>
						</div>
						<br>
						<h5 class="" style="margin-top: 0; margin-bottom: 0;color:#9c4893;">FEASIBILTY ASSESSMENT</h5>
						<hr style="background-color: #9c4893; height:1px; margin-top: 0; margin-bottom: 1;">
						<div class="row">
							<div class="col-6">
								<label for="risk_assessment_images">Select Files</label>
								<div>
									<input type="file" name="feasibility_assessment_images[]" id="feasibility_assessment_images" class="form-control" multiple accept=".pdf,.jpg,.jpeg,.png">						
								</div>
							</div>
							<div class="col-6">
								<div>
						            <label class="control-label" for="FEASIBILTY ASSESSMENT/COMMENTS">FEASIBILTY ASSESSMENT/COMMENTS</label>
									<textarea id="feasibility_assessment_comment" name="feasibility_assessment_comment" class="form-control" value="" rows="1" placeholder="FEASIBILTY ASSESSMENT/COMMENTS"oninput="this.value=this.value.toUpperCase();"><?php echo $row_fasb['feasibility_assessment_comment']; ?></textarea>
								</div>
						    </div>
						 </div>
						
						 <div class="">
							<div style="">
								
								<?php
								$dir = "../feasibility_images/";
								$result = mysqli_query($conn, "SELECT id, file_name FROM quot_feasibility_files WHERE quot_id='$qot_id' AND file_for=2");
								echo '<div style="display: flex; flex-wrap: wrap; gap: 15px;">'; // Start a flex container

								while ($row = mysqli_fetch_assoc($result)) {
									$row = utility::validate_crypt_data($row);
									$product_images = $row['file_name'];

									if (is_file($dir . $product_images)) {
										$ext = pathinfo($product_images, PATHINFO_EXTENSION);
										$file_nameee = basename($product_images);
										if ($ext == "jpg" || $ext == "jpeg" || $ext == "png") {
											$image_path = '<a href="../' . $dir . $product_images . '" target="_blank" class="primary text-primary">' . $file_nameee . '</a>';
										} else if ($ext == "pdf") {
											$image_path = '<a href="../' . $dir . $product_images . '" target="_blank">
												<span class="primary text-primary" title="' . $product_images . '">' . utility::ellipsis($file_nameee, 100) . '</span>
											</a>';
										}

												
										$delete_sign = '<span class="feasibility_files" alt="' . $row['id'] . '" data-product_image="' . $product_images . '" style="cursor: pointer; color: red; font-size: 20px;">&times;</span>'. '<i class="fas fa-sync-alt fa-spin" style="display:none;" id="delete_image_load_' . $row['id'] . '"></i>' . '<i class="fa fa-check" id="delete_image_done_' . $row['id'] . '" style="color:#bad23a;font-size: 20px;display:none;"></i>';


									} else {
										$image_path = '<img style="width:100px;border:1px solid #777" src="../' . $dir . 'no-image.gif">';
										$delete_sign = ''; 
									}

									
									echo '<div id="image_record_no_' . $row['id'] . '">' . $image_path . $delete_sign . '</div>';
								}

								echo '</div>'; 
								?>				
							</div>
						</div>	
					  <div class="card-footer">
						<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
						<input type="hidden" id="quot_id" name="quot_id" value="<?php echo $_REQUEST['id'];?>">
						<input type="hidden" id="from" name="from" value="<?php echo $from;?>">
						<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
						<input type="hidden" id="section_status_feasibility" name="section_status_feasibility" value="">
						<button type="button" id="submit_incomplete" class="btn btn-danger" onclick="submitFormFsbltyStatus(1,'spinner_feasibility_incomplete')">
							Save Incomplete
							<i class="fas fa-sync-alt fa-spin" style="display:none;" id="spinner_feasibility_incomplete"></i>
						</button>
						<button type="button" id="submit_completed" class="btn btn-success" onclick="submitFormFsbltyStatus(2,'spinner_feasibility_completed')">
							Section Completed
							<i class="fas fa-sync-alt fa-spin" style="display:none;" id="spinner_feasibility_completed"></i>
						</button>
						<div style="float:right;">
							<button type="button" id="prevButton" class="btn btn-secondary" onclick="ToPrevTab()">Previous</button>
							<button type="button" id="nextButton" class="btn btn-secondary" onclick="ToNextTab()">Next</button>

					   </div>
					  </div>
                </form>
</section>
<script type="text/javascript">


function submitFormFsbltyStatus(status, spinnerId) {
    document.getElementById('section_status_feasibility').value = status;

    document.querySelectorAll('.fa-spin').forEach(function(spinner) {
        spinner.style.display = 'none';
    });
    document.getElementById(spinnerId).style.display = 'inline-block';
    document.getElementById('FeasbilityForm').submit();
}
	$(".feasibility_files").click(function() {
    if (confirm('Are you sure you want to delete this?')) {
        var imageid = $(this).attr("alt");
        var product_image = $(this).attr("data-product_image");

        if (imageid != "") {
            $('#delete_image_load_' + imageid).show();  
            var form_data = { 'imageid': imageid, 'product_image': product_image };

            $.ajax({
                async: true,
                type: "POST",
                url: site_url + "/quotation_management/index?page=ajax_actions&action=delete_feasibility_files",
                data: form_data,
                success: function(result) {
                    var resultObj = jQuery.parseJSON(result);
                    if (resultObj.status == "success") {
                        $('#delete_image_done_' + imageid).show(); 
                        $('#delete_image_load_' + imageid).hide();

                        setTimeout(function() {
                            $('#delete_image_done_' + imageid).hide();
                            $('#image_record_no_' + imageid).remove();  
                        }, 1000);
                    } else {
                        alert('Error deleting the image.');
                    }
                }
            });
        }
    } else {
        return false;  
    }
});
</script>