Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-categories.php
index d3fb3b9d62d6fffe5997a4549f67819d29f96f01..d1ddf06e1feeea0cb8cfed22275d33a37f0765c7 100644 (file)
@@ -16,7 +16,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 *
@@ -49,20 +49,27 @@ $whereStatement = " WHERE `visible`='Y'";
 if (isAdmin()) $whereStatement = '';
 
 // Get all categories
-$result = SQL_QUERY("SELECT `id`,`cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC", __FILE__, __LINE__);
+$result = sqlQuery('SELECT
+       `id`,
+       `cat`
+FROM
+       `{?_MYSQL_PREFIX?}_cats`
+' . $whereStatement . '
+ORDER BY
+       `sort` ASC', __FILE__, __LINE__);
 
 // Are there entries?
-if (!SQL_HASZERONUMS($result)) {
-       $LEAST = false;
+if (!ifSqlHasZeroNumRows($result)) {
+       $LEAST = FALSE;
        if (isFormSent()) {
                $count = '0';
                foreach (postRequestElement('cat') as $categoryId => $joined) {
                        if ($joined != 'Y') $count++;
                } // END - foreach
 
-               if ((SQL_NUMROWS($result) - $count) < getLeastCats()) {
+               if ((sqlNumRows($result) - $count) < getLeastCats()) {
                        unsetPostRequestElement('ok');
-                       $LEAST = true;
+                       $LEAST = TRUE;
                } // END - if
        } // END - if
 
@@ -80,14 +87,14 @@ if (!SQL_HASZERONUMS($result)) {
                        switch ($joined) {
                                case 'Y':
                                        // Check if this category has an entry
-                                       if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($categoryId))) == 0) {
+                                       if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($categoryId))) == 0) {
                                                // No, so add it
-                                               addSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`,`cat_id`) VALUES (%s,%s)", getMemberId(), bigintval($categoryId)));
+                                               addSql(sprintf('INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)', getMemberId(), bigintval($categoryId)));
                                        } // END - if
                                        break;
 
                                case 'N':
-                                       addSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1", getMemberId(), bigintval($categoryId)));
+                                       addSql(sprintf('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1', getMemberId(), bigintval($categoryId)));
                                        break;
                        } // END - switch
                } // END - foreach
@@ -107,14 +114,14 @@ if (!SQL_HASZERONUMS($result)) {
                        displayMessage('{--MEMBER_CATEGORIES_NOT_SAVED--}');
                }
        } else {
-               if ($LEAST === true) {
+               if ($LEAST === TRUE) {
                        // Also here we have to secure it... :(
                        displayMessage('{--CHOOSE_MORE_CATEGORIES--}');
                } // END - if
 
                // Load all categories of this member
                $OUT = '';
-               while ($content = SQL_FETCHARRAY($result)) {
+               while ($content = sqlFetchArray($result)) {
                        // Default he has not joined, add color switch
                        $content['jn'] = ' checked="checked"';
                        $content['jy'] = '';
@@ -128,21 +135,21 @@ if (!SQL_HASZERONUMS($result)) {
                                } // END - if
                        } else {
                                // Check if he has an entry
-                               if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($content['id']))) == 1) {
+                               if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($content['id']))) == 1) {
                                        $content['jn'] = '';
                                        $content['jy'] = ' checked="checked"';
                                } // END - if
                        }
 
                        // Load row template
-                       $OUT .= loadTemplate('member_cats_row', true, $content);
+                       $OUT .= loadTemplate('member_cats_row', TRUE, $content);
                } // END - while
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load footer template
-               loadTemplate('member_cats', false, $OUT);
+               loadTemplate('member_cats', FALSE, $OUT);
        }
 } else {
        // No cateogries are defined yet
@@ -150,7 +157,7 @@ if (!SQL_HASZERONUMS($result)) {
 }
 
 // Free result
-SQL_FREERESULT($result);
+sqlFreeResult($result);
 
 // [EOF]
 ?>