changeset 7:d76020022881

Various fixes, cleanups and improvements.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Dec 2012 09:35:30 +0200
parents 2a9267ad0ceb
children 4c5f651aa107
files admin.inc.php msite.inc.php results.inc.php
diffstat 3 files changed, 80 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/admin.inc.php	Wed Dec 05 08:14:04 2012 +0200
+++ b/admin.inc.php	Wed Dec 05 09:35:30 2012 +0200
@@ -47,7 +47,7 @@
 
 function strencode(str)
 {
-  return encodeURIComponent(escape(str));
+  return encodeURIComponent(str);
 }
 
 
@@ -166,7 +166,7 @@
   {
     var item = document.getElementById(prefix+id);
     item.style.display = "none";
-    setTimeout(func, 550);
+    setTimeout(func, 50);
   }
 
   if (confirm("Are you sure you want to delete "+dsc+" #"+id+"?"))
@@ -224,7 +224,7 @@
 
   var msuccess = function(txt)
   {
-    setTimeout("refreshNews();", 550);
+    setTimeout("refreshNews();", 50);
   }
 
   sendPOSTRequest(
@@ -260,7 +260,7 @@
 
   var msuccess = function(txt)
   {
-    setTimeout("refreshCompos();", 550);
+    setTimeout("refreshCompos();", 50);
   }
 
   sendPOSTRequest("action=add&type=compo&"+args, msuccess);
@@ -282,7 +282,7 @@
 
   var msuccess = function(txt)
   {
-    setTimeout("refreshEntries();", 550);
+    setTimeout("refreshEntries();", 50);
   }
 
   sendPOSTRequest("action=add&type=entry&compo_id="+id+"&"+args, msuccess);
@@ -309,7 +309,12 @@
 {
   var args = makePostArgs({"enabled":3, "name":0}, "vo", id);
 
-  sendPOSTRequest("action=update&type=voter&id="+id+"&"+args);
+  var msuccess = function(txt)
+  {
+    setTimeout("refreshVoters();", 50);
+  }
+
+  sendPOSTRequest("action=update&type=voter&id="+id+"&"+args, msuccess);
 }
 
 
@@ -322,8 +327,9 @@
   var str = "";
   for (var id in registeredTabs)
   {
-    str += "<a href=\"#\" onClick=\"switchActiveTab('"+
-      id+"')\">"+registeredTabs[id]+"</a>";
+    str += "<a id=\"cc"+id+
+      "\"href=\"#\" onClick=\"switchActiveTab('"+id+
+      "')\">"+registeredTabs[id]+"</a>";
   }
   
   str += "<a class=\"admin\" href=\"logout\">Logout</a>";
@@ -352,9 +358,11 @@
   for (var id in registeredTabs)
   {
     var ob = document.getElementById(id);
-    if (ob)
+    var ccob = document.getElementById("cc"+id);
+    if (ob && ccob)
     {
       ob.style.display = (tab == id) ? "block" : "none";
+      ccob.style.borderTop = (tab == id) ? "4px solid white" : "none";
       if (tab == id)
       {
         setTimeout("refresh"+ registeredTabs[id] +"();", 10);
@@ -372,7 +380,15 @@
 
 <!-- ========================== -->
 
-<div id="ntab0">
+<div id="tabGeneral">
+  <form method="post" action="" onsubmit="return updateGeneral()">
+  <hr />
+  </form>
+</div>
+
+<!-- ========================== -->
+
+<div id="tabNews">
   <form method="post" action="" onsubmit="return addNews()">
     <input id="nntitle" type="text" size="40" /><br />
     <textarea id="nntext" rows="5" cols="60"></textarea><br />
@@ -386,20 +402,19 @@
 
 <!-- ========================== -->
 
-<div id="ntab1">
-<div id="nattendees">
-</div>
+<div id="tabAttendees">
+  <div id="nattendees"></div>
 </div>
 
 <!-- ========================== -->
 
-<div id="ntab2">
+<div id="tabDump">
   <div id="ndump"></div>
 </div>
 
 <!-- ========================== -->
 
-<div id="ntab3">
+<div id="tabCompos">
   <form method="post" action="" onsubmit="return addCompo()">
     <input id="ncname" type="text" size="64" /><br />
     <textarea id="ncdescription" rows="5" cols="60"></textarea><br />
@@ -412,13 +427,13 @@
 
 <!-- ========================== -->
 
-<div id="ntab4">
+<div id="tabEntries">
   <div id="nentries"></div>
 </div>
 
 <!-- ========================== -->
 
-<div id="ntab5">
+<div id="tabVoters">
   <p>
     Key entries can only be generated via the shell-utility 'keygen'.
   </p>
@@ -428,13 +443,14 @@
 <!-- ========================== -->
 
 <script type="text/javascript">
-  registerTab("ntab0", "News");
-  registerTab("ntab1", "Attendees");
-  registerTab("ntab2", "Dump");
-  registerTab("ntab3", "Compos");
-  registerTab("ntab4", "Entries");
-  registerTab("ntab5", "Voters");
+  registerTab("tabGeneral", "Settings");
+  registerTab("tabNews", "News");
+  registerTab("tabAttendees", "Attendees");
+  registerTab("tabDump", "Dump");
+  registerTab("tabCompos", "Compos");
+  registerTab("tabEntries", "Entries");
+  registerTab("tabVoters", "Voters");
   updateTabList();
-  switchActiveTab("ntab0");
+  switchActiveTab("tabVoters");
 </script>
 <? } ?>
\ No newline at end of file
--- a/msite.inc.php	Wed Dec 05 08:14:04 2012 +0200
+++ b/msite.inc.php	Wed Dec 05 09:35:30 2012 +0200
@@ -30,20 +30,50 @@
 function stSessionExpire($type)
 {
   // Check for session expiration
-  if (!isset($_SESSION["expires"]) || $_SESSION["expires"] < time())
+  if (!isset($_SESSION["expires"]))
+  {
+    if (stGetSetting("debug")) error_log("Session $type expires due to expire time not set.");
     return FALSE;
+  }
+  
+  if ($_SESSION["expires"] < time())
+  {
+    if (stGetSetting("debug")) error_log("Session $type / ".session_id()." expires due to timeout ".$_SESSION["expires"]." < ".time());
+    return FALSE;
+  }
 
   // Add more time to expiration
+  if (stGetSetting("debug")) error_log("Adding more time to $type session ".session_id()." :: ".stGetSetting($type));
   $_SESSION["expires"] = time() + stGetSetting($type);
   return TRUE;
 }
 
 
+function stSessionEnd($ok)
+{
+  if (stGetSetting("debug")) error_log("END session ".$_SESSION["type"]." / ".$_SESSION["expires"]." == ".$ok);
+  $_SESSION = array();
+  if (ini_get("session.use_cookies"))
+  {
+    $params = session_get_cookie_params();
+    setcookie(session_name(), "", time() - 242000,
+      $params["path"], $params["domain"],
+      $params["secure"], $params["httponly"]
+    );
+  }
+  @session_destroy();
+  return $ok;
+}
+
+
 function stAdmSessionAuth()
 {
   if (@session_start() === TRUE && isset($_SESSION["admPassword"]) &&
       $_SESSION["admPassword"] == stGetSetting("admPassword"))
+  {
+    if (stGetSetting("debug")) error_log("AUTH admin session.");
     return stSessionExpire("admTimeout");
+  }
   else
     return FALSE;
 }
@@ -53,12 +83,17 @@
 {
   if (@session_start() === TRUE)
   {
+    if (stGetSetting("debug")) error_log("START admin session OK.");
+    $_SESSION["type"] = "admin";
     $_SESSION["admPassword"] = stGetSetting("admPassword");
     $_SESSION["expires"] = time() + stGetSetting("admTimeout");
     return TRUE;
   }
   else
+  {
+    if (stGetSetting("debug")) error_log("START admin session --FAILED--");
     return FALSE;
+  }
 }
 
 
@@ -75,6 +110,7 @@
 {
   if (@session_start() === TRUE)
   {
+    $_SESSION["type"] = "vote";
     $_SESSION["expires"] = time() + stGetSetting("voteTimeout");
     return TRUE;
   }
@@ -89,22 +125,6 @@
 }
 
 
-function stSessionEnd($ok)
-{
-  $_SESSION = array();
-  if (ini_get("session.use_cookies"))
-  {
-    $params = session_get_cookie_params();
-    setcookie(session_name(), "", time() - 242000,
-      $params["path"], $params["domain"],
-      $params["secure"], $params["httponly"]
-    );
-  }
-  @session_destroy();
-  return $ok;
-}
-
-
 function stGetSetting($name)
 {
   global $siteSettings, $siteDefaults;
--- a/results.inc.php	Wed Dec 05 08:14:04 2012 +0200
+++ b/results.inc.php	Wed Dec 05 09:35:30 2012 +0200
@@ -32,10 +32,10 @@
           $index = 1;
           foreach ($fres as $entry)
           {
-            printf("%3s.  %-35s  by  %-25s (%d pts)\n",
+            printf("%3s.  %s  by  %s (%d pts)\n",
               $index,
-              chentities($entry["name"]),
-              ($showAuthors ? chentities($entry["author"]) : "-"),
+              chentities(sprintf("%-35s", $entry["name"])),
+              chentities(sprintf("%-25s", $showAuthors ? $entry["author"] : "-")),
               $entry["votesum"]);
             $index++;
           }