<?php
session_start();
include '../../classes/teachers.php';
$teacher=new Teachers("../../manage/connection.php");
$address="";
$image="default.jpg";
$admin=$_SESSION['admin']['id'];
if(isset($_POST['fullname']) && isset($_POST['phone']) && isset($_POST['gender']) && isset($_POST['password']))
{
    if(isset($_POST['address']))
    {
        $address=htmlentities($_POST['address']);
    }
    $fullname=htmlentities($_POST['fullname']);
    $phone=htmlentities($_POST['phone']);
    $password=md5($_POST['password']);
    $gender=htmlentities($_POST['gender']);
    if(isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name']))
    {
        $temp_name=$_FILES['image']['tmp_name'];
        $image=$phone.'_'.$_FILES['image']['name'];
        move_uploaded_file($temp_name,'../images/'.$image);
    }
    
    if(!$teacher->findTeacher($phone))
    {
        if($teacher->addTeacher($fullname, $phone, $address, $gender, $password, $image, $admin))
        {
            echo 'Teacher Added';
        }
        else
        {
            echo 'Could Not Add';
        }
    }
    else
    {
        echo "Teacher Already Exist";
    }
}
else
{
    if(!isset($_POST['fullname']))
    {
        echo '<div>Name Not Set</div>';
    }
    if(!isset($_POST['phone']))
    {
        echo '<div>Phone Not Set</div>';
    }
    if(!isset($_POST['gender']))
    {
        echo '<div>Gender Not Set</div>';
    }
    if(!isset($_POST['password']))
    {
        echo '<div>Passwor Not Set</div>';
    }
}
?>