view show.php @ 1041:f188caaedf0f

Implement force reloading of show screen web-page.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 20 Nov 2015 10:48:18 +0200
parents ffacd904fd1f
children 511147c1e119
line wrap: on
line source

<?
//
// FAPWeb - Simple Web-based Demoparty Management System
// Party information display system
// (C) Copyright 2012-2015 Tecnic Software productions (TNSP)
//
require_once "mconfig.inc.php";
require_once "msite.inc.php";
require_once "msession.inc.php";
require_once "majax.inc.php";

$pageCSS = "css/show.css";

stSetupCacheControl();

cmPrintPageHeader("PARTY INFORMATION DISPLAY SYSTEM", "", FALSE);
stCommonAJAX("showajax.php", "show.php");
?>

<!-- ========================== -->

<noscript>
  <div class="notice">
    <h1>Javascript required</h1>
    <p>
    The compo system page requires Javascript to be enabled for the AJAX functionality.
    <br />
    <a href="#">Please enable Javascript and reload this page</a>.
    </p>
  </div>
</noscript>

<div class="showView" id="mainView"></div>

<!-- ========================== -->

<script type="text/javascript">

var failCount = 0;
var lastUpdate = 0;
var errorView = false;


function updateView(txt)
{
  var view = document.getElementById("mainView");
  if (view && txt != false && txt != "")
    view.innerHTML = txt;
}


function displayError()
{
  // Increase failure count
  if (++failCount >= 3 && !errorView)
  {
    errorView = true;
    updateView("<div class=\"slideHeader\"><div class=\"slideHeaderDiv\"></div></div><div class=\"slideText\"><div class=\"guru\">Software Failure.&nbsp;&nbsp;&nbsp;Press left mouse button to continue.<br />Guru Meditation #00000004.0000AAC0</div></div>");
  }
}


//
// Update view when triggered by main tick
//
function viewChanged()
{
  var msuccess2 = function(txt)
  {
    // Successfully fetched new data, initiate view update
    updateView(txt);
  }

  var msuccess1 = function(txt)
  {
    lastUpdate = txt;
    jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError);
  }

  jsSendPOSTRequest("action=get&type=update", msuccess1, displayError);
}


//
// Main tick function, check for updates from server
//
var timeOutSet = false;

function tickMain()
{
  timeOutSet = false;

  var msuccess = function(txt)
  {
    failCount = 0;
    if (txt == "changed")
    {
      viewChanged();
      if (!timeOutSet)
      {
        setTimeout("tickMain();", 250);
        timeOutSet = true;
      }
    }
    else
    if (txt == "reload")
    {
      location.reload();
    }
    else
    {
      if (!timeOutSet)
      {
        setTimeout("tickMain();", 500);
        timeOutSet = true;
      }
    }
  }
  
  var mfail = function(txt)
  {
    displayError();
    if (!timeOutSet)
    {
      setTimeout("tickMain();", 5000);
      timeOutSet = true;
    }
  }

  jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail);
}

setTimeout("tickMain();", 100);
viewChanged();

</script>
<?
cmPrintPageFooter(FALSE);
?>