예제 #1
0
//$csv = array_map('str_getcsv', (file($file['tmp_name'])), [";"]);
$data = file_get_contents($file['tmp_name']);
$lines = explode(PHP_EOL, $data);
$csv = [];
foreach ($lines as $line) {
    $csv[] = str_getcsv($line, ";");
}
//$pdo = new PDO('mysql:host=localhost;dbname=vokabeltrainer', 'root', '123');
$date = date("Y-m-d");
//$statement = $pdo->prepare("INSERT INTO vocables (own_language, foreign_language, lesson, next_date, user_id) VALUES (:ol, :fl, :lesson, :next_date, :user_id)");
foreach ($csv as $row) {
    if (count($row) == 1 and $row[0] != "") {
        $name = getLessonName($row[0]);
        $lesson = $db->getLessonByName($name);
        if ($lesson) {
            $lesson_id = $lesson->getId();
        } else {
            $new_lesson = new Lesson($name);
            $lesson_id = $db->saveLesson($new_lesson)->getId();
        }
    } else {
        $voc = new Vocable($user_id, $row[1], $row[0], $lesson_id, $date);
        /*$newVoc["ol"] = $row[1];
        		$newVoc["fl"] = $row[0];
        		$newVoc["lesson"] = $lesson_id;
        		$newVoc["next_date"] = $date;
        		$newVoc["user_id"] = $user_id;
        		$statement->execute($newVoc);*/
        $db->createVoc($voc);
    }
}
<?php

session_start();
require_once '../models/database.php';
require_once '../models/vocable.php';
require_once '../models/lesson.php';
$db = new DatabaseConnector($_SESSION['user_id']);
if (isset($_POST['change'])) {
    $lesson = $db->getLessonByName($_POST['name']);
    $lesson->setName($_POST['new_name']);
    $db->updateLesson($lesson);
    header("Location: ../manage_lessons.inc.php");
    die;
}
$newLesson = new Lesson($_POST["newLesson"]);
$lesson = $db->saveLesson($newLesson);
if ($lesson) {
    echo $_POST['origin'];
} else {
    /*echo $statement->queryString;
    		echo $statement->errorInfo()[2];*/
    echo FALSE;
}