]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/member/what-categories.php
Fixed category saving, added unique key, removed deprecated templates:
[mailer.git] / inc / modules / member / what-categories.php
index debdd3bcede01b51dcd2225e9df5205479fe0074..13075a351e7460a95849f4b0e5960920c7176cfa 100644 (file)
@@ -52,7 +52,7 @@ if (isAdmin()) $whereStatement = '';
 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC", __FILE__, __LINE__);
 
 // Do we have entries?
-if (SQL_NUMROWS($result) > 0) {
+if (!SQL_HASZERONUMS($result)) {
        $LEAST = false;
        if (isFormSent()) {
                $count = '0';
@@ -60,7 +60,7 @@ if (SQL_NUMROWS($result) > 0) {
                        if ($joined != 'Y') $count++;
                } // END - foreach
 
-               if ((SQL_NUMROWS($result) - $count) < getConfig('least_cats')) {
+               if ((SQL_NUMROWS($result) - $count) < getLeastCats()) {
                        unsetPostRequestParameter('ok');
                        $LEAST = true;
                } // END - if
@@ -82,8 +82,11 @@ if (SQL_NUMROWS($result) > 0) {
                                        $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
                                                array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
 
-                                       if (!SQL_HASZERONUMS($result_user)) {
-                                               $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
+                                       // Debug message
+                                       //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'cat='.$cat.',joined='.$joined.',getMemberId()='.getMemberId().',SQL_HASZERONUMS()='.intval(SQL_HASZERONUMS($result_user)));
+
+                                       if (SQL_HASZERONUMS($result_user)) {
+                                               $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)";
                                        } // END - if
 
                                        // Free memory
@@ -115,7 +118,7 @@ if (SQL_NUMROWS($result) > 0) {
        } else {
                if ($LEAST === true) {
                        // Also here we have to secure it... :(
-                       loadTemplate('admin_settings_saved', false, '{--CATS_LEAST--}');
+                       loadTemplate('admin_settings_saved', false, '{--CHOOSE_MORE_CATEGORIES--}');
                } // END - if
 
                // Put some data into constants for the template
@@ -133,7 +136,7 @@ if (SQL_NUMROWS($result) > 0) {
                        $content['jy'] = '';
 
                        // When we found an entry don't read it, just change the jx elements
-                       if (isPostRequestParameterSet('cat')) {
+                       if ((isFormSent()) && (isPostRequestParameterSet('cat'))) {
                                // Form sent?
                                if (postRequestParameter('cat', $content['id']) =='Y') {
                                        $content['jy'] = ' checked="checked"';
@@ -144,7 +147,7 @@ if (SQL_NUMROWS($result) > 0) {
                                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 and switch colors