New functions introduced, several rewrites:
[mailer.git] / inc / modules / admin / what-config_cats.php
index e9008fb4e8647de4d7a6e29776cb6e51c19ac308..96b8cfd3e2f7a977d054333052dc2d5e58cd6130 100644 (file)
@@ -40,7 +40,7 @@
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
 addMenuDescription('admin', __FILE__);
@@ -50,16 +50,20 @@ $CATS = '';
 
 if (isPostRequestElementSet('add')) {
        // Add a new category
-       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE cat='%s' LIMIT 1",
-       array(postRequestElement('catname')), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
+               array(postRequestElement('catname')), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == '0') {
                // Category does not exists, we simply add it...
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (cat, visible, sort) VALUES ('%s','%s','%s')",
-               array(postRequestElement('catname'), postRequestElement('visible'), bigintval(postRequestElement('parent') + 1)), __FILE__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
+                       array(
+                               postRequestElement('catname'),
+                               postRequestElement('visible'),
+                               bigintval(postRequestElement('parent') + 1)
+                       ), __FILE__, __LINE__);
                $content = getMessage('CATEGORY_ADDED');
        } else {
                // Category does already exists
-               $content = "<span class=\"admin_failed\">{--CATEGORY_ALREADY_EXISTS--}</span>";
+               $content = '<span class="admin_failed">{--CATEGORY_ALREADY_EXISTS--}</span>';
        }
 
        // Free memory
@@ -76,37 +80,36 @@ if (isPostRequestElementSet('add')) {
 
                // Is the entry set?
                if (!empty($cat)) {
-                       switch (getRequestElement('do'))
-                       {
+                       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",
-                                       array(
-                                       $cat,
-                                       postRequestElement('vis', $id),
-                                       postRequestElement('sort', $id),
-                                       $id
-                                       ), __FILE__, __LINE__);
+                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
+                                               array(
+                                                       $cat,
+                                                       postRequestElement('vis', $id),
+                                                       postRequestElement('sort', $id),
+                                                       $id
+                                               ), __FILE__, __LINE__);
                                        $TEXT = getMessage('CATEGORIES_SAVED');
                                        break;
 
                                case 'del': // Delete categories
                                        SQL_QUERY_ESC("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",
+                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
                                                array($id), __FILE__, __LINE__);
                                        $TEXT = getMessage('CATEGORIES_DELETED');
                                        break;
-                       }
+                       } // END - switch
                } else {
                        // Entry not saved
-                       $TEXT .= sprintf(getMessage('CATEGORY_NOT_SAVED'), $id);
+                       $TEXT .= getMaskedMessage('CATEGORY_NOT_SAVED', $id);
                }
-       }
+       } // END - foreach
 
        if (isset($TEXT)) {
                // Display message
                loadTemplate('admin_settings_saved', false, $TEXT);
-       }
+       } // END - if
 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
        // Delete categories
        $OUT = ''; $SW = 2;
@@ -129,15 +132,14 @@ if (isPostRequestElementSet('add')) {
                // Load row template and switch colors
                $OUT .= loadTemplate('admin_del_cats_row', true, $content);
                $SW = 3 - $SW;
-       }
+       } // END - foreach
 
        // Load main template
        loadTemplate('admin_del_cats', false, $OUT);
 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
        // Edit categories
        $OUT = ''; $SW = 2;
-       foreach (postRequestElement('sel') as $id => $value)
-       {
+       foreach (postRequestElement('sel') as $id => $value) {
                // Load data from the category
                $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
                array(bigintval($id)), __FILE__, __LINE__);
@@ -156,7 +158,7 @@ if (isPostRequestElementSet('add')) {
                // Load row template and switch colors
                $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
                $SW = 3 - $SW;
-       }
+       } // END - foreach
 
        // Load main template
        loadTemplate('admin_edit_cats', false, $OUT);
@@ -177,8 +179,9 @@ if (isPostRequestElementSet('add')) {
                        $content['vis'] = translateYesNo($content['visible']);
 
                        // Put cat descriptions into variable for the selection box
-                       if (strlen($content['cat']) > 20) $content['cat'] = substr($content['cat'], 0, 17)."...";
-                       $CATS .= "      <option value=\"".$content['sort']."\">".$content['cat']."</option>\n";
+                       $cat = $content['cat'];
+                       if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
+                       $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
 
                        // Load row template and switch color
                        $OUT .= loadTemplate('admin_config_cats_row', true, $content);