update favicon if it's your turn.
authorArun Persaud <arun@nubati.net>
Sat, 17 Aug 2013 15:24:36 +0000 (08:24 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 17 Aug 2013 15:24:36 +0000 (08:24 -0700)
Added a simple php script that returns via json if it's your turn and
then check this every 10s using javascript.

include/output.php
js/layout.js
pics/edoko-favicon-your-turn.png [new file with mode: 0644]
testfav.php [new file with mode: 0644]

index 67c1870bb01ef2e7a06fb97ee424122de4090d69..6e5f15f9465e975baf41e24927126d410753491e 100644 (file)
@@ -423,7 +423,7 @@ function output_header()
      <title>e-Doko</title>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width; initial-scale=1.0;" />
-     <link rel="shortcut icon" href="pics/edoko-favicon.png" />
+     <link id="favicon" rel="shortcut icon" href="pics/edoko-favicon.png" />
      <link rel="stylesheet" media="all" href="<?php echo autoversion("css/bootstrap.css"); ?>" />
      <link rel="stylesheet" href="<?php echo autoversion("css/standard.css"); ?>" />
      <link rel="stylesheet" href="<?php echo autoversion("css/dateinput.css"); ?>"/>
index 88c85e520368e995a561f692003593e46c9366af..ae8a8af7f7c5d27475ac7f88a0d3c6e6c2633163 100644 (file)
@@ -35,3 +35,33 @@ $('div.code').addClass('offset2 span2');
 $('div.database').addClass('span2');
 $('div.graphics').addClass('span2');
 $('div.translation').addClass('span2');
+
+// favicon as indicator if it's your turn
+document.head || (document.head = document.getElementsByTagName('head')[0]);
+
+function checkFavicon() {
+    /* check if it's your turn */
+    url=window.location.href;
+    url=url.substring(0, url.lastIndexOf('index.php'))+"testfav.php";
+
+    $.getJSON(url)
+       .done(function( json ) {
+
+           var link = document.createElement('link'),
+           oldLink = document.getElementById('favicon');
+           link.id = 'favicon';
+           link.rel = 'shortcut icon';
+
+           if(json.turn=="yes")
+               link.href = "pics/edoko-favicon-your-turn.png";
+           else
+               link.href = "pics/edoko-favicon.png";
+
+           if (oldLink)
+               document.head.removeChild(oldLink);
+
+           document.head.appendChild(link);
+       });
+}
+checkFavicon();
+setInterval(checkFavicon,10000);
diff --git a/pics/edoko-favicon-your-turn.png b/pics/edoko-favicon-your-turn.png
new file mode 100644 (file)
index 0000000..71604fc
Binary files /dev/null and b/pics/edoko-favicon-your-turn.png differ
diff --git a/testfav.php b/testfav.php
new file mode 100644 (file)
index 0000000..7d29897
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/* Copyright 2013 Arun Persaud <arun@nubati.net>
+ *
+ *   This file is part of e-DoKo.
+ *
+ *   e-DoKo is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   e-DoKo is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+error_reporting(E_ALL);
+
+session_start();
+
+include_once("config.php");                /* needs to be first in list, since other includes use this */
+include_once("./include/db.php");          /* database only */
+
+/* open the database */
+$DBopen = DB_open();
+if($DBopen<0)
+  exit();
+
+if(isset($_SESSION['id']))
+  {
+    $myid = $_SESSION['id'];
+
+    $result = DB_query_array("SELECT count(player) from Game ".
+                            " WHERE player=".DB_quote_smart($myid).
+                            " AND ( status='pre' OR  status='play' ) ");
+    if($result[0])
+      $ret=array('turn'=>'yes');
+    else
+      $ret=array('turn'=>'no');
+
+    echo json_encode($ret);
+  };
+
+DB_close();
+
+/*
+ *Local Variables:
+ *mode: php
+ *mode: hs-minor
+ *End:
+ */
+?>