diff --git a/scripts/export.php b/scripts/export.php new file mode 100644 index 0000000..e1d16f4 --- /dev/null +++ b/scripts/export.php @@ -0,0 +1,41 @@ + $value) { + $answer = new Answer(); + $answer->id = trim($key); + $answer->text = trim($value); + if($key == $r['correct']){$answer->correct = true;} + $answers[] = $answer; + } + + $data[] = array( + "id" => trim($r['id']), + "question" => trim($r['question']), + "answers" => $answers + ); + +} + +header('Content-type: application/json'); +echo json_encode( $data ); + +?> diff --git a/scripts/import.php b/scripts/import.php new file mode 100644 index 0000000..9edba6b --- /dev/null +++ b/scripts/import.php @@ -0,0 +1,70 @@ +"; + echo $title."
"; + echo $responses[$id]."
"; + + print_r($answers); + echo "

"; + */ + + $query="INSERT questions VALUES($id, '$title', '".serialize($answers)."', ".$responses[$id].")"; + mysqli_query($conn,$query); + + } + $id = substr($row[0], 1, 4); + $title = $row[1]; + $answers = []; + } else { + $answers[$row[0]] = $row[1]; + } + + +} + + +fclose($myfile); + +?> diff --git a/scripts/replace.sh b/scripts/replace.sh new file mode 100755 index 0000000..704c231 --- /dev/null +++ b/scripts/replace.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "" > tmp + +while read p; do + INIT=${p:0:2} + + if [[ "${p:0:4}" =~ ^[0-9]+$ ]] && [ "${p:0:1}" == "${1:0:1}" ]; then + echo $TMP_ROW >> tmp + TMP_ROW="#${p:0:4} | "$'\n'"${p:4}" + elif [ $INIT == "1." ] || [ $INIT == "2." ] || [ $INIT == "3." ]; then + echo $TMP_ROW >> tmp + TMP_ROW="${p:0:1} | "$'\n'"${p:2}" + else + TMP_ROW="$TMP_ROW $p" + fi + +done < $1 + +echo $TMP_ROW >> tmp + +sed -i -e 's/- //g' tmp + +mv tmp ../data/$1