<?php
include "scrinit.php";
date_default_timezone_set("Europe/Athens");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:2px solid black;padding:3px;font-size:13pt; }
<p style="font-size:11px;"></p>
table.myTable1 { border-collapse:collapse; }
table.myTable1 td, table.myTable1 th { border:1px solid black;padding:4px;font-size:12pt; }

@page { size 8.5in 11in; margin: 2cm }
div.page { page-break-after: always }

@media print {
    #Header, #Footer { display: none !important; }
}
</style>
</head>
<body>
<?php

require("dbconnect.php");
$sql = mysqli_query($con,"SELECT * FROM generalinfo" );
$row = mysqli_fetch_array($sql);
$schname=$row['schoolname'];
$xronia=$row['year'];
$logo=$row['logo'];
$result = $dbcon->prepare("SELECT tmima,mitroo,eponimo,onoma FROM allstudentinfo  order by tmima,eponimo,onoma");
$result->execute();
while($row=$result->fetch(PDO::FETCH_ASSOC))
{
	?>
	<div class="page">
	<table>
      <tr>
        <td rowspan="2"> <img src=<?php echo $logo;?>  /> </td>
        <td><?php echo $schname." /"." ΣΧΟΛΙΚΗ ΧΡΟΝΙΑ ".$xronia;?> </td>
        </tr>
    </table>
    <h3><center> ΠΡΟΓΡΑΜΜΑ ΔΗΜΙΟΥΡΓΙΚΟΤΗΤΑ - ΔΡΑΣΗ - ΚΟΙΝΩΝΙΚΗ ΠΡΟΣΦΟΡΑ </center></h3>
    <h4><center> ΑΝΑΛΥΤΙΚΗ ΚΑΤΑΣΤΑΣΗ ΣΥΜΜΕΤΟΧΗΣ ΕΤΟΥΣ</center></h4>
    <br>
	<?php
	$mitroo=$row['mitroo'];
	$r2 = $dbcon->prepare("SELECT * FROM ddk where mitroo=? ");
	$r2->execute([$mitroo]);
	$row2=$r2->fetch(PDO::FETCH_ASSOC);
	?>
	<br>
	<table style='width:800px' class='myTable' >
	<tr>
	<th colspan=2 align='center'> ΟΝΟΜΑΤΕΠΩΝΥΜΟ ΜΑΘΗΤΗ/ΤΡΙΑΣ </th>
	<th align='center'> ΤΜΗΜΑ </th>
	</tr>
	<tr>
	<td colspan=2 align='center'> <?php echo $row['eponimo']."  ".$row['onoma'];?> </td>
	<td align='center'> <?php echo $row['tmima']; ?> </td>
	</tr>
	</table>
	
	<br><br>
	<table style='width:800px' class='myTable1' >
	<tr style='border:1px solid black;padding:4px;font-size:12px'  >
	<tr>
	<th> ΔΡΑΣΤΗΡΙΟΤΗΤΑ </th>
	<th> ΜΟΝΑΔΕΣ </th>
	</tr>
	<?php
	$r1 = mysqli_query($con,"SELECT * FROM ddkportfolio");
	$i=0;
	$j=1;
	$sum=0;
	$gr=$list=array();
	
	while($row1=mysqli_fetch_array($r1))
	{
		$olditem=$row1['portfolio'];
		$group=$row1['mark'];
		if ($group == 0)
		{
			
			if (count($list) > 0 )
			{
				//echo "<tr>";
				//echo "<td>".$olditem."</td>";
				//echo "</tr>";
						
				for ($k=1;$k<$j;$k++)
				{
				  echo "<tr>";
				  echo "<td>".$list[$k]."</td>"; 
				  echo "<td align='center'>".$gr[$k]."</td>";
				  echo "</tr>";
				}
				$j=1;
				$list=$gr=array();
			}
		}
		else
		{
			$i++;
			$fx="f".$i;
			$g=$row2["$fx"];
			$sum=$sum+$g;
			if ($g > 0)
			{
				$list[$j]=$row1['portfolio'];
				$gr[$j]=$g;
				//echo "<tr>";
				//echo "<td>".$list[$j]."</td>"; 
				//echo "<td>".$gr[$j]."</td>";
				//echo "</tr>";
				
				$j++;
			}
		}			
		//$row1=mysqli_fetch_array($r1);
	}
	
	echo "<tr>";echo "<td>"."<br/>"."</td>"."</tr>";
	echo "<tr>";
	echo "<td rowspan=2>". "<b>"."ΣΥΝΟΛΟ ΜΟΝΑΔΩΝ: "."</b>"."</td>"; 
	echo "<td rowspan=2 align='center'>"."<b>".$sum."</b>"."</td>";
	echo "</tr>";
	echo "</table>";
	for ($l=1;$l <= 5;$l++)
	{
		echo "<br>";
	}
	echo "<table style='width:800px'>";
	echo "<tr>";
	echo "<td rowspan=2 align='right'>". "<b>"."Ο Διευθυντής "."</b>"."</td>"; 
	echo "</tr>";
	echo "<tr>";echo "<td>"."<br/>"."</td>"."</tr>";
	echo "<tr>";echo "<td>"."<br/>"."</td>"."</tr>";
	echo "<tr>";echo "<td>"."<br/>"."</td>"."</tr>";
	echo "<td rowspan=2 align='right'>"."Τάσος Τάσου"."</td>";
	echo "</tr>";
	echo "</table>";
	?>
	</div>
<?php
}

?>	
</body>
</html>