# HG changeset patch # User Matti Hamalainen # Date 1382475521 -10800 # Node ID 75cf14ee99a7abd271d7e27f77ac05d12d6ab43c # Parent e04f6e3c04f7827ef9dca3af76ad45c1833439de More work on party information system. diff -r e04f6e3c04f7 -r 75cf14ee99a7 createdb.php --- a/createdb.php Tue Oct 22 22:05:00 2013 +0300 +++ b/createdb.php Tue Oct 22 23:58:41 2013 +0300 @@ -144,8 +144,27 @@ "attendees" => "id INTEGER PRIMARY KEY AUTOINCREMENT, regtime INT, name VARCHAR(64), groups VARCHAR(64), oneliner VARCHAR(64), email VARCHAR(80), key_id INT DEFAULT NULL", "votekeys" => "id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR(64), active INT DEFAULT 0", - "votes" => "id INTEGER PRIMARY KEY AUTOINCREMENT, entry_id INT DEFAULT NULL, voter_id INT DEFAULT NULL, value INT DEFAULT 0", + + "displayVars" => "key VARCHAR(32) PRIMARY KEY, vtype INT, vstr VARCHAR(128), vtext TEXT, vint INT, desc VARCHAR(128)", + "displayPages" => "id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR(128), text VARCHAR(4096)", + "displayListData" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(128)", + "displayListPages" => "id INTEGER PRIMARY KEY AUTOINCREMENT, list_id INT DEFAULT 0, page_id INT DEFAULT 0", +); + +$siteDisplayVars = array( + "tempPageDuration" => array(VT_INT, 120, "Temporary page display time (seconds)"), + "tempPage" => array(VT_INT, 0, "Temporary page ID"), + + "showMode" => array(VT_INT, 0, "Currently active display mode"), + + "activePageMode" => array(VT_INT, 0, "Current active page display mode"), + "activePage" => array(VT_INT, 0, "Current active page"), + "activePageExpire" => array(VT_INT, 0, "Expiration timestamp of current page"), + + "rotateDuration" => array(VT_INT, 60, "Page rotation time per page (seconds)"), + "rotateList" => array(VT_INT, 0, "Current rotation list ID"), + "rotateListIndex" => array(VT_INT, 0, "Current index in rotation list"), ); $siteTestData = array( @@ -188,6 +207,29 @@ array("penis song", "reed/flt", 2, "penis.mod"), array("jenkka", "aegis", 2, "jenkka.mod"), ), + + "displayPages" => array( + "title,text", + "%s,%s", + array("Next Up", "

Next up: 4k intro

4k intro compo is about to begin

... in about 10 minutes."), + array("Astu to infodesk", "

Astu

Please come to orga info desk!"), + array("Gentle Eye mainos", "

Buy Amiga stuff!

Gentle Eye Oy is selling Amiga-related stuff near organizer desk!"), + ), + + "displayListData" => array( + "name", + "%s", + array("Main rotation"), + array("Next Up"), + ), + + "displayListPages" => array( + "list_id,page_id", + "%d,%d", + array(1,2), + array(1,3), + array(2,1), + ), ); @@ -255,12 +297,11 @@ } -function stAddSettings() +function stAddSettings($settings, $table) { - global $siteDefaults; - echo "Adding settings to settings table.\n"; + echo "Adding settings to '".$table."' table.\n"; - foreach ($siteDefaults as $key => $data) + foreach ($settings as $key => $data) { switch ($data[0]) { @@ -272,7 +313,7 @@ } $sql = stPrepareSQL( - "INSERT INTO settings (key,vtype,".$var.",desc) VALUES (%s,%d,".$type.",%s)", + "INSERT INTO ".$table." (key,vtype,".$var.",desc) VALUES (%s,%d,".$type.",%s)", $key, $data[0], $data[1], $data[2]); stExecSQL($sql); @@ -352,7 +393,10 @@ case "new": if (stCreateTables()) - stAddSettings(); + { + stAddSettings($siteDefaults, "settings"); + stAddSettings($siteDisplayVars, "displayVars"); + } if ($addData) stAddTestData(); diff -r e04f6e3c04f7 -r 75cf14ee99a7 msite.inc.php --- a/msite.inc.php Tue Oct 22 22:05:00 2013 +0300 +++ b/msite.inc.php Tue Oct 22 23:58:41 2013 +0300 @@ -17,6 +17,9 @@ define("SESS_USER", "user"); define("SESS_ADMIN", "admin"); +define("SMODE_ROTATE", 1); +define("SMODE_COMPO", 2); + // // Different voting modes diff -r e04f6e3c04f7 -r 75cf14ee99a7 show.php --- a/show.php Tue Oct 22 22:05:00 2013 +0300 +++ b/show.php Tue Oct 22 23:58:41 2013 +0300 @@ -11,14 +11,7 @@ stSetupCacheControl(); -// Initiate SQL database connection -if (!stConnectSQLDB()) - die("Could not connect to SQL database."); - -// Fetch non-"hardcoded" settings from SQL database -stReloadSettings(); - -cmPrintPageHeader("PARTY DISPLAY", "", FALSE); +cmPrintPageHeader("PARTY INFORMATION DISPLAY SYSTEM", "", FALSE); stCommonAJAX("showajax.php", "show.php", TRUE); ?> @@ -35,18 +28,8 @@ -
-
- -
-
-

Next up

-

4k intro competition

-
-
- -
-
+
+
@@ -92,7 +75,7 @@ updateView(txt); } - sendPOSTRequest("mode=get", msuccess, displayError); + sendPOSTRequest("action=get", msuccess, displayError); } @@ -105,15 +88,28 @@ { failCount = 0; if (txt == "changed") + { viewChanged(); + setTimeout("tickMain();", 500); + } + else + { + setTimeout("tickMain();", 2000); + } + } + + var mfail = function(txt) + { + displayError(); + setTimeout("tickMain();", 5000); } - sendPOSTRequest("mode=check", msuccess, displayError); + sendPOSTRequest("action=check", msuccess, mfail); } -setTimeout("tickMain();", 500); -setTimeout("tickAnim();", 20); +setTimeout("tickMain();", 1000); +setInterval("tickAnim();", 25); \n"; + + if ($title !== false) + echo + "
".$title."
\n"; + + echo + "
#".$entry["show_id"]."
\n". + "
".chentities($entry["name"])."
\n"; + + if ($compo["showAuthors"]) + echo "
".chentities($entry["author"])."
\n"; + + echo + "
".chentities($entry["info"])."
\n". + " \n"; +} + +function stPrintCompoPage($compo, $entry, $prev) +{ + echo + "
\n". + "
\n". + "
".chentities($compo["name"])." competition
\n". + "
\n"; + + if ($entry !== false) + stPrintCompoEntry($entry, "compoNext", $compo, false); + + if ($prev !== false) + stPrintCompoEntry($prev, "compoPrev", $compo, "Previous entry"); +} + + +function stPrintRotationPage($page) +{ + echo + "
\n". + "
\n". + "
\n". + "
\n". + $page["text"]. + "
\n"; +} + + +// Handle requests stSetupCacheControl(); -// Initiate SQL database connection if (!stConnectSQLDB()) die("Could not connect to SQL database."); -// Fetch non-"hardcoded" settings from SQL database -stReloadSettings(); + +// Fetch party display variables and settings +if (($res = stExecSQL("SELECT * FROM displayVars")) !== FALSE) +{ + $displayVars = array(); + $displayVarsChanged = array(); + + foreach ($res as $row) + { + switch ($row["vtype"]) + { + case VT_INT: $val = intval($row["vint"]); break; + case VT_BOOL: $val = intval($row["vint"]) ? true : false; break; + case VT_STR: $val = $row["vstr"]; break; + case VT_TEXT: $val = $row["vtext"]; break; + } + $displayVars[$row["key"]] = $val; + } +} +else + exit; + + +function stGetDisplayVar($name) +{ + global $displayVars; + if (isset($displayVars[$name])) + return $displayVars[$name]; + else + die("No display setting for '".$name."'.\n"); +} + + +function stSetDisplayVar($name, $value) +{ + global $displayVars, $displayVarsChanged; + if (isset($displayVars[$name])) + { + $displayVars[$name] = $value; + $displayVarsChanged[$name] = true; + } + else + die("No display setting for '".$name."'.\n"); +} -// XMLHttp responses -$action = "ERROR"; -if (stChkRequestItem("action") && stChkRequestItem("type")) -{ - $action = $_REQUEST["action"]; - $type = $_REQUEST["type"]; -} - +$action = stChkRequestItem("action") ? $_REQUEST["action"] : ""; switch ($action) { - case "get": - // - // Get specific data - // - switch ($type) + case "check": + // Check if there has been any change + $changed = FALSE; + if (stGetDisplayVar("tempPageDuration") > 0 && stGetDisplayVar("tempPage") > 0) + { + $sql = stPrepareSQL("SELECT * FROM displayPages WHERE id=%d", + stGetDisplayVar("tempPage")); + + if (($res = stFetchSQL($sql)) !== false) + { + stSetDisplayVar("tempPageDuration", 0); + stSetDisplayVar("activePageMode", SMODE_ROTATE); + stSetDisplayVar("activePage", stGetDisplayVar("tempPage")); + stSetDisplayVar("activePageExpire", time() + stGetDisplayVar("tempPageDuration")); + $changed = TRUE; + } + } + else + switch (stGetDisplayVar("showMode")) { - case "votes": - $sql = "SELECT * FROM votes ORDER BY utime DESC"; + case SMODE_ROTATE: + default: + stSetDisplayVar("activePageMode", SMODE_ROTATE); + + if (stGetDisplayVar("rotateList") == 0) + { + stSetDisplayVar("rotateList", 1); + stSetDisplayVar("activePageExpire", 0); + $changed = TRUE; + } + + if (time() >= stGetDisplayVar("activePageExpire") && + stGetDisplayVar("rotateList") > 0) + { + error_log("page rotated"); + + // Get list of pages from active rotation list + $list = stGetDisplayVar("rotateList"); + $sql = stPrepareSQL( + "SELECT * FROM displayListPages WHERE list_id=%d ORDER BY id", + $list); + + if (($pageList = stFetchSQL($sql)) !== false) + { + // Get page at current index + $index = stGetDisplayVar("rotateListIndex"); + + if (count($pageList) < $index) + { + $page_id = $pageList[$index]["page_id"]; + stSetDisplayVar("activePage", $page_id); + stSetDisplayVar("activePageExpire", time() + stGetDisplayVar("rotatePageTime")); + } + + // Rotate to next page + if (++$index >= count($pageList)) + $index = 0; + + stSetDisplayVar("rotateListIndex", $index); + $changed = TRUE; + } + } + else + if (stGetDisplayVar("activePage") != -1) + { + // Emergency page + stSetDisplayVar("activePage", -1); + stSetDisplayVar("activePageExpire", time() + stGetDisplayVar("rotatePageTime")); + $changed = TRUE; + } + break; + + case SMODE_COMPO: break; } + + $changed = FALSE; - // - // Perform query if we need to, output results - // - if (isset($sql) && ($res = stExecSQLCond($sql, "")) !== FALSE) - { - if ($type == "votes") - { - } - } + + echo $changed ? "changed" : "nochange"; + stSetStatus(200, "OK"); break; - case "set": - // - // Set vote - // - if ($type == "votes" && stChkRequestItem("voter_id") && - stChkRequestItem("entry_id") && stChkRequestItem("vote")) + case "get": + // Based on the currently active mode ... + switch (stGetDisplayVar("activePageMode")) { - stGetCompoList(FALSE); + case SMODE_ROTATE: + // Page rotation mode, display currently active page + if (stGetDisplayVar("activePage") > 0) + { + $sql = stPrepareSQL("SELECT * FROM displayPages WHERE id=%d", + stGetDisplayVar("activePage")); + + if (($page = stFetchSQL($sql)) !== false) + stPrintRotationPage($page); + } + else + { + echo "
ERROR!
\n"; + } + break; - stSubmitOneVote(stGetRequestItem("voter_id"), stGetRequestItem("entry_id"), stGetRequestItem("vote")); + case SMODE_COMPO: + // Competition mode + $compo = stFetchSQL(stPrepareSQL( + "SELECT * FROM compos WHERE id=%d", + stGetDisplayVar("compoCompo"))); + + $prev = stFetchSQL(stPrepareSQL( + "SELECT * FROM entries WHERE id=%d", + stGetDisplayVar("compoPrevEntry"))); + + $entry = stFetchSQL(stPrepareSQL( + "SELECT * FROM entries WHERE id=%d", + stGetDisplayVar("compoCurrEntry"))); + + if ($compo !== false) + stPrintCompoPage($compo, $entry, $prev); + break; } - else - stSetStatus(902, "No data."); break; default: @@ -69,4 +240,21 @@ break; } + +// Save changed variables +foreach (stExecSQL("SELECT * FROM displayVars") as $item) +if (isset($displayVarsChanged[$item["key"]])) +{ + $val = $displayVars[$item["key"]]; + switch ($item["vtype"]) + { + case VT_INT: $vsql = stPrepareSQL("vint=%d", $val); break; + case VT_BOOL: $vsql = stPrepareSQL("vint=%d", $val ? 1 : 0); break; + case VT_STR: $vsql = stPrepareSQL("vstr=%s", $val); break; + case VT_TEXT: $vsql = stPrepareSQL("vtext=%s", $val); break; + } + + $sql = "UPDATE displayVars SET ".$vsql." WHERE key=".$db->quote($item["key"]); + stExecSQL($sql); +} ?> \ No newline at end of file