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

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

$test_ref = "quarterly_test_nlmkgroup01_20211216.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20211207.xml";
//$test_ref = "quarterly_test_leroyind138_20210928.xml"; // todo XXXXXXXXXXXXXXXXX
//$test_ref = "quarterly_test_nlmkgroup01_20210930.xml";
//$test_ref = "quarterly_test_nlmkgroup04_20210930.xml";
//$test_ref = "quarterly_test_nlmkgroup06_20210928.xml";
//$test_ref = "quarterly_test_nlmkgroup03_20210928.xml";
//$test_ref = "quarterly_test_nlmkgroup02_20210927.xml";
//$test_ref = "quarterly_test_nlmkind01_20210927.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20210928.xml";
//$test_ref = "quarterly_test_nlmkgroup01_20210617.xml"; // should be almost same as group 05 except task 1
//$test_ref = "quarterly_test_nlmkgroup05_20210615.xml";
//$test_ref = "quarterly_test_nlmkgroup04_20210615.xml";
//$test_ref = "quarterly_test_nlmkgroup03_20210615.xml";
//$test_ref = "quarterly_test_nlmkind01_20210610.xml";
//$test_ref = "quarterly_test_nlmkgroup02_20210621.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20210615.xml";
//$test_ref = "quarterly_test_rrwlind05_20210316.xml";
//$test_ref = "quarterly_test_leroyind133_20210317.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20210316.xml";
//$test_ref = "quarterly_test_kasperskyind185_20201008.xml"; 
//$test_ref = "quarterly_test_rrwcgroup5_20201007.xml";
//$test_ref = "quarterly_test_cherkizovogroup4_20201008.xml";
//$test_ref = "quarterly_test_kasperskyind185_20200618.xml"; 
//$test_ref = "quarterly_test_kasperskyind198_20200616.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20200617.xml";
//$test_ref = "quarterly_test_cherkizovoind01_20200616.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20200318.xml";
//$test_ref = "quarterly_test_vebind17_20200317.xml";
//$test_ref = "quarterly_test_vebind20_20200317.xml";
//$test_ref = "quarterly_test_cherkizovoind01_20200317.xml";
//$test_ref = "quarterly_test_cherkizovogroup4_20200317.xml";
//$test_ref = "exit_test_kasperskyind192_20191212.xml";
//$test_ref = "quarterly_test_yandexind15_20191210.xml";
//$test_ref = "quarterly_test_cherkizovogroup4_20191210.xml";
//$test_ref = "exit_test_kasperskyind211_20191118.xml";
//$test_ref = "quarterly_test_cherkizovogroup4_20190919.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20190918.xml";
//$test_ref = "quarterly_test_yandexind15_20190917.xml";
//$test_ref = "quarterly_test_afigroup1_20190917.xml";
//$test_ref = "quarterly_test_cherkizovogroup4_20190620.xml";
//$test_ref = "quarterly_test_afigroup1_20190620.xml";
//$test_ref = "quarterly_test_rrwcgroup5_20190619.xml";
${'xml'.$test}=simplexml_load_file("inc_quarterly_tests/".$test_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}->sbook_test_name."</h1>\n";
echo "<div align=\"right\" style=\"font-size:70%; color: #cdcdcd;\">by D.Potter</div></div>\n";
echo "&nbsp;</div>\n";

echo "<div style=\"margin-left: 35%\" align=\"left\">\n";
echo "<h2>Company: ".${'xml'.$test}->sbook_test_company. "</h2><br />\n";
echo "<h3>Group: ".${'xml'.$test}->sbook_test_group. "</h3><br />\n";
echo "<h3>Target level: ".${'xml'.$test}->sbook_test_level. "</h3><br />\n";
echo "<h3>Test date: ".${'xml'.$test}->sbook_test_date. "</h3><br /><br />\n";
echo "<h3>Student name: ______________________________________________  </h3><br /><br />\n";
echo "<h3>Score: </h3><br />\n";
echo "</div>\n";
  /************* end heading *************/
}

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

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

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

//read first line
$first_line = file($file);
list($exercise_type, $exercise_name, $selection_number, $instructions) = explode(";", $first_line[0]);
//echo "<em>".$first_line[0]."</em><br />";
//echo "<img valign=\"bottom\" src=\"pix/icons8-drill-100.png\" width=\"35\" border=\"0\" alt=\"controlled practice\"> <h3>".$exercise_type."</h3> - ";
if ($sbook_test_mcq->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_mcq->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 />";

//read first line, but do nothing with it
$handle = fopen($file, "r");
$line = fgets($handle);

//now read the rest of the file line by line
if ($handle) {
    while (($line = fgets($handle, 4096)) !== false) {
        // do something with $line here
list($question, $A1, $A2, $A3, $answer) = explode(";", $line);
echo "<li>".$question."<br />";
echo "<ol type=\"a\">";
$A1 = trim($A1);
if (!empty($A1)) {
  echo "<li>".$A1."</li>";
}
$A2 = trim($A2);
if (!empty($A2)) {
  echo "<li>".$A2."</li>";
}
$A3 = trim($A3);
if (!empty($A3)) {
  echo "<li>".$A3."</li>";
}
echo "</ol>";
echo "</li>";
echo "<div class=\"show_key3\">".$answer."</div>";
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
echo "</ol>";
}

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


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

$path_to_csv_match = trim($sbook_test_match->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->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_match->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) {
        // do something with $line here
//list($question, $A1, $A2, $A3, $answer) = explode(";", $line_match);
list($question, $answer) = explode(";", $line_match);
$word_to_scramble = $question;

include ("sbook_plugins/scramble_words.inc");

$search = $question;
$lines_to_number = str_replace("$search", '<span class="sbook_scrambled_word">'.$scrambled_word.'</span><!--<span class="show_key_sbook">'.$word_to_scramble.'</span>-->', $question);
$question = $lines_to_number;

echo "<div class=\"flex-container\">";
echo "<div class=\"column_test32\">";
echo "<li>".$question;
echo "<div class=\"show_key3\">".$word_to_scramble."<br /><br /><br /></div>";
echo "</div><!-- class column test --> \n";

echo "<div class=\"column_test\">\n";
echo "<span style=\"font-size: 90%\">".$answer."</span></li><br />";
echo "</div><!-- class column test --> \n";
echo "</div><!-- end flex --> \n";
    }
echo "</ol>\n";
echo "</div><!-- class column test --> \n";
}
if (!feof($handle_match)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle_match);
}
} // end foreach as match


foreach (${'xml'.$test}->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}->sbook_test_lis as $sbook_test_lis) {
echo "<div class=\"column_test\">";
  
if ($sbook_test_lis->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_lis->exercise_nr . "</span></h3> ";
}
$exercise_name = trim($sbook_test_lis->exercise_name);
if (!empty($exercise_name)) {
echo "<h3>".$sbook_test_lis->exercise_name."</h3><br />\n";
}
$instructions = trim($sbook_test_lis->instructions);
if (!empty($instructions)) {
echo "    <em>".$sbook_test_lis->instructions ."</em>\n";
}

$topics_for_lis = trim($sbook_test_lis->topics_for_lis);
if (!empty($topics_for_lis)) {
$topics_to_recycle = $topics_for_lis;
/*
$topics_to_recycle = preg_replace ('/^/m', '<li>', $topics_to_recycle);
$topics_to_recycle = preg_replace ('/$/m', '</li>', $topics_to_recycle);

echo "<ol class=\"zebra\"><ol type=\"a\">";
echo $topics_to_recycle;
echo "</ol></ol>";
 */
echo "<pre>".$topics_to_recycle."</pre>";
}

$key = trim($sbook_test_lis->key);
if (!empty($key)) {
//echo "<div class=\"show_key3\">".$key."</div>";
echo "<div class=\"show_key3\"><pre>".$key."</pre></div>";
}

echo "</div> <!-- end flex-container -->\n";
} // end foreach as lis



foreach (${'xml'.$test}->sbook_test_wri as $sbook_test_wri) {
echo "<div class=\"column_test\">";
  
if ($sbook_test_wri->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_wri->exercise_nr . "</span></h3> ";
}
$exercise_name = trim($sbook_test_wri->exercise_name);
if (!empty($exercise_name)) {
echo "<h3>".$sbook_test_wri->exercise_name."</h3><br />\n";
}
$instructions = trim($sbook_test_wri->instructions);
if (!empty($instructions)) {
echo "    <em>".$sbook_test_wri->instructions ."</em>\n";
}

$topics_for_wri = trim($sbook_test_wri->topics_for_wri);
if (!empty($topics_for_wri)) {
$topics_to_recycle = $topics_for_wri;
$topics_to_recycle = preg_replace ('/^/m', '<li>', $topics_to_recycle);
$topics_to_recycle = preg_replace ('/$/m', '</li><br />', $topics_to_recycle);

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

echo "</div> <!-- end flex-container -->\n";
} // end foreach as wri


foreach (${'xml'.$test}->sbook_test_rea_wri as $sbook_test_rea_wri) {
echo "<div class=\"column_test\">";
  
if ($sbook_test_rea_wri->exercise_nr[0] != null) {
echo "<h3><span class=\"sbook_exercise_no\">".$sbook_test_rea_wri->exercise_nr . "</span></h3> ";
}
$exercise_name = trim($sbook_test_rea_wri->exercise_name);
if (!empty($exercise_name)) {
echo "<h3>".$sbook_test_rea_wri->exercise_name."</h3><br />\n";
}
$instructions = trim($sbook_test_rea_wri->instructions);
if (!empty($instructions)) {
echo "    <em>".$sbook_test_rea_wri->instructions ."</em>\n";
}

$topics_for_wri = trim($sbook_test_rea_wri->topics_for_wri);
if (!empty($topics_for_wri)) {
$topics_to_recycle = $topics_for_wri;
//$topics_to_recycle = preg_replace ('/^/m', '<li>', $topics_to_recycle);
//$topics_to_recycle = preg_replace ('/$/m', '</li>', $topics_to_recycle);

echo "<pre style=\"white-space: pre-wrap; font-size : 1em;font-family : 'Tahoma, Helvetica, Verdana, Arial, sans-serif';\">";
echo $topics_to_recycle;
echo "</pre>";
}
$key = trim($sbook_test_rea_wri->key);
if (!empty($key)) {
echo "<div class=\"show_key3_to_print_for_feedback\">".$key."</div>";
}
echo "</div> <!-- end flex-container -->\n";
} // end foreach as rea_wri

echo "</div> <!-- end flex-container -->\n";
?>
