$db_con = new Db_Connection();
 $test_data = $_POST['test_data'];
 $error = '';
 if (is_numeric($test_id)) {
     //test has been created successfully, or test ID for update is there
     //insert containers:
     $db_containers = array();
     //will hold mapping of object ID to database ID (needed for insertion of solutions)
     for ($i = 0; $i < $test_data['containers']['counter']; $i++) {
         $container = $test_data['containers']['objects'][$i];
         $db_containers[$i] = $container['db_id'];
         //mapping to current ID (will hold null if new container, updated below)
         if ($container['deleted'] == 'false') {
             //NEW CONTAINER:
             if ($container['newly_created'] == 'true') {
                 $container_id = $db_con->insertEntry(false, 'dragdrop_containers', array("container_test_ID" => $test_id, "container_text" => $container['container_text']));
                 $db_containers[$i] = $container_id;
             } else {
                 if ($container['edited'] == 'true') {
                     $db_con->updateEntry(false, 'dragdrop_containers', array("container_text" => $container['container_text']), array("where" => "container_ID = " . $container['db_id']));
                 }
             }
             //else if
         } else {
             if ($container['newly_created'] == 'false') {
                 $db_con->deleteEntries(false, 'dragdrop_containers', array("where" => "container_ID = " . $container['db_id']));
             }
         }
         //else
     }
     //for
 $test_data = $_POST['test_data'];
 $error = '';
 if (is_numeric($test_id)) {
     //test has been created successfully, or test ID for update is there
     //insert, update etc. the questions:
     for ($i = 0; $i < $test_data['questions']['counter']; $i++) {
         $question = $test_data['questions']['objects'][$i];
         if ($question['deleted'] == 'false') {
             //NEW QUESTION:
             if ($question['newly_created'] == 'true') {
                 insertNewQuestion($question, $test_id);
             } else {
                 if ($question['added_from_db'] == 'true') {
                     if ($question['edited'] == 'false') {
                         //question added unchanged -> only lookup necessary
                         $db_con->insertEntry(false, 'dynmc_lookup', array("lookup_question_ID" => $question['db_id'], "lookup_test_ID" => $test_id));
                     } else {
                         //question has been edited after being added from DB -> insert as a new question
                         insertNewQuestion($question, $test_id);
                     }
                     //else
                 } else {
                     if ($question['edited'] == 'true') {
                         $save_to_change = true;
                         $question_check = $db_con->selectEntries(false, 'dynmc_lookup', array("where" => "lookup_question_ID = " . $question['db_id']));
                         if (sizeof($question_check) > 1) {
                             //question used more than once
                             $save_to_change = false;
                         } else {
                             //check whether question appears again unchanged in this test
                             for ($j = 0; $j < $test_data['questions']['counter']; $j++) {
 //prepare general test info:
 if ($_POST['action'] == 'new') {
     $test_id = createNewTestGeneral($_POST['save_test']);
 } else {
     $test_id = $_POST['save_test']['test_ID'];
     updateTestGeneral($_POST['save_test']);
 }
 //else
 $db_con = new Db_Connection();
 $test_data = $_POST['test_data'];
 $error = '';
 if (is_numeric($test_id)) {
     //test has been created successfully, or test ID for update is there
     //GRID OF NEW TEST:
     if ($_POST['action'] == 'new') {
         $db_con->insertEntry(false, 'crossword_grid', array("grid_test_ID" => $test_id, "grid_x" => $test_data['grid']['x'], "grid_y" => $test_data['grid']['y']));
     } else {
         if ($test_data['grid']['edited'] == 'true') {
             $db_con->updateEntry(false, 'crossword_grid', array("grid_x" => $test_data['grid']['x'], "grid_y" => $test_data['grid']['y']), array("where" => "grid_test_ID = " . $test_id));
         }
     }
     //else if
     for ($i = 0; $i < $test_data['questions']['counter']; $i++) {
         $question = $test_data['questions']['objects'][$i];
         if ($question['deleted'] == 'false' && $question['number'] != 'null') {
             //word has not been deleted and has been placed
             //NEW QUESTION:
             if ($question['newly_created'] == 'true') {
                 $question_id = $db_con->insertEntry(false, 'crossword_questions', array("question_test_ID" => $test_id, "question_text" => $question['question_text'], "question_correct_answer" => $question['correct_answer'], "question_position_x" => $question['position']['x'], "question_position_y" => $question['position']['y'], "question_orientation" => $question['position']['orientation'], "question_number" => $question['number']));
             } else {
                 if ($question['edited'] == 'true') {