changeset 14:e36c4d2b09c4

Fix settings to work, clean up the code, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Dec 2012 16:13:08 +0200
parents cb4af708e295
children ea0f98a0bed8
files admin.inc.php ajax.php compos.inc.php createdb.php event.inc.php index.php keygen.php news.inc.php
diffstat 8 files changed, 126 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/admin.inc.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/admin.inc.php	Thu Dec 06 16:13:08 2012 +0200
@@ -1,4 +1,33 @@
 <?
+function stCreateSettingsData()
+{
+  $args = array();
+
+  if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE)
+  {
+    foreach ($res as $item)
+    {
+      switch ($item["vtype"])
+      {
+        case VT_STR:
+        case VT_TEXT: $type = 0; break;
+        case VT_INT: $type = 4; break;
+        case VT_BOOL: $type = 3; break;
+      }
+      $args[] = "\"".$item["key"]."\":".$type;
+    }
+  }
+
+  echo
+  "\n".
+  "function updateSettings()\n".
+  "{\n".
+  "  var args = makePostArgs({".implode(",", $args)."}, \"st\", \"\");\n".
+  "  sendPOSTRequest(\"action=update&type=settings&\"+args);\n".
+  "  return false;\n".
+  "}\n";
+}
+
 // Check if sessions are enabled
 if (!stChkSetting("admPassword"))
 {
@@ -31,6 +60,9 @@
 {
 ?>
 <script type="text/javascript">
+// <? stCreateSettingsData(); ?>
+
+
 function statusMsg(msg)
 {
   document.getElementById("nstatus").innerHTML = msg;
@@ -87,7 +119,10 @@
       else
       if (req.status == 200)
       {
-        success(req.responseText);
+        if (success)
+        {
+          success(req.responseText);
+        }
         statusMsg(req.statusText);
       }
       else
@@ -115,7 +150,7 @@
     var elem = document.getElementById(fprefix + id + fsuffix);
     if (!elem)
     {
-      alert("No such DOM element '"+ id +"'.");
+      alert("No such DOM element '"+ fprefix + id + fsuffix +"'.");
       return "";
     }
 
@@ -123,14 +158,18 @@
     {
       case 0:
       case 1:
+      case 4:
         {
           var str = strtrim(elem.value);
-          if (fields[id] == 1 && str == "")
+          if ((fields[id] == 1 || fields[id] == 4) && str == "")
           {
             alert("One or more of the fields are empty.");
             return "";
           }
-          res.push(id+"="+strencode(str));
+          if (fields[id] == 4)
+            res.push(id+"="+parseInt(elem.value));
+          else
+            res.push(id+"="+strencode(str));
         }
         break;
 
@@ -324,17 +363,6 @@
 }
 
 
-function updateSettings()
-{
-  var args = makePostArgs({
-    "oneliner":0,
-    "email":0
-    }, "st", "");
-
-  sendPOSTRequest("action=update&type=settings&"+args);
-}
-
-
 var registeredTabs = Object();
 
 
--- a/ajax.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/ajax.php	Thu Dec 06 16:13:08 2012 +0200
@@ -96,7 +96,40 @@
         break;
 
       case "settings":
-        $sql = "SELECT * FROM settings";
+        $prefix = "st";
+
+        echo
+        "<table>\n";
+        foreach (stExecSQL("SELECT * FROM settings WHERE vtype<>".VT_TEXT) as $item)
+        {
+          echo
+          " <tr>\n".
+          "  <td>";
+          $id = $item["key"];
+          switch ($item["vtype"])
+          {
+            case VT_INT:
+              echo stGetFormTextInput(10, 10, "", $id, $prefix, $item["vint"]);
+              break;
+            case VT_STR:
+              echo stGetFormTextInput(40, 128, "", $id, $prefix, $item["vstr"]);
+              break;
+            case VT_BOOL:
+              echo stGetFormCheckBoxInput("", $id, $prefix, $item["vint"], "");
+              break;
+          }
+          echo "</td>\n".
+          "  <td>".$item["desc"]."</td>\n".
+          " </tr>\n";
+        }
+        echo "</table>\n";
+
+        foreach (stExecSQL("SELECT * FROM settings WHERE vtype=".VT_TEXT) as $item)
+        {
+          echo "<h2>".chentities($item["desc"])."</h2>\n".
+          stGetFormTextArea(10, 60, "", $item["key"], $prefix, $item["vtext"]).
+          "\n<br />\n";
+        }
         break;
       
       case "entries":
@@ -205,7 +238,7 @@
         "  <th class=\"vid\">#</th>\n".
         "  <th class=\"vkey\">Vote key</th>\n".
         "  <th class=\"vname\">Name</th>\n".
-        "  <th style=\"vactive\">Active</th>\n".
+        "  <th class=\"vactive\">Active</th>\n".
         " </tr>\n";
         $row = 0;
         foreach ($res as $item)
@@ -227,10 +260,6 @@
         }
         echo "</table>\n";
       }
-      else
-      if ($type == "settings")
-      {
-      }
     }
     break;
 
@@ -356,6 +385,25 @@
       execSQLCond($sql, "OK, voter updated.");
     }
     else
+    if ($type == "settings")
+    {
+      foreach (stExecSQL("SELECT * FROM settings") as $item)
+      if (stChkRequestItem($item["key"]))
+      {
+        $val = stGetRequestItem($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 settings SET ".$vsql." WHERE key=".$db->quote($item["key"]);
+        execSQLCond($sql, "OK, setting updated.");
+      }
+    }
+    else
       setStatus(902, "No data.");
     break;
 
--- a/compos.inc.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/compos.inc.php	Thu Dec 06 16:13:08 2012 +0200
@@ -1,22 +1,6 @@
-<h1>General</h1>
-<p class="notice">
-YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY.
-</p>
+<?
+echo stGetSetting("compoDescription");
 
-<p class="note">
-If there are enough entries, then AGA/OCS/ECS demos will be run in separate compos.
-<br />
-Remote entries are welcome!
-</p>
-
-<p>
-The compo machine will be an <b>A1200 with an 060/50 and lots of
-RAM</b>. An <b>A500 1.3 512k/512k</b> will also be available if your
-prod is not AGA compatible.
-</p>
-
-<h1>Compos</h1>
-<?
 function stConvSwitchMode(&$str, &$mode, $newMode)
 {
   if ($newMode != $mode)
--- a/createdb.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/createdb.php	Thu Dec 06 16:13:08 2012 +0200
@@ -22,7 +22,26 @@
   "showVoteAuthors"  => array(VT_BOOL, false, "Show entry authors on voting page"),
 
   "eventDescription" => array(VT_TEXT, "", "Event general description / timetables etc."),
-  "compoDescription" => array(VT_TEXT, "", "Compo general description"),
+  "compoDescription" => array(VT_TEXT, "
+<h1>General</h1>
+<p class=\"notice\">
+YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY.
+</p>
+
+<p class=\"note\">
+If there are enough entries, then AGA/OCS/ECS demos will be run in separate compos.
+<br />
+Remote entries are welcome!
+</p>
+
+<p>
+The compo machine will be an <b>A1200 with an 060/50 and lots of
+RAM</b>. An <b>A500 1.3 512k/512k</b> will also be available if your
+prod is not AGA compatible.
+</p>
+
+<h1>Compos</h1>
+", "Compo general description"),
   "siteInfoText"     => array(VT_TEXT,
 "<a href=\"news\"><img src=\"img/fapsm.png\" alt=\"Finnish Amiga Party 2012\" class=\"logo\" /></a><div id=\"date\">30.11. - 2.12.2012<br />Helsinki, Finland<br />@ old location<br />Entry 15 EUR + prod</div>",
   "Site header text"),
--- a/event.inc.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/event.inc.php	Thu Dec 06 16:13:08 2012 +0200
@@ -1,25 +1,3 @@
-<h1>Event program &amp; schedule</h1>
-<ul>
- <li><b>Aegis</b> of DSS and FAG will be performing a DJ gig.</li>
- <li>.. and possible additional live acts. More info to come.</li>
-</ul>
-
-<h2>Friday 30.11.</h2>
-<ul>
- <li><b>18:00</b> - <i>Doors open</i>.</li>
- <li><b>22:00</b> - DJ set by Aegis.</li>
-</ul>
-
-<h2>Saturday 1.12.</h2>
-<ul>
- <li><b>14:00</b> - Deadline for remote entries.</li>
- <li><b>18:00</b> - Deadline for the entries delivered on location.</li>
- <li><b>20:00</b> - Competitions start.</li>
-</ul>
-
-Competition schedule and voting deadline will depend on number of entries.
-
-<h2>Sunday 2.12.</h2>
-<ul>
- <li><b>12:00</b> - Party over?</li>
-</ul>
+<?
+echo stGetSetting("eventDescription");
+?>
--- a/index.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/index.php	Thu Dec 06 16:13:08 2012 +0200
@@ -33,8 +33,7 @@
 ?>
 <div id="headerbox">
  <div id="header">
-  <a href="news"><img src="img/fapsm.png" alt="Finnish Amiga Party 2012" class="logo" /></a>
-  <div id="date">30.11. - 2.12.2012<br />Helsinki, Finland<br />@ old location<br />Entry 15 EUR + prod</div>
+ <? echo stGetSetting("siteInfoText") ?>
  </div>
  <div id="menu">
   <a href="news">News</a>
--- a/keygen.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/keygen.php	Thu Dec 06 16:13:08 2012 +0200
@@ -56,7 +56,7 @@
       
       // Generate one keycode
       $key = "";
-      for ($n = 0; $n < stGetSetting("votekeylen", 8); $n++)
+      for ($n = 0; $n < stGetSetting("voteKeyLength"); $n++)
         $key .= $keyChars[rand() % strlen($keyChars)];
 
       // Check if it already exists, to avoid duplicates
--- a/news.inc.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/news.inc.php	Thu Dec 06 16:13:08 2012 +0200
@@ -1,21 +1,6 @@
-<div style="text-align: center;">
-<img src="img/fap.png" alt="FAP" />
-<!--
-<br />
-<img src="img/2012.png" alt="2012" />
-<p>
-Organized by Finnish Amiga Group
-</p>
--->
-<p>
-Pure Amiga demoscene party, all traditional Amiga compos and purely Amiga-oriented program.
-<br />
-<span class="notice">
-YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY.
-</span>
-</p>
-</div>
 <?
+echo stGetSetting("newsDescription");
+
 if (($res = stExecSQL("SELECT * FROM news ORDER BY utime DESC")) !== FALSE)
 {
   foreach ($res as $item)