changeset 766:4a8bcf738bd4

Clarify entry editing horror by using some defined constants instead of just magic values for mode.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Nov 2014 12:22:54 +0200
parents 24e56d150a3e
children 1337c483b9f9
files admajax.php
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Nov 20 12:14:47 2014 +0200
+++ b/admajax.php	Thu Nov 20 12:22:54 2014 +0200
@@ -10,6 +10,12 @@
 require_once "msession.inc.php";
 
 
+// Define modes for entry editing code
+define("EEMODE_NORMAL", 0);
+define("EEMODE_EDIT", 1);
+define("EEMODE_ADD", 2);
+
+
 function stValidateRequestCompoData($full, $ctype)
 {
   $res = TRUE;
@@ -187,10 +193,10 @@
   {
     echo
       "  <div class=\"entryRow ".($row % 2 == 1 ? "rodd" : "reven").
-      "\" id=\"entry".$eid."\"".($mode ? "" : " onClick=\"activateEntry(".$eid.")\"").">\n";
+      "\" id=\"entry".$eid."\"".($mode == EEMODE_NORMAL ? " onClick=\"activateEntry(".$eid.")\"" : "").">\n";
   }
 
-  if ($mode != 2 && $compo["ctype"] == COMPO_NORMAL)
+  if ($mode != EEMODE_ADD && $compo["ctype"] == COMPO_NORMAL)
   {
     echo
       "   <div class=\"entryCell entryShowID\">".($item["show_id"] > 0 ? $item["show_id"] : "-")."</div>\n";
@@ -223,11 +229,11 @@
 
       echo
       "   <div class=\"entryCell entryNotes\">\n".
-      "    ".stGetEditFormTextArea($mode, $mode == 2 ? "Info shown during compo" : "Info", 2, 30, "info", $eid, $prefix, $item["info"])."\n".
-      "    ".stGetEditFormTextArea($mode, $mode == 2 ? "Notes for internal use" : "Notes", 2, 30, "notes", $eid, $prefix, $item["notes"])."\n".
+      "    ".stGetEditFormTextArea($mode, $mode == EEMODE_ADD ? "Info shown during compo" : "Info", 2, 30, "info", $eid, $prefix, $item["info"])."\n".
+      "    ".stGetEditFormTextArea($mode, $mode == EEMODE_ADD ? "Notes for internal use" : "Notes", 2, 30, "notes", $eid, $prefix, $item["notes"])."\n".
       "   </div>\n";
 
-      if ($mode == 0 || $mode == 1)
+      if ($mode == EEMODE_NORMAL || $mode == EEMODE_EDIT)
       {
         echo "   <div class=\"entryCell entryPreview\">".$previewTypeList[$compo["preview_type"]][0]." / \n";
 
@@ -239,7 +245,7 @@
         echo "   </div>\n";
       }
 
-      if ($mode == 1)
+      if ($mode == EEMODE_EDIT)
       {
         $sql =
           "SELECT compos.*, ".
@@ -283,7 +289,7 @@
   }
 
 /* XXX TODO .. flags disabled for now
-  if ($mode == 0 || $mode == 1)
+  if ($mode == EEMODE_NORMAL || $mode == EEMODE_EDIT)
   {
     echo "   <div class=\"entryCell\">";
     foreach ($entryFlagsList as $flag => $fdata)
@@ -297,8 +303,7 @@
 
   switch ($mode)
   {
-    case 1:
-
+    case EEMODE_EDIT:
       echo
       "<div class=\"entryCell entryActions\">\n".
       stGetFormButtonInput("update", $eid, $prefix, "Update", "updateEntry(".$item["compo_id"].",".$eid.")").
@@ -306,7 +311,7 @@
       "</div>\n";
       break;
     
-    case 2:
+    case EEMODE_ADD:
       echo
       "   <div class=\"entryCell\">".stGetFormButtonInput("add", $item["compo_id"], $prefix, "Add new", "addEntry(".$item["compo_id"].")")."</div>\n";
       break;
@@ -1496,11 +1501,11 @@
             "flags" => 0,
             "evalue" => 0,
             ),
-            0, TRUE, "ne", $compo, 2);
+            0, TRUE, "ne", $compo, EEMODE_ADD);
           echo "<div class=\"entries\">\n";
           $row = 0;
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id." ORDER BY id ASC") as $entry)
-            stPrintEntryItemData($entry, $row++, TRUE, "en", $compo, 0);
+            stPrintEntryItemData($entry, $row++, TRUE, "en", $compo, EEMODE_NORMAL);
           echo "</div>\n";
         }
         break;
@@ -1508,7 +1513,10 @@
       case "entry":
         $res = stFetchSQL(stPrepareSQL("SELECT * FROM entries WHERE id=%D", "id"));
         if ($res !== FALSE)
-          stPrintEntryItemData($res, -1, FALSE, "en", FALSE, stGetRequestItem("edit", FALSE) ? 1 : 0);
+        {
+          stPrintEntryItemData($res, -1, FALSE, "en", FALSE,
+            stGetRequestItem("edit", FALSE) ? EEMODE_EDIT : EEMODE_NORMAL);
+        }
         else
           stError("No such entry ID!");
         break;