Fix for rewritting code #3
[mailer.git] / inc / modules / admin / what-admins_mails.php
index 8cbbd054faf753555dda51e69dccf761fcf0f0dc..d07a7d120eec2591ea76413cc94403830b6b465b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 08/14/2004 *
- * ================                             Last change: 10/22/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 08/14/2004 *
+ * ===================                          Last change: 10/22/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-admins_mails.php                            *
@@ -46,16 +46,16 @@ addMenuDescription('admin', __FILE__);
 
 if (isPostRequestElementSet('edit')) {
        // Check if entires are checked
-       $SEL = countPostSelection();
-       if ($SEL > 0) {
+       if (countPostSelection() > 0) {
                // Add option for events
-               $GLOBALS['cache_array']['admins'] = generateOptionList('admins', 'id', 'login', '', 'email');
+               $adminsList = generateOptionList('admins', 'id', 'login', '', 'email');
                $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`",
-                       array($template), __FILE__, __LINE__);
-                       $OUT = ''; $adminId2 = 0;
+                       $result = SQL_QUERY_ESC("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
+                               array($template), __FILE__, __LINE__);
+                       $OUT = '';
+                       $adminId2 = '0';
                        while ($content = SQL_FETCHARRAY($result)) {
                                // @TODO Can this be rewritten???
                                $OUT .= "<select name=\"admin_id[".$content['id']."]\" size=\"1\" class=\"admin_select\">
@@ -69,24 +69,24 @@ if (isPostRequestElementSet('edit')) {
                                }
                                $OUT .= generateOptionList('admins', 'id', 'login', $content['admin_id'], 'email');
                                $OUT .= "</select>\n<br />\n";
-                               $adminId2 = $content['admin_id']; $id2 = $content['id'];
-                       }
+
+                               // Transfer ids
+                               $adminId2 = $content['admin_id'];
+                               $id2 = $content['id'];
+                       } // END - while
 
                        // Free memory
                        SQL_FREERESULT($result);
 
-                       $content = array(
-                               'sw'      => $SW,
-                               'id'      => $id,
-                               'id2'     => $id2,
-                               'tpl'     => $template,
-                               'admins'  => $GLOBALS['cache_array']['admins']
-                       );
+                       // Prepare content
+                       $content['sw']            = $SW;
+                       $content['mail_template'] = $template;
+                       $content['admins']        = $adminsList;
 
                        if ($adminId2 > 0) {
                                // Add form for an additional admin
                                $OUT .= loadTemplate('admin_admins_mails_edit_form', true, $content);
-                       }
+                       } // END - if
 
                        // Save full rendered content
                        $content['content'] = $OUT;
@@ -104,12 +104,19 @@ if (isPostRequestElementSet('edit')) {
        }
 } else {
        // Load all assigned mails
-       $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, m.mail_template", __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__);
 
        if (SQL_NUMROWS($result) > 0) {
                // Shall I change entries?
@@ -119,13 +126,13 @@ ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
 
                        // Ok, update database
                        foreach (postRequestElement('admin_id') as $id => $content['admin_id']) {
-                               // Secure IDs
+                               // Secure ids
                                $id  = bigintval($id);
                                $content['admin_id'] = bigintval($content['admin_id']);
 
                                // 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
@@ -144,19 +151,27 @@ ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
                        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);