<?php
echo "<div class=\"flex-container\">";
    echo "<div class=\"sbook_left_column\">\n";
    //echo "<div class=\"sbook_left_column\" style=\"width: 40%;\">\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 : 80%;
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 "<div class=\"sbook_middle_right_column\" style=\"width: 55%; font-size: 120%;\">\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>";
  }
//
    echo "</pre>";
    echo "</div><!-- end sbook_middle_right_column -->\n";
echo "</div> <!-- end flex-container -->\n";

// display questions on the left + article middle & right
echo "<div class=\"flex-container\">";
    echo "<div class=\"sbook_left_column\">\n";

    include ('js/swap_divs_w_click.js');
//echo "<div id=\"swapper-first_".$uniq_div_from_activity_title."\" style=\"display:block; float: left; width: 40%;\">";
echo "<div id=\"swapper-first_".$uniq_div_from_activity_title."\" style=\"display:block;\">";
    echo "<div class=\"movable_match_2_columns_aa\"><!-- use aa for 40% -->\n";
echo "<a href=\"javascript:SwapDivsWithClick('swapper-first_".$uniq_div_from_activity_title."','swapper-other_".$uniq_div_from_activity_title."')\"><img src=\"".$xml4tpath0."pix/icons8-hand-with-pen-100.png\" width=\"35em\" border=\"0\" alt=\"Take notes\" />  Take notes</a>\n";

        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";
}
/*** hide in short reading  
if (trim($qa->hint) != null) {
echo "<span style=\"font-style: italic; font-size: 85%;\">".$qa->hint."</span>\n";
}
***/
}
        echo "</ol>";

    echo "</div><!-- end class match 2 columns_aa -->\n";
echo "</div><!-- end swapper first -->\n";

// DISPLAY (hidden by default)
//echo "<div id=\"swapper-other_".$uniq_div_from_activity_title."\" style=\"display:none; float: left; position: fixed; bottom: 55%; margin-left: 2%; z-index: 1000; width: 18%;\">\n"; // 20210409-0026
//echo "<div id=\"swapper-other_".$uniq_div_from_activity_title."\" style=\"display:none; float: left; position: fixed; z-index: 1000;\">\n";
echo "<div id=\"container_swapper_other\">\n";
//echo "<div id=\"swapper-other_".$uniq_div_from_activity_title."\" style=\"display:none; float: left; position: fixed; bottom: 55%; margin-left: 80%; z-index: 1000; width: 18%;\">\n"; // 20261105
echo "<div id=\"swapper-other_".$uniq_div_from_activity_title."\" style=\"display:none;\">\n"; // 20261116
echo "<div id=\"take_notes_floating01_width\">\n";
    include ('sbook_plugins/take_notes_floating01.inc');
echo "</div><!-- end take_notes_floating01_width -->\n";
echo "</div><!-- end swap other -->\n";
echo "</div><!-- end container_swapper_other -->\n";

//$fileNameToSaveAs = `date +%Y%m%d`."_{$sbook}_ref_notes_{$member}.txt";
$activity_title = trim(preg_replace("/[^\da-z]/i", '_',$activity->activity_title));
$fileNameToSaveAs = $sbook_ref."_".$activity_title."_notes_".$member."_".date('Ymd_His').".txt";
include ('js/save_text_as_file.js');

echo "<style>\n";
echo "#empty_div2mov_cards".$uniq_div_from_activity_title." {\n";
echo "position: relative;\n";
echo "width: 100%;";
echo "max-height: 20%;"; 
echo "padding: 0.1em;\n";
echo "}\n";

echo "#div2mov_cards".$uniq_div_from_activity_title." {\n";
echo "z-index: 9;\n";
echo "position: absolute;\n";
echo "top: -14em;";
echo "left: -80%; /*-16em; */";
echo "width: 170%;";
echo "display: inline-block;\n";
echo "box-shadow: 0px 0px 4px 2px #052a3a;\n";
echo "resize: both;";
echo "height: 35em; /*30em;*/"; 
echo "overflow-y: scroll;"; 
echo "}\n";

// Can't hide scrollbars in Firefox...
// Hide scrollbar for Chrome, Safari and Opera 
echo "#div2mov_cards".$uniq_div_from_activity_title."::-webkit-scrollbar {";
echo "display: none;";
echo "}\n";
// Hide scrollbar for IE and Edge
echo "#div2mov_cards".$uniq_div_from_activity_title." {";
echo "ms-overflow-style: none;";
echo "}\n";

echo "</style>\n";

echo "<script>\n";
echo"dragElement(document.getElementById(('div2mov_cards".$uniq_div_from_activity_title."')));";
include ('js/div2mov_cards.js');
echo "</script>\n";
//
   // echo "</pre>";
    echo "</div><!-- end sbook_left_column -->\n";

    echo "<div class=\"sbook_middle_right_column\">\n";


// display article
echo "<div class=\"flex-container\">";
$col = 1; // set column number
foreach($activity->article_w_columns->section->column as $column) { 
    echo "<div contenteditable=\"true\" 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";
echo "</div> <!-- end flex-container -->\n";
echo "</div> <!-- end flex-container -->\n";
?>
