<?php
include "scrinit.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function validate () {
  if(document.getElementById('perigrafi').value=="") {
    alert("Η καταγγελία δεν γίνεται να είναι άδεια!!!");
    return false;
  }
  return true;
}
$(function() {
 $("#arsimperiforas").bind("changepara", function() {
     $.ajax({
         url: "changepara.php",
         data: "arsimperiforas="+$("#arsimperiforas").val(),
         success: function(html) {
             $("#eidostimo").html(html);
         }
     });
 }); 
});
function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=200, top='+top+', left='+left);
}
</script>

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


</head>

<body>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$name=$_SESSION['n'];
$tmimaid=$_SESSION['tmimaid'];
//$fl=$_SESSION['fl'];
$aranaforas=$_SESSION['aranaf'];

if (isset($_POST['submit1'])) {$aranaforas=$_POST['aranaf'];}
if (isset($_GET['data'])) 
{
	$aranaforas=$_GET['data'];
	$sql = mysqli_query($con,"SELECT mitroo FROM kataggelia WHERE aranaforas='$aranaforas'  " );
	$row = mysqli_fetch_array($sql);
	$mitr=$row['mitroo'];
	$_SESSION['mitr']=$mitr;
}

$sql=mysqli_query($con,"SELECT voi_id  FROM voithos  WHERE  class_id='$tmimaid' " );
$row = mysqli_fetch_array($sql);
$vdidk = $row['voi_id'];
$_SESSION['vdidk']=$vdidk;
$sql1 = mysqli_query($con,"SELECT Name FROM teachers WHERE  PMP='$vdidk'" );
$row1 = mysqli_fetch_array($sql1);
$vdnamek = $row1['Name'];
$_SESSION['vdnamek']=$vdnamek;

?>
<h3>ΛΕΠΤΟΜΕΡΕΙΕΣ ΚΑΤΑΓΓΕΛΙΑΣ:</h3>
<?php
$query = mysqli_query($con,"SELECT MAX(aranaforas) FROM kataggelia ");
$results = mysqli_fetch_array($query);
$aranaf = $results['MAX(aranaforas)'] + 1;

if ($aranaforas == $aranaf) 
{
//$result =mysqli_query($con, "SELECT Name,PMP FROM teachers ORDER BY Name ");
$sql = mysqli_query($con,"SELECT * FROM paraptoma ");
$sql1 = mysqli_query($con,"SELECT * FROM eidostimorias ");
$perigrafi="";
$sxolia="";
$flag=0;
?>
<form method="post" name = "form1" action='addkataggeliakath.php' onsubmit='return validate()'>
<fieldset style="width:1000px">
ΑΡ. ΚΑΤΑΓΓΕΛΙΑΣ:<input type='text'   name= 'aranaforas' value="<?php echo $aranaforas; ?>" size="6"  required /><br /><br />
ΑΡ. ΜΗΤΡΩΟΥ:<input type='text'  name= 'mitroo' value="<?php echo $mitr; ?>" size=9 /> 
&nbsp;&nbsp;&nbspΟΝΟΜΑΤΕΠΩΝΥΜΟ:<input type='text'  name= 'stname' value="<?php echo $stname; ?>" size=40  /> <br /><br />
ΒΟΗΘΟΣ:<input type='text'  name='bd' value="<?php echo $vdnamek; ?>" />   
<input type=text name='kathig' value="<?php echo $usr; ?>" hidden />
<br /><br />
ΗΜΕΡ. ΚΑΤΑΓΓΕΛΙΑΣ:<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='100' rows='5' id='perigrafi'  required > <?php echo ltrim($perigrafi);?> </textarea ><br/ ><br />
<p><b>
Ο ΠΕΙΘΑΡΧΙΚΟΣ ΚΩΔΙΚΑΣ ΠΑΡΑΒΙΑΣΤΗΚΕ ΣΕ ΟΤΙ ΑΦΟΡΑ:</b><br>
<select name='arsimpx'  >
<?php
while ($row = mysqli_fetch_array($sql)) 
{
	$arsimp1=$row['code'];
	$perig=$row['perigrafi'];
	$metro=$row['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='100' rows='3'> <?php echo ltrim($sxolia);?> </textarea ><br/ ><br />
<input type=text name='katastasi' value="<?php echo "0"; ?>" hidden /> 
<input type='text'  name= 'flag' value="<?php echo $flag; ?>" hidden />
<input type='text'  name= 'datetimo' value="<?php echo " "; ?>" hidden />
<input type='text'  name= 'eidostimo' value="<?php echo ""; ?>" hidden />
<input type='text'  name= 'periodoi' value="<?php echo 0; ?>" hidden />
<br /><br /> 
<input type='Submit' name='Submit' value='ΚΑΤΑΧΩΡΗΣΗ ΚΑΤΑΓΓΕΛΙΑΣ' >
<?php echo " &nbsp&nbsp&nbsp ";?> 
<input type="button" style="color:blue " onclick="window.open('listpeda.php?metro=<?php echo $metro;?>','','width=600,height=500')" value="Παιδαγωγικά Μέτρα" />
</fieldset>
</form>	
<?PHP
}
else
{
$flag=1;
$sql = mysqli_query($con,"SELECT * FROM kataggelia WHERE aranaforas='$aranaforas'  " );
$row = mysqli_fetch_array($sql);
$vdid=   $row['bd'];
$kataggelon= $row['kataggelon'];
$datekata= $row['datekata'];
$perigrafi=$row['perigrafi'];
$sxolia=$row['sxolia'];
$arsimp = $row['arsimperiforas'];
$datetimo = $row['datetimo'];
$eidostimo = $row['eidostimo'];
$periodoi = $row['periodoi'];
$katastasi = $row['katastasi'];
$timcode = $row['timoriacode'];

$sql1=mysqli_query($con,"SELECT Name  FROM teachers  WHERE  PMP='$vdid' " );
$row1 = mysqli_fetch_array($sql1);
$vdname = $row1['Name'];

$sql2 = mysqli_query($con,"SELECT Name FROM teachers  WHERE  PMP='$kataggelon'" );
$row2 = mysqli_fetch_array($sql2);
$teacher = $row2['Name'];

$sql3 = mysqli_query($con,"SELECT perigrafi FROM eidostimorias  WHERE  code='$timcode'" );
$row3 = mysqli_fetch_array($sql3);
$eidostimo = $row3['perigrafi'];

$sql4 = mysqli_query($con,"SELECT perigrafi,metro FROM paraptoma  WHERE  code='$arsimp'" );
$row4 = mysqli_fetch_array($sql3);
$perpara = $row4['perigrafi'];
$metro = $row4['metro'];
?>


<form method="post" name = "form1" action="addkataggeliakath.php">
<fieldset>
ΑΡ. ΚΑΤΑΓΓΕΛΙΑΣ:<input type='text'  name= 'aranaforas' value="<?php echo $aranaforas; ?>" size=6  /><br /><br />
ΑΡ. ΜΗΤΡΩΟΥ:<input type='text'  name= 'mitroo' value="<?php echo $mitr; ?>" size=9 /> 
ΟΝΟΜΑΤΕΠΩΝΥΜΟ:<input type='text'  name= 'stname' value="<?php echo $stname; ?>" size=40  /> <br /><br />
ΒΟΗΘΟΣ:<input type='text'  name='bd' value="<?php echo $vdname; ?>" />  
ΚΑΤΑΓΓΕΛΙΑ ΑΠΟ: <input type='text'  name='kathig' value="<?php echo $teacher; ?>" /> 
<br /><br />
ΗΜΕΡ. ΚΑΤΑΓΓΕΛΙΑΣ:<input type="date"  name = 'datekata' value =<?php echo $datekata; ?>  ><br /><br />
ΠΕΡΙΓΡΑΦΗ:<br />
<textarea name='perigrafi' cols='100' rows='5'> <?php echo $perigrafi;?> </textarea ><br/ ><br />
ΣΧΟΛΙΑ:<br />
<textarea name='sxolia' cols='100' rows='3'> <?php echo $sxolia;?> </textarea ><br/ ><br />
ΑΡ. ΣΥΜΠΕΡΙΦΟΡΑΣ:<input type='text'  name= 'arsimp' value="<?php echo $arsimp." - ".$perpara; ?>" size=70 />

<br /><br />
ΗΜΕΡ. ΤΙΜΩΡΙΑΣ:<input type="date"  name = 'datetimo' value =<?php echo $datetimo; ?>  ><br />
<br />
ΕΙΔΟΣ ΤΙΜΩΡΙΑΣ:<input type='text'  name='eidostimo' value="<?php echo $eidostimo; ?>" size=100 />

<br /><br />
ΠΟΙΝΗ ΣΕ ΠΕΡΙΟΔΟΥΣ:<input type='text'  name= 'periodoi' value="<?php echo $periodoi; ?>" size=9 />
<br /><br /> 
ΚΑΤΑΣΤΑΣΗ ΚΑΤΑΓΓΕΛΙΑΣ:<select name='katastasi'>
  <option value="0"<?php if ($katastasi == 0) echo ' selected="selected"'; ?>>0 - ΚΑΤΑΧΩΡΗΘΗΚΕ</option>
  <option value="1"<?php if ($katastasi == 1) echo ' selected="selected"'; ?>>1 - ΕΚΚΡΕΜΕΙ</option>
  <option value="2"<?php if ($katastasi == 2) echo ' selected="selected"'; ?>>2 - ΟΛΟΚΛΗΡΩΘΗΚΕ</option>   
</select> 
</select>

<input type='text'  name= 'flag' value="<?php echo $flag; ?>" hidden />

<br /><br /> 
<input type='Submit' name='Submit' value='ΚΑΤΑΧΩΡΗΣΗ ΚΑΤΑΓΓΕΛΙΑΣ' >
<?php echo " &nbsp&nbsp&nbsp ";?> 
<input type="button" style="color:blue " onclick="window.open('listpeda.php?metro=<?php echo $metro;?>','','width=600,height=500')" value="Προγραμματισμός Μαθήματος" />

</fieldset>
</form>	
<?php
}

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

</body>
</html>