<?php
	$session_path="../../session_check.php";
	$classes="../../../classes/main_classes.php";

	require_once($session_path);
	require_once($classes);

	if($user_id==null){
	    die("<p class='alert alert-warning'>You are not logged in</p>");
	}

	if(!isset($_POST['mg_id'])){
		echo "<p class='alert alert-warning'>Invalid request</p>";
	}
	$mg_id=addslashes($_POST["mg_id"]);

	//OBJECTS
	$retrieveObj=new RETRIEVE();
	$rowcountObj=new ROWCOUNT();

?>
<table class="table table-hover table-responsive-lg" id="miscellaneous_good_supporting_images_table">
	<thead>
		<tr>
			<th>
				<span>Image</span>
			</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		<?php
			$get_supporting_images=$retrieveObj->retriever("miscellaneous_good_images","*","mg_image_type='secondary_image' and mg_id",$mg_id,"fetchAll");
                    if($get_supporting_images!="1020"){
                    	$element_id="element_id";
                        foreach ($get_supporting_images as $supporting_image) {
                        	$element_id=$element_id."Ot";
		?>	
				<tr id="<?php echo $element_id ?>">	    		
					<td class="">
						<?php
							echo '<img class="m-1 supporting_image" style="max-height:75px;" src="../img/miscellaneous_goods/'.$supporting_image->mg_image.'?timestamp'.time().'"/>';
						?>
					</td>
					<td id="<?php echo $element_id.'Dbtn' ?>">
						
						<form id="<?php echo $element_id.'form' ?>" class="mb-0" style="display: inline;">
			                <input type="hidden" name="remove_miscellaneous_good_supporting_image_note" value="<?php echo $supporting_image->mg_image_id; ?>">
			                <button  onclick="remove_miscellaneous_good_supporting_image('<?php echo $element_id.'form' ?>','<?php echo $element_id ?>','add_supporting_image_response')" type="submit" title="Remove" class="btn btn-danger"><span class="fas fa-trash"></span> Remove</button>
			            </form>
					</td>
				</tr>
		<?php
				}
			}
		?>
	</tbody>
</table>

<script>  
 $(document).ready(function(){  
     var table = $('#miscellaneous_good_supporting_images_table').DataTable({
      columnDefs: [
        {bSortable: false, targets: [0,1]} 
      ]
    }); 
     $("thead").addClass("font-weight-bold");
 });  
 </script> 