<?php
session_start();
include '../../classes/admins.php';
$admin=new Admins("../../manage/connection.php");
$address="";
$image="default.jpg";
// $admin=$_SESSION['admin']['id'];
if(isset($_POST['fullname']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['password']))
{
    
    $fullname=htmlentities($_POST['fullname']);
    $phone=htmlentities($_POST['phone']);
    $password=md5($_POST['password']);
    $email=htmlentities($_POST['email']);
    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(!$admin->findAdmin($phone) && !$admin->findAdmin($email))
    {
        if($admin->addAdmin($fullname,$phone, $email, $password))
        {
            echo 'Admin Added';
        }
        else
        {
            echo 'Could Not Add';
        }
    }
    else
    {
        echo "Admin 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['email']))
    {
        echo '<div>Email Not Set</div>';
    }
    if(!isset($_POST['password']))
    {
        echo '<div>Passwor Not Set</div>';
    }
}
?>