Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-email_details.php
index 33d0af91689e60e24e218f1a1e31f979817bc2cb..f941962989d977ccfea4ddad1274984fbbcef8cd 100644 (file)
  * $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 *
  * along with this program; if not, write to the Free Software          *
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
  * MA  02110-1301  USA                                                  *
- * -------------------------------------------------------------------- *
- *           Moded What-email_details.php   / also Editet !             *
- * Auf langsammen Servern (wie mein z.B Dauert das Laden)               *
- * enorm hoch zu lang. Jetzt werden nur auftraege aufgelistet die       *
- * NEU sind ( DB NEW) oder ADMIN freischalten muss (DB ADMIN )          *
- * oder noch als TEMP gespecihert sind                                  *
- * der rest der schon als SEND sich melden darf wird per                *
- * what-email_archiv .php aufgerufen                                    *
- * beste gruesse Robert Niedziela / www.personal-webserver.de           *
- * oder auch www.mc-p.org                                               *
  ************************************************************************/
 
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
-addMenuDescription('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
-// Normal mails ordered by your members
-//              0     1       2       3       4           5          6          7       8        9          10
-$sql = "SELECT id, sender, subject, text, receivers, payment_id, data_type, timestamp, url, target_send, cat_id
-FROM `{?_MYSQL_PREFIX?}_pool`
-WHERE data_type IN('ADMIN','TEMP','NEW','ACTIVE')
-ORDER BY timestamp DESC";
+// Is 'sql_patches' updated?
+if (!isExtensionInstalledAndNewer('sql_patches', '0.7.4')) {
+       // No, abort here
+       displayMessage(generateExtensionOutdatedMessage('sql_patches', '0.7.4'));
+       return FALSE;
+} // END - if
 
-$WHO = getMessage('_ALL');
+// Normal mails ordered by your members
+$sql = "SELECT
+       `id`,
+       `sender`,
+       `subject`,
+       `text`,
+       `receivers`,
+       `payment_id`,
+       `data_type`,
+       `timestamp`,
+       `url`,
+       `target_send`,
+       `mails_sent`,
+       `cat_id`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+WHERE
+       `data_type` IN('ADMIN','TEMP','NEW','ACTIVE')
+ORDER BY
+       `timestamp` DESC";
+
+$WHO = '';
 $SQL2 = '';
 
-if (isGetRequestElementSet(('mid'))) {
+if ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
        // Only a specific mail shall be displayed
-       //              0     1       2       3       4           5          6          7       8        9          10
-       $sql = "SELECT id, sender, subject, text, receivers, payment_id, data_type, timestamp, url, target_send, cat_id
-        FROM `{?_MYSQL_PREFIX?}_pool`
-        WHERE `id`='".bigintval(getRequestElement('mid'))."'
-        LIMIT 1";
-       $WHO = getMessage('MAIL_ID').": ".getRequestElement('mid');
+       $sql = sprintf('SELECT
+       `id`,
+       `sender`,
+       `subject`,
+       `text`,
+       `receivers`,
+       `payment_id`,
+       `data_type`,
+       `timestamp`,
+       `url`,
+       `target_send`,
+       `mails_sent`,
+       `cat_id`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+WHERE
+       `id`=%s
+LIMIT 1',
+               bigintval(getRequestElement('id'))
+       );
+       $WHO = '{--MAIL_ID--}' . ': ' . getRequestElement('id');
 } elseif (isGetRequestElementSet('userid')) {
        // All mails by a specific member shall be displayed
-       //              0     1       2       3       4           5          6          7       8        9          10
-       $sql = "SELECT id, sender, subject, text, receivers, payment_id, data_type, timestamp, url, target_send, cat_id
-FROM `{?_MYSQL_PREFIX?}_pool`
-WHERE sender='".bigintval(getRequestElement('userid'))."'
-ORDER by timestamp DESC";
-       $WHO = getMessage('USER_ID').": ".getRequestElement('userid');
+       $sql = sprintf('SELECT
+       `id`,
+       `sender`,
+       `subject`,
+       `text`,
+       `receivers`,
+       `payment_id`,
+       `data_type`,
+       `timestamp`,
+       `url`,
+       `target_send`,
+       `mails_sent`,
+       `cat_id`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+WHERE
+       `sender`=%s
+ORDER BY
+       `timestamp` DESC',
+               bigintval(getRequestElement('userid'))
+       );
+       $WHO = '{--USER_ID--}' . ': ' . getRequestElement('userid');
 }
 
-if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
-       // Bonus mails sent by you
-       //               0     1       2        3        4      5       6          7       8      9         10          11        12
-       $SQL2 = "SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, clicks
-FROM `{?_MYSQL_PREFIX?}_bonus`
-WHERE is_notify='N'
-ORDER BY timestamp DESC";
+// Init result_bonus
+$result_bonus = FALSE;
 
+if ((isExtensionActive('bonus')) && (empty($WHO))) {
        // Check for maximum pages
-       $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
-}
+       $result_bonus = sqlQuery("SELECT
+       `id`,
+       `subject`,
+       `text`,
+       `receivers`,
+       `points`,
+       `time`,
+       `data_type`,
+       `timestamp`,
+       `url`,
+       `cat_id`,
+       `target_send`,
+       `mails_sent`,
+       `clicks`,
+       (`mails_sent` - `clicks`) AS `unconfirmed`
+FROM
+       `{?_MYSQL_PREFIX?}_bonus`
+WHERE
+       `is_notify`='N'
+ORDER BY
+       `timestamp` DESC", __FILE__, __LINE__);
+} // END - if
 
 // Check for maximum pages
-$result_normal = SQL_QUERY($sql, __FILE__, __LINE__);
+$result_normal = sqlQuery($sql, __FILE__, __LINE__);
 
 // Set offset an current page to default values
 if (!isGetRequestElementSet('page')) setGetRequestElement('page', 1);
@@ -103,7 +160,7 @@ if (!isGetRequestElementSet('page')) setGetRequestElement('page', 1);
 if (!isGetRequestElementSet('offset')) {
        if (isConfigEntrySet('mails_page')) {
                // Set config entry
-               setGetRequestElement('offset', getConfig('mails_page'));
+               setGetRequestElement('offset', getMailsPage());
        } else {
                // Set default one
                setGetRequestElement('offset', 10);
@@ -111,9 +168,9 @@ if (!isGetRequestElementSet('offset')) {
 } // END - if
 
 // Add limitation to SQL string
-if (!isGetRequestElementSet(('mid'))) {
+if (!(isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
        // Create limitation line
-       $add = " LIMIT ".(bigintval(getRequestElement('offset')) * bigintval(getRequestElement('page')) - bigintval(getRequestElement('offset'))).", ".bigintval(getRequestElement('offset'));
+       $add = ' LIMIT ' . (bigintval(getRequestElement('offset')) * bigintval(getRequestElement('page')) - bigintval(getRequestElement('offset'))) . ', ' . bigintval(getRequestElement('offset'));
 
        // For normal mails
        $sql .= $add;
@@ -123,124 +180,102 @@ if (!isGetRequestElementSet(('mid'))) {
 } // END - if
 
 // Run SQL query for normal mails
-$result_list = SQL_QUERY($sql, __FILE__, __LINE__);
-if ((!empty($SQL2)) && ($WHO == getMessage('_ALL'))) $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
+$result_list = sqlQuery($sql, __FILE__, __LINE__);
+if ((!empty($SQL2)) && (empty($WHO))) {
+       $result_bonus = sqlQuery($SQL2, __FILE__, __LINE__);
+} // END - if
 
 // Calculate pages
-$PAGES = '0';
+$numPages = '0';
 if (isConfigEntrySet('mails_page')) {
-       $PAGES = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.3);
+       $numPages = round(sqlNumRows($result_normal) / getMailsPage() + 0.3);
 } // END - if
 
 // Free result
-SQL_FREERESULT($result_normal);
+sqlFreeResult($result_normal);
 
-$MAIL = false;
-if (SQL_NUMROWS($result_list) > 0) {
+$MAIL = FALSE;
+if (!ifSqlHasZeroNumRows($result_list)) {
        // Init rows
-       $OUT = ''; $content = array();
+       $OUT = '';
 
        // Walk through all entries
-       while ($pool = SQL_FETCHARRAY($result_list)) {
+       while ($content = sqlFetchArray($result_list)) {
                // Unconfirmed mails and sent mails
-               $result_uncon = SQL_QUERY_ESC("SELECT max_rec, clicks FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
-               array(bigintval($pool['id'])), __FILE__, __LINE__);
-               list($pool['sent_email'], $pool['clicks']) = SQL_FETCHROW($result_uncon);
-               SQL_FREERESULT($result_uncon);
+               $result_uncon = sqlQueryEscaped("SELECT (`max_rec` - `clicks`) AS `unconfirmed` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
+                       array(bigintval($content['id'])), __FILE__, __LINE__);
+
+               // Load and merge data
+               $content = merge_array($content, sqlFetchArray($result_uncon));
+
+               // Free result
+               sqlFreeResult($result_uncon);
 
                // Unconfirmed mails
-               $pool['unconfirmed'] = $pool['sent_email'] - $pool['clicks'];
-               if ($pool['unconfirmed'] > 0) {
-                       // Add link to list_unconfirmed what-file
-                       $pool['unconfirmed'] = "<strong><a href=\"{%url=modules.php?module=admin&amp;what=list_unconfirmed&amp;mid=" . $pool['id'] . "%}\">" . $pool['unconfirmed'] . "</a></strong>";
-               } elseif ($pool['unconfirmed'] < 0) {
-                       // Sometimes rarely displayed minus values will be "fixed" to zero
-                       $pool['unconfirmed'] = '0';
-               }
+               $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], ($content['unconfirmed']), 'normal');
 
                // Prepare content
-               $content = $pool;
-               $content['sender_link'] = generateUserProfileLink($pool['sender']);
-               $content['payment']     = getPaymentTitlePrice($pool['payment_id']);
-               $content['category']    = getCategory($pool['cat_id']);
-               $content['receivers']   = convertReceivers($pool['receivers']);
-               $content['type']        = translatePoolType($pool['data_type']);
-               $content['frametester'] = generateFrametesterUrl($pool['url']);
-               $content['timestamp']   = generateDateTime($pool['timestamp'], 0);
+               $content['timestamp']   = generateDateTime($content['timestamp'], 0);
 
                // Load row template
-               $OUT .= loadTemplate('admin_list_emails_row', true, $content);
+               $OUT .= loadTemplate('admin_list_emails_row', TRUE, $content);
        } // END - while
 
        // Free memory
-       SQL_FREERESULT($result_list);
+       sqlFreeResult($result_list);
 
        // Add navigation (with change box and colspan=3)
-       $content['nav'] = '';
-       if ($PAGES > 1) $content['nav'] = addEmailNavigation($PAGES, getConfig('mails_page'), false, 3, true);
+       $content['nav'] = addEmailNavigation($numPages, getMailsPage(), FALSE, 3, TRUE);
 
        // Prepare content
        $content['rows'] = $OUT;
        $content['who'] = $WHO;
 
        // Mail orders are in pool so we can display them
-       loadTemplate('admin_list_emails', false, $content);
+       loadTemplate('admin_list_emails', FALSE, $content);
 
-       $MAIL = true;
-       if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
-               // Check only if bonus extension is active
-               if (SQL_NUMROWS($result_bonus) > 0) outputHtml('<br /><br />');
+       $MAIL = TRUE;
+       if ((isExtensionActive('bonus')) && (empty($WHO))) {
+               // Only check if bonus extension is active
+               if (!ifSqlHasZeroNumRows($result_bonus)) outputHtml('<br /><br />');
        } // END - if
-}
+} // END - if
 
-if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
+if ((isExtensionActive('bonus')) && (empty($WHO))) {
        // Load bonus mails only when extension is active
-       if (SQL_NUMROWS($result_bonus) > 0) {
+       if (!ifSqlHasZeroNumRows($result_bonus)) {
                // Calculate pages
-               $PAGES = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
+               $numPages = round(sqlNumRows($result_bonus) / getMailsPage() + 0.5);
 
                // List emails
-               $OUT = ''; $content = array();
-               while ($bonus = SQL_FETCHARRAY($result_bonus)) {
-                       // Calculate unconfirmed emails
-                       $bonus['unconfirmed'] = $bonus['mails_sent'] - $bonus['clicks'];
-
-                       // Add link?
-                       if ($bonus['unconfirmed'] > 0) {
-                               // Add link to list_unconfirmed what-file
-                               $bonus['unconfirmed'] = "<strong><a href=\"{%url=modules.php?module=admin&amp;what=list_unconfirmed&amp;bid=" . $bonus['id'] . "%}\">" . $bonus['unconfirmed'] . "</a></strong>";
-                       } // END - if
+               $OUT = '';
+               while ($content = sqlFetchArray($result_bonus)) {
+                       // Add link to list_unconfirmed what-file
+                       $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], $content['unconfirmed'], 'bonus');
 
                        // Prepare content
-                       $content = $bonus;
-                       $content['time']        = createFancyTime($content['time']);
-                       $content['category']    = getCategory($content['cat_id']);
-                       $content['receivers']   = convertReceivers($content['receivers']);
-                       $content['type']        = translatePoolType($content['data_type']);
-                       $content['frametester'] = generateFrametesterUrl($content['url']);
                        $content['timestamp']   = generateDateTime($content['timestamp'], 0);
 
                        // Load row template
-                       $OUT .= loadTemplate('admin_list_bonus_emails_row', true, $content);
+                       $OUT .= loadTemplate('admin_list_bonus_emails_row', TRUE, $content);
                } // END - while
 
                // Add navigation (without change box but with colspan=3)
-               $content['nav'] = '';
-               if ($PAGES > 1) $content['nav'] = addEmailNavigation($PAGES, getConfig('mails_page'), false, 3, true);
+               $content['nav'] = addEmailNavigation($numPages, getMailsPage(), FALSE, 3, TRUE);
 
                // Prepare content
                $content['rows'] = $OUT;
 
                // Load main template
-               loadTemplate('admin_list_bonus_emails', false, $content);
-               $MAIL = true;
+               loadTemplate('admin_list_bonus_emails', FALSE, $content);
+               $MAIL = TRUE;
        } // END - if
 } // END - if
 
-if ($MAIL === false) {
+if ($MAIL === FALSE) {
        // No mail orders fond
-       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
+       displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
 } // END - if
 
-//
+// [EOF]
 ?>