<?php
echo "<div class=\"flex-container\">";
    echo "<div class=\"sbook_left_column\">\n";
  if (!empty(trim($activity->activity_icon)))  {
        echo "<div class=\"sbook_activity_icon".$uniq_div_from_activity_title."\"> <a id=\"".$activity->hw_anchor."\" name=\"".$activity->hw_anchor."\"> &nbsp; ".$activity->activity_title."</a></div>";
?>

<style>
div.sbook_activity_icon<?php echo $uniq_div_from_activity_title ?>::before {
content: "";
background : url(<?php echo $xml4tpath0.$activity->activity_icon ?>) top no-repeat;
background-size: contain;
width: 1em;
height: 1em;
margin-right: 1%;
padding: 1em;
/*transform: scale(0.2); */
display: inline; /*mandatory*/
/*border: solid 1px;  */
}
div.sbook_activity_icon<?php echo $uniq_div_from_activity_title ?> {
max-width : 100%;
line-height: 2em;
margin-left: 1%;
padding-top: 1.2em;
padding-left: 0.2em;
padding-right: 0.5em;
padding-bottom: 0.2em;
text-overflow: ellipsis;
word-wrap: break-word; 
box-shadow: 0px 8px 20px 0px rgba(0,0,0,0.2);
text-align :center;
font-size : 120%;
font-weight : bold;
font-family : sans-serif;
color: white;
background-color: #d6e51f; /*#e7f25b; */
/*background-color: #ababad; */
}
</style>

<?php

  }
  else {     echo "<div class=\"sbook_reading\"> <a id=\"".$activity->hw_anchor."\" name=\"".$activity->hw_anchor."\"> &nbsp; ".$activity->activity_title."</a></div>";
  }
//
    echo "</div><!-- end sbook_left_column -->\n";
    echo "<div class=\"sbook_middle_right_column\">\n";
    echo "<pre class=\"sbook_lesson_plan\">";

        echo "<span class=\"sbook_exercise_no\">".$activity->activity_id."</span>";
if (!empty($activity->activity_lead_in)) {
echo "<span class=\"sbook_activity_lead_in\">".$activity->activity_lead_in."</span>\n";
}
if (!empty($activity->instructions)) {
    $search = '^(.*).mp3$';
    $activity->instructions = preg_replace ('/'.$search.'/m', '<audio id="audio" controls><source src="'.$xml4tpathmedia.'$1.mp3" type="audio/mp3"></audio>', $activity->instructions);

echo "<span class=\"sbook_instructions\">".$activity->instructions."</span>";
}

    if (!empty($activity->instructions02))  {
    echo "\n<span class=\"sbook_instructions02\">".$activity->instructions02."</span>";
  }
$instructions_demo = trim($activity->instructions_demo);
  if (!empty($activity->instructions_demo))  {
    echo "<div class=\"sbook_instructions_demo\">".$activity->instructions_demo."</div><br />";
  }
        
// floating questions above long text
// adapted from edit_short_reading_floating.inc 
// DISPLAY (hidden by default)
//echo "<div style=\"float: left; position: fixed; bottom: 10%; margin-left: 15%; z-index: 1000; height: 22%; width: 40%; overflow-y: scroll; opacity: 0.9; filter: alpha(opacity=90); background-color: #c4f48e;\">\n"; // based on swapper-other
echo "<div class=\"floating_qa\">\n"; // 20261117
//echo "<div style=\"float: left; position: fixed; bottom: 12%; margin-right: 50%; z-index: 1000; height: 22%; width: 45%; overflow-y: scroll; opacity: 0.9; filter: alpha(opacity=90); background-color: #c4f48e;\">\n"; // based on swapper-other
        echo "<ol>";
foreach($activity->qa as $qa) { 
  echo "<li>".$qa->qs."</li>";
  //include ('inc/xml_show_definition.inc');
if ($qa->ans != null) {
  echo "<span class=\"show_key_sbook\">".$qa->ans."</span><br />\n";
}
}
        echo "</ol>";
echo "</div><!-- end floating_qa -->\n";
//echo "</div><!-- end container_swapper_other -->\n";


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

// display article
echo "<div class=\"flex-container two-columns\">";
$col = 1; // set column number
foreach($activity->article_w_columns->section->column as $column) { 
    //echo "<div contenteditable=\"true\" class=\"sbook_article_w_columns\">\n";
    echo "<div contenteditable=\"true\" focus=\"outline: none;\" class=\"sbook_article_w_columns\">\n";
$list_of_popup_definitions = trim($activity->article_w_columns->section->popup_definitions);
$list_of_popup_definitions = preg_replace('/;/m', '|', $list_of_popup_definitions); // definitions need replacing ; 
$list_of_popup_definitions = preg_replace('/[\r\n]+/m', ';', $list_of_popup_definitions); // end of lines need better delimiter
$list_of_popup_definitions = explode(';',($list_of_popup_definitions)); // explode needs ; rather than \r\n
foreach($list_of_popup_definitions as $popup_definition) { 

// select only word i.e. search - v2
$word_wo_definition = $popup_definition;
$word_wo_definition = preg_replace ('/=.*$/m', '', $word_wo_definition);
$word_wo_definition = preg_replace ('/^to /m', '', $word_wo_definition); // needed for infinitive form of verbs
// $word_wo_definition = strtolower($word_wo_definition); // needed for expressions at begining of a sentence but fails
$word_wo_definition = trim ($word_wo_definition); // mandatory!

// select only definition i.e. replace - v2
$word_w_definition = $popup_definition;
$word_w_definition = preg_replace ('/^.*=/m', '', $word_w_definition);

//$search ="circumspect"; // works
$search = $word_wo_definition;
//var_dump ($word_wo_definition);
$column_before = $column;
$column = str_replace("$search", '<span class="sbook_word_needing_popup">'.$word_wo_definition.'</span><div class="sbook_definition_of_word_needing_popup">'.$word_w_definition.'</div>', $column_before);
// tried using str_ireplace for words with capitalisation but failed 
// search should be case-insensitive AND replacement not changed
//$column = str_ireplace("$search", '<span class="sbook_word_needing_popup">'.$word_wo_definition.'</span><div class="sbook_definition_of_word_needing_popup">'.$word_w_definition.'</div>', $column_before);

}
    /* cut pop-up definition */
    //echo $column;
    echo $col++.". ".$column;
    echo "</div><!-- /class sbook_article_w_columns -->\n";
}
    echo "<div style=\"clear: both;\"></div>\n";
echo "</div> <!-- end flex-container -->\n";
?>
