<?php
include('../include/config.php');
error_reporting(0);
session_start();
$iduser=$_SESSION['user_idd'];
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');

$em='';

if(isset($_POST['te']))
{
$te=addslashes($_POST['te']);
$claz=addslashes($_POST['claz']);

$query=mysqli_query($con,"select * from Classteachers where Teacher='$te'");
$num=mysqli_fetch_array($query);
if($num>0)
{
echo "Selected teacher already assigned to another class";
}else
{
  $query2=mysqli_query($con,"select * from Classteachers where Clazzz='$claz'");
$num=mysqli_fetch_array($query2);
if($num>0)
{
echo 'Class already assigned to another teacher';
}else
{
$sql=mysqli_query($con,"INSERT INTO Classteachers(Teacher,Clazzz) values('$te','$claz')");
if($sql)
{
$msg='assigned a teacher to '.$claz;
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "Successfully saved";
}else
{
echo 'Unable to save';
}  
}

}
}

?>