Exemple #1
0
$stmt = $auth_user->runQuery("SELECT * FROM admin WHERE id=:user_id");
$stmt->execute(array(":user_id" => $user_id));
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);
$service = new PostService();
$listguard = $service->listGuard();
$listpost = $service->listPost();
if (isset($_POST["validate"])) {
    $interval = $_POST["hour"];
    $heure = $_POST["date"];
    $guard = $_POST["guard"];
    $post = $_POST["post"];
    $debut = $_POST["debut"];
    $fin = $_POST["fin"];
    try {
        $guard_id = $service->getGuardId($guard);
        $poste_id = $service->getPostId($post);
        $stmt = $service->runQuery("SELECT poste_id, guard_id FROM guardtours WHERE poste_id=:poste_id OR guard_id=:guard_id");
        $stmt->execute(array(':poste_id' => $poste_id, ":guard_id" => $guard_id));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($row['poste_id'] == $poste_id) {
            $error[] = "sorry this post already taken !";
        } else {
            if ($row['guard_id'] == $guard_id) {
                $error[] = "sorry this guard already taken !";
            } else {
                $service->registerTools($heure, $interval, $debut, $fin, $guard_id, $poste_id);
            }
        }
    } catch (PDOException $e) {
        echo $e->getMessage();
    }