Fix for rewritting code #2
[mailer.git] / inc / modules / admin / what-admins_mails.php
index 3f4159727d4e8c36ae765cc537c40ff508b2b7fb..21ad2e4bdb11bfe6324953b55dcc4cd2be902cfe 100644 (file)
@@ -52,7 +52,7 @@ if (isPostRequestElementSet('edit')) {
                $SW = 2; $rowNameS = '';
                foreach (postRequestElement('sel') as $template => $sel) {
                        // First of all load data from DB
-                       $result = SQL_QUERY_ESC("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
+                       $result = SQL_QUERY_ESC("SELECT `admin_id`, `id`, `mail_template` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
                                array($template), __FILE__, __LINE__);
                        $OUT = '';
                        $adminId2 = '0';
@@ -131,7 +131,7 @@ ORDER BY
 
                                // Update entry
                                addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_mails` SET admin_id=%s WHERE `id`=%s ORDER BY `id` LIMIT 1",
-                               array($content['admin_id'], $id), __FILE__, __LINE__, false));
+                                       array($content['admin_id'], $id), __FILE__, __LINE__, false));
 
                                if (($content['admin_id'] < 1) && (isPostRequestElementSet('template', $id))) {
                                        // Remove any other admin entries
@@ -150,19 +150,27 @@ ORDER BY
                        runFilterChain('run_sqls');
 
                        // Query again...
-                       $result = SQL_QUERY("SELECT m.id, m.admin_id, a.login, m.mail_template FROM `{?_MYSQL_PREFIX?}_admins_mails` AS m, `{?_MYSQL_PREFIX?}_admins` AS a WHERE m.admin_id=a.id OR m.admin_id < 1 ORDER BY m.admin_id", __FILE__, __LINE__);
+                       $result = SQL_QUERY("SELECT
+       m.id, m.admin_id, a.login, m.mail_template
+FROM
+       `{?_MYSQL_PREFIX?}_admins_mails` AS m
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_admins` AS a
+ON
+       m.admin_id=a.id
+WHERE
+       (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
+ORDER BY
+       m.admin_id ASC,
+       m.mail_template ASC", __FILE__, __LINE__);
                } // END - if
 
                // List found entries
                $OUT = ''; $SW = 2;
-               while ($data = SQL_FETCHARRAY($result)) {
+               while ($content = SQL_FETCHARRAY($result)) {
                        // Prepare content
-                       $content = array(
-                               'sw'   => $SW,
-                               'id'   => $data['id'],
-                               'tpl'  => $data['mail_template'],
-                               'alnk' => generateAdminLink($data['admin_id'])
-                       );
+                       $content['sw']   = $SW;
+                       $content['alnk'] = generateAdminLink($content['admin_id']);
 
                        // Load row template
                        $OUT .= loadTemplate('admin_admins_mails_list_row', true, $content);