<?php
if ($include_heading == "no") {
${'xml'.$test_log}=simplexml_load_file("inc_test_logs/".$test_log_ref);// or die("Error: Cannot create object $ xml");
  // don't include heading in xml_load_clog.inc
  // test_ref used from clog
//

// GENERATE TOTAL SCORE (BUT DON'T SHOW YET...)
${'total_exercises'.$test_log_ref} = 0; // multiply later by 100
${'total_score'.$test_log_ref} = 0; // add later to get %

foreach (${'xml'.$test_log}->sbook_test_mcq as $sbook_test_mcq) {
${'total_exercises'.$test_log_ref}++;
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}+$sbook_test_mcq->sub_score);
}
foreach (${'xml'.$test_log}->sbook_test_open_cloze as $sbook_test_open_cloze) {
${'total_exercises'.$test_log_ref}++;
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}+$sbook_test_open_cloze->sub_score);
}
foreach (${'xml'.$test_log}->sbook_test_cloze_sentence as $sbook_test_cloze_sentence) {
${'total_exercises'.$test_log_ref}++;
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}+$sbook_test_cloze_sentence->sub_score);
}
foreach (${'xml'.$test_log}->sbook_test_match as $sbook_test_match) {
${'total_exercises'.$test_log_ref}++;
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}+$sbook_test_match->sub_score);
}
foreach (${'xml'.$test_log}->sbook_test_wri as $sbook_test_wri) {
${'total_exercises'.$test_log_ref}++;
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}+$sbook_test_wri->sub_score);

// MUST INCLUDE IN LAST LOOP DUE TO BUG BELOW
${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}/${'total_exercises'.$test_log_ref}); 
}

// BUG - DIVIDE OPERATION WILL END PHP DISPLAY
//
//${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref}/${'total_exercises'.$test_log_ref}); 
//${'total_score'.$test_log_ref} = ((${'total_score'.$test_log_ref})/(${'total_exercises'.$test_log_ref})); 
//${'total_score'.$test_log_ref} = (${'total_score'.$test_log_ref} % ${'total_exercises'.$test_log_ref}); 
//${'total_score'.$test_log_ref} /= (${'total_exercises'.$test_log_ref}); // /= is divide

//$a = ${'total_score'.$test_log_ref};
//$b = ${'total_exercises'.$test_log_ref};
//${'total_score'.$test_log_ref} /= $b; 

//${'total_score'.$test_log_ref} = (intdiv("${'total_score'.$test_log_ref}", "${'total_exercises'.$test_log_ref}")); 
//${'total_score'.$test_log_ref} = (intdiv(${'total_score'.$test_log_ref}, ${'total_exercises'.$test_log_ref})); 

${'total_score'.$test_log_ref} = (round(${'total_score'.$test_log_ref}, 1)); // round up to avoid decimals
echo "<h3>".${'xml'.$test_log}->sbook_test_student_name."</h3> <h2>".${'total_score'.$test_log_ref}."%</h2>\n";
if (!empty (${'xml'.$test_log}->sbook_test_teacher_comments)) {
echo "<em>".${'xml'.$test_log}->sbook_test_teacher_comments."</em>\n";
}

// SHOW SUMMARY (BUT DON'T CALCULATE AGAIN!)
foreach (${'xml'.$test_log}->sbook_test_mcq as $sbook_test_mcq) {
echo $sbook_test_mcq->exercise_name." (".$sbook_test_mcq->selection_number.")  <meter value=".$sbook_test_mcq->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_mcq->sub_score."%\n";
}
foreach (${'xml'.$test_log}->sbook_test_open_cloze as $sbook_test_open_cloze) {
echo $sbook_test_open_cloze->exercise_name." (".$sbook_test_open_cloze->selection_number.")  <meter value=".$sbook_test_open_cloze->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_open_cloze->sub_score."%\n";
}
foreach (${'xml'.$test_log}->sbook_test_cloze_sentence as $sbook_test_cloze_sentence) {
echo $sbook_test_cloze_sentence->exercise_name." (".$sbook_test_cloze_sentence->selection_number.")  <meter value=".$sbook_test_cloze_sentence->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_cloze_sentence->sub_score."%\n";
}
foreach (${'xml'.$test_log}->sbook_test_match as $sbook_test_match) {
echo $sbook_test_match->exercise_name." (".$sbook_test_match->selection_number.")  <meter value=".$sbook_test_match->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_match->sub_score."%\n";
}
foreach (${'xml'.$test_log}->sbook_test_wri as $sbook_test_wri) {
echo $sbook_test_wri->exercise_name." (".$sbook_test_wri->selection_number.")  <meter value=".$sbook_test_wri->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_wri->sub_score."%\n";
}


// SHOW / HIDE FULL PAGE TEST
$short_test_log_ref= str_replace(".xml",'',$test_log_ref);
echo "<button id=\"button_toggle_visibility_menu\" onclick=\"toggle_visibility('div2unhide$short_test_log_ref')\" style=\"border: none; background-color: black; color: white; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius:8px; box-shadow: 0px 6px 6px 0px rgba(0,0,0,0.2); font-weight: bold;\">show / hide test details</button>\n";
}

else {
// was copy pasted from xml_load_quarterly_test_session.inc but now tweaked
/************* heading ***************/
echo "<div id=\"main\" class=\"main\" type=\"text/css\"> ";
echo "<div id=\"topic_area\" class=\"topic_area\" type=\"text/css\">";

/************* file ref ***************/
//$test_log_ref = $_GET["test_log_ref"];
//$test_log_ref = "test_log_AntonDunaykin_20230611_1328_quarterly_test_nlmkitspc39_20230608.xml";

${'xml'.$test_log}=simplexml_load_file("inc_test_logs/".$test_log_ref);// or die("Error: Cannot create object $ xml");

echo "<div width=\"40%;\" style=\"float: left;\">\n";
echo "<h1><img src=\"pix/icons8-quiz-100.png\" width=\"70em\" border=\"0\" alt=\"test name\">".${'xml'.$test_log}->sbook_test_ref."</h1>\n";
echo "<div align=\"right\" style=\"font-size:70%; color: #cdcdcd;\">by D.Potter</div></div>\n";
echo "  </div>\n";

echo "<div style=\"margin-left: 35%\" align=\"left\">\n";
echo "<h2>Company: ".${'xml'.$test_log}->sbook_test_company. "</h2><br />\n";
$test_log_log_contents = $test_log_log_contents."<sbook_test_company>".${'xml'.$test_log}->sbook_test_company."</sbook_test_company>\n";
echo "<h3>Group: ".${'xml'.$test_log}->sbook_test_group. "</h3><br />\n";
$test_log_log_contents = $test_log_log_contents."<sbook_test_group>".${'xml'.$test_log}->sbook_test_group."</sbook_test_group>\n";
echo "<h3>Target level: ".${'xml'.$test_log}->sbook_test_level. "</h3><br />\n";
$test_log_log_contents = $test_log_log_contents."<sbook_test_level>".${'xml'.$test_log}->sbook_test_level."</sbook_test_level>\n";
echo "<h3>Test date: ".${'xml'.$test_log}->sbook_test_date. "</h3><br /><br />\n";
echo "<h3>Test submitted: ".${'xml'.$test_log}->sbook_test_date_submitted. "</h3><br /><br />\n";
echo "<h3>Student name: ".${'xml'.$test_log}->sbook_test_student_name."</h3><br /><br />\n";
echo "<h3>E-mail: ".${'xml'.$test_log}->sbook_test_student_email."</h3><br /><br />\n";
echo "<h3>Score: </h3><br />\n"; // todo
echo "<meter value=$posted_score min=\"0\" low=".((${'num_qs'.$uniq_id}+1)/2)." max=".(${'num_qs'.$uniq_id}+1)."></meter> ".${'sub_score'.$uniq_id}."% ";
echo $exercise_type." ".$exercise_name." (".$selection_number.")<br />\n";

echo "</div>\n";
  /************* end heading *************/
}

// needed for toggle show / hide
echo "<div id=\"div2unhide$short_test_log_ref\" style=\"display: none;\">\n"; 

echo "<div class=\"flex-container\">";



foreach (${'xml'.$test_log}->sbook_test_mcq as $sbook_test_mcq) {
echo "<div class=\"column_test\">";

if (!empty($sbook_test_mcq->path_to_csv)) {
//echo "<ol class=\"zebra\">";
echo "<ol>";
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_mcq->exercise_nr . "</span></h3> ";
}
echo "<h3>".$sbook_test_mcq->exercise_type."</h3> (".$sbook_test_mcq->selection_number.")";
echo "<h5>".$sbook_test_mcq->exercise_name."</h5>";
echo "<meter value=".$sbook_test_mcq->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_mcq->sub_score."% <br />\n";
echo "<style=\"font-size:70%\"><em>".$sbook_test_mcq->instructions."</em></font><br /><br />";

foreach ($sbook_test_mcq->qa as $qa) {
echo "<li>".$qa->qs."<br />";
echo "<ol type=\"a\">";
foreach ($qa->ans as $answer) {
  echo "<li>".$answer."</li>";
}
if (trim($qa->submitted_answer) == trim($qa->true)) {
echo "✓ ".$qa->submitted_answer."<br />";
}
if (trim($qa->submitted_answer) != trim($qa->true)) {
echo "<strike>".$qa->submitted_answer."</strike><br />";
echo "✓ ".$qa->true."<br />";
}
//echo "(score: ".$qa->score.")<br />";
echo "</ol>";
echo "</li>";
} // foreach ()
echo "</ol>";
echo "</div><!-- class column test --> \n";
} // end foreach as mcq



foreach (${'xml'.$test_log}->sbook_test_open_cloze as $sbook_test_open_cloze) {
echo "<div class=\"column_test\">";

if (!empty($sbook_test_open_cloze->path_to_csv)) {
//echo "<ol class=\"zebra\">";
echo "<ol>";
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_open_cloze->exercise_nr . "</span></h3> ";
}
echo "<h3>".$sbook_test_open_cloze->exercise_type."</h3> (".$sbook_test_open_cloze->selection_number.")";
echo "<h5>".$sbook_test_open_cloze->exercise_name."</h5>";
echo "<meter value=".$sbook_test_open_cloze->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_open_cloze->sub_score."% <br />\n";
echo "<style=\"font-size:70%\"><em>".$sbook_test_open_cloze->instructions."</em></font><br /><br />";

foreach ($sbook_test_open_cloze->qa as $qa) {
echo "<li>".$qa->qs."<br />";
echo "<ol type=\"a\">";
foreach ($qa->ans as $answer) {
  echo "<li>".$answer."</li>";
} // end of foreach ($qa->ans as $answer)

// bug
// test_log_IgorGlazyrin_20230606_2210_quarterly_test_nlmkitspc40_20230608.xml
// (was|were) is not recognised any more...
// but (at what time|what time|when) is...
// rrwc gp5
// inc_drills/grammar_reported_speech_selection_b1_02.csv
//  ('d|would) give (me|us|them) a discount

// XXXXXXXXXXXXXXXXX TODO CONTINUE DEBUGGING FROM HERE
// 20240621-1111 todo update display 
$question_name2 = preg_replace("/[^\da-z]/i", '',(trim($qa->true)));
$question_name2 = preg_replace('/\s+/', '', (trim($qa->true)));
echo "question name 2:".$question_name2."<br />";

//$answer2 = preg_replace('/\s+/', '', $answer);
$answer2 = preg_replace('/\s+/', '', $qa->submitted_answer);
echo "answer 2:".$answer2."<br />";
//if(!preg_match_all('/\A'.(trim($qa->submitted_answer)).'\z/',(trim($qa->true)))) {
//if(!preg_match_all('/\A'.$answer2.'\z/',$question_name2)) { // orig 20240621
if(!preg_match_all('/\b'.$question_name2.'\b/',$answer2)) {
//if (trim($qa->submitted_answer) != trim($qa->true)) {
echo "<strike>".$qa->submitted_answer."</strike><br />";
echo "✓ ".$qa->true."<br />";
}
else {
//echo "<div class=\"show_key2\">✓ ".$answer."</div><br />\n";
echo "✓ ".$answer."<br />";
}
/***
if(preg_match_all('/\A'.(trim($qa->submitted_answer)).'\z/',(trim($qa->true)))) {
//if (trim($qa->submitted_answer) == trim($qa->true)) {
echo "✓ ".$qa->submitted_answer."<br />";
}
***/
//echo "(score: ".$qa->score.")<br />";
echo "</ol>";
echo "</li>";
} // foreach ()
echo "</ol>";
echo "</div><!-- class column test --> \n";
} // end foreach as open_cloze



foreach (${'xml'.$test_log}->sbook_test_cloze_sentence as $sbook_test_cloze_sentence) {
echo "<div class=\"column_test\">";

if (!empty($sbook_test_cloze_sentence->path_to_csv)) {
//echo "<ol class=\"zebra\">";
echo "<ol>";
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_cloze_sentence->exercise_nr . "</span></h3> ";
}
echo "<h3>".$sbook_test_cloze_sentence->exercise_type."</h3> (".$sbook_test_cloze_sentence->selection_number.")";
echo "<h5>".$sbook_test_cloze_sentence->exercise_name."</h5>";
echo "<meter value=".$sbook_test_cloze_sentence->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_cloze_sentence->sub_score."% <br />\n";
echo "<style=\"font-size:70%\"><em>".$sbook_test_cloze_sentence->instructions."</em></font><br /><br />";

foreach ($sbook_test_cloze_sentence->qa as $qa) {
echo "<li>".$qa->qs."<br />";
echo "<ol type=\"a\">";
foreach ($qa->ans as $answer) {
  echo "<li>".$answer."</li>";
}
if (trim($qa->submitted_answer) == trim($qa->true)) {
echo "✓ ".$qa->submitted_answer."<br />";
}
if (trim($qa->submitted_answer) != trim($qa->true)) {
echo "<strike>".$qa->submitted_answer."</strike><br />";
echo "✓ ".$qa->true."<br />";
}
//echo "(score: ".$qa->score.")<br />";
echo "</ol>";
echo "</li>";
} // foreach ()
echo "</ol>";
echo "</div><!-- class column test --> \n";
} // end foreach as open_cloze



foreach (${'xml'.$test_log}->sbook_test_match as $sbook_test_match) {
echo "<div class=\"column_test\">";

echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_match->exercise_nr . "</span></h3> ";
echo "<h3>".$sbook_test_match->exercise_type."</h3> (".$sbook_test_match->selection_number.")";
echo "<h5>".$sbook_test_match->exercise_name."</h5><br />";
echo "<style=\"font-size:70%\"><em>".$sbook_test_match->instructions."</em></font><br /><br />";
echo "<ol>\n";
foreach ($sbook_test_match->qa as $qa) {
//echo "<div class=\"column_test32\">";
echo "<li>".$qa->qs;
if (trim($qa->submitted_answer) == trim($qa->true)) {
echo "✓ ".$qa->submitted_answer."\n";
}
if (trim($qa->submitted_answer) != trim($qa->true)) {
echo "<strike>".$qa->submitted_answer."</strike><br />";
echo "✓ ".$qa->true."\n";
}
echo "</li>";
} // foreach ()
echo "</ol>";
echo "</div><!-- class column test --> \n";
} // end foreach as test_match


foreach (${'xml'.$test_log}->sbook_test_wri as $sbook_test_wri) {
echo "<div class=\"column_test\">";

echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_wri->exercise_nr . "</span></h3> ";
//echo "<h3>".$sbook_test_wri->exercise_type."</h3> (".$sbook_test_wri->selection_number.")";
echo "<h3>".$sbook_test_wri->exercise_name."</h3><br />";
//echo "<h5>".$sbook_test_wri->exercise_name."</h5><br />";
echo "<meter value=".$sbook_test_wri->sub_score."  min=\"0\" low=\"50\" max=\"100\"></meter> ".$sbook_test_wri->sub_score."% <br />\n";
echo "<style=\"font-size:70%\"><em>".$sbook_test_wri->instructions."</em></font>";

$topics_for_wri = trim($sbook_test_wri->topics_for_wri);
if (!empty($topics_for_wri)) {
$topics_to_recycle = $topics_for_wri;
echo "<ol class=\"zebra\" type=\"a\">".$topics_to_recycle."</ol>";
}

$suggested_answer = trim($sbook_test_wri->suggested_answer);
if (!empty($suggested_answer)) {
echo "Suggested correction: \n";
echo "<div class=\"show_key3_to_print_for_feedback\">".$suggested_answer."</div>";
}
$key = trim($sbook_test_wri->key);
if (!empty($key)) {
echo "<div class=\"show_key3_to_print_for_feedback\">".$key."</div>";
}
echo "</div>\n";
echo "<div class=\"column_test\">";

// todo
// echo "<div id=\"div2save\" contenteditable=\"true\" onblur=\"saveContentsEditable()\">".$text.$txt."\n";
echo "<div id=\"div2save\" contenteditable=\"true\" style=\"line-height: 170%; word-spacing: 1rem; letter-spacing: .2rem;\">\n";
echo $sbook_test_wri->submitted_answer;
echo "</div><!-- class column test --> \n";

echo "</div><!-- class column test --> \n";
} // end foreach as test_wri




foreach (${'xml'.$test_log}->sbook_test_match_jumbled_definitions as $sbook_test_match_jumbled_definitions) {
echo "<div class=\"column_test\">";

$path_to_csv_match = trim($sbook_test_match_jumbled_definitions->path_to_csv);
if (!empty($path_to_csv_match)) {
//echo "<ol class=\"zebra\">";
$file_match = $path_to_csv_match;

//read first line
$first_line_match = file($file_match);
list($exercise_type, $exercise_name, $selection_number, $instructions) = explode(";", $first_line_match[0]);
if ($sbook_test_match_jumbled_definitions->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_match_jumbled_definitions->exercise_nr . "</span></h3> ";
}
echo "<h3>".$exercise_type."</h3> (".$selection_number.")";
echo "<h5>".$exercise_name."</h5><br />";
echo "<style=\"font-size:70%\"><em>".$instructions."</em></font><br /><br />";

echo "<ol>\n";
echo "<div class=\"flex-container\">";

$path_to_csv_match = trim($sbook_test_match_jumbled_definitions->path_to_csv);
if (!empty($path_to_csv_match)) {

// read all the lines in the file into an array with file( )
$lines_csv = file($path_to_csv_match);
// load file into an array
$lines_csv = array($lines_csv);

foreach ($lines_csv as $line_csv) {
  // remove 1st element from csv file, e.g. Instructions
  $line_csv = array_slice($line_csv, 1);
  // change order of lines
  shuffle($line_csv);
  foreach ($line_csv as $line) {
$line = preg_replace ('/;.*$/','', $line);
    echo "<span style=\"margin: 0.3em; border: solid 1px; padding: 0.5em\">".$line."</span>";
  }
}
  }
echo "</div><!-- end flex --> \n";
echo "</ol>\n";
} // if (!empty($path_to_csv_match))

if (!empty($path_to_csv_match)) {
//echo "<ol class=\"zebra\">";
echo "<ol>\n";
$file_match2 = $path_to_csv_match;
//read first line, but do nothing with it
$handle_match2 = fopen($file_match2, "r");
$line_match2 = fgets($handle_match2);

//now read the rest of the file line by line
if ($handle_match2) {
    while (($line_match2 = fgets($handle_match2, 4096)) !== false) {
        // do something with $line here
list($question, $answer) = explode(";", $line_match2);

echo "<div class=\"flex-container\">";
echo "<li><span style=\"font-size: 90%\">".$answer."</span><br />";
echo "<div class=\"show_key3\">".$question."<br /></div></li>";
echo "</div><!-- end flex --> \n";
    }
}
echo "</ol>\n";
echo "</div><!-- class column test --> \n";
if (!feof($handle_match2)) {
        echo "Error: unexpected fgets() fail 2\n";
    }
    fclose($handle_match2);
} // if (!empty($path_to_csv_match))
} // end foreach as match_jumbled_definitions


foreach (${'xml'.$test_log}->sbook_test_shuffled as $sbook_test_shuffled) {
echo "<div class=\"column_test\">";
// need to add '_match' from imported sbook_plugins/csv_load_deck_shuffled.inc 
// may have to add in box09 answer in csv file
// don't need to convert ^ to ;

$path_to_csv_match = trim($sbook_test_shuffled->path_to_csv);
if (!empty($path_to_csv_match)) {
//echo "<ol class=\"zebra\">";
$file_match = $path_to_csv_match;

//read first line
$first_line_match = file($file_match);
// imported from sbook_plugins/csv_load_deck_shuffled.inc
// need to add '_match' from imported sbook_plugins/csv_load_deck_shuffled.inc 
list($exercise_type, $exercise_name, $selection_number, $instructions,$background_image,$key_image) = explode("^", $first_line_match[0]); 
if ($sbook_test_shuffled->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_shuffled->exercise_nr . "</span></h3> ";
}
echo "<h3>".$exercise_type."</h3> (".$selection_number.")";
echo "<h5>".$exercise_name."</h5><br />";
echo "<style=\"font-size:70%\"><em>".$instructions."</em></font><br /><br />";
echo "<ol>\n";
//read first line, but do nothing with it
$handle_match = fopen($file_match, "r");
$line_match = fgets($handle_match);

//now read the rest of the file line by line
if ($handle_match) {
    while (($line_match = fgets($handle_match, 4096)) !== false) {
      
//list($txt_id,$subject,$auxiliary_vb,$lexical_vb,$past_participle,$object,$preposition,$object2,$hint,$answer) = explode(";", $line);
// imported from sbook_plugins/csv_load_deck_shuffled.inc
list($txt_id,$subject,$auxiliary_vb,$lexical_vb,$past_participle,$object,$preposition,$object2,$hint,$answer) = explode("^", $line_match);

  if ((empty(trim($subject))) || (empty(trim($auxiliary_vb))) || (empty(trim($lexical_vb))) || (empty(trim($past_participle))) || (empty(trim($object))) || (empty(trim($preposition))) || (empty(trim($object2))) || (empty(trim($hint))) || (empty(trim($answer)))) {

$subject_wo_spaces = preg_replace('/^/m',"&nbsp;",$subject);
$subject = preg_replace('/^/m',"&nbsp;",$subject);
$auxiliary_vb_wo_spaces = preg_replace('/^/m',"&nbsp;",$auxiliary_vb);
$auxiliary_vb = preg_replace('/^/m',"&nbsp;",$auxiliary_vb);
$lexical_vb_wo_spaces = preg_replace('/^/m',"&nbsp;",$lexical_vb);
$lexical_vb = preg_replace('/^/m',"&nbsp;",$lexical_vb);
$past_participle_wo_spaces = preg_replace('/^/m',"&nbsp;",$past_participle);
$past_participle = preg_replace('/^/m',"&nbsp;",$past_participle);
$object_wo_spaces = preg_replace('/^/m',"&nbsp;",$object);
$object = preg_replace('/^/m',"&nbsp;",$object);
$preposition_wo_spaces = preg_replace('/^/m',"&nbsp;",$preposition);
$preposition = preg_replace('/^/m',"&nbsp;",$preposition);
$object2_wo_spaces = preg_replace('/^/m',"&nbsp;",$object2);
$object2 = preg_replace('/^/m',"&nbsp;",$object2);
$hint_wo_spaces = preg_replace('/^/m',"&nbsp;",$hint);
$hint = preg_replace('/^/m',"&nbsp;",$hint);
$answer_wo_spaces = preg_replace('/^/m',"&nbsp;",$answer);
$answer = preg_replace('/^/m',"&nbsp;",$answer);
  }

  if ((!empty(trim($subject))) || (!empty(trim($auxiliary_vb))) || (!empty(trim($lexical_vb))) || (!empty(trim($past_participle))) || (!empty(trim($object))) || (!empty(trim($preposition))) || (!empty(trim($object2))) || (!empty(trim($hint))) || (!empty(trim($answer)))) {

$subject_wo_spaces = preg_replace('/[^\da-z]/i',"_",$subject);
$auxiliary_vb_wo_spaces = preg_replace('/[^\da-z]/i',"_",$auxiliary_vb);
$lexical_vb_wo_spaces = preg_replace('/[^\da-z]/i',"_",$lexical_vb);
$past_participle_wo_spaces = preg_replace('/[^\da-z]/i',"_",$past_participle);
$object_wo_spaces = preg_replace('/[^\da-z]/i',"_",$object);
$preposition_wo_spaces = preg_replace('/[^\da-z]/i',"_",$preposition);
$object2_wo_spaces = preg_replace('/[^\da-z]/i',"_",$object2);
$hint_wo_spaces = preg_replace('/[^\da-z]/i',"_",$hint);
$answer_wo_spaces = preg_replace('/[^\da-z]/i',"_",$answer);

  }
echo "<div style=\"margin-left: 40%;\" class=\"show_key3\">".$answer."<br /></div>";

$box01 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box01 = $box01. "<div id=\"div2mov_cards_box01_".$uniq_div_from_activity_title.$txt_id.$subject_wo_spaces."\">";
$box01 = $box01.  "<span contenteditable=\"true\">".$subject."</span>";
$box01 = $box01. "</div>";
$box01 = $box01. "</div>";

$box02 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box02 = $box02. "<div id=\"div2mov_cards_box02_".$uniq_div_from_activity_title.$txt_id.$auxiliary_vb_wo_spaces."\">";
$box02 = $box02.  "<span contenteditable=\"true\">".$auxiliary_vb."</span>";
$box02 = $box02. "</div>";
$box02 = $box02. "</div>";

$box03 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box03 = $box03. "<div id=\"div2mov_cards_box03_".$uniq_div_from_activity_title.$txt_id.$lexical_vb_wo_spaces."\">";
$box03 = $box03.  "<span contenteditable=\"true\">".$lexical_vb."</span>";
$box03 = $box03. "</div>";
$box03 = $box03. "</div>";

$box04 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box04 = $box04. "<div id=\"div2mov_cards_box04_".$uniq_div_from_activity_title.$txt_id.$past_participle_wo_spaces."\">";
$box04 = $box04.  "<span contenteditable=\"true\">".$past_participle."</span>";
$box04 = $box04. "</div>";
$box04 = $box04. "</div>";

$box05 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box05 = $box05. "<div id=\"div2mov_cards_box05_".$uniq_div_from_activity_title.$txt_id.$object_wo_spaces."\">";
$box05 = $box05.  "<span contenteditable=\"true\">".$object."</span>";
$box05 = $box05. "</div>";
$box05 = $box05. "</div>";

$box06 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box06 = $box06. "<div id=\"div2mov_cards_box06_".$uniq_div_from_activity_title.$txt_id.$preposition_wo_spaces."\">";
$box06 = $box06.  "<span contenteditable=\"true\">".$preposition."</span>";
$box06 = $box06. "</div>";
$box06 = $box06. "</div>";

$box07 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box07 = $box07. "<div id=\"div2mov_cards_box07_".$uniq_div_from_activity_title.$txt_id.$object2_wo_spaces."\">";
$box07 = $box07.  "<span contenteditable=\"true\">".$object2."</span>";
$box07 = $box07. "</div>";
$box07 = $box07. "</div>";

$box08 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box08 = $box08. "<div id=\"div2mov_cards_box08_".$uniq_div_from_activity_title.$txt_id.$hint_wo_spaces."\">";
$box08 = $box08.  "<span contenteditable=\"true\">".$hint."</span>";
$box08 = $box08. "</div>";
$box08 = $box08. "</div>";

$box09 = "<div style=\"float: left; position: relative; width: 150%; margin-left: 0%; padding: 0.8em; font-size: 80%;\">";
$box09 = $box09. "<div id=\"div2mov_cards_box09_".$uniq_div_from_activity_title.$txt_id.$answer_wo_spaces."\">";
$box09 = $box09.  "<span contenteditable=\"true\">".$answer."</span>";
$box09 = $box09. "</div>";
$box09 = $box09. "</div>";

// important not to include answer!
//$shuffled_lines = (array($box01,$box02,$box03,$box04,$box05,$box06,$box07,$box08,$box09));
$shuffled_lines = (array($box01,$box02,$box03,$box04,$box05,$box06,$box07,$box08));
shuffle ($shuffled_lines);
foreach ($shuffled_lines as $shuffled_line) {
echo $shuffled_line;
}
echo "<div style=\"clear: both;\"></div>\n";

  if ((!empty(trim($subject))) || (!empty(trim($auxiliary_vb))) || (!empty(trim($lexical_vb))) || (!empty(trim($past_participle))) || (!empty(trim($object))) || (!empty(trim($preposition))) || (!empty(trim($object2))) || (!empty(trim($hint))) || (!empty(trim($answer)))) {

echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box01_".$uniq_div_from_activity_title.$txt_id.$subject_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of subjects
echo "<style>\n";
echo "#div2mov_cards_box01_".$uniq_div_from_activity_title.$txt_id.$subject_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #dbd039;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";

echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box02_".$uniq_div_from_activity_title.$txt_id.$auxiliary_vb_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of auxiliary_vbs
echo "<style>\n";
echo "#div2mov_cards_box02_".$uniq_div_from_activity_title.$txt_id.$auxiliary_vb_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #67e328;\n";
//echo "background-color: lime;\n";
//echo "background-color: #94fc07;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box03_".$uniq_div_from_activity_title.$txt_id.$lexical_vb_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of lexical_vbs
echo "<style>\n";
echo "#div2mov_cards_box03_".$uniq_div_from_activity_title.$txt_id.$lexical_vb_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #4bb217;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box04_".$uniq_div_from_activity_title.$txt_id.$past_participle_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of past_participles
echo "<style>\n";
echo "#div2mov_cards_box04_".$uniq_div_from_activity_title.$txt_id.$past_participle_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #0c8f23;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box05_".$uniq_div_from_activity_title.$txt_id.$object_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of objects
echo "<style>\n";
echo "#div2mov_cards_box05_".$uniq_div_from_activity_title.$txt_id.$object_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #4e55b6;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box06_".$uniq_div_from_activity_title.$txt_id.$preposition_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of prepositions
echo "<style>\n";
echo "#div2mov_cards_box06_".$uniq_div_from_activity_title.$txt_id.$preposition_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #b6ac4e;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box07_".$uniq_div_from_activity_title.$txt_id.$object2_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

// touch individual items of object2s
echo "<style>\n";
echo "#div2mov_cards_box07_".$uniq_div_from_activity_title.$txt_id.$object2_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: #6f4eb6;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box08_".$uniq_div_from_activity_title.$txt_id.$hint_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

echo "<style>\n";
echo "#div2mov_cards_box08_".$uniq_div_from_activity_title.$txt_id.$hint_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: Chocolate;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";


echo "<script>\n";
echo "dragElement(document.getElementById(('div2mov_cards_box09_".$uniq_div_from_activity_title.$txt_id.$answer_wo_spaces ."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";

echo "<style>\n";
echo "#div2mov_cards_box09_".$uniq_div_from_activity_title.$txt_id.$answer_wo_spaces." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "display: inline;\n";
echo "text-align: center;\n";
echo "cursor: pointer;\n";
//echo "color: #efefef;\n";
echo "color: black;\n";
echo "font-size: 120%;\n";
echo "padding: 0.1em;\n";
echo "border: 1px dotted grey;\n";
echo "mini-width: 10%;\n";
echo "float: left;\n";
//echo "background-color: LightSalmon;\n";
echo "background-color: #ccc;\n";
echo "box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.2);\n";
echo "}\n";
echo "</style>\n";
  } // if (!empty(trim($object2)))

} //while (($line = fgets($handle, 4096)) !== false)

    if (!feof($handle_match)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle_match);
} //if ($handle_match)
} // if (!empty($path_to_csv_match))

echo "</div><!-- class column test --> \n";

} // end foreach as match

echo "</div> <!-- end flex-container -->\n";
echo "</div> <!-- end div id div2unhide$short_test_log_ref display: none -->\n";
?>
