<?php
include "scrinit.php";
include "logo.php";
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
table.myTable1 { border-collapse:collapse; }
table.myTable1 td, table.myTable th { border:1px solid black;padding:2px;font-size:13px; }
<p style="font-size:09px;"></p>
</style>
<h3>ΟΜΑΔΙΚΗ ΚΑΤΑΓΓΕΛΙΑ</h4>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];

$sql = "SELECT mitroo,tmima,eponimo,onoma  FROM allstudentinfo order by tmima,eponimo,onoma ASC ";
$result = $dbcon->prepare($sql);
$result->execute();
$sql2 = mysqli_query($con,"SELECT * FROM paraptoma ");
$sql1 = mysqli_query($con,"SELECT * FROM eidostimorias ");

?>
<TABLE class='mytable1'>
<TR>
<TD>
<h4>ΛΕΠΤΟΜΕΡΕΙΕΣ ΚΑΤΑΓΓΕΛΙΑΣ:</h4>
<div style="overflow:scroll;margin-left:5px;background:#F5F9F0;width:730px; height: 450px">
<form  method="post" >
<div >

ΗΜΕΡ. ΚΑΤΑΓΓΕΛΙΑΣ:<input type="date"  name = 'datekata' value =<?php if (isset($_POST['dt'])) { echo $dt;$_SESSION['dt']=$dt; } else {$dt=date('Y-m-d');echo $dt;} ?>  ><br /><br />
<b>ΠΕΡΙΓΡΑΦΗ:</b><br />
<textarea name='perigrafi' cols='70' rows='7' id='perigrafi'  required > <?php echo ltrim($perigrafi);?> </textarea ><br/ ><br />
<p><b>
Ο ΠΕΙΘΑΡΧΙΚΟΣ ΚΩΔΙΚΑΣ ΠΑΡΑΒΙΑΣΤΗΚΕ ΣΕ ΟΤΙ ΑΦΟΡΑ:</b><br>
<select name='arsimpx'  >
<?php
while ($row2 = mysqli_fetch_array($sql2)) 
{
	$arsimp1=$row2['code'];
	$perig=$row2['perigrafi'];
	$metro=$row2['metro'];
    ?>
    <option value= '<?php echo $arsimp1;?>'  <?php if($arsimp1 == $arsimp){echo("selected");}?>> <?php echo $arsimp1." - ".$perig." - (".$metro." )";?></option>
    <?php
}
?>
</select>
<p/>
<b>ΣΧΟΛΙΑ:</b><br />
<textarea name='sxolia' cols='70' rows='5'> <?php echo ltrim($sxolia);?> </textarea ><br/ ><br />

</div>
</TD>
<td> </td>
<TD>
<h4>ΕΠΙΛΟΓΗ ΜΑΘΗΤΩΝ/ΤΡΙΩΝ ΓΙΑ ΚΑΤΑΓΓΕΛΙΑ</h4>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:500px; height: 450px">
<?php
echo "<table style='width:470px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>ΜΗΤΡΩΟ</th>
<th>ΤΜΗΜΑ</th>
<th>ΟΝΟΜΑΤΕΠΩΝΥΜΟ</th>
<th></th>
<th>ΕΠΙΛΟΓΗ</th>
</tr>";
$i=1;
while ($row=$result->fetch(PDO::FETCH_ASSOC)) 
  { 
    $am[$i]=$row['mitroo'];
	$tm1[$i]=$row['tmima'];
	$namet[$i]=$row['eponimo']." ".$row['onoma'];;
	echo "<tr>";
	echo "<td>".$am[$i]."</td>";
	echo "<td>".$tm1[$i]."</td>";
	echo "<td>".$namet[$i]."</td>";
	echo "<td>"." "."</td>";
    echo "<td ALIGN=center>"."<input type='checkbox' name='mitr[]' value='$am[$i]'  {$checked} >"."</td>";
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
</TD>
</TR>
</TABLE>
<br>
<input type="submit" name="maziki" value="Καταχώρηση Καταγγελίας" >
<br><br>
</form>	
<?php
if (isset($_POST['maziki'])) 
{
	$perx=$_POST['perigrafi'];
	$datek=$_POST['datekata'];
	$arsimpx=$_POST['arsimpx'];
	$sxoliax=$_POST['sxolia'];
	$mitrx=$_POST['mitr'];
	$cc=count($mitrx);
	
	$query = mysqli_query($con,"SELECT MAX(aranaforas) FROM kataggelia ");
	$results = mysqli_fetch_array($query);
	$aranaforas = $results['MAX(aranaforas)'];
	$i=1;
	foreach ($mitrx as $mitr)
	{
    $sql = mysqli_query($con,"SELECT eponimo,onoma,tmima FROM allstudentinfo WHERE mitroo='$mitr'  " );
	$row = mysqli_fetch_array($sql);
	$stname[$i]=$row['eponimo']." ".$row['onoma'];
	$tmima[$i]=$row['tmima'];
	
	$sql=mysqli_query($con,"SELECT voi_id  FROM voithos  WHERE  class_id='$tmima[$i]' " );
	$row = mysqli_fetch_array($sql);
	$vdidk[$i] = $row['voi_id'];
	
	$sql1 = mysqli_query($con,"SELECT Name FROM teachers WHERE  PMP='$vdidk[$i]'" );
	$row1 = mysqli_fetch_array($sql1);
	$vdnamek[$i] = $row1['Name'];
	
	$arn[$i]=$aranaforas+$i;
	$sqlin=mysqli_query($con,"INSERT INTO kataggelia (aranaforas,mitroo,tmima,bd,kataggelon,datekata,perigrafi,
                  sxolia,arsimperiforas) 
				  VALUES (NULL,'$mitr','$tmima[$i]','$vdidk[$i]','$usr','$datek','$perx','$sxoliax','$arsimpx') ");

   if (!$sqlin) 
   { 
   echo "error";
   }
  else
   {
     echo "Η καταγγελία για ".$stname[$i]." του τμήματος ".$tmima[$i]." καταχωρήθηκε με αριθμό: ".$arn[$i];
     echo "<br>"."<br>";
   }
	
	
	
	$i++;
	
	}
} 


 ?>
<br> <br>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>