<?php
include "scrinit.php";
include "logo1.php";
date_default_timezone_set("Europe/Athens");

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<script type="text/javascript" src="js/jquery-1.11.3-jquery.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<style>
.fset
{
    width:600px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
.label1
{
display:inline-block;
width:150px;
margin-right:10px;
text-align:right;
}
.label2
{
display:inline-block;
width:130px;
margin-right:10px;
text-align:right;
}
.button {
  display: inline-block;
  padding: 8px 20px;
  font-size: 18px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  outline: none;
  color: #fff;
  background-color: #4CAF50;
  border: none;
  border-radius: 10px;
  box-shadow: 0 9px #999;
}

.button:hover {background-color: #D4AC0D}

.button:active {
  background-color: #3e8e41;
  box-shadow: 0 3px #666;
  transform: translateY(2px);
}

</style>
</head>
<body>
<h3> ΑΝΕΒΑΣΜΑ ΦΩΤΟΓΡΑΦΙΑΣ ΑΠΟΛΥΤΗΡΙΟΥ</h3>
<?php
include "dbconnect.php";
$usr=$_SESSION['usr'];
$sql=mysqli_query($con, "SELECT onoma,eponimo,tmima,pateras FROM allstudentinfo WHERE mitroo='$usr' ");
$row=mysqli_fetch_array($sql);
$mitroo=$usr;
$name=$row['eponimo']." ".$row['onoma'];
$tmima=$row['tmima'];
$namep=$row['pateras'];

$path = 'uploads/'; // upload directory
$sqlm=mysqli_query($con, "SELECT filen,chkim FROM img WHERE mitroo='$mitroo' ");
$in=mysqli_num_rows($sqlm);
if ($in > 0 )
{
	$rowm=mysqli_fetch_array($sqlm);
	$img1=$path.$rowm['filen'];
	$chk=$rowm['chkim'];
	if ($chk==0) $ap='EKKREMEI';
	if ($chk==1) $ap='ΕΓΚΡΙΘΗΚΕ';
	if ($chk==9) $ap='ΑΠΟΡΡΙΦΘΗΚΕ';
}
else
{
	$img1='dummy.jpg';
	$chk=0;
	$ap='EKKREMEI';
	$in=0;
}

?>
<form id="form" method="post" enctype="multipart/form-data">
<fieldset fieldset class="fset" >
<legend> ΣΤΟΙΧΕΙΑ ΜΑΘΗΤΗ / ΤΡΙΑΣ </legend>
<p>
<label class="label1" >ΜΗΤΡΩΟ:</label>
<input type="text" class="form-control" name="mitroo" value='<?php echo $mitroo; ?>' size ='10' required />
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <label class="label2"  >ΤΜΗΜΑ: </label>
<input type="text" class="form-control" value='<?php echo $tmima; ?>' name="tmima" size='8' required />
</p>
<p>
<label class="label1" >ΟΝΟΜΑΤΕΠΩΝΥΜΟ:</label>
<input type="text" value='<?php echo $name; ?>' name="name"  required />
</p>
<p>
<label class="label1" >ΟΝΟΜΑ ΠΑΤΕΡΑ:</label>
<input type="text" value='<?php echo $namep; ?>' name="namep"  required />
</p>
<p>
<label class="label1" >ΑΠΟΔΟΧΗ ΦΩΤΟΓΡ.:</label>
<input type="text" value='<?php echo $ap; ?>' name="ap"  required />
</p>
<p style="color: red; text-align: center">Η ΦΩΤΟ ΝΑ ΕΙΝΑΙ ΣΕ ΜΟΡΦΗ JPEG, ΜΕΓΕΘΟΣ 3.5 x 4.5 εκατ., ΕΓΧΡΩΜΗ, ΣΕ ΑΝΑΛΥΣΗ 300dpi. ΟΤΑΝ Η ΦΩΤΟ ΕΜΦΑΝΙΣΤΕΙ ΣΤΗΝ ΟΘΟΝΗ ΣΑΣ ΣΗΜΑΙΝΕΙ ΠΩΣ ΑΝΕΒΗΚΕ ΜΕ ΕΠΙΤΥΧΙΑ</p>
<p>
<input id="uploadImage" type="file" accept="image/*" name="image" />
<br>
</p>
<img src=<?php echo $img1; ?> /> 
<br><br>
<input class="button" type="submit" value="Ανέβασμα-Upload"  >
</fieldset>
</form>
<div id="err"></div>
<?php
if ($chk == 0 or $chk == 9)
{
$valid_extensions = array('jpeg', 'jpg'); // valid extensions
$path = 'uploads/'; // upload directory

if(!empty($_POST['name']) || !empty($_POST['mitroo']) || !empty($_POST['namep']) || $_FILES['image'])
{
$img = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];

// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
  $image_info   = getimagesize($tmp);
  $imw  = $image_info[0];echo $imw;
  $imh = $image_info[1];echo $imh;
  $imt   = $image_info[2];
if (($imw < 450 and $imw > 300) and ($imh < 550 and $imh > 400))
{
	// check's valid format
	if(in_array($ext, $valid_extensions)) 
	{
		$imgf = $mitroo.'.jpg'; 	
		$path = $path.strtolower($imgf);

		  
		$mitroo = $_POST['mitroo'];
		//insert form data in the database
		$sqlm=mysqli_query($con, "SELECT chkim FROM img WHERE mitroo='$mitroo' ");
		$in=mysqli_num_rows($sqlm);
		if ($in > 0 )
		{
			$rowm=mysqli_fetch_array($sqlm);
			$chk=$rowm['chkim']; 
			if ($chk <> 1) 
			{
				mysqli_query($con, "delete from img where mitroo='$mitroo'");
				$insert = $dbcon->query("INSERT into img (mitroo,filen) VALUES ('$mitroo','$imgf')");
				move_uploaded_file($tmp,$path);
				header('Location: '.$_SERVER['REQUEST_URI']);
			}
			if ($chk == 1) 
			{
				$mes='ΔΕΝ ΜΠΟΡΕΙΤΕ ΝΑ ΑΛΛΑΞΕΤΕ ΦΩΤΟΓΡΑΦΙΑ ΠΟΥ ΕΧΕΙ ΕΓΚΡΙΘΕΙ';
				echo "<script type='text/javascript'>alert('$mes');</script>";
				
			}
		}
		else
		{
			$insert = $dbcon->query("INSERT into img (mitroo,filen) VALUES ('$mitroo','$imgf')");
			move_uploaded_file($tmp,$path);
			
		}
		$mes='Η ΦΩΤΟΓΡΑΦΙΑ ΣΑΣ ΑΝΕΒΗΚΕ ΜΕ ΕΠΙΤΥΧΙΑ';
		echo "<script type='text/javascript'>alert('$mes');</script>";	
		header('Location: '.$_SERVER['REQUEST_URI']);
	}
	else
	{
		$mes='Η ΦΩΤΟΓΡΑΦΙΑ ΔΕΝ ΕΙΝΑ ΣΕ ΜΟΡΦΗ JPEG';
		echo "<script type='text/javascript'>alert('$mes');</script>";	
	}

}
else
{
      $mes='ΤΟ ΜΕΓΕΘΟΣ ΤΗΣ ΦΩΤΟΓΡΑΦΙΑ ΔΕΝ ΕΙΝΑΙ 3,5X4,5 εκ ΣΤΑ 300 dpi';
		echo "<script type='text/javascript'>alert('$mes');</script>";
}
}
}
?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>

</html>