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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| <?php
session_start();
class Emploi{
// variables //
/**
* @var int The article ID from the database
*/
public $id = null;
/**
* @var int When the article is to be / was first published
*/
public $dateEmploi = null;
/**
* @var string Full title of the article
*/
public $contrat = null;
/**
* @var string A short summary of the article
*/
public $description= null;
/**
* @var string The HTML content of the article
*/
public $salaire = null;
/**
* @var string The HTML content of the article
*/
public $titre = null;
/**
* @var string The HTML content of the article
*/
public $identifiant = null;
/**
* @var string The HTML content of the article
*/
public $mdp = null;
/**
* @var string The HTML content of the article
*/
public $experience = null;
/**
* @var string The HTML content of the article
*/
public $emploi = null;
/**
* @var string The HTML content of the article
*/
public $postal = null;
/**
* @var string The HTML content of the article
*/
public $ville= null;
/**
* @var string The HTML content of the article
*/
public $pays = null;
/**
* @var string The HTML content of the article
*/
// Contructeur //
public function __construct( $data=array() ) {
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
if ( isset( $data['dateEmploi'] ) ) $this->dateEmploi = (int) $data['dateEmploi'];
if ( isset( $data['contrat'] ) ) $this->contrat = $data['contrat'] ;
if ( isset( $data['titre'] ) ) $this->titre = $data['titre'] ;
if ( isset( $data['description'] ) ) $this->description = $data['description'];
if ( isset( $data['salaire'] ) ) $this->salaire = $data['salaire'] ;
if ( isset( $data['identifiant'] ) ) $this->identifiant = $data['identifiant'] ;
if ( isset( $data['mdp'] ) ) $this->mdp = $data['mdp'] ;
if ( isset( $data['experience'] ) ) $this->experience = $data['experience'] ;
if ( isset( $data['pays'] ) ) $this->pays = $data['pays'] ;
if ( isset( $data['postal'] ) ) $this->postal = $data['postal'] ;
if ( isset( $data['ville'] ) ) $this->ville = $data['ville'] ;
}
// fonction pour recuperer une id d un article et le vsualiser //
public static function getById( $id ) {
$conn = new PDO( DSN, USER, PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8') );
$sql = "SELECT *, UNIX_TIMESTAMP(dateEmploi) AS dateEmploi FROM emplois WHERE id = :id";
$st = $conn->prepare( $sql );
$st->bindValue( ":id", $id, PDO::PARAM_INT );
$st->execute();
$row = $st->fetch();
$conn = null;
if ( $row ) return new Emploi( $row );
}
// fonction pour recuperer les info bd //
public static function getList() {
$db = new PDO(DSN, USER, PASSWORD);
$sql=$db->prepare("SELECT * FROM emplois"); // on prépare notre requête
$sql->execute();
while($lignes=$sql->fetch(PDO::FETCH_OBJ))
{
$lignes->dateEmploi= date("d/m/Y",strtotime($lignes->dateEmploi));
$tableau[]=$lignes;
}
return $tableau;
}
// fonction pour se connecter en admin bd //
public static function connexion($identifiant,$mdp){
$db= new pdo(DSN,USER,PASSWORD);
$sql = "SELECT * FROM utilisateurs WHERE identifiant = :identifiant AND mdp=:mdp";
$st = $db->prepare( $sql );
$st->bindValue( ":identifiant", $identifiant, PDO::PARAM_INT );
$st->bindValue( ":mdp", $mdp, PDO::PARAM_INT );
$st->execute();
$row = $st->fetch();
if (isset($row['identifiant'])&&!empty($row['identifiant'])&& isset($row['mdp'])&&!empty($row['mdp'])&&$row['type']=='admin')
{
$_SESSION['identifiant']=$row['identifiant'];
$_SESSION['mdp']=$row['mdp'];
header('location:/oxylis/Core/utilisateurs/admin.php');
}
else {
echo "Erreur de connexion" ; }
}
// fonction se deconnecter //
public static function deconnexion (){
session_destroy();
header('location:../index.php'); }
// fonction pour inserer les infos bd //
public function insert(){
try
{
$db= new pdo(DSN,USER,PASSWORD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$sql = "INSERT INTO emplois(contrat,dateEmploi,description,experience,pays,postal,salaire,titre,ville) VALUES(:contrat,:dateEmploi,:description,:experience,:pays,:postal,:salaire,:titre,:ville)";
$in=$db->prepare($sql);
$in->bindValue( ":contrat", $_POST['contrat'], PDO::PARAM_STR );
$in->bindValue( ":dateEmploi", $_POST['dateEmploi'], PDO::PARAM_INT );
$in->bindValue( ":description", $_POST['description'], PDO::PARAM_STR );
$in->bindValue( ":experience", $_POST['experience'], PDO::PARAM_STR );
$in->bindValue( ":pays", $_POST['pays'], PDO::PARAM_STR);
$in->bindValue( ":postal", $_POST['postal'], PDO::PARAM_INT );
$in->bindValue( ":salaire", $_POST['salaire'], PDO::PARAM_STR );
$in->bindValue( ":titre", $_POST['titre'], PDO::PARAM_STR );
$in->bindValue( ":ville", $_POST['ville'], PDO::PARAM_STR );
$in->execute();
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
}
// fonction pour updater un article //
public function update(){
try
{
if ( is_null( $this->id ) ) trigger_error ( "Emploi::update(): l'id est null", E_USER_ERROR );
$db= new pdo(DSN,USER,PASSWORD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$sql = " UPDATE emplois SET contrat= :contrat, dateEmploi = :dateEmploi, description = :description, experience = :experience, pays = :pays,postal=:postal,salaire=:salaire,titre=:titre,ville=:ville WHERE id =:id";
$in=$db->prepare($sql);
$in->bindValue( ":contrat", $this->contrat, PDO::PARAM_STR );
$in->bindValue( ":dateEmploi", $this->dateEmploi, PDO::PARAM_INT );
$in->bindValue( ":description", $this->description, PDO::PARAM_STR );
$in->bindValue( ":experience", $this->experience, PDO::PARAM_STR );
$in->bindValue( ":pays", $this->pays, PDO::PARAM_STR);
$in->bindValue( ":postal",$this->postal, PDO::PARAM_INT );
$in->bindValue( ":salaire",$this->salaire, PDO::PARAM_STR );
$in->bindValue( ":titre", $this->titre, PDO::PARAM_STR );
$in->bindValue( ":ville", $this->ville, PDO::PARAM_STR );
$in->bindValue( ":id", $this->id, PDO::PARAM_INT );
$in->execute();
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
}
}
?> |
Partager