public function prepareData()
 {
     // variable info that depends on displayed page
     if ($this->page_request != "error") {
         include_once getcwd() . '/web/scripts/page-data/elrh_' . $this->page_request . '_data.php';
         $this->page_data = array_merge($this->page_data, ELRHPageData::prepareData($this->item_request, $this->mysqli));
     } else {
         $this->page_data["title"] = "Alois Sečkár - Domovská stránka";
     }
     // always presented info
     if ($this->page_data["mysql"] == true) {
         // menu
         include_once getcwd() . '/web/scripts/elrh_menu_creator.php';
         $this->page_data["menu"] = ELRHMenuCreator::createMenuContent();
         // breadcrumb navigation
         include_once getcwd() . '/web/scripts/elrh_navigation_creator.php';
         $this->page_data["navigation"] = ELRHNavigationCreator::createNavigationContent($this->page_request, $this->item_request, $this->mysqli);
         // info displayed in footer
         // current version number and last update date
         $result = $this->mysqli->query("SELECT value FROM elrh_main WHERE var='last_update' OR var='system_version'");
         $data = $result->fetch_array();
         $this->page_data["update"] = $data["value"];
         $data = $result->fetch_array();
         $this->page_data["version"] = $data["value"];
     } else {
         $this->page_data["menu"] = ' ♦ Not connected ♦ ';
         $this->page_data["navigation"]["top"] = '&raquo;&nbsp;<a href="" target="_self" title="Index">INDEX</a>';
         $this->page_data["navigation"]["bottom"] = '';
         $this->page_data["update"] = "???";
         $this->page_data["version"] = "???";
     }
 }
 public static function renderContent($page_data)
 {
     // use "echo" function to render all contents of current page
     if ($page_data["display"] == "error") {
         // there was wrong url input
         echo '<h1>' . $page_data["texts"]["gallery_headline"] . '</h1>' . PHP_EOL;
         echo '<p class="red-note">' . PHP_EOL;
         echo $page_data["texts"]["gallery_error"] . PHP_EOL;
         echo '</p>' . PHP_EOL;
         echo '<p>' . PHP_EOL;
         echo '<a href="/gallery">' . $page_data["texts"]["gallery_back"] . '</a>' . PHP_EOL;
         echo '</p>' . PHP_EOL;
     } else {
         if ($page_data["display"] == "image") {
             // there is request for displaying particular image
             if ($page_data["exists"] == true) {
                 // image found
                 // image title
                 echo '<h1>';
                 echo $page_data["entry"]["name"];
                 // admin options
                 if (isset($_SESSION["user"])) {
                     echo ' <a href="/admin/select_image/' . $page_data["entry"]["iid"] . '"><img src="/images/edit.png" title="' . $page_data["texts"]["gallery_edit"] . '" alt="' . $page_data["texts"]["gallery_edit"] . '" height="24" /></a>';
                 }
                 echo '</h1>' . PHP_EOL;
                 // some meta-info
                 echo '<p>' . PHP_EOL;
                 echo '<strong>' . $page_data["texts"]["gallery_author"] . ': ' . $page_data["entry"]["author_name"] . '</strong>' . PHP_EOL;
                 echo '<br />' . PHP_EOL;
                 echo '<strong>' . $page_data["texts"]["gallery_cat"] . ': <a href="/gallery/g/' . $page_data["parent"]["id"] . '" title="' . $page_data["parent"]["name"] . '">' . $page_data["parent"]["name"] . '</a></strong>' . PHP_EOL;
                 echo '<br />' . PHP_EOL;
                 echo '<strong>' . $page_data["texts"]["gallery_created"] . ':</strong> ' . $page_data["entry"]["created"] . PHP_EOL;
                 echo '</p>' . PHP_EOL;
                 // dscr
                 echo '<p>' . PHP_EOL;
                 if (!empty($page_data["entry"]["dscr"])) {
                     echo $page_data["entry"]["dscr"] . PHP_EOL;
                 } else {
                     // default "no dscr" text
                     echo $page_data["texts"]["gallery_dscr"] . PHP_EOL;
                 }
                 echo '</p>' . PHP_EOL;
                 // top navbox
                 include_once getcwd() . '/scripts/content-helpers/elrh_navigation_creator.php';
                 // set lang variables array to be feed to helper method
                 $lang["prev"] = $page_data["texts"]["global_image_prev"];
                 $lang["gallery"] = $page_data["texts"]["global_image_gallery"];
                 $lang["next"] = $page_data["texts"]["global_image_next"];
                 $lang["move_backwards"] = $page_data["texts"]["gallery_move_backwards"];
                 $lang["move_forwards"] = $page_data["texts"]["gallery_move_forwards"];
                 $navbox = ELRHNavigationCreator::createImageNavbox($page_data["entry"]["iid"], $page_data["entry"]["prev"], $page_data["entry"]["next"], $page_data["parent"]["id"], $lang);
                 // image and nagivation
                 echo '<table>' . PHP_EOL;
                 // top navbox
                 echo '<tr><td>' . $navbox . '</td></tr>' . PHP_EOL;
                 // image itself
                 echo '<tr><td>' . PHP_EOL;
                 // resize, but only if needed (if wider than 800px)
                 $img_data = getImageSize(getcwd() . '/content/gallery/' . $page_data["entry"]["image"]);
                 if ($img_data[0] > 800) {
                     $size_restriction = 'width="800"';
                 } else {
                     $size_restriction = "";
                 }
                 echo '<a href="/content/gallery/' . $page_data["entry"]["image"] . '" title="' . $page_data["texts"]["gallery_full"] . '" target="_blank"><img class="boxed" src="/content/gallery/' . $page_data["entry"]["image"] . '" alt="' . $page_data["entry"]["name"] . '" ' . $size_restriction . ' /></a>' . PHP_EOL;
                 echo '</td></tr>' . PHP_EOL;
                 // bottom navbox
                 echo '<tr><td>' . $navbox . '</td></tr>' . PHP_EOL;
                 echo '</table>' . PHP_EOL;
             } else {
                 // image not found
                 echo '<h1>' . $page_data["texts"]["gallery_headline"] . '</h1>' . PHP_EOL;
                 echo '<p class="red-note">' . PHP_EOL;
                 echo $page_data["texts"]["gallery_noimage"] . PHP_EOL;
                 echo '</p>' . PHP_EOL;
                 echo '<p>' . PHP_EOL;
                 echo '<a href="/gallery">' . $page_data["texts"]["gallery_back"] . '</a>' . PHP_EOL;
                 echo '</p>' . PHP_EOL;
             }
         } else {
             if ($page_data["display"] == "gallery") {
                 // there is request for displaying particular gallery
                 if ($page_data["exists"] == true) {
                     // gallery found
                     // gallery title
                     echo '<h1>';
                     echo $page_data["entry"]["name"];
                     // admin options
                     if (isset($_SESSION["user"])) {
                         echo ' <a href="/admin/select_gallery/' . $page_data["entry"]["gid"] . '"><img src="/images/edit.png" title="' . $page_data["texts"]["gallery_edit"] . '" alt="' . $page_data["texts"]["gallery_edit"] . '" height="24" /></a>';
                     }
                     echo '</h1>' . PHP_EOL;
                     // some meta-info
                     echo '<p>' . PHP_EOL;
                     echo '<strong>' . $page_data["texts"]["gallery_author"] . ': ' . $page_data["entry"]["author_name"] . '</strong>' . PHP_EOL;
                     echo '<br />' . PHP_EOL;
                     echo '<strong>' . $page_data["texts"]["gallery_cat"] . ': ';
                     if (!empty($page_data["parent"])) {
                         echo '<a href="/gallery/g/' . $page_data["parent"]["id"] . '" title="' . $page_data["parent"]["name"] . '">' . $page_data["parent"]["name"] . '</a></strong>' . PHP_EOL;
                     } else {
                         echo '<a href="/gallery" title="' . $page_data["texts"]["gallery_parent"] . '">' . $page_data["texts"]["gallery_parent"] . '</a></strong>' . PHP_EOL;
                     }
                     echo '<br />' . PHP_EOL;
                     echo '<strong>' . $page_data["texts"]["gallery_date"] . ': ' . $page_data["entry"]["created"] . '</strong>' . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                     // gallery dscr
                     echo '<p>' . PHP_EOL;
                     echo $page_data["entry"]["dscr"] . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                     // related galleries
                     echo '<h3>' . $page_data["texts"]["gallery_galleries"] . '</h3>' . PHP_EOL;
                     if (!empty($page_data["galleries"])) {
                         echo '<ul>' . PHP_EOL;
                         foreach ($page_data["galleries"] as $current) {
                             echo '<li><a href="/gallery/g/' . $current["id"] . '" title="' . $current["name"] . '">' . $current["name"] . '</a> [' . $current["images"] . ']</li>' . PHP_EOL;
                         }
                         echo '</ul>' . PHP_EOL;
                     }
                     // images
                     echo '<h3>' . $page_data["texts"]["gallery_images"] . '</h3>' . PHP_EOL;
                     if (!empty($page_data["images"])) {
                         // show records in table - up to 6 images in one row
                         echo '<table>' . PHP_EOL;
                         $x = 0;
                         foreach ($page_data["images"] as $current) {
                             // open new row (before each 6 images)
                             if ($x == 0) {
                                 echo '<tr>' . PHP_EOL;
                             }
                             // show each one image in separate table cell
                             echo '<td><a href="/gallery/i/' . $current["id"] . '"><img class="boxed" src="/content/gallery/thumbs/' . $current["image"] . '" title="' . $current["name"] . '" alt="' . $current["name"] . '" ></a></td>' . PHP_EOL;
                             // increase "row counter" in the end
                             $x++;
                             // close row (after each 6 images) and reset counter
                             if ($x > 6) {
                                 echo '</tr>' . PHP_EOL;
                                 $x = 0;
                             }
                         }
                         echo '</table>' . PHP_EOL;
                     } else {
                         // no images
                         echo '<p>' . PHP_EOL;
                         echo $page_data["texts"]["gallery_images_none"] . PHP_EOL;
                         echo '</p>' . PHP_EOL;
                     }
                     // total images and link back to parent gallery
                     include_once getcwd() . '/scripts/content-helpers/elrh_output_handler.php';
                     echo '<p>' . PHP_EOL;
                     echo '<strong>' . $page_data["texts"]["gallery_images_total_1"] . ' ' . $page_data["entry"]["images"] . ' ' . ELRHOutputHandler::adjustImageCountText($page_data["texts"]["gallery_images_total_2"], $page_data["entry"]["images"], $page_data["lang"]) . '</strong>' . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                     echo '<p>' . PHP_EOL;
                     echo '<strong>' . $page_data["texts"]["gallery_cat"] . ':</strong> ' . PHP_EOL;
                     if (!empty($page_data["parent"])) {
                         echo '<a href="/gallery/g/' . $page_data["parent"]["id"] . '" title="' . $page_data["parent"]["name"] . '">' . $page_data["parent"]["name"] . '</a>' . PHP_EOL;
                     } else {
                         echo '<a href="/gallery" title="' . $page_data["texts"]["gallery_parent"] . '">' . $page_data["texts"]["gallery_parent"] . '</a>' . PHP_EOL;
                     }
                     echo '</p>' . PHP_EOL;
                 } else {
                     // gallery not found
                     echo '<h1>' . $page_data["texts"]["gallery_headline"] . '</h1>' . PHP_EOL;
                     echo '<p class="red-note">' . PHP_EOL;
                     echo $page_data["texts"]["gallery_nogallery"] . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                     echo '<p>' . PHP_EOL;
                     echo '<a href="/gallery">' . $page_data["texts"]["gallery_back"] . '</a>' . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                 }
             } else {
                 // there is request for displaying gallery index
                 echo '<h1>' . $page_data["texts"]["gallery_headline"] . '</h1>' . PHP_EOL;
                 echo '<p>' . PHP_EOL;
                 echo $page_data["texts"]["gallery_info"] . PHP_EOL;
                 echo '</p>' . PHP_EOL;
                 echo '<hr />' . PHP_EOL;
                 // list of galleries
                 if (!empty($page_data["galleries"])) {
                     foreach ($page_data["galleries"] as $row) {
                         // gallery title
                         echo '<h2>';
                         echo $row["name"];
                         // admin options
                         if (isset($_SESSION["user"])) {
                             echo ' <a href="/admin/select_gallery/' . $row["id"] . '"><img src="/images/edit.png" title="' . $page_data["texts"]["gallery_edit"] . '" alt="' . $page_data["texts"]["gallery_edit"] . '" height="16" /></a>';
                         }
                         echo '</h2>' . PHP_EOL;
                         // description (shorten to 200 letters if needed)
                         include_once getcwd() . '/scripts/content-helpers/elrh_output_handler.php';
                         echo '<p><em>' . ELRHOutputHandler::shortenText($row["dscr"], 250, '/gallery/g/' . $row["id"], $page_data["texts"]["gallery_more"]) . '</em></p>' . PHP_EOL;
                         // images
                         echo '<h3>' . $page_data["texts"]["gallery_images"] . '</h3>' . PHP_EOL;
                         // display up to first 7 images
                         if (!empty($page_data[$row["name"]]["images"])) {
                             foreach ($page_data[$row["name"]]["images"] as $current) {
                                 echo '<a href="/gallery/i/' . $current["id"] . '"><img class="boxed" src="/content/gallery/thumbs/' . $current["image"] . '" title="' . $current["name"] . '" alt="' . $current["name"] . '" /></a>&nbsp;' . PHP_EOL;
                             }
                             // display total images count
                             echo '<p>' . PHP_EOL;
                             echo '<strong>' . $page_data["texts"]["gallery_images_total_1"] . ' ' . $row["images"] . ' ' . ELRHOutputHandler::adjustImageCountText($page_data["texts"]["gallery_images_total_2"], $row["images"], $page_data["lang"]) . '</strong>' . PHP_EOL;
                             echo ' [<a href="/gallery/g/' . $row["id"] . '" title="' . $row["name"] . '">' . $page_data["texts"]["gallery_display"] . '</a>]' . PHP_EOL;
                             echo '</p>' . PHP_EOL;
                         } else {
                             // no images found
                             echo '<p>' . PHP_EOL;
                             echo $page_data["texts"]["gallery_images_none"] . ' [<a href="/gallery/g/' . $row["id"] . '" title="' . $row["name"] . '">' . $page_data["texts"]["gallery_display"] . '</a>]' . PHP_EOL;
                             echo '</p>' . PHP_EOL;
                         }
                         // related galleries
                         echo '<h3>' . $page_data["texts"]["gallery_galleries"] . '</h3>' . PHP_EOL;
                         if (!empty($page_data[$row["name"]]["galleries"])) {
                             echo '<ul>' . PHP_EOL;
                             foreach ($page_data[$row["name"]]["galleries"] as $current) {
                                 echo '<li><a href="/gallery/g/' . $current["id"] . '" title="' . $current["name"] . '">' . $current["name"] . '</a> [' . $current["images"] . ']</li>' . PHP_EOL;
                             }
                             echo '</ul>' . PHP_EOL;
                         }
                         // related articles
                         echo '<h3>' . $page_data["texts"]["gallery_articles"] . '</h3>' . PHP_EOL;
                         if (!empty($page_data[$row["name"]]["articles"])) {
                             echo '<ul>' . PHP_EOL;
                             foreach ($page_data[$row["name"]]["articles"] as $current) {
                                 echo '<li><a href="/articles/' . $current["id"] . '" title="' . $current["name"] . '">' . $current["name"] . '</a> [' . $current["author_name"] . ']</li>' . PHP_EOL;
                             }
                             echo '</ul>' . PHP_EOL;
                         }
                         echo '<hr />' . PHP_EOL;
                     }
                 } else {
                     // no galleries
                     echo '<p class="red-note">' . PHP_EOL;
                     echo $page_data["texts"]["gallery_nocontent"] . PHP_EOL;
                     echo '</p>' . PHP_EOL;
                 }
             }
         }
     }
 }
 public function prepareData()
 {
     // variable initial set (to avoid possible warnings later)
     $this->page_data["texts"]["null"] = "";
     $this->page_data["item_title"] = "";
     // TODO allow other languages
     $this->page_data["lang"] = "cz";
     // set mySQL
     $this->getMySQLConnection();
     // variable info that depends on displayed page
     // mysql must work and page must exist
     if ($this->page_data["mysql"] == true) {
         if ($this->page_request != "error") {
             // get additional data to be displayed
             include_once getcwd() . '/pages/page-data/elrh_' . $this->page_request . '_data.php';
             $this->page_data = array_merge($this->page_data, ELRHPageData::prepareData($this->item_request, $this->mysqli));
             // get language variables for given page
             include_once getcwd() . '/scripts/data-helpers/elrh_text_retriever.php';
             $this->page_data["texts"] = ELRHTextRetriever::getTextsForPage($this->mysqli, $this->page_data["lang"], $this->page_request);
             // for admin requests we need special "output" text variable
             if (!empty($this->page_data["admin_output"])) {
                 $this->page_data["texts"]["admin_output"] = ELRHTextRetriever::getText($this->mysqli, $this->page_data["lang"], $this->page_data["admin_output"]);
             }
         } else {
             // get global site title
             include_once getcwd() . '/scripts/data-helpers/elrh_db_extractor.php';
             $this->page_data["title"] = ELRHDataExtractor::retrieveItem($this->mysqli, "SELECT value FROM elrh_settings WHERE var='global_title'", "value");
         }
     }
     // always presented info
     // mysql must work
     if ($this->page_data["mysql"] == true) {
         // global site text values
         include_once getcwd() . '/scripts/data-helpers/elrh_sitedata_retriever.php';
         $this->page_data["texts"] = array_merge($this->page_data["texts"], ELRHSitedataCreator::createSiteTexts($this->mysqli, $this->page_data["lang"]));
         $this->page_data["settings"] = ELRHSitedataCreator::createSiteSettings($this->mysqli);
         // page title
         // concluding from global title and possibly from particular page subtitle or article/gallery/image title
         // global_site_title contains always presented global title - set up along with global texts
         // $this->page_request."_headline" stands for page headline (and therefore subtitle) - set up along with particular page texts
         // item_title may contain item-specific title - set up along with page data
         // for "index" and "error" use simplified title
         if ($this->page_request == "index" || $this->page_request == "error") {
             $this->page_data["title"] = $this->page_data["settings"]["global_title"];
         } else {
             include_once getcwd() . '/scripts/content-helpers/elrh_title_creator.php';
             $this->page_data["title"] = ELRHTitleCreator::createSiteTitle($this->page_data["settings"]["global_title"], $this->page_data["texts"][$this->page_request . "_headline"], $this->page_data["item_title"]);
         }
         // menu
         include_once getcwd() . '/scripts/content-helpers/elrh_menu_creator.php';
         $this->page_data["menu"] = ELRHMenuCreator::createMenuContent($this->page_data["texts"]);
         // bottom navigation
         include_once getcwd() . '/scripts/content-helpers/elrh_navigation_creator.php';
         $this->page_data["nav"] = ELRHNavigationCreator::createNavigationContent($this->page_data["lang"], $this->mysqli);
     } else {
         // set hard-core default values
         $this->page_data["title"] = 'ELRHistory Web - NoDB';
         $this->page_data["menu"]["top"] = '<div id="menu">&nbsp;Not connected</div>';
         $this->page_data["nav"] = '&raquo;&nbsp;<a href="/" title="Index">INDEX</a>';
     }
 }