<?php
include "scrinit.php";
include $menu;
?><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; }

.fieldset1
{
    width:600px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;	
    border-radius:4px;	
}

.label1
{
display:inline-block;
width:95px;
margin-right:10px;
text-align:right;
}
.label2
{
display:inline-block;
width:150px;
margin-right:10px;
text-align:right;
}
</style>
<br>
<h3>ΑΡΧΙΚΟΠΟΙΗΣΗ ΠΑΡΑΜΕΤΡΩΝ ΣΥΣΤΗΜΑΤΟΣ </h3>
<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
//.................................... generalinfo ...................
$sql = $dbcon->prepare("SELECT * FROM generalinfo " );
$sql->execute();
$row=$sql->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount();

$school=$row['schoolname'];
$year=$row['year'];
$logo=$row['logo'];
$tel=$row['tel'];
$adr1=$row['adr1'];
//.................................... sysset SMS ...........................
$sql2 = $dbcon->prepare("SELECT * FROM sysset " );
$sql2->execute();
$row2=$sql2->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount();

$smsuser=$row2['smsuser'];
$smspass=$row2['smspass'];
$smsname=$row2['smsname'];
$smscode=$row2['smscode'];
$smsalert=$row2['tohead'];
$smsasf=$row2['toasf'];
//.................................... parameters ...........................
$sql1 = $dbcon->prepare("SELECT * FROM parameters " );
$sql1->execute();
$row=$sql1->fetch(PDO::FETCH_ASSOC);

$hpass=$row['hpass'];
$gymnasio=$row['gymnasio'];
//$pedagogikes=$row['pedagogikes'];
//$apousies=$row['apousies'];
//$omiloi=$row['omiloi'];
$diaga=$row['diaga'];
$diagb=$row['diagb'];
$atetrs=$row['atetrs'];
$atetre=$row['atetre'];
$btetrs=$row['btetrs'];
$btetre=$row['btetre'];

//$diloseis=$row['diloseis'];
$smskath=$row['smskath'];
$apkath=$row['apkath'];
$aptime=$row['aptime'];
if ($apkath==0){$aptime=0;}

?>
<form  name="params" method="post" >

<fieldset fieldset class="fieldset1"  >
<legend> <?php echo "<b>"."ΣΤΟΙΧΕΙΑ ΣΧΟΛΕΙΟΥ/ΧΡΟΝΙΑΣ"."</b>"; ?> </legend>
<p><label class="label1" >ΣΧΟΛΕΙΟ:</label><input type='text' size='60' name='school' value = "<?php echo $school; ?>" /></p>
<p><label class="label1" > ΣΧΟΛΙΚΗ ΧΡΟΝΙΑ:</label><input type='text' name='year' size='20' value = "<?php echo $year; ?>" /></p>
<p><label class="label1" > ΔΙΕΥΘΥΝΣΗ:</label><input type='text' name='adr1' size='60' value = "<?php echo $adr1; ?>" /></p>
<p><label class="label1" > ΤΗΛΕΦΩΝΟ:</label><input type='text' name='tel' size='12' value = "<?php echo $tel; ?>" />
&nbsp&nbsp&nbsp&nbspΛΟΓΟΤΥΠΟ ΣΧΟΛΕΙΟΥ:<input type='text' name='logo' size='4' value = "<?php echo $logo; ?>" /></p>
</fieldset>
<br> <br>
<?php
echo "<table style='width:800px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#66CC99' >
<th>ΠΑΡΑΜΕΤΡΟΣ</th>
<th>ΤΙΜΗ 1</th>
<th>ΤΙΜΗ 2</th>
<th></th>
</tr>";
?>
<tr>
<td ><b>Κωδικοί Πρόσβασης :</b></td>
<td ><Input type = 'Radio' name ='hpass' value= '1' <?php if ($hpass==1) {echo "checked";}else{echo "";}?> >Hashed Passwords</td>
<td ><Input type = 'Radio' name ='hpass' value= '0' <?php if ($hpass==0) {echo "checked";}else{echo "";}?> >Plain Passwords </td>
<td></td>
<tr>
<td ><b>Τύπος Σχολείου :</b></td>
<td ><Input type = 'Radio' name ='gymnasio' value= '1' <?php if ($gymnasio==1) {echo "checked";}else{echo "";}?> >Γυμνάσιο </td>
<td ><Input type = 'Radio' name ='gymnasio' value= '2' <?php if ($gymnasio==2) {echo "checked";}else{echo "";}?> >Λύκειο </td>
<td ><Input type = 'Radio' name ='gymnasio' value= '3' <?php if ($gymnasio==3) {echo "checked";}else{echo "";}?> >Αθλητικό </td>
<tr>
<td ><b>A' Τετράμηνο:</b></td>
<td ><b>Αρχή :</b> <Input type = 'date' name ='atetrs' value= <?php echo $atetrs; ?>  > </td>
<td ><b>Τέλος :</b> <Input type = 'date' name ='atetre' value= <?php echo $atetre; ?> > </td>
<td></td>
<tr>
<td ><b>B' Τετράμηνο:</b></td>
<td ><b>Αρχή :</b> <Input type = 'date' name ='btetrs' value= <?php echo $btetrs; ?> size='3' > </td>
<td ><b>Τέλος :</b> <Input type = 'date' name ='btetre' value= <?php echo $btetre; ?> size='3' > </td>
<td></td>
<tr>
<td ><b>Τελευταία Ημερ. Διαγωνισμάτων:</b></td>
<td ><b>Α΄τετρ :</b> <Input type = 'date' name ='diaga' value= <?php echo $diaga; ?>  > </td>
<td ><b>Β΄τετρ :</b> <Input type = 'date' name ='diagb' value= <?php echo $diagb; ?> > </td>
<td></td>
<tr>
<td ><b>Αυτόματη αποστολή SMS για αργοπορία :</b></td>
<td ><Input type = 'Radio' Name ='smskath' value= '1' <?php if ($smskath==1) {echo "checked";}else{echo "";}?> >ΝΑΙ - Αποστολή </td>
<td ><Input type = 'Radio' Name ='smskath' value= '0' <?php if ($smskath==0) {echo "checked";}else{echo "";}?> >ΟΧΙ</td>
<td></td>
<tr>
<td ><b>Καταχώρηση απουσίας απο καθυστέρηση :</b></td>
<td ><Input type = 'Radio' Name ='apkath' value= '1' <?php if ($apkath==1) {echo "checked";}else{echo "";}?> >ΝΑΙ - Καταχώρηση</td>
<td ><Input type = 'Radio' Name ='apkath' value= '0' <?php if ($apkath==0) {echo "checked";}else{echo "";}?> >ΟΧΙ</td>
<td ><b>Χρόνος:</b> <Input type = 'text' name ='aptime' value= <?php echo $aptime; ?> size='3' > </td>
</tr>
</table>
</fieldset>
<br> <br>
<h4> ΚΩΔΙΚΟΙ-ΠΑΡΑΜΕΤΡΟΙ ΓΙΑ ΑΠΟΣΤΟΛΗ SMS </h4>
<?php
echo "<table style='width:800px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#66CC99' >
<th>ΠΑΡΑΜΕΤΡΟΣ</th>
<th>ΤΙΜΗ</th>
</tr>";
?>
<tr>
<td ><b>Όνομα Χρήστη(User Name) :</b></td>
<td ><Input type = 'text' name ='smsuser' value=<?php echo $smsuser;?> > </td>
<tr>
<td ><b>Κωδικός Χρήστη(Password) :</b></td>
<td ><Input type = 'text' name ='smspass' value=<?php echo $smspass;?> > </td>
<tr>
<td ><b>Όνομα Αποστολέα :</b></td>
<td ><Input type = 'text' name ='smsname' value=<?php echo $smsname;?> > </td>
<tr>
<td ><b>Κωδικός Αποστολής :</b></td>
<td ><Input type = 'text' name ='smscode' value=<?php echo $smscode;?> > </td>
<tr>
<td ><b>Κινητό τηλ για Alert :</b></td>
<td ><Input type = 'text' name ='smsalert' value=<?php echo $smsalert;?> > </td>
<tr>
<td ><b>Κινητό για Ασφάλεια :</b></td>
<td ><Input type = 'text' name ='smsasf' value=<?php echo $smsasf;?> > </td>
<tr>
</table>
</fieldset>
<br />
<input type="submit" name="paramtrs" value="Καταχώρηση" >
</fieldset>
</form>	
<?php
if(isset($_POST['paramtrs']))
{
$school=$_POST['school'];
$year=$_POST['year'];
$logo=$_POST['logo'];
$tel=$_POST['tel'];
$adr1=$_POST['adr1'];

$hpass=$_POST['hpass'];
$gymnasio=$_POST['gymnasio'];	
$diaga=$_POST['diaga'];
$diagb=$_POST['diagb'];
$atetrs=$_POST['atetrs'];
$atetre=$_POST['atetre'];
$btetrs=$_POST['btetrs'];
$btetre=$_POST['btetre'];

//$diloseis=$row['diloseis'];
$smskath=$_POST['smskath'];
$apkath=$_POST['apkath'];
$aptime=$_POST['aptime'];   

$smsuser=$_POST['smsuser'];
$smspass=$_POST['smspass'];
$smsname=$_POST['smsname']; 
$smscode=$_POST['smscode']; 
$smsalert=$_POST['smsalert']; 
$smsasf=$_POST['smsasf'];

$sql = $dbcon->prepare("SELECT * FROM generalinfo " );
$sql->execute();
$row=$sql->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount(); 
if ($count > 0)
{
$sql = $dbcon->prepare("UPDATE generalinfo set schoolname=?,year=?,logo=?,tel=?,adr1=? "); 
$sql->execute([$school,$year,$logo,$tel,$adr1]);
}
else
{
$sql = $dbcon->prepare("Insert into generalinfo (schoolname,year,logo,tel,adr1) values (?,?,?,?,?) "); 
$sql->execute([$school,$year,$logo,$tel,$adr1]);
}	
try
{ 
$sql2 = $dbcon->prepare("SELECT * FROM parameters " );
$sql2->execute();
$row2=$sql2->fetch(PDO::FETCH_ASSOC);
$count=$sql2->rowCount();
if ($count > 0)
{
$sql = $dbcon->prepare("UPDATE parameters set hpass=?,gymnasio=?,diaga=?,diagb=?,atetrs=?,atetre=?,btetrs=?,btetre=?,smskath=?,apkath=?,aptime=? "); 
}
else
{
$sql = $dbcon->prepare("INSERT INTO parameters (hpass,gymnasio,diaga,diagb,atetrs,atetre,btetrs,btetre,smskath,apkath,aptime) values (?,?,?,?,?,?,?,?,?,?,?) "); 	
}
$sql->execute([$hpass,$gymnasio,$diaga,$diagb,$atetrs,$atetre,$btetrs,$btetre,$smskath,$apkath,$aptime]);	
}
catch(PDOException $e)
{
    handle_sql_errors($selectQuery, $e->getMessage());
}

$sql = $dbcon->prepare("SELECT * FROM sysset " );
$sql->execute();
$row=$sql->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount();
if ($count > 0)
{
$sql = $dbcon->prepare("UPDATE sysset set smspass=?,smsuser=?,smscode=?,smsname=?,tohead=?,toasf=? "); 
$sql->execute([$smspass,$smsuser,$smscode,$smsname,$smsalert,$smsasf]);
}
else
{
$sql = $dbcon->prepare("insert into sysset (smspass,smsuser,smscode,smsname,tohead,toasf) values (?,?,?,?,?,?) "); 
$sql->execute([$smspass,$smsuser,$smscode,$smsname,$smsalert,$smsasf]);	
}
}
function handle_sql_errors($query, $error_message)
{
    echo '<pre>';
    echo $query;
    echo '</pre>';
    echo $error_message;
    die;
}
?>
<br /><br />
<h3>ΓΙΑ ΕΠΙΒΕΒΑΙΩΣΗ ΤΩΝ ΠΑΡΑΜΕΤΡΩΝ ΕΠΕΛΕΞΕ ΞΑΝΑ ΤΗΝ ΑΡΧΙΚΟΠΟΙΗΣΗ ΑΠΟ ΤΟ ΜΕΝΟΥ</h3>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>

</body>
</html>