1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
   |  
<?php
session_start();
 
include('filters/auth_filter.php');
require("config/database.php");
require("includes/functions.php");
require('includes/constants.php');
 
if(isset($_GET['id'])){
	//Récupérer les infos sur l'user en bdd en utilisant son id
	$user = find_user_by_id($_GET['id']);
 
	if(!$user){
		redirect('index.php');
	}
}else{
	redirect('profile.php?id='.get_session('user_id'));
}
 
 
if (isset($_POST['update'])) {
	$errors = [];
	 //Si tous les champs ont été remplis
	 if (not_empty(['name', 'city','country','sex','bio'])) {
 
		 extract($_POST);
 
		 $q = $db->prepare("UPDATE users SET name = :name, city = :city, country = :country,
							sex= :sex, twitter = :twitter, github = :github, available_for_hiring = :available_for_hiring, 
							bio = :bio WHERE id = :id'");
 
		$q->execute(array(
					'name' => $name,
					'city' => $city,
					'country' => $country,
					'sex' => $sex,
					'twitter' => $twitter,
					'github' => $github,
					'available_for_hiring' => !empty($available_for_hiring) ? '1' : '0',
					'bio' => $bio,
					'id' => $_SESSION['user_id']
 
	 ));
		set_flash("Félicitations, votre profil a été mis à jour ! ");			
 
	}else{
		save_input_data();
		$errors[] = "Veuillez remplir tous les champs marqués d'un (*)";
	}
 
 } else {      
 
		clear_input_data();  
 
		} 
require("views/profile.view.php");
?> | 
Partager