changeset 620:8444fe96120e

Implement setting groups for admin interface settings. This is just the backend and database stuff tho, still needs the actual interface code.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 01 Nov 2014 05:41:21 +0200
parents 2b4ea04adeea
children 9ad53fda22bc
files dbdefs.inc.php managedb.php
diffstat 2 files changed, 189 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/dbdefs.inc.php	Sat Nov 01 05:40:22 2014 +0200
+++ b/dbdefs.inc.php	Sat Nov 01 05:41:21 2014 +0200
@@ -1,45 +1,106 @@
 <?
 
-$dbVersion = 13;
+$dbVersion = 14;
 
 //
 // Site settings and defaults we put in
 //
-$siteDefaults = array(
-  "maxAttendeesHard" => array(VT_INT, 60, "Maximum attendees (HARD limit, <= 0 means no limit)"),
-  "maxAttendeesSoft" => array(VT_INT, 50, "Maximum attendees (soft limit, <= 0 means no limit)"),
+$siteSettingsGroups = array(
+  "general"   => array("General", "General settings"),
+  "html"      => array("HTML", "Global HTML blurbs"),
+  "news"      => array("News", "News related settings"),
+  "register"  => array("Register", "Visitor registration"),
+  "event"     => array("Event", "Event related settings"),
+  "compos"    => array("Compos", "Compo related settings"),
+);
+
+$siteDefaultSettings = array(
+
+  //
+  // General site settings
+  //
+  "general" => array(
+    "maxAttendeesHard" => array(VT_INT, 60, "Maximum attendees (HARD limit, <= 0 means no limit)"),
+    "maxAttendeesSoft" => array(VT_INT, 50, "Maximum attendees (soft limit, <= 0 means no limit)"),
 
-  "userTimeout"      => array(VT_INT, 120, "User pages (voting) timeout in minutes"),
-  "admTimeout"       => array(VT_INT, 15, "Administration interface timeout in minutes"),
+    "userTimeout"      => array(VT_INT, 120, "User pages (voting) timeout in minutes"),
+    "admTimeout"       => array(VT_INT, 15, "Administration interface timeout in minutes"),
+
+    "showAdmin"        => array(VT_BOOL, false, "Always show administration interface link on the menu"),
+    "showAttendees"    => array(VT_BOOL, true, "Show attendees list"),
+    "allowVoting"      => array(VT_BOOL, false, "Enable voting (individual compos must be enabled as well)"),
 
-  "showAdmin"        => array(VT_BOOL, false, "Always show administration interface link on the menu"),
-  "showAttendees"    => array(VT_BOOL, true, "Show attendees list"),
-  "allowRegister"    => array(VT_BOOL, false, "Enable event registration"),
-  "allowVoting"      => array(VT_BOOL, false, "Enable voting (individual compos must be enabled as well)"),
+    "showResults"      => array(VT_BOOL, false, "Enable results page"),
+    "showResAuthors"   => array(VT_BOOL, true, "Show entry authors on results page"),
+
+    "showInfoTextOnAbout" => array(VT_BOOL, false, "Show site info HTML on About page"),
+
+  ),
+
+  "html" => array(
+    "siteMenuHeader" => array(VT_TEXT, "<div>13.FAP:&gt; <span class=\"mblink\">&#9632;</span></div>", "Site menu header text"),
+    "siteMenuFooter" => array(VT_TEXT, "", "Site menu footer text"),
+    "siteExtraHTML" => array(VT_TEXT, "<div id=\"sponsors\">Gentle Eye</div>", "Extra global HTML code (f.e. sponsors box)"),
 
-  "showResults"      => array(VT_BOOL, false, "Enable results page"),
-  "showResAuthors"   => array(VT_BOOL, true, "Show entry authors on results page"),
+    "siteInfoText" => array(VT_TEXT, "
+<a href=\"about\">
+<img src=\"img/fapsm.png\" alt=\"Finnish Amiga Party 2013\" class=\"logo\" /></a>
+<div id=\"date\">
+5.-8.12.2013<br />
+Helsinki, Finland<br />
+@ old location<br />
+<span class=\"notice\">Entry 15 EUR + prod</span>
+</div>", "Site header text"),
 
-  "requireEMail"     => array(VT_BOOL, false, "Require e-mail address in registrations"),
+  "aboutDescription" => array(VT_TEXT, "
+<div style=\"text-align: center;\">
+<img src=\"img/fap.png\" alt=\"FAP\" />
+<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>",
+  "About page text"),
+
 
-  "showNews"         => array(VT_BOOL, true, "Enable News link on main menu + News page"),
-  "showNewsOnAbout"  => array(VT_BOOL, true, "Show latest news item on About page"),
-  "showSchedule"     => array(VT_BOOL, true, "Enable Schedule link on main menu + Schedule page"),
-  "showCompos"       => array(VT_BOOL, true, "Enable Compos link on main menu + Compos page"),
+  "voteFinishedText" => array(VT_TEXT, "
+<h1>Yay, you have voted!</h1>
+<p>Now go FAP some more! And make a demo about it.</p>",
+  "Message shown after successful voting"),
+
+  ),
 
-  "registerInfoText" => array(VT_TEXT, "<p>
+  //
+  // News related
+  //
+  "news" => array(
+    "showNews"         => array(VT_BOOL, true, "Enable News link on main menu + News page"),
+    "showNewsOnAbout"  => array(VT_BOOL, true, "Show latest news item on About page"),
+    "newsHeader"  => array(VT_TEXT, "", "News page header text"),
+  ),
+  
+  //
+  // Attendee/visitor registration
+  //
+  "register" => array(
+    "requireEMail"     => array(VT_BOOL, false, "Require e-mail address in registrations"),
+    "allowRegister"    => array(VT_BOOL, false, "Enable event registration"),
+    "registerInfoText" => array(VT_TEXT, "<p>
 Only your <b>handle</b> and the answer to the botcheck are strictly required.
 If you plan on joining the IRC channel
 (<a href=\"irc://#fap2013@ircnet\">#fap2013 @ IRCNet</a>) or staying up to date by other means,
 <b>e-mail</b> is not required either.
 </p>", "Registration page info text"),
 
-  "registerPostText" => array(VT_TEXT, "
+    "registerPostText" => array(VT_TEXT, "
 <h1>Registration successful</h1>
 <p>Now go make a demo about it!</p>",
   "Successful post-registration note text"),
 
-  "registerLimitExceeded" => array(VT_TEXT, "
+    "registerLimitExceeded" => array(VT_TEXT, "
 <h1>Sorry, registration disabled!</h1>
 <p>
 Registration to the event is not available at this time due to
@@ -48,7 +109,7 @@
 ",
   "Registration attendee limit exceeded note text"),
 
-  "registerNotEnabled" => array(VT_TEXT, "
+    "registerNotEnabled" => array(VT_TEXT, "
 <h1>Sorry, registration disabled!</h1>
 <p>
 Registration to the event is not enabled at this time.
@@ -63,7 +124,15 @@
 some other means (IRC, for example.)</p>
 ", "No e-mail address registration note"),
 
-  "eventDescription" => array(VT_TEXT, "
+  ),
+
+  //
+  // Event / schedule information
+  //
+  "event" => array(
+    "showSchedule"     => array(VT_BOOL, true, "Enable Schedule link on main menu + Schedule page"),
+
+    "eventDescription" => array(VT_TEXT, "
 <h1>Event program &amp; schedule</h1>
 <ul>
  <li><b>Aegis</b> of DSS and FAG will be performing a DJ gig.</li>
@@ -91,8 +160,15 @@
 </ul>
 ", "Event general description / timetables etc."),
 
-
-  "compoDescription" => array(VT_TEXT, "
+  ),
+  
+  //
+  // Competitions
+  //
+  "compos" => array(
+    "showCompos"       => array(VT_BOOL, true, "Enable Compos link on main menu + Compos page"),
+  
+    "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.
@@ -112,43 +188,7 @@
 
 <h1>Compos</h1>
 ", "Compo general description"),
-
-
-  "siteInfoText"     => array(VT_TEXT, "
-<a href=\"about\">
-<img src=\"img/fapsm.png\" alt=\"Finnish Amiga Party 2013\" class=\"logo\" /></a>
-<div id=\"date\">
-5.-8.12.2013<br />
-Helsinki, Finland<br />
-@ old location<br />
-<span class=\"notice\">Entry 15 EUR + prod</span>
-</div>", "Site header text"),
-
-
-  "newsHeader"  => array(VT_TEXT, "", "News page header text"),
-
-
-  "aboutDescription"  => array(VT_TEXT, "
-<div style=\"text-align: center;\">
-<img src=\"img/fap.png\" alt=\"FAP\" />
-<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>",
-  "About page text"),
-
-  "voteFinishedText" => array(VT_TEXT, "
-<h1>Yay, you have voted!</h1>
-<p>Now go FAP some more! And make a demo about it.</p>",
-  "Message shown after successful voting."),
-
-  "siteMenuHeader" => array(VT_TEXT, "<div>13.FAP:&gt; <span class=\"mblink\">&#9632;</span></div>", "Site menu header text"),
-  "siteMenuFooter" => array(VT_TEXT, "", "Site menu footer text"),
-  "siteExtraHTML" => array(VT_TEXT, "<div id=\"sponsors\">Gentle Eye</div>", "Extra global HTML code (f.e. sponsors box)"),
+  ),
 );
 
 
@@ -157,6 +197,12 @@
 //
 $sqlTables = array(
   // Site settings
+  "settings_groups" => array(
+    array("id"           , "INTEGER", "PRIMARY KEY", "AUTOINCREMENT"),
+    array("name"         , "VARCHAR(64)"),
+    array("description"  , "VARCHAR(128)"),
+  ),
+
   "settings" => array(
     array("key"          , "VARCHAR(32)", "PRIMARY KEY"),
     array("vtype"        , "INT"),
@@ -164,6 +210,7 @@
     array("vtext"        , "TEXT"),
     array("vint"         , "INT"),
     array("sdesc"        , "VARCHAR(128)"),
+    array("vgroup"       , "INT"),
   ),
 
   "news" => array(
@@ -362,6 +409,10 @@
     "rot_list_data" => array("table" => "rotationListData"),
     "rot_list_slides" => array("table" => "rotationListSlides"),
   ),
+  
+  14 => array(
+    "settings_groups" => array("table" => FALSE),
+  ),
 );
 
 
--- a/managedb.php	Sat Nov 01 05:40:22 2014 +0200
+++ b/managedb.php	Sat Nov 01 05:41:21 2014 +0200
@@ -12,6 +12,7 @@
   "dbVersion" => array(VT_INT, $dbVersion, "Database version"),
 );
 
+// Add database meta table into tables to be created
 $sqlTables["dbmeta"] = array(
   array("key"          , "VARCHAR(32)", "PRIMARY KEY"),
   array("vtype"        , "INT"),
@@ -34,8 +35,13 @@
   {
     echo " - '".$name."'\n";
     stDBExecSQL($dbh, "DROP TABLE IF EXISTS ".$name);
-    if (!stDBCreateOneTable($dbh, $name, stDBGetTableSchema($dbh, $schemaData)) && !$upgrade)
-      return FALSE;
+    if (!stDBCreateOneTable($dbh, $name, stDBGetTableSchema($dbh, $schemaData)))
+    {
+      if (!$upgrade)
+        return FALSE;
+      else
+        echo "\nFailed to create table '".$name."'\n";
+    }
   }
   return TRUE;
 }
@@ -71,12 +77,9 @@
 }
 
 
-function stAddSettings($inDB, $outDB, $settings, $table, $upgrade)
+function stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $group = FALSE)
 {
-  echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.";
-
   $status = TRUE;
-  stDBBeginTransaction($outDB);
 
   foreach ($settings as $key => $data)
   {
@@ -92,6 +95,11 @@
       default:      die("Invalid type in default settings '".$key."', type=".$data[0]."\n");
     }
 
+    $sqlFmt =
+      "INSERT INTO ".$table." (key,vtype,".$var.",sdesc".
+      ($group !== FALSE ? ",vgroup" : "").") VALUES (%s,%d,".$type.",%s".
+      ($group !== FALSE ? ",%d" : "").")";
+
     // Check if we are upgrading
     if ($upgrade)
     {
@@ -105,18 +113,16 @@
         if ($res["vtype"] != $data[0])
           die("Oops! Data type of '".$key."' does not match in table '".$table.". DB upgrade failed.\n");
 
-        $sql = stDBPrepareSQL($outDB,
-          "INSERT INTO ".$table." (key,vtype,".$var.",sdesc) VALUES (%s,%d,".$type.",%s)",
-          $key, $data[0], $res[$var], $data[2]);
+        $sql = stDBPrepareSQL($outDB, $sqlFmt,
+          $key, $data[0], $res[$var], $data[2], $group);
       }
     }
 
     if ($sql === false)
     {
       // Normal insertion of default data
-      $sql = stDBPrepareSQL($outDB,
-        "INSERT INTO ".$table." (key,vtype,".$var.",sdesc) VALUES (%s,%d,".$type.",%s)",
-        $key, $data[0], $data[1], $data[2]);
+      $sql = stDBPrepareSQL($outDB, $sqlFmt,
+        $key, $data[0], $data[1], $data[2], $group);
     }
 
     if (stDBExecSQL($outDB, $sql) === FALSE)
@@ -125,13 +131,61 @@
       break;
     }
   }
-  echo "\n";
 
-  stDBCommitTransaction($outDB);
   return $status;
 } 
 
 
+function stAddSettingsGroup($inDB, $outDB, $groups, $groupData, $groupTable, $table, $upgrade)
+{
+  echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.\n";
+  foreach ($groups as $groupID => $settings)
+  {
+    if (!isset($groupData[$groupID]))
+    {
+      echo "Group data not set for settings group ID '".$groupID."'.\n";
+      return FALSE;
+    }
+    
+    // Add group
+    echo " - Group '".$groupID."' -> ".$groupData[$groupID][1].".";
+    $sql = stDBPrepareSQL($outDB,
+      "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)",
+      $groupData[$groupID][0], $groupData[$groupID][1]);
+
+    if (($gid = stDBExecSQLInsert($outDB, $sql)) === false)
+    {
+      echo "\nFailed to add group '".$groupID."'\n";
+      return FALSE;
+    }
+    
+    // Add settings to the group
+    stDBBeginTransaction($outDB);
+    if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === false)
+    {
+      echo "\nFailed to add settings to group '".$groupID."'\n";
+      return FALSE;
+    }
+    stDBCommitTransaction($outDB);
+    echo "\n";
+  }
+
+  return TRUE;
+}
+
+
+function stAddSettingsNormal($inDB, $outDB, $settings, $table, $upgrade)
+{
+  stDBBeginTransaction($outDB);
+  echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.";
+  $status = stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade);
+  echo "\n";
+  if ($status !== FALSE)
+    stDBCommitTransaction($outDB);
+  return $status;
+}
+
+
 function stAddTestData($outDB)
 {
   global $siteTestData;
@@ -201,7 +255,7 @@
     // Do not migrate excluded tables (or excluded tables with old names)
     $sequences = array();
     $inTable = $upgrade ? stUpgradeMap("table", $table) : $table;
-    if (in_array($inTable, $excluded) || in_array($table, $excluded))
+    if ($inTable === FALSE || in_array($inTable, $excluded) || in_array($table, $excluded))
       continue;
 
     // Process each row of the input table
@@ -353,9 +407,9 @@
     // Create tables, add defaults
     if (stCreateTables($inDB, FALSE))
     {
-      stAddSettings($inDB, $inDB, $dbMetaData, "dbmeta", FALSE);
-      stAddSettings($inDB, $inDB, $siteDefaults, "settings", FALSE);
-      stAddSettings($inDB, $inDB, $siteDisplayVars, "display_vars", FALSE);
+      stAddSettingsNormal($inDB, $inDB, $dbMetaData, "dbmeta", FALSE, FALSE);
+      stAddSettingsGroup($inDB, $inDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", FALSE);
+      stAddSettingsNormal($inDB, $inDB, $siteDisplayVars, "display_vars", FALSE, FALSE);
     }
     
     if ($addTestData)
@@ -380,7 +434,7 @@
     if ($outSpec == $inSpec)
       die("The input and output databases CAN NOT BE SAME.\nBe VERY CAREFUL to not accidentally specify same db!\n");
 
-    echo "Using database spec '".$inSpec."'.\n";
+    echo "Using INPUT database spec '".$inSpec."'.\n";
 
     if (($inDB = stConnectSQLDBSpec($inSpec)) === false)
       die("Could not connect to SQL database '".$inSpec."'.\n");
@@ -409,13 +463,13 @@
         exit;
 
       // Migrate data from setting tables ..
-      if (!stAddSettings($inDB, $outDB, $siteDefaults, "settings", TRUE))
+      if (!stAddSettingsGroup($inDB, $outDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", TRUE))
         exit;
 
-      if (!stAddSettings($inDB, $outDB, $siteDisplayVars, "display_vars", TRUE))
+      if (!stAddSettingsNormal($inDB, $outDB, $siteDisplayVars, "display_vars", TRUE))
         exit;
 
-      stAddSettings($inDB, $outDB, $dbMetaData, "dbmeta", TRUE);
+      stAddSettingsNormal($inDB, $outDB, $dbMetaData, "dbmeta", TRUE);
 
       // Migrate other tables
       if (!stMigrateTables($inDB, $outDB, $upgrade, array("settings", "display_vars", "dbmeta")))
@@ -440,7 +494,7 @@
 //
 // Clean up permissions
 //
-foreach (array("managedb.php") as $filename)
+foreach (array("managedb.php", "wanktool.php") as $filename)
 {
   if (chmod($filename, 0700) === FALSE)
   {