2016-12-30 05:16:13 +00:00
|
|
|
<?php
|
|
|
|
require_once("includes/include.php");
|
2016-12-31 04:01:14 +00:00
|
|
|
$questionArray = [];
|
2016-12-30 10:01:50 +00:00
|
|
|
$files = glob("files/*");
|
|
|
|
foreach($files as $file) {
|
2016-12-31 04:01:14 +00:00
|
|
|
$questions = [];
|
2016-12-30 10:01:50 +00:00
|
|
|
$fileOpen = file_get_contents($file);
|
|
|
|
$fileOpen = implode("\n", array_slice(explode("\n", $fileOpen), 6));
|
|
|
|
$fileOpen = substr($fileOpen, 1);
|
|
|
|
$data = explode("%", $fileOpen);
|
2016-12-30 05:16:13 +00:00
|
|
|
$data = array_map('trim', $data);
|
2016-12-30 10:01:50 +00:00
|
|
|
foreach ($data as $i => $d) {
|
|
|
|
if (empty($d)) continue;
|
2016-12-30 08:56:35 +00:00
|
|
|
if (strpos(strtolower($d), 'question') !== false) {
|
2016-12-30 10:01:50 +00:00
|
|
|
$fullQuestion = substr(preg_replace('/^.+\n/', '', $d), 1); //Strip useless firstline.
|
2016-12-30 05:16:13 +00:00
|
|
|
$numbers = explode(" ", $fullQuestion);
|
|
|
|
$questions[$i]['questionNumber'] = $numbers[0]; // Get # of question
|
|
|
|
$lengthOfNumber = strlen($questions[$i]['questionNumber']); //Get length of #
|
|
|
|
$splitNewLine = explode("\n", trim($fullQuestion)); //Split rest into lines.
|
2016-12-30 10:01:50 +00:00
|
|
|
$twoLineQuestion = $imageFirstLine = $threeLineQuestion = false;
|
2016-12-30 08:56:35 +00:00
|
|
|
if (strpos(strtolower($splitNewLine[0]), '<img') !== false) {
|
|
|
|
preg_match('/".*?"/', $splitNewLine[0], $matches);
|
|
|
|
$questions[$i]['image'] = strtoupper($matches[0]);
|
2016-12-30 10:01:50 +00:00
|
|
|
|
2016-12-31 04:01:14 +00:00
|
|
|
if (strpos($splitNewLine[1], ':') !== false && !empty(trim($splitNewLine[2]))) {
|
2016-12-30 08:56:35 +00:00
|
|
|
$twoLineQuestion = true;
|
|
|
|
}
|
|
|
|
$cutOutImageShit = explode(">", $splitNewLine[1]);
|
|
|
|
$trashBin = array_shift($cutOutImageShit);
|
|
|
|
$firstLine = implode(" ", $cutOutImageShit);
|
|
|
|
$questions[$i]['question'] = trim(substr(($twoLineQuestion ? $firstLine . " "
|
|
|
|
. $splitNewLine[2] : $firstLine), $lengthOfNumber));
|
|
|
|
} else {
|
|
|
|
if (strpos($splitNewLine[0], ':') !== false || !empty(trim($splitNewLine[1]))) {
|
2016-12-30 10:01:50 +00:00
|
|
|
if (strpos($splitNewLine[0], ':') !== false) {
|
|
|
|
$twoLineQuestion = true;
|
|
|
|
if (strpos(strtolower($splitNewLine[1]), '<img') !== false) {
|
|
|
|
$twoLineQuestion = false;
|
|
|
|
preg_match('/".*?"/', $splitNewLine[1], $matches);
|
|
|
|
$questions[$i]['image'] = strtoupper($matches[0]);
|
|
|
|
}
|
|
|
|
} elseif (!empty(trim($splitNewLine[2]))) {
|
|
|
|
$threeLineQuestion = true;
|
|
|
|
}
|
2016-12-30 08:56:35 +00:00
|
|
|
}
|
|
|
|
$questions[$i]['question'] = trim(substr(($twoLineQuestion ? $splitNewLine[0] . " "
|
|
|
|
. $splitNewLine[1] : $splitNewLine[0]), $lengthOfNumber));
|
|
|
|
}
|
2016-12-30 10:01:50 +00:00
|
|
|
$x = $b = 1;
|
|
|
|
foreach ($splitNewLine as $a => $line) {
|
2016-12-31 04:01:14 +00:00
|
|
|
//Don't ask what this witchcraft is. I don't know either.
|
2016-12-30 10:01:50 +00:00
|
|
|
if ($a == 0) continue;
|
|
|
|
if (($twoLineQuestion || $imageFirstLine) && $a == 1) continue;
|
|
|
|
if ($threeLineQuestion || ($twoLineQuestion && $imageFirstLine) && $a == 2) continue;
|
|
|
|
if ($imageFirstLine && $threeLineQuestion && $a == 3) continue;
|
|
|
|
if (empty(trim($line))) continue;
|
|
|
|
if (strpos(strtolower($line), 'totallines') !== false) continue;
|
2016-12-30 08:56:35 +00:00
|
|
|
|
2016-12-30 10:01:50 +00:00
|
|
|
if (strpos(strtolower($line), '<img') !== false) {
|
2016-12-30 05:16:13 +00:00
|
|
|
preg_match('/".*?"/', $line, $matches);
|
|
|
|
$questions[$i]['image'] = strtoupper($matches[0]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$questions[$i]['answers'][$b] = trim($line);
|
|
|
|
$b++;
|
|
|
|
}
|
2016-12-30 10:01:50 +00:00
|
|
|
} elseif (strpos(strtolower($d), 'ans ') !== false) {
|
|
|
|
$questions[$i - 1]['correctAnswer'] = substr($d, 3);
|
2016-12-30 05:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-31 04:01:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
//CHECK ALL THE STUFF IS CORRECT.
|
|
|
|
foreach($questions as $q) {
|
|
|
|
$bad = false;
|
|
|
|
if(count($q['answers']) != 4) $bad = true;
|
|
|
|
if(!$q['correctAnswer']) $bad = true;
|
|
|
|
if(!$q['questionNumber']) $bad = true;
|
|
|
|
if(empty(trim($q['question']))) $bad = true;
|
|
|
|
foreach($q['answers'] as $a) {
|
|
|
|
if(empty(trim($a))) $bad = true;
|
2016-12-30 05:16:13 +00:00
|
|
|
}
|
2016-12-31 04:01:14 +00:00
|
|
|
if($bad) var_dump($q);
|
|
|
|
}
|
|
|
|
|
|
|
|
$questionArray = array_merge($questionArray, $questions);
|
2016-12-30 05:16:13 +00:00
|
|
|
|
2016-12-31 04:01:14 +00:00
|
|
|
}
|
|
|
|
exit();
|
|
|
|
$i = $b = $d = $a = $count = 0; //Clear the useless stuff from above.
|
|
|
|
foreach ($questionArray as $q) {
|
|
|
|
$db = new db();
|
|
|
|
$db->query("INSERT INTO question(question_time, questiondata_number, questiondata_content, questiondata_image)
|
|
|
|
VALUES(:qTime, :qNumber, :qContent, :qImage)");
|
|
|
|
$db->bind("qTime", time());
|
|
|
|
$db->bind("qNumber", $q['questionNumber'] ?: 0);
|
|
|
|
$db->bind("qContent", $q['question']);
|
|
|
|
$db->bind("qImage", $q['image'] ?: "");
|
|
|
|
$db->execute();
|
|
|
|
$lastRow = $db->lastInsertId();
|
|
|
|
$db->kill(); //IS THIS EVEN NEEDED?
|
|
|
|
$row = 1;
|
|
|
|
foreach ($q['answers'] as $a) {
|
|
|
|
$db = new db();
|
|
|
|
$db->query("INSERT INTO answer(answer_time, answerdata_content, answerdata_question, answerdata_correct)
|
|
|
|
VALUES(:aTime, :aContent, :aQuestion, :aCorrect)");
|
|
|
|
$db->bind("aTime", time());
|
|
|
|
$db->bind("aContent", $a);
|
|
|
|
$db->bind("aQuestion", $lastRow);
|
|
|
|
$db->bind("aCorrect", ($q['correctAnswer'] == $row ? "1" : "0"));
|
|
|
|
$db->execute();
|
|
|
|
$db->kill();
|
|
|
|
$row++;
|
2016-12-30 05:16:13 +00:00
|
|
|
}
|
2016-12-31 04:01:14 +00:00
|
|
|
$db = null;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
echo "Inserted " . $count . " questions.";
|