Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-list_cats.php
index 7f687ad36ad23661d5e1fb7689d50056a060f269..919e203a054c10c25657ff9fad3febd72a3374ac 100644 (file)
@@ -17,7 +17,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -48,25 +48,28 @@ addYouAreHereLink('admin', __FILE__);
 $CATS = '';
 
 if (isFormSent('add')) {
+       // Default message
+       $content = '<span class="bad">{--CATEGORY_ALREADY_EXISTS--}</span>';
+
        // Add a new category
-       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
+       $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
                array(postRequestElement('catname')), __FILE__, __LINE__);
-       if (SQL_HASZERONUMS($result)) {
+
+       if (ifSqlHasZeroNumRows($result)) {
                // Category does not exists, we simply add it...
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
+               sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
                        array(
                                postRequestElement('catname'),
                                postRequestElement('visible'),
                                bigintval(postRequestElement('parent') + 1)
                        ), __FILE__, __LINE__);
+
+               // Category has been added
                $content = '{--CATEGORY_ADDED--}';
-       } else {
-               // Category does already exists
-               $content = '<span class="bad">{--CATEGORY_ALREADY_EXISTS--}</span>';
-       }
+       } // END - if
 
        // Free memory
-       SQL_FREERESULT($result);
+       sqlFreeResult($result);
 
        // Display message
        displayMessage($content);
@@ -81,7 +84,7 @@ if (isFormSent('add')) {
                if (!empty($cat)) {
                        switch (getRequestElement('do')) {
                                case 'edit': // Change categories
-                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s',`visible`='%s',`sort`=%s WHERE `id`=%s LIMIT 1",
+                                       sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s',`visible`='%s',`sort`=%s WHERE `id`=%s LIMIT 1",
                                                array(
                                                        $cat,
                                                        postRequestElement('visible', $id),
@@ -92,9 +95,9 @@ if (isFormSent('add')) {
                                        break;
 
                                case 'delete': // Delete categories
-                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
+                                       sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
                                                array($id), __FILE__, __LINE__);
-                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
+                                       sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
                                                array($id), __FILE__, __LINE__);
                                        $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
                                        break;
@@ -124,12 +127,12 @@ if (isFormSent('add')) {
        $OUT = '';
        foreach (postRequestElement('sel') as $id => $value) {
                // Load data from the category
-               $result = SQL_QUERY_ESC("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
                        array(bigintval($id)), __FILE__, __LINE__);
-               $content = SQL_FETCHARRAY($result);
+               $content = sqlFetchArray($result);
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Prepare data for the row template
                $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
@@ -145,13 +148,22 @@ if (isFormSent('add')) {
        $CATS = '';
 
        // Load all categories
-       $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
-       if (!SQL_HASZERONUMS($result)) {
+       $result = sqlQuery("SELECT
+       `id`,
+       `cat`,
+       `visible`,
+       `sort`
+FROM
+       `{?_MYSQL_PREFIX?}_cats`
+ORDER BY
+       `sort` ASC", __FILE__, __LINE__);
+
+       if (!ifSqlHasZeroNumRows($result)) {
                // Init variables
                $OUT = '';
 
                // List already existing categories for editing
-               while ($content = SQL_FETCHARRAY($result)) {
+               while ($content = sqlFetchArray($result)) {
                        // Put cat descriptions into variable for the selection box
                        if (strlen($content['cat']) > 40) $content['cat'] = substr($content['cat'], 0, 37) . '...';
                        $CATS .= '<option value="' . $content['sort'] . '">' . $content['cat'] . '</option>';
@@ -161,7 +173,7 @@ if (isFormSent('add')) {
                } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load main template
                loadTemplate('admin_list_cats', FALSE, $OUT);