$joined) { if ($joined != 'Y') $count++; } // END - foreach if ((sqlNumRows($result) - $count) < getLeastCats()) { unsetPostRequestElement('ok'); $LEAST = TRUE; } // END - if } // END - if // Is the form sent? if (isFormSent()) { // Start counting all $count = '0'; // Ini SQLs here initSqls(); // Go through all entries foreach (postRequestElement('cat') as $categoryId => $joined) { // Has the user joined on this category? 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) { // No, so add it 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))); break; } // END - switch } // END - foreach // Are there entries? if (countSqls() > 0) { // Run SQL commands $count = runFilterChain('run_sqls'); } // END - if // Categories saved? if ($count > 0) { // Output message displayMessage('{--MEMBER_CATEGORIES_SAVED--}'); } else { // None save displayMessage('{--MEMBER_CATEGORIES_NOT_SAVED--}'); } } else { 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 = sqlFetchArray($result)) { // Default he has not joined, add color switch $content['jn'] = ' checked="checked"'; $content['jy'] = ''; // When we found an entry don't read it, just change the jx elements if ((isFormSent()) && (isPostRequestElementSet('cat'))) { // Form sent? if (postRequestElement('cat', $content['id']) =='Y') { $content['jy'] = ' checked="checked"'; $content['jn'] = ''; } // 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) { $content['jn'] = ''; $content['jy'] = ' checked="checked"'; } // END - if } // Load row template $OUT .= loadTemplate('member_cats_row', TRUE, $content); } // END - while // Free result sqlFreeResult($result); // Load footer template loadTemplate('member_cats', FALSE, $OUT); } } else { // No cateogries are defined yet displayMessage('{--MEMBER_NO_CATEGORIES--}'); } // Free result sqlFreeResult($result); // [EOF] ?>