Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-edit_emails.php
index c03be85a37c421c0933cf5bfa34f5a6529a407f4..f3f41f68ab9fc545004a2486f10b138fd315c05b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/28/2003 *
- * ===============                              Last change: 04/09/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
+ * ===================                          Last change: 04/09/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-edit_emails.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 - 2009 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * 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')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
-addMenuDescription('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
 if ((isFormSent()) && (!isPostRequestElementSet('id'))) {
        unsetPostRequestElement('ok');
-}
+} // END - if
 
-$result = SQL_QUERY("SELECT id, sender, subject, payment_id, cat_id FROM `{?_MYSQL_PREFIX?}_pool` ORDER BY timestamp", __FILE__, __LINE__);
-if (SQL_NUMROWS($result) > 0) {
-       if (isFormSent()) {
-               // Make mail editable...
-               $result = SQL_QUERY_ESC("SELECT subject, text, url FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
-               array(bigintval(postRequestElement('id'))), __FILE__, __LINE__);
-               list($subj, $text, $url) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+// Form sent or anything else? ;-)
+if ((isFormSent('edit')) && (isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
+       // Get data
+       $content = getPoolDataFromId(postRequestElement('id'));
 
-               // Prepare constant for template
-               $content['id']       = bigintval(postRequestElement('id'));
-               $content['url']      = $url;
-               $content['subject']  = $subj;
-               $content['text']     = $text;
+       // Load template
+       loadTemplate('admin_edit_email', FALSE, $content);
+} elseif ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'bonus')) {
+               // Make also this email editable
+               $result = sqlQueryEscaped('SELECT
+       `id`,
+       `subject`,
+       `text`,
+       `url`
+FROM
+       `{?_MYSQL_PREFIX?}_bonus`
+WHERE
+       `id`=%s
+LIMIT 1',
+               array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
 
-               // Load template
-               loadTemplate('admin_edit_email', false, $content);
-       } elseif (isPostRequestElementSet('save')) {
-               // Save changes
-               SQL_QUERY_ESC("UPDATE
-       `{?_MYSQL_PREFIX?}_pool`
+       // Fetch row
+       $content = sqlFetchArray($result);
+
+       // Free result
+       sqlFreeResult($result);
+
+       // Load template
+       loadTemplate('admin_edit_bonus_email', FALSE, $content);
+} elseif (isFormSent('do_edit')) {
+       // Save changes
+       if ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
+               // Update pool
+               $isUpdated = updatePoolDataById(postRequestElement('id'), NULL, array('subject' => postRequestElement('subject'), 'text' => postRequestElement('text'), 'url' => postRequestElemenet('url')));
+               if ($isUpdated === TRUE) {
+                       $content = '{--ADMIN_EMAIL_CHANGES_SAVED--}';
+               } else {
+                       $content = '<span class="bad">{--ADMIN_EMAIL_CHANGES_NOT_SAVED--}</span>';
+               }
+       } elseif ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'bonus')) {
+               // Update pool
+               sqlQueryEscaped("UPDATE
+       `{?_MYSQL_PREFIX?}_bonus`
 SET
        `subject`='%s',
        `text`='%s',
@@ -77,49 +98,56 @@ WHERE
        `id`=%s
 LIMIT 1",
                        array(
-                               postRequestElement('subj'),
+                               postRequestElement('subject'),
                                postRequestElement('text'),
                                postRequestElement('url'),
                                bigintval(postRequestElement('id')),
                        ), __FILE__, __LINE__);
 
-               if (SQL_AFFECTEDROWS() == 1) {
-                       $content = getMessage('SETTINGS_SAVED');
+               if (!ifSqlHasZeroAffectedRows()) {
+                       $content = '{--ADMIN_EMAIL_CHANGES_SAVED--}';
                } else {
-                       $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
+                       $content = '<span class="bad">{--ADMIN_EMAIL_CHANGES_NOT_SAVED--}</span>';
                }
-
-               // Display message
-               loadTemplate('admin_settings_saved', false, $content);
        } else {
-               // There are mail orders available
-               $OUT = ''; $SW = 2;
-               while ($content = SQL_FETCHARRAY($result)) {
-                       // Prepare data for the row template
-                       // @TODO Rewritings: subj->subject in template
-                       $content = array(
-                               'sw'   => $SW,
-                               'id'   => $content['id'],
-                               'subj' => $content['subject'],
-                               'userid'  => generateUserProfileLink($content['sender']),
-                               'pay'  => getPaymentTitlePrice($content['payment_id']),
-                               'cat'  => getCategory($content['cat_id']),
-                       );
+               // No valid action
+               $content = '<span class="bad">{--ADMIN_EDIT_EMAIL_FAILED--}</span>';
+       }
+
+       // Display message
+       displayMessage($content);
+} else {
+       // Query the pool
+       $result = sqlQuery('SELECT
+       `id`,
+       `sender`,
+       `subject`,
+       `payment_id`,
+       `cat_id`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+ORDER BY
+       `sender` ASC,
+       `timestamp` ASC', __FILE__, __LINE__);
 
+       // Entries found?
+       if (!ifSqlHasZeroNumRows($result)) {
+               // There are mail orders available
+               $OUT = '';
+               while ($content = sqlFetchArray($result)) {
                        // Load row template and switch colors
-                       $OUT .= loadTemplate('admin_edit_email_row', true, $content);
-                       $SW = 3 - $SW;
-               }
+                       $OUT .= loadTemplate('admin_edit_email_row', TRUE, $content);
+               } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load email template
-               loadTemplate('admin_edit_email_select', false, $OUT);
+               loadTemplate('admin_edit_email_select', FALSE, $OUT);
+       } else {
+               // No mail orders left in pool
+               displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
        }
-} else {
-       // No mail orders left in pool
-       loadTemplate('admin_settings_saved', false, "<span class=\"admin_failed\">{--ADMIN_NO_MAILS_IN_POOL--}</span>");
 }
 
 // [EOF]