<?php
// https://www.archline.hu/maintenance/banner.php?serial=MzYwNzAwODM0MDEyMzQ1Ng==&build=MjM0&lang=eng|hun|ger
require('config.php');

$serial = base64_decode(str_replace(" ", "+", $_GET['serial']));
$build = base64_decode(str_replace(" ", "+", $_GET['build']));
$ctrCode = substr($serial, 0, 2);
$prgType = substr($serial, 6, 1);
$prgCode = substr($serial, 7, 2);
$bldCode = (int)$build;
$lngCode = (isset($_GET['lang']) ? trim(addslashes(strtolower($_GET['lang']))) : NULL);
$hlNum = substr($serial, 0, 6);
$id = (isset($_GET['bid']) && (int)base64_decode(str_replace(" ", "+", $_GET['bid'])) > 0 ? (int)base64_decode(str_replace(" ", "+", $_GET['bid'])) : NULL);

if ($id > 0) {
  $sql = "SELECT * FROM `albanner` WHERE id=" . $id;
} else {
  if (strpos($hlNum, "x") === FALSE) // normál ág
  {
    $sql = "SELECT * FROM `www_archline_hu`.`albanner` WHERE 
            " . ($lngCode > '' ? " `lang`='" . $lngCode . "' AND " : "") . "
            " . ($bldCode > 0  ? " (`build`=" . $bldCode . " OR `build`=0 OR `build` IS NULL) AND " : "") . "
          	`from_datetime`<=CURRENT_TIMESTAMP AND 
          	`end_datetime`>CURRENT_TIMESTAMP AND 
          	`published`='Y' AND 
      			(substring(`pattern`,1,6)='" . $ctrCode . "xxxx' OR substring(`pattern`,1,6)='xxxxxx') AND 
      			(substring(`pattern`,7,1)='" . $prgType . "' OR substring(`pattern`,7,1)='x') AND 
      			(substring(`pattern`,8,2)='" . $prgCode . "' OR substring(`pattern`,8,2)='xx') 
          ORDER BY `priority` DESC, `add_datetime` DESC 
          LIMIT 10;";
  } else // teszteléshez!
  {
    $sql = "SELECT * FROM `www_archline_hu`.`albanner` WHERE 
            " . ($lngCode > '' ? " `lang`='" . $lngCode . "' AND " : "") . "
            " . ($bldCode > 0  ? " (`build`=" . $bldCode . " OR `build`=0 OR `build` IS NULL) AND " : "") . "
          	`from_datetime`<=CURRENT_TIMESTAMP AND 
          	`end_datetime`>CURRENT_TIMESTAMP AND 
          	`published`='Y' AND 
      			(substring(`pattern`,1,6)='" . $ctrCode . "xxxx' OR substring(`pattern`,1,6)='xxxxxx') AND 
      			(substring(`pattern`,7,1)='" . $prgType . "' OR substring(`pattern`,7,1)='x') AND 
      			(substring(`pattern`,8,2)='" . $prgCode . "' OR substring(`pattern`,8,2)='xx') 
          ORDER BY `priority` DESC, `add_datetime` DESC 
          LIMIT 10;";
  }
}


$msh2->query($sql);
$res = $msh2->fetchAssoc();

if ($_SERVER['REMOTE_ADDR'] == '188.6.239.155' && isset($_GET['test'])) {
  print "serial: " . $serial . " build: " . $bldCode . " result: " . count($res) . "<br />" . $sql;
}

?>
<!doctype html>

<html lang="en">

<head>
  <meta charset="utf-8">

  <title>ARCHLine.XP banner</title>
  <meta name="description" content="ARCHLine.XP banner">

  <link rel="stylesheet" type="text/css" href="css/ticker-style.css" />
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

  <script src="js/jquery.min.js" type="text/javascript"></script>
  <script src="js/jquery.ticker.js" type="text/javascript"></script>

  <!--[if lt IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
  <![endif]-->

  <style type="text/css">
    body {
      color: #000000;
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
      font-size: 14px;
    }
  </style>

</head>

<body>
  <ul id="js-news" class="js-hidden">
    <?php foreach ($res as $row) : ?>
      <?php if ($row['link'] > '') : ?>
        <li class="news-item"><a href="<?= $row['link'] ?>" target="_blank"><?= strip_tags($row['message'], '<i><b><strong>') ?></a></li>
      <?php else : ?>
        <li class="news-item"><?= strip_tags($row['message'], '<i><u><b><strong>') ?></li>
      <?php endif; ?>
    <?php endforeach; ?>
  </ul>


  <script type="text/javascript">
    jQuery(function() {
      jQuery('#js-news').ticker({
        speed: 0.10, // The speed of the reveal
        ajaxFeed: false, // Populate jQuery News Ticker via a feed
        feedUrl: false, // The URL of the feed
        // MUST BE ON THE SAME DOMAIN AS THE TICKER
        feedType: 'xml', // Currently only XML
        htmlFeed: true, // Populate jQuery News Ticker via HTML
        debugMode: false, // Show some helpful errors in the console or as alerts. SHOULD BE SET TO FALSE FOR PRODUCTION SITES!
        controls: false, // Whether or not to show the jQuery News Ticker controls
        titleText: '', // To remove the title set this to an empty String
        displayType: 'fade', // Animation type - current options are 'reveal' or 'fade'
        direction: 'ltr', // Ticker direction - current options are 'ltr' or 'rtl'
        pauseOnItems: <?= (count($res) > 1 ? 4000 : 600000) ?>, // The pause on a news item before being replaced
        fadeInSpeed: 300, // Speed of fade in animation
        fadeOutSpeed: 300 // Speed of fade out animation      
      });
    });
  </script>
</body>

</html>