<?php
include '../../classes/admins.php';
$admin=new Admins("../../manage/connection.php");
$address="";
$image="default.jpg"; 
if(isset($_POST['fullname']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['password']))
{ 
    $fullname=htmlentities($_POST['fullname']);
    $phone=htmlentities($_POST['phone']);
    $email=htmlentities($_POST['email']);
    $admin_id=htmlentities($_POST['admin_id']);
    
    if($admin->findAdmin($phone) || $admin->findAdmin($email))
    {
        $tInfo=$admin->getAdmin($admin_id);
        if(isset($_POST['password']) && !$_POST['password']=="")
        {
            $password=md5($_POST['password']);
        }
        else
        {
            $password=$tInfo['password'];
        }
        // Check for image
        // 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);
        // }
        // else
        // {
        //     $image=$tInfo['image'];
        // }


        if($admin->updateAdmin($admin_id, $fullname, $phone, $email, $password))
        {
            echo 'Admin Updated';
        }
        else
        {
            echo 'Could Not Update';
        }
    }
    else
    {
        echo "Admin Not 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['password']))
    {
        echo '<div>Passwor Not Set</div>';
    }
}
?>