diff ajax.php @ 53:71256605546b

More work on admin interface.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Oct 2013 08:43:39 +0300
parents cba0b944da79
children 4fac95384753
line wrap: on
line diff
--- a/ajax.php	Sat Oct 05 07:29:42 2013 +0300
+++ b/ajax.php	Sat Oct 05 08:43:39 2013 +0300
@@ -66,6 +66,9 @@
 switch ($action)
 {
   case "dump":
+    //
+    // Perform generic data dump
+    //
     if (($res = execSQLCond(
       "SELECT * FROM attendees WHERE email NOT NULL AND email != '' ORDER BY regtime DESC",
       "Dump OK.")) !== FALSE)
@@ -89,6 +92,9 @@
     break;
 
   case "get":
+    //
+    // Get specific data
+    //
     switch ($type)
     {
       case "news":
@@ -201,9 +207,7 @@
         echo
         "<table class=\"attendees\">\n".
         " <tr>\n".
-        "  <th>Name</th>\n".
-        "  <th class=\"groups\">Group(s)</th>\n".
-        "  <th class=\"regtime\">Registered</th>\n".
+        "  <th class=\"rname\">Name</th>\n".
         "  <th class=\"oneliner\">Oneliner</th>\n".
         "  <th class=\"email\">E-mail</th>\n".
         "  <th>Actions</th>\n".
@@ -238,26 +242,47 @@
     break;
 
   case "delete":
+    //
+    // Delete entry
+    //
     if (stChkRequestItem("id"))
     {
       $id = intval(stGetRequestItem("id"));
 
       if ($type == "news")
+      {
         $sql = stPrepareSQL("DELETE FROM news WHERE id=%d AND persist=0", $id);
+        execSQLCond($sql, "OK, news item ".$id." deleted.");
+      }
       else
       if ($type == "attendees")
+      {
+        // Attendees require some more work
         $sql = stPrepareSQL("DELETE FROM attendees WHERE id=%d", $id);
+        execSQLCond($sql, "OK, attendee ".$id." deleted.");
+
+        $sql = stPrepareSQL("DELETE FROM votes WHERE voter_id=%d", $id);
+        execSQLCond($sql, "OK, attendee ".$id." votes deleted.");
+      }
       else
       if ($type == "entries")
+      {
+        // .. as do compo entries
         $sql = stPrepareSQL("DELETE FROM entries WHERE id=%d", $id);
+        execSQLCond($sql, "OK, entry ".$id." deleted.");
 
-      execSQLCond($sql, "OK, ".$type." item ".$id." deleted.");
+        $sql = stPrepareSQL("DELETE FROM votes WHERE entry_id=%d", $id);
+        execSQLCond($sql, "OK, entry ".$id." votes deleted.");
+      }
     }
     else
       setStatus(901, "No ID specified.");
     break;
 
   case "add":
+    //
+    // Add new entry
+    //
     if ($type == "news" && stChkRequestItem("text") &&
       stChkRequestItem("author") && stChkRequestItem("title"))
     {
@@ -278,10 +303,24 @@
       execSQLCond($sql, "OK, compo added.");
     }
     else
+    if ($type == "attendees" && stChkRequestItem("name") &&
+      stChkRequestItem("groups") && stChkRequestItem("email") &&
+      stChkRequestItem("oneliner"))
+    {
+      $sql = stPrepareSQL(
+        "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)",
+        time(), "name", "groups", "oneliner", "email");
+
+      execSQLCond($sql, "OK, attendee added.");
+    }
+    else
       setStatus(902, "No data.");
     break;
 
   case "update":
+    //
+    // Update existing entry
+    //
     if ($type == "attendees" && stChkRequestItem("id") &&
       stChkRequestItem("email") && stChkRequestItem("oneliner") &&
       stChkRequestItem("active"))