<?php
include '../config/index.php';
include '../module/index.php';
 
$data = new Database;

$con  = $data->connect();

$user = new User($con);

$post = filter_var_array($_POST,FILTER_SANITIZE_FULL_SPECIAL_CHARS);

$name        = $post['name'];
$phone       = $post['phone'];

$address     = $post['address'];

$file        = $_FILES['file']['name'];

$temp        = $_FILES['file']['tmp_name'];
    
$valid_extensions = array('png','jpeg'); // valid extensions

$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));

$image = time().'.'.$ext;

$path = '../assets/img/'.$image; // upload directory

if(!in_array($ext,$valid_extensions)){
   $_SESSION['t_error_c']  = 'Invalid image format Only png, are allowed';
   echo $data->redirect('../account/../index?edit=site');
}else{
  if(move_uploaded_file($temp,$path)){
      echo $user->updateProfile($name,$phone,$address,$image);
      //echo $user->createTransaction($amount,$user_id,$reference,'nill',$c,$status,'Credit');
       $_SESSION['t_error_c']  = 'profile settings updated successfully ';
       echo $data->redirect('../account/../index?home=home');
  }else{
     $_SESSION['t_error_c']  = 'error uploading file';
      echo $data->redirect('../account/../index?edit=edit');
  }

}


?>