<?php 
# session_start();

$image_group="notes";

?>
 
  <form id="upload_form" method="POST" action="upload.php" enctype="multipart/form-data">
 <div class="vsBoxNew"  hidden >
	
			<table width="100%" border="0" style="padding:0px;margin-bottom:0px;"   >
				<tr >
					<td>
						<input hidden type="file"  id="image" name="image" onchange="javascript:file_onchange(this);" required="required"/>
						<a href="javascript:document.getElementById('image').click();" class="button red" > Επιλογή αρχείου  </a> 
					</td>
					<td colspan="3" style="width:100%;  " >
						<INPUT type="text" id="image_name" name="image_name" >
					</td>
					<td style="width:20%  ">	
						<a href="javascript:upload('upload_form');" class="button blue" > Upload </a>
					</td>
				</tr> 
				<tr >
					<td style="width:15%;  ">
					 <a  class="button " > Περιγραφή αρχείου </a>	
					</td>							
					<td colspan="3" style="width:100%;  ">
						<input type="text" name="perigrafi" id="perigrafi" class="form-control"  />
					</td>

				</tr> 						
			  </table>
				<div hidden style="top:-100px;width:50%;">
					<input type="text" id="image_group" name="image_group" value="<?php echo $image_group;?>">  
				</div>
				<input  type="text" name="IDc" id="IDc" hidden value="<?php echo $IDc;?>"> 
			
 
 </div>
 
<div class="scroll" style="height:54vh; margin-bottom:0px;padding-bottom:0px;box-shadow:none; " > 
	
	<div class="sticky">
		<table class="gridList" >
			<tr class="tblCaption" height="22">
				<td class="c w20">A/A</td>
				<td class="c w50">img</td>
				<td class="c hide1">Αρχείο</td>
				<td class="c">Περιγραφή</td>
				<td class="c w100 hide1">Μέγεθος</td>
				<td class="c w40" > </td>
			</tr>
		</table> 
	</div>

 <table class="gridListNoCaption"  > 
	 
<?php
 $RecNo=0;
   $flds="image_name, perigrafi, image_group ";
 $filter=filter_make($flds, $FindWhat);
 $query=" SELECT * FROM images " . $filter ; 
 	if($filter=='') {
				$query.=" WHERE image_group='$image_group' and image_group_id=$IDNote ";
				}
				else{ 
				$query.=" AND image_group='$image_group' and image_group_id=$IDNote ";
				}
 	   
if($SortValue==''){$query=$query ." ORDER BY image_id ";} else {$query=$query." ORDER BY " . $SortValue . " desc ";} 		 

 
	$num_rows=RecordsCount($conn,$query);
       $RecNo=$num_rows;   
     $FromRec=($pgNo-1)*$RecsPP ;
       $pgMax=intval($num_rows/$RecsPP)+1;
       $query=$query .  ' LIMIT ' .$FromRec . ', ' . $RecsPP ;
      $result=mysqli_query($conn, $query);
	    $iRow=$FromRec;
 
 # echo $query;
 
 while ($rs = mysqli_fetch_array($result)) {
 
$iRow +=1;

$image_id = $rs['image_id'];
$image_group=$rs['image_group']; 
$image_name = $rs['image_name'];
$perigrafi = $rs['perigrafi'];
$location = $rs['location'];
$image_size = $rs['image_size'];
 
 
 $del_icon="icons/16/del16.png";
 
# $frmOpen='"'.$MyIDFieldName.'","'.$IDOrgMonadas.'","'.$MyADDFormName.'",'.$w.','.$h ;

// ========================================
//        List
// ========================================
	echo "<tr class='tablerowdata' > ";
    echo "<td class='r w20'>$iRow</td>";
	echo "<td class='c w50'><a href='$location'><img src='$location' width='24px' height='24px'/></a></td>";
    echo "<td class='l hide1'>$image_name</td>";
	echo "<td class='l'>$perigrafi</td>";
	echo "<td class='r w100 hide1'>$image_size</td>";	
	echo "<td class='c w40'><a href='javascript:delete_file($image_id,\"$location\")' class='icon icon-trash'></a></td>";
    echo "</tr>";   
 }
 
for ($x = $iRow+1; $x <= $pgNo*$RecsPP; $x++) {
    echo "<tr class='tablerowdata' >  ";
    echo "<td class='r w20' ></td>";
	echo "<td class='c w50'></td>";
    echo "<td class='l hide1'></td>";
	echo "<td class='l'></td>";
	echo "<td class='l w100 hide1'></td>";
	echo "<td class='c w40'><a href='javascript:document.getElementById(\"image\").click()' class='icon icon-folder-open-alt'></a></td>";	
    echo "</tr>";
 }	
 

?>
</table>

<?php include 'include/recs_div_bottom.php'; ?>

</div>
   
</form>  
 
<script language="JavaScript" type="text/JavaScript">
 
function file_onchange(myFile){
 var filename = document.getElementById('image').value;
 filename= filename.split('\\').pop().split('/').pop();
 document.getElementById('image_name').value = filename;
 document.getElementById('perigrafi').value=filename;
  var per = prompt('Περιγραφή αρχείου : ');
  if(per==null){} else {
	   document.getElementById('perigrafi').value=per;
		upload('upload_form');
    }
 }
 
function upload(my_form){
	if (document.getElementById("image").value!="") { 
	document.getElementById(my_form).submit();
	}
}	
</script>		