Category edit/delete fixed
[mailer.git] / 0.2.1 / inc / modules / admin / what-config_cats.php
index 13480ff..01108f7 100644 (file)
  ************************************************************************/\r
 \r
 // Some security stuff...\r
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))\r
-{\r
+if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {\r
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";\r
        require($INC);\r
-}\r
+}
+\r
 // Add description as navigation point\r
 ADD_DESCR("admin", basename(__FILE__));\r
+
+// Init variable to avoid a notice
+$CATS = "";
 \r
 OPEN_TABLE("100%", "admin_content admin_content_align", "");\r
-if (isset($_POST['add']))\r
-{\r
+if (isset($_POST['add'])) {\r
        // Add a new category\r
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_cats WHERE cat='%s' LIMIT 1",\r
         array(addslashes($_POST['catname'])), __FILE__, __LINE__);\r
-       if (SQL_NUMROWS($result) == 0)\r
-       {\r
+       if (SQL_NUMROWS($result) == 0) {\r
                // Category does not exists, we simply add it...\r
                $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_cats (cat, visible, sort) VALUES ('%s', '%s', '%s')",\r
                 array(addslashes($_POST['catname']), $_POST['visible'], bigintval($_POST['parent'] + 1)), __FILE__, __LINE__);\r
                $content = "<SPAN class=\"admin_done\">".CATEGORY_ADDED."</SPAN>";\r
-       }\r
-        else\r
-       {\r
-               // Free memory\r
-               SQL_FREERESULT($result);\r
-\r
+       } else {\r
                // Category does already exists\r
                $content = "<SPAN class=\"admin_failed\">".CATEGORY_ALREADY_EXISTS."</SPAN>";\r
        }\r
+
+       // Free memory
+       SQL_FREERESULT($result);
 \r
        // Display message\r
        LOAD_TEMPLATE("admin_settings_saved", false, $content);\r
-}\r
- elseif (isset($_POST['ok']))\r
-{\r
+} elseif ((isset($_POST['ok'])) && (isset($_POST['id'])) && (is_array($_POST['id']))) {\r
        // Change or delete categories...\r
-       $TEXT = "";\r
-       foreach ($_POST['cat'] as $id=>$cat)\r
-       {\r
+       $TEXT = "";
+       foreach ($_POST['id'] as $id=>$cat) {\r
                // Secure ID\r
                $id = bigintval($id);\r
-\r
-               switch ($_GET['do'])\r
-               {\r
-               case "edit": // Change categories\r
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_cats SET cat='%s', visible='%s', sort='%s' WHERE id=%d LIMIT 1",\r
-                        array($cat, $_POST['vis'][$id], $_POST['sort'][$id], $id), __FILE__, __LINE__);\r
-                       $TEXT = CATEGORIES_SAVED;\r
-                       break;\r
-\r
-               case "del": // Delete categories\r
-                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1",\r
-                        array($id), __FILE__, __LINE__);\r
-                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",\r
-                        array($id), __FILE__, __LINE__);\r
-                       $TEXT = CATEGORIES_DELETED;\r
-                       break;\r
+
+               // Is the entry set?
+               if (!empty($cat)) {\r
+                       switch ($_GET['do'])\r
+                       {\r
+                       case "edit": // Change categories\r
+                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_cats SET cat='%s', visible='%s', sort=%d WHERE id=%d LIMIT 1",\r
+                                array($cat, $_POST['vis'][$id], $_POST['sort'][$id], $id), __FILE__, __LINE__);\r
+                               $TEXT = CATEGORIES_SAVED;\r
+                               break;\r
+\r
+                       case "del": // Delete categories\r
+                               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1",\r
+                                array($id), __FILE__, __LINE__);\r
+                               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",\r
+                                array($id), __FILE__, __LINE__);\r
+                               $TEXT = CATEGORIES_DELETED;\r
+                               break;\r
+                       }
+               } else {
+                       // Entry not saved
+                       $TEXT .= sprintf(CATEGORY_NOT_SAVED, $id);
                }\r
        }\r
-       if (isset($TEXT))\r
-       {\r
+
+       if (isset($TEXT)) {\r
                // Display message\r
                LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);\r
        }\r
@@ -125,9 +127,7 @@ if (isset($_POST['add']))
 \r
        // Load main template\r
        LOAD_TEMPLATE("admin_del_cats");\r
-}\r
- elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))\r
-{\r
+} elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {\r
        // Edit categories\r
        $SW = 2; $OUT = "";\r
        foreach ($_POST['sel'] as $id=>$value)\r