changeset 66:230aacc22cb4

Move some functions to site lib.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Oct 2013 17:59:24 +0300
parents 72b22729ae7e
children 23eba98e1575
files ajax.php msite.inc.php
diffstat 2 files changed, 49 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/ajax.php	Sat Oct 05 12:51:31 2013 +0300
+++ b/ajax.php	Sat Oct 05 17:59:24 2013 +0300
@@ -34,33 +34,6 @@
 }
 
 
-function setStatus($val, $msg)
-{
-  global $statusSet;
-  if (!$statusSet)
-  {
-    header("Status: ".$val." ".$msg);
-  }
-  $statusSet = TRUE;
-}
-
-
-function execSQLCond($sql, $okmsg)
-{
-  if (($res = stExecSQL($sql)) !== FALSE)
-  {
-    if ($okmsg != "")
-      setStatus(200, $okmsg);
-    return $res;
-  }
-  else
-  {
-    setStatus(900, "Error in SQL execution.");
-    return FALSE;
-  }
-}
-
-
 // XMLHttp responses
 $action = "ERROR";
 if (stChkRequestItem("action") && stChkRequestItem("type"))
@@ -76,7 +49,7 @@
     //
     // Perform generic data dump
     //
-    if (($res = execSQLCond(
+    if (($res = stExecSQLCond(
       "SELECT * FROM attendees WHERE email NOT NULL AND email != '' ORDER BY regtime DESC",
       "Dump OK.")) !== FALSE)
     {
@@ -207,7 +180,7 @@
     //
     // Perform query if we need to, output results
     //
-    if (isset($sql) && ($res = execSQLCond($sql, "")) !== FALSE)
+    if (isset($sql) && ($res = stExecSQLCond($sql, "")) !== FALSE)
     {
       if ($type == "news")
       {
@@ -294,31 +267,31 @@
       if ($type == "news")
       {
         $sql = stPrepareSQL("DELETE FROM news WHERE id=%d AND persist=0", $id);
-        execSQLCond($sql, "OK, news item ".$id." deleted.");
+        stExecSQLCond($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.");
+        stExecSQLCond($sql, "OK, attendee ".$id." deleted.");
 
         $sql = stPrepareSQL("DELETE FROM votes WHERE voter_id=%d", $id);
-        execSQLCond($sql, "OK, attendee ".$id." votes deleted.");
+        stExecSQLCond($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.");
+        stExecSQLCond($sql, "OK, entry ".$id." deleted.");
 
         $sql = stPrepareSQL("DELETE FROM votes WHERE entry_id=%d", $id);
-        execSQLCond($sql, "OK, entry ".$id." votes deleted.");
+        stExecSQLCond($sql, "OK, entry ".$id." votes deleted.");
       }
     }
     else
-      setStatus(901, "No ID specified.");
+      stSetStatus(901, "No ID specified.");
     break;
 
   case "add":
@@ -332,7 +305,7 @@
         "INSERT INTO news (utime,title,text,author) VALUES (%d,%S,%Q,%S)",
         time(), "title", "text", "author");
 
-      execSQLCond($sql, "OK, news item added.");
+      stExecSQLCond($sql, "OK, news item added.");
     }
     else
     if ($type == "compo" && stChkRequestItem("name") &&
@@ -342,7 +315,7 @@
         "INSERT INTO compos (name,description,visible,voting,showAuthors) VALUES (%S,%Q,0,0,0)",
         "name", "description");
 
-      execSQLCond($sql, "OK, compo added.");
+      stExecSQLCond($sql, "OK, compo added.");
     }
     else
     if ($type == "attendees" && stChkRequestItem("name") &&
@@ -353,7 +326,7 @@
         "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)",
         time(), "name", "groups", "oneliner", "email");
 
-      execSQLCond($sql, "OK, attendee added.");
+      stExecSQLCond($sql, "OK, attendee added.");
     }
     else
     if ($type == "entry" && stChkRequestItem("name") &&
@@ -363,10 +336,10 @@
         "INSERT INTO entries (name,author,compo_id,filename) VALUES (%S,%S,%D,%S)",
         "name", "author", "compo_id", "filename");
 
-      execSQLCond($sql, "OK, entry added.");
+      stExecSQLCond($sql, "OK, entry added.");
     }
     else
-      setStatus(902, "No data.");
+      stSetStatus(902, "No data.");
     break;
 
   case "update":
@@ -385,7 +358,7 @@
           "active" => "B",
         ));
 
-      execSQLCond($sql, "OK, attendee updated.");
+      stExecSQLCond($sql, "OK, attendee updated.");
     }
     else
     if ($type == "news" && stChkRequestItem("id") &&
@@ -400,7 +373,7 @@
           "author" => "S"
         ));
 
-      execSQLCond($sql, "OK, news item updated.");
+      stExecSQLCond($sql, "OK, news item updated.");
     }
     else
     if ($type == "compo" && stChkRequestItem("id") &&
@@ -418,7 +391,7 @@
           "showAuthors" => "B",
         ));
 
-      execSQLCond($sql, "OK, compo updated.");
+      stExecSQLCond($sql, "OK, compo updated.");
     }
     else
     if ($type == "entry" && stChkRequestItem("id") &&
@@ -434,7 +407,7 @@
           "compo_id" => "D",
         ));
 
-      execSQLCond($sql, "OK, entry updated.");
+      stExecSQLCond($sql, "OK, entry updated.");
     }
     else
     if ($type == "settings")
@@ -452,15 +425,15 @@
         }
         
         $sql = "UPDATE settings SET ".$vsql." WHERE key=".$db->quote($item["key"]);
-        execSQLCond($sql, "OK, setting updated.");
+        stExecSQLCond($sql, "OK, setting updated.");
       }
     }
     else
-      setStatus(902, "No data.");
+      stSetStatus(902, "No data.");
     break;
 
   default:
-    setStatus(404, "Not Found");
+    stSetStatus(404, "Not Found");
     break;
 }
 
--- a/msite.inc.php	Sat Oct 05 12:51:31 2013 +0300
+++ b/msite.inc.php	Sat Oct 05 17:59:24 2013 +0300
@@ -504,4 +504,33 @@
     }
   }
 }
+
+
+function stSetStatus($val, $msg)
+{
+  global $statusSet;
+  if (!$statusSet)
+  {
+    header("Status: ".$val." ".$msg);
+  }
+  $statusSet = TRUE;
+}
+
+
+function stExecSQLCond($sql, $okmsg)
+{
+  if (($res = stExecSQL($sql)) !== FALSE)
+  {
+    if ($okmsg != "")
+      stSetStatus(200, $okmsg);
+    return $res;
+  }
+  else
+  {
+    stSetStatus(900, "Error in SQL execution.");
+    return FALSE;
+  }
+}
+
+
 ?>
\ No newline at end of file