Some cleanups/improvements
[mailer.git] / inc / modules / admin / what-admins_mails.php
index 8fe0f649e470032157ec7b56337c259e6df8e1e7..fc188c5f11b2c3b54e354c5edc155e9319f9b02e 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -47,26 +47,31 @@ if (isFormSent('edit')) {
        // Check if entires are checked
        if (ifPostContainsSelections()) {
                // Add option for events
-               $adminsList = generateOptionList('admins', 'id', 'login', '', 'email');
                $rows = '';
-               foreach (postRequestParameter('sel') as $template => $sel) {
+               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 = sqlQueryEscaped("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
                                array($template), __FILE__, __LINE__);
                        $OUT = '';
                        $adminId2 = '0'; $id = '0';
-                       while ($content = SQL_FETCHARRAY($result)) {
+                       while ($content = sqlFetchArray($result)) {
                                // @TODO Can this be rewritten to an API function?
                                $OUT .= '<select name="admin_id[' . $content['id'] . ']" size="1" class="form_select">
 <option value="0"';
-                               if ($content['admin_id'] == '0') $OUT .= ' selected="selected"';
-                               $OUT .= '>{--ADMINS_ALL_ADMINS--}</option>';
+                               if (is_null($content['admin_id'])) {
+                                       $OUT .= ' selected="selected"';
+                               } // END - if
+                               $OUT .= '>{--ADMIN_TO_ALL_ADMINS--}</option>';
+
                                if (isExtensionActive('events')) {
                                        $OUT .= '<option value="-1"';
-                                       if ($content['admin_id'] == '-1') $OUT .= ' selected="selected"';
-                                       $OUT .= '>{--ADMINS_TO_USER_EVENTS--}</option>';
-                               }
-                               $OUT .= generateOptionList('admins', 'id', 'login', $content['admin_id'], 'email');
+                                       if ($content['admin_id'] == '-1') {
+                                               $OUT .= ' selected="selected"';
+                                       } // END - if
+                                       $OUT .= '>{--ADMIN_ADMINS_TO_USER_EVENTS--}</option>';
+                               } // END - if
+
+                               $OUT .= generateOptions('admins', 'id', 'login', $content['admin_id'], 'email');
                                $OUT .= '</select>';
 
                                // Transfer ids
@@ -75,73 +80,76 @@ if (isFormSent('edit')) {
                        } // END - while
 
                        // Free memory
-                       SQL_FREERESULT($result);
+                       sqlFreeResult($result);
 
                        // Prepare content
                        $content['id']            = $id;
                        $content['mail_template'] = $template;
-                       $content['admins']        = $adminsList;
+                       $content['admins']        = generateOptions('admins', 'id', 'login', '', 'email');
 
-                       if ($adminId2 > 0) {
+                       if (isValidId($adminId2)) {
                                // Add form for an additional admin
-                               $OUT .= loadTemplate('admin_admins_mails_edit_form', true, $content);
+                               $OUT .= loadTemplate('admin_admins_mails_edit_form', TRUE, $content);
                        } // END - if
 
                        // Save full rendered content
                        $content['content'] = $OUT;
 
                        // Start outputing line
-                       $rows .= loadTemplate('admin_admins_mails_edit_row', true, $content);
+                       $rows .= loadTemplate('admin_admins_mails_edit_row', TRUE, $content);
                } // END - foreach
 
                // Edit checked entries
-               loadTemplate('admin_admins_mails_edit', false, $rows);
+               loadTemplate('admin_admins_mails_edit', FALSE, $rows);
        } else {
                // Nothing selected
-               loadTemplate('admin_settings_saved', false, '{--ADMINS_NO_MAIL_CHECKED--}');
+               displayMessage('{--ADMINS_NO_MAIL_CHECKED--}');
        }
 } else {
        // Load all assigned mails
-       $result = SQL_QUERY("SELECT
-       m.id, m.admin_id, a.login, m.mail_template
+       $result = sqlQuery("SELECT
+       `m`.`id`,
+       `m`.`admin_id`,
+       `a`.`login`,
+       `m`.`mail_template`
 FROM
-       `{?_MYSQL_PREFIX?}_admins_mails` AS m
+       `{?_MYSQL_PREFIX?}_admins_mails` AS `m`
 LEFT JOIN
-       `{?_MYSQL_PREFIX?}_admins` AS a
+       `{?_MYSQL_PREFIX?}_admins` AS `a`
 ON
-       m.admin_id=a.id
+       `m`.`admin_id`=`a`.`id`
 WHERE
-       (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
+       (`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__);
+       `m`.`admin_id` ASC,
+       `m`.`mail_template` ASC", __FILE__, __LINE__);
 
-       if (!SQL_HASZERONUMS($result)) {
+       if (!ifSqlHasZeroNums($result)) {
                // Shall I change entries?
-               if (isFormSent('change')) {
+               if (isFormSent('do_edit')) {
                        // Init SQLs
                        initSqls();
 
                        // Ok, update database
-                       foreach (postRequestParameter('admin_id') as $id => $content['admin_id']) {
+                       foreach (postRequestElement('admin_id') as $id => $content['admin_id']) {
                                // 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));
+                               addSql(sqlQueryEscaped("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));
 
-                               if (($content['admin_id'] < 1) && (isPostRequestParameterSet('template', $id))) {
+                               if ((!isValidId($content['admin_id'])) && (isPostRequestElementSet('template', $id))) {
                                        // Remove any other admin entries
-                                       addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
-                                       array(postRequestParameter('template', $id), $id), __FILE__, __LINE__, false));
+                                       addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
+                                       array(postRequestElement('template', $id), $id), __FILE__, __LINE__, FALSE));
                                } // END - if
 
-                               if (postRequestParameter('admin_new', postRequestParameter('template', $id)) > 0) {
+                               if (postRequestElement('admin_new', postRequestElement('template', $id)) > 0) {
                                        // Add new admin
-                                       addSql(SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
-                                       array($content['admin_id'], postRequestParameter('template', $id)), __FILE__, __LINE__, false));
+                                       addSql(sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
+                                       array($content['admin_id'], postRequestElement('template', $id)), __FILE__, __LINE__, FALSE));
                                } // END - if
                        } // END - foreach
 
@@ -149,36 +157,39 @@ ORDER BY
                        runFilterChain('run_sqls');
 
                        // Query again...
-                       $result = SQL_QUERY("SELECT
-       m.id, m.admin_id, a.login, m.mail_template
+                       $result = sqlQuery("SELECT
+       `m`.`id`,
+       `m`.`admin_id`,
+       `a`.`login`,
+       `m`.`mail_template`
 FROM
-       `{?_MYSQL_PREFIX?}_admins_mails` AS m
+       `{?_MYSQL_PREFIX?}_admins_mails` AS `m`
 LEFT JOIN
-       `{?_MYSQL_PREFIX?}_admins` AS a
+       `{?_MYSQL_PREFIX?}_admins` AS `a`
 ON
-       m.admin_id=a.id
+       `m`.`admin_id`=`a`.`id`
 WHERE
-       (m.admin_id=a.id OR m.admin_id < 1) AND m.mail_template != ''
+       (`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__);
+       `m`.`admin_id` ASC,
+       `m`.`mail_template` ASC", __FILE__, __LINE__);
                } // END - if
 
                // List found entries
                $OUT = '';
-               while ($content = SQL_FETCHARRAY($result)) {
+               while ($content = sqlFetchArray($result)) {
                        // Load row template
-                       $OUT .= loadTemplate('admin_admins_mails_list_row', true, $content);
+                       $OUT .= loadTemplate('admin_admins_mails_list_row', TRUE, $content);
                } // END - while
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load template
-               loadTemplate('admin_admins_mails_list', false, $OUT);
+               loadTemplate('admin_admins_mails_list', FALSE, $OUT);
        } else {
                // No entries found
-               loadTemplate('admin_settings_saved', false, '{--ADMINS_MAILS_NO_ENTRIES--}');
+               displayMessage('{--ADMIN_ADMINS_MAILS_NO_ENTRIES--}');
        }
 }