function displayAllUsers()
{
    $usersDAO = new UsersDAO(MaBD::getInstance());
    $users = $usersDAO->getAll();
    foreach ($users as $user) {
        displayUser($user);
    }
}
Exemple #2
0
 static function getInstance()
 {
     if (self::$pdo == null) {
         $dsn = "mysql:host=localhost;dbname=dgenthia;charset=utf8";
         self::$pdo = new PDO($dsn, "dgenthia", "dgenthia");
     }
     return self::$pdo;
 }
function displayAllMovies()
{
    $moviesDAO = new MoviesDAO(MaBD::getInstance());
    $movies = $moviesDAO->getAll();
    foreach ($movies as $movie) {
        displayMovie($movie);
    }
}
 static function getInstance()
 {
     if (self::$pdo == null) {
         $dbHost = getenv('OPENSHIFT_MYSQL_DB_HOST');
         $dbName = getenv('OPENSHIFT_GEAR_NAME');
         $dbUser = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
         $dbPassword = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
         self::$pdo = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8", $dbUser, $dbPassword);
     }
     return self::$pdo;
 }
Exemple #5
0
<?php

require_once "autoload.php";
function afficheTout($contacts)
{
    echo "------- Tous les contacts :\n";
    foreach ($contacts->getAll() as $c) {
        echo $c, "\n";
    }
    echo "---------------------------\n";
}
$moi = new Contact(array('id' => DAO::UNKNOWN_ID, 'nom' => "Genthial", 'prénom' => "Damien", 'tél' => "04 75 99 99 99"));
echo $moi, "\n";
$contacts = new ContactsDAO(MaBD::getInstance());
echo $contacts->getOne(1), "\n";
echo $contacts->getOne(2), "\n";
echo "------- Tous les contacts :\n";
foreach ($contacts->getAll() as $c) {
    echo $c, "\n";
}
echo "---------------------------\n";
echo "Enregistrement de ";
$contacts->insert($moi);
echo $moi, "\n";
echo "------- Tous les contacts triés par nom :\n";
foreach ($contacts->getAll("ORDER BY nom") as $c) {
    echo $c, "\n";
}
echo "---------------------------\n";
echo "Modification de {$moi}\n";
$moi->tél = "04 75 41 88 12";
Exemple #6
0
<?php

require_once "autoload.php";
$factory = new ContactsDAO(MaBD::getInstance());
$lesContacts = $factory->getAll("ORDER by nom");
//echo json_encode($lesContacts, JSON_PRETTY_PRINT);
echo json_encode($lesContacts);
<?php

// test des cas particuliers dans DAO et TableObject :
//  - table composée d'un seul champ clé autoincrémentée
require_once "autoload.php";
echo "------- Avant insertion :\n";
$nouv = new OneAutoIncremented(array('num' => DAO::UNKNOWN_ID));
echo "{$nouv}\n";
echo "------- Après insertion :\n";
$oneDAO = new OneAutoIncrementedDAO(MaBD::getInstance());
$oneDAO->insert($nouv);
echo "{$nouv}\n";
echo "------- Après getOne({$nouv->num}) :\n";
$dernierInsere = $oneDAO->getOne($nouv->num);
echo "{$dernierInsere}\n";
echo "------- Toutes les valeurs :\n";
foreach ($oneDAO->getAll() as $one) {
    echo "{$one}\n";
}
echo "------- Toutes les valeurs en ordre inverse :\n";
foreach ($oneDAO->getAll("ORDER BY num DESC") as $one) {
    echo "{$one}\n";
}
echo "------- Toutes les valeurs après suppression du dernier inséré :\n";
$oneDAO->delete($dernierInsere);
foreach ($oneDAO->getAll() as $one) {
    echo "{$one}\n";
}
exit(0);
    $mov_director = isset($_POST["mov_director"]) ? escapeCharacters($_POST["mov_director"]) : null;
    $mov_year = isset($_POST["mov_year"]) ? escapeCharacters($_POST["mov_year"]) : null;
    $mov_image = isset($_FILES["mov_image"]["name"]) ? $_FILES["mov_image"]["name"] : null;
    $old_mov_image = isset($_POST["old_mov_image"]) ? escapeCharacters($_POST["old_mov_image"]) : null;
    // Si l'utilisateur a uploadé une nouvelle image
    if (!empty($mov_image)) {
        // On la déplace sur le serveur
        $mov_image_on_server = "./images/" . $mov_image;
        move_uploaded_file($_FILES["mov_image"]["tmp_name"], $mov_image_on_server);
        $mov_image = $mov_image_on_server;
    } else {
        // Sinon l'ancienne photo est l'actuelle
        $mov_image = $old_mov_image;
    }
    // On sauvegarde les modifications
    $moviesDAO = new MoviesDAO(MaBD::getInstance());
    $movie = new Movie($mov_id, $mov_title, $mov_description_short, $mov_description_long, $mov_director, $mov_year, $mov_image);
    $res = $moviesDAO->update($movie);
}
?>

<!DOCTYPE HTML>
<html>

<?php 
include_once "includes/Head.php";
?>

<body>
    <?php 
include_once "includes/NavBar.php";
<?php

// test des cas particuliers dans DAO et TableObject :
//  - table composée seulement de deux clés étrangères, constituant la clé primaire
require_once "autoload.php";
$assoADAO = new AssociationTableDAO(MaBD::getInstance());
echo "------- Valeurs avant insertion :\n";
foreach ($assoADAO->getAll() as $one) {
    echo "{$one}\n";
}
echo "------- getOne(array(1, 2)) :\n";
$one = $assoADAO->getOne(array(1, 2));
echo "{$one}\n";
echo "------- Insertion de array('num' => 4, 'id' => 4) :\n";
$nouv = new AssociationTable(array('num' => 4, 'id' => 4));
$assoADAO->insert($nouv);
echo "------- getOne(array(4, 4)) :\n";
$dernierInsere = $assoADAO->getOne(array(4, 4));
echo "{$dernierInsere}\n";
echo "------- Toutes les valeurs :\n";
foreach ($assoADAO->getAll() as $one) {
    echo "{$one}\n";
}
echo "------- Toutes les valeurs pour num = 1:\n";
foreach ($assoADAO->getAll("WHERE num='1'") as $one) {
    echo "{$one}\n";
}
echo "------- Toutes les valeurs après suppression du dernier inséré :\n";
$assoADAO->delete($dernierInsere);
foreach ($assoADAO->getAll() as $one) {
    echo "{$one}\n";
<?php

// Test d'une classe dérivée : Administratif hérite de Administratif
require_once "autoload.php";
$moi = new Administratif(array('personneId' => DAO::UNKNOWN_ID, 'nom' => "Genthial", 'prénom' => "Damien", 'courriel' => "*****@*****.**", 'bureau' => "A999", 'poste' => "999"));
echo $moi, "\n";
$administratifs = new AdministratifsDAO(MaBD::getInstance());
echo $administratifs->getOne(1), "\n";
echo $administratifs->getOne(2), "\n";
echo "------- Tous les administratifs :\n";
foreach ($administratifs->getAll() as $p) {
    echo $p, "\n";
}
echo "---------------------------\n";
echo "Enregistrement de ";
$administratifs->insert($moi);
echo $moi, "\n";
echo "------- Tous les administratifs triés par nom :\n";
foreach ($administratifs->getAll("ORDER BY nom") as $p) {
    echo $p, "\n";
}
echo "---------------------------\n";
echo "Modification de {$moi}\n";
$moi->courriel = "*****@*****.**";
$moi->poste = "812";
$administratifs->update($moi);
echo "\t==> {$moi}\n";
echo "------- Tous les administratifs triés par prénom :\n";
foreach ($administratifs->getAll("ORDER BY prénom") as $p) {
    echo $p, "\n";
}
Exemple #11
0
require_once "autoload.php";
// ------- contrôleur -------
session_start();
// Préparation des paramètres
$param['login'] = isset($_POST['login']) ? trim($_POST['login']) : "";
$param['password'] = isset($_POST['password']) ? trim($_POST['password']) : "";
$param['erreur'] = false;
$param['message'] = "";
if (isset($_POST['quoi'])) {
    // le formulaire a été soumis
    if (empty($param['login']) || empty($param['password'])) {
        $param['erreur'] = true;
        $param['message'] = "Merci de saisir un nom et un mot de passe...";
    } else {
        // Recherche de l'identification dans la base
        $administrateurs = new AdministrateursDAO(MaBD::getInstance());
        $user = $administrateurs->checkUser($param['login'], $param['password']);
        if ($user == null) {
            $param['erreur'] = true;
            $param['message'] = "Erreur d'authentification (" . $param['login'] . ").";
        } else {
            $_SESSION['login'] = $user->login;
            header("Location: gestion.php");
            exit(0);
        }
    }
}
// ------- vue -------
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    header('Location: index.php');
    exit(0);
}
// Fonction qui permet d'éviter les injections JavaScript
function escapeCharacters($data)
{
    return htmlspecialchars($data);
}
// Récupération de toutes les données saisies
$user_username = isset($_POST["user_username"]) ? escapeCharacters($_POST["user_username"]) : null;
$user_password = isset($_POST["user_password"]) ? escapeCharacters($_POST["user_password"]) : null;
$invalidInformation = false;
// Si l'utilisateur a saisi des informations
if (isset($user_username) && isset($user_password)) {
    // On cherche à vérifier les informations saisies
    $usersDAO = new UsersDAO(MaBD::getInstance());
    $user = $usersDAO->isCorrectUser($user_username, $user_password);
    // Si les information sont correctes, on stocke les informations dans la session courante
    if (isset($user)) {
        $_SESSION["id"] = $user->user_id;
        $_SESSION["username"] = $user->user_username;
        $_SESSION["password"] = $user->user_password;
        header('Location: index.php');
        exit(0);
    } else {
        $invalidInformation = true;
    }
}
?>

<!DOCTYPE HTML>
Exemple #13
0
<?php

require_once "autoload.php";
$pdo = MaBD::getInstance();
var_dump($pdo);
$stmt = $pdo->query("SELECT * FROM AssociationTable");
print_r($stmt->fetchAll(PDO::FETCH_ASSOC));