<?php

session_start();
require_once '../models/database.php';
require_once '../models/lesson.php';
$db = new DatabaseConnector($_SESSION['user_id']);
$lesson = $db->getLessonById($_POST['id']);
$lesson->setActive($_POST['state'] == "true" ? 1 : 0);
$db->updateLesson($lesson);
/*$pdo = new PDO("mysql:host=localhost;dbname=vokabeltrainer", "root", "123");
	$lesson["id"]=$_POST['id'];
	$lesson["state"]=($_POST['state']=="true"?1:0);
	$statement=$pdo->prepare("UPDATE lessons SET active = :state WHERE id = :id");
	$statement->execute($lesson);*/
echo "Set lesson with id " . $lesson->getId() . " to " . $lesson->getActive();
Example #2
0
if (isset($_POST['result'])) {
    $db->scheduleVoc($_SESSION['current_id'], $_POST['result'], $_SESSION['plan']);
    if ($_POST['result'] == "right") {
        $_SESSION['right_c']++;
        $db->setResultCount('right_c', $_SESSION['right_c']);
        if ($db->getVocById($_SESSION['current_id'])->getStep() == 6) {
            $_SESSION['mastered_c']++;
            $db->setResultCount('mastered_c', $_SESSION['mastered_c']);
        }
    } elseif ($_POST['result'] == "wrong") {
        $_SESSION['wrong_c']++;
        $db->setResultCount('wrong_c', $_SESSION['wrong_c']);
    }
}
#  Now return the next vocable
$new_voc = $db->getNextVocable();
if (!$new_voc) {
    die("end");
}
$_SESSION['current_id'] = $new_voc->getId();
//shuffle based on direction setting
if ($_SESSION['direction'] == "of") {
    $new_voc->swap();
} elseif ($_SESSION['direction'] == "ra") {
    $new_voc->swapRandomly();
}
$lesson = $db->getLessonById($new_voc->getLesson());
$data = $new_voc->toArray();
$data["lesson_name"] = $lesson->getName();
//echo $new_voc->toJSON();
echo json_encode($data);