Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-admins_mails.php
index 6029cfd708628e6dcd4763f4cdc8813d3ca63ac7..b8b916c57691a410b8e5fa0a00f32852e86467d0 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                            *
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2015 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 *
  ************************************************************************/
 
 // Some security stuff...
-if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
 // Add description as navigation point
-ADD_DESCR('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
-if (REQUEST_ISSET_POST('edit')) {
+if (isFormSent('edit')) {
        // Check if entires are checked
-       $SEL = countPostSelection();
-       if ($SEL > 0) {
+       if (ifPostContainsSelections()) {
                // Add option for events
-               $GLOBALS['cache_array']['admins'] = generateOptionList('admins', "id", "login", '', 'email');
-               $SW = 2; $rowNameS = '';
-               foreach (REQUEST_POST('sel') as $template => $sel) {
+               $rows = '';
+               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`",
+                       $result = sqlQueryEscaped("SELECT `admin_id`, `id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `id` ASC",
                                array($template), __FILE__, __LINE__);
-                       $OUT = ''; $aid2 = 0;
-                       while ($content = SQL_FETCHARRAY($result)) {
-                               // @TODO Can this be rewritten???
-                               $OUT .= "<select name=\"admin_id[".$content['id']."]\" size=\"1\" class=\"admin_select\">
-<option value=\"0\"";
-                               if ($content['admin_id'] == '0') $OUT .= ' selected="selected"';
-                               $OUT .=">{--ADMINS_ALL_ADMINS--}</option>\n";
-                               if (EXT_IS_ACTIVE('events')) {
-                                       $OUT .= "<option value=\"-1\"";
-                                       if ($content['admin_id'] == '-1') $OUT .= ' selected="selected"';
-                                       $OUT .= ">{--ADMINS_TO_USER_EVENTS--}</option>\n";
-                               }
-                               $OUT .= generateOptionList('admins', "id", "login", $content['admin_id'], 'email');
-                               $OUT .= "</select>\n<br />\n";
-                               $aid2 = $content['admin_id']; $id2 = $content['id'];
-                       }
+                       $OUT = '';
+                       $adminId2 = '0'; $id = '0';
+                       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 (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"';
+                                       } // END - if
+                                       $OUT .= '>{--ADMIN_ADMINS_TO_USER_EVENTS--}</option>';
+                               } // END - if
+
+                               $OUT .= generateOptions('admins', 'id', 'login', $content['admin_id'], 'email');
+                               $OUT .= '</select>';
+
+                               // Transfer ids
+                               $adminId2 = $content['admin_id'];
+                               $id = $content['id'];
+                       } // END - while
 
                        // Free memory
-                       SQL_FREERESULT($result);
+                       sqlFreeResult($result);
 
-                       $content = array(
-                               'sw'      => $SW,
-                               'id'      => $id,
-                               'id2'     => $id2,
-                               'tpl'     => $template,
-                               'admins'  => $GLOBALS['cache_array']['admins']
-                       );
+                       // Prepare content
+                       $content['id']            = $id;
+                       $content['mail_template'] = $template;
+                       $content['admins']        = generateOptions('admins', 'id', 'login', '', 'email');
 
-                       if ($aid2 > 0) {
+                       if (isValidId($adminId2)) {
                                // Add form for an additional admin
-                               $OUT .= LOAD_TEMPLATE("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
-                       $rowNameS .= LOAD_TEMPLATE("admin_admins_mails_edit_row", true, $content);
-                       $SW = 3 - $SW;
-               }
-
-               // @TODO Rewrite this constant
-               define('__ADMINS_ROWS', $rowNameS);
+                       $rows .= loadTemplate('admin_admins_mails_edit_row', TRUE, $content);
+               } // END - foreach
 
                // Edit checked entries
-               LOAD_TEMPLATE("admin_admins_mails_edit");
+               loadTemplate('admin_admins_mails_edit', FALSE, $rows);
        } else {
                // Nothing selected
-               LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMINS_NO_MAIL_CHECKED'));
+               displayMessage('{--ADMINS_NO_MAIL_CHECKED--}');
        }
 } else {
        // Load all assigned mails
-       $result = SQL_QUERY("SELECT DISTINCT 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__);
-
-       if (SQL_NUMROWS($result) > 0) {
+       $result = sqlQuery("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 (!ifSqlHasZeroNumRows($result)) {
                // Shall I change entries?
-               if (REQUEST_ISSET_POST('change')) {
+               if (isFormSent('do_edit')) {
                        // Init SQLs
-                       INIT_SQLS();
+                       initSqls();
 
                        // Ok, update database
-                       foreach (REQUEST_POST('admin_id') as $id => $content['admin_id']) {
-                               // Secure IDs
+                       foreach (postRequestElement('admin_id') as $id => $content['admin_id']) {
+                               // Secure ids
                                $id  = bigintval($id);
                                $content['admin_id'] = bigintval($content['admin_id']);
 
                                // Update entry
-                               ADD_SQL(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) && (REQUEST_ISSET_POST('template', $id))) {
+                               if ((!isValidId($content['admin_id'])) && (isPostRequestElementSet('template', $id))) {
                                        // Remove any other admin entries
-                                       ADD_SQL(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' AND id != '%s'",
-                                               array(REQUEST_POST('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 (REQUEST_POST('admin_new', REQUEST_POST('template', $id)) > 0) {
+                               if (postRequestElement('admin_new', postRequestElement('template', $id)) > 0) {
                                        // Add new admin
-                                       ADD_SQL(SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES ('%s','%s')",
-                                               array($content['admin_id'], REQUEST_POST('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
 
@@ -148,38 +157,41 @@ ORDER BY m.admin_id, m.mail_template", __FILE__, __LINE__);
                        runFilterChain('run_sqls');
 
                        // Query again...
-                       $result = SQL_QUERY("SELECT DISTINCT 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 = sqlQuery("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)) {
-                       // Prepare content
-                       $content = array(
-                               'sw'   => $SW,
-                               'id'   => $data['id'],
-                               'tpl'  => $data['mail_template'],
-                               'alnk' => generateAdminLink($data['admin_id'])
-                       );
-
+               $OUT = '';
+               while ($content = sqlFetchArray($result)) {
                        // Load row template
-                       $OUT .= LOAD_TEMPLATE("admin_admins_mails_list_row", true, $content);
-                       $SW = 3 - $SW;
+                       $OUT .= loadTemplate('admin_admins_mails_list_row', TRUE, $content);
                } // END - while
 
                // Free result
-               SQL_FREERESULT($result);
-
-               // @TODO Rewrite this constant
-               define('__MAILS_ROWS', $OUT);
+               sqlFreeResult($result);
 
                // Load template
-               LOAD_TEMPLATE("admin_admins_mails_list");
+               loadTemplate('admin_admins_mails_list', FALSE, $OUT);
        } else {
                // No entries found
-               LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMINS_MAILS_NO_ENTRIES'));
+               displayMessage('{--ADMIN_ADMINS_MAILS_NO_ENTRIES--}');
        }
 }
 
-//
+// [EOF]
 ?>