예제 #1
0
<?php

session_start();
require_once '../models/database.php';
require_once '../models/vocable.php';
require_once '../models/lesson.php';
#  This script calculates the next_date field for right vocs and resets wrong ones.
#  It returns all information that is needed for the javascript to update the site with new vocs,
#  that is: own_/foreign_language, lesson, step, index
$db = new DatabaseConnector($_SESSION['user_id']);
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
예제 #2
0
<?php

session_start();
require_once '../models/database.php';
require_once '../models/vocable.php';
$date = date("Y-m-d");
$db = new DatabaseConnector($_SESSION['user_id']);
//if request come from change-site, update the vocable and return to managing page
if (isset($_POST['change'])) {
    $voc = $db->getVocById($_POST['id']);
    $voc->setOwnLang($_POST['ownLanguage']);
    $voc->setForeignLang($_POST['foreignLanguage']);
    $db->updateVoc($voc);
    header("Location: " . $_POST['origin']);
    die;
}
$voc = new Vocable($_SESSION['user_id'], $_POST["ownLanguage"], $_POST["foreignLanguage"], $_POST["lesson"], $date);
$db->createVoc($voc);
/*$pdo = new PDO("mysql:host=localhost;dbname=vokabeltrainer", "root", "123");
	#Prepare Array for insert
	$newVocable["ol"]=$_POST["ownLanguage"];
	$newVocable["fl"]=$_POST["foreignLanguage"];
	$newVocable["lesson"]=$_POST["lesson"];
	$newVocable["nextDate"]=$_POST["date"];
	$newVocable["user_id"]=$_SESSION['user_id'];
	$statement = $pdo->prepare("INSERT INTO vocables (own_language, foreign_language, lesson, next_date, user_id) VALUES (:ol, :fl, :lesson, :nextDate, :user_id)");

	$statement->execute($newVocable);
	
	$id=$pdo->lastInsertId();*/
echo TRUE;
<?php

session_start();
require_once '../models/database.php';
require_once '../models/vocable.php';
require_once '../models/lesson.php';
$ids = json_decode($_POST['ids']);
$db = new DatabaseConnector($_SESSION['user_id']);
$step = $_POST['step'];
foreach ($ids as $id) {
    $voc = $db->getVocById($id);
    if ($voc->getStep() > $step) {
        $voc->setStep($step);
    }
    $db->updateVoc($voc);
}
echo "Done";