<?php session_start();
if(!empty($_SESSION['admin_connect_id']))
{ require('../../config.php');

date_default_timezone_set('Africa/Algiers');
$updated_at=date('Y-m-d H:i:s');


$nom=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['nom']))) ;
$prenom=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['prenom']))) ;
$type=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['type']))) ;

$username=mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['username']))) ;

$name_f=  mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['image']))) ;
$id_user=  mysqli_real_escape_string($con,htmlspecialchars(trim($_POST['id_user']))) ;


if(isset($_FILES['files']))
{   $file_name = $_FILES['files']['name'];
     $namef = $_FILES['files']['name'];
     $file_size =$_FILES['files']['size'];
     $file_tmp =$_FILES['files']['tmp_name'];
     $file_type=$_FILES['files']['type'];
     $desired_dir="../../assets/img_user/";

    if(is_dir("$desired_dir/".$file_name)==false){
      $name_f=   md5(uniqid()) . ".jpg" ;
      $target = "$desired_dir/" . $name_f ;
      move_uploaded_file($file_tmp, $target );
    }

      }


        $sql1 = "UPDATE users SET
        nom='$nom',
        prenom='$prenom',
        type='$type',
        type='$type',
        username='$username',
        img='$name_f',
        updated_at='$updated_at'
        
        
         where id='$id_user' ";

            if(mysqli_query($con,$sql1)){echo 1; }else{

            	echo mysqli_error($con);
            }

}
?>