Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-unlock_emails.php
index ddc051d56eecb756aab1ab6cd3510d24fc689869..848c797aaf538c72bfb6db90bb053c510373a3a8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/28/2003 *
- * ===============                              Last change: 07/13/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
+ * ===================                          Last change: 07/13/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-unlock_emails.php                           *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Werbebuchungen freigeben                         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * 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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
-// Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
-// Define some variables
-global $DATA, $link;
+// Add description as navigation point
+addYouAreHereLink('admin', __FILE__);
 
 // Check for mails
-$result_main = SQL_QUERY("SELECT id, sender, subject, payment_id, timestamp, url, target_send, cat_id FROM "._MYSQL_PREFIX."_pool WHERE data_type='ADMIN' ORDER BY timestamp", __FILE__, __LINE__);
-
-OPEN_TABLE("100%", "admin_content admin_content_align", "");
-if ((SQL_NUMROWS($result_main) > 0) || (isset($_POST['lock'])))
-{
-       // Count checked checkboxes
-       $SEL = 0;
-       if (isset($_POST['sel']))
-       {
-               // Are there checked boxes?
-               if (count($_POST['sel']) > 0)
-               {
-                       // Count now... We use an own function for now
-                       $SEL = SELECTION_COUNT($_POST['sel']);
-               }
-       }
-       if (isset($_POST['accept']))
-       {
-               if ($SEL > 0)
-               {
+$result_main = sqlQuery("SELECT
+       `id`,
+       `url`,
+       `subject`,
+       `text`,
+       `sender`,
+       `timestamp`,
+       `target_send`,
+       `payment_id`,
+       `cat_id`
+FROM
+       `{?_MYSQL_PREFIX?}_pool`
+WHERE
+       `data_type`='ADMIN'
+ORDER BY
+       `timestamp` ASC", __FILE__, __LINE__);
+
+if ((!ifSqlHasZeroNumRows($result_main)) || (isFormSent('lock'))) {
+       if (isFormSent('accept')) {
+               if (ifPostContainsSelections()) {
                        // Accept mail orders
-                       foreach ($_POST['sel'] as $id=>$value)
-                       {
-                               // Secure ID number
+                       foreach (postRequestElement('sel') as $id => $value) {
+                               // Secure id number
                                $id = bigintval($id);
 
-                               // Unlock selected email
-                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='NEW' WHERE id=%d AND data_type='ADMIN' LIMIT 1",
-                                array($id), __FILE__, __LINE__);
-                               if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 1)
-                               {
-                                       // Order placed in queue...
-                                       $result = SQL_QUERY_ESC("SELECT url, subject, sender FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
-                                        array($id), __FILE__, __LINE__);
-                                       $DATA = SQL_FETCHROW($result);
-                                       SQL_FREERESULT($result);
+                               // Get pool data from given id
+                               $content = getPoolDataFromId($id);
+
+                               // Found some data?
+                               if (isFilledArray($content)) {
+                                       // Is the surfbar installed?
+                                       // @TODO Rewrite these if-blocks to a filter
+                                       if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
+                                               // Then "migrate" the URL to the surfbar
+                                               doSurfbarAdminMigrateUrl($content['url'], $content['sender']);
+                                       } // END - if
 
                                        // Check for bonus extension version >= 0.4.4 for the order bonus
-                                       if ((GET_EXT_VERSION("bonus") >= "0.4.4") && ($_CONFIG['bonus_active'] == "Y"))
-                                       {
+                                       if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
                                                // Add points directly
-                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET bonus_order=bonus_order+".$_CONFIG['bonus_order']." WHERE userid=%d LIMIT 1",
-                                                array(bigintval($DATA[2])), __FILE__, __LINE__);
+                                               sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+{?bonus_order?} WHERE `userid`=%s LIMIT 1",
+                                                       array(bigintval($content['sender'])), __FILE__, __LINE__);
 
                                                // Subtract bonus points from system
-                                               BONUS_POINTS_HANDLER($_CONFIG['bonus_order']);
-                                       }
+                                               handleBonusPoints(getBonusOrder(), $content['sender']);
+                                       } // END - if
 
                                        // Load email template
-                                       $msg_user = LOAD_EMAIL_TEMPLATE("order-accept", "", $DATA[2]);
+                                       $message_user = loadEmailTemplate('member_order_accepted', $content, $content['sender']);
 
                                        // Send email
-                                       SEND_EMAIL($DATA[2], MEMBER_ORDER_ACCEPTED, $msg_user);
-                               }
-                       }
+                                       sendEmail($content['sender'], '{--MEMBER_ORDER_ACCEPTED--}', $message_user);
+
+                                       // Unlock selected email
+                                       updatePoolDataById($id, 'data_type', 'NEW', NULL, " AND `data_type`='ADMIN'");
+                               } // END - if
+                       } // END - foreach
 
                        // Set message
-                       $MSG = ADMIN_MAILS_ACTIVATED;
-               }
-                else
-               {
+                       $message = '{--ADMIN_MAILS_ACTIVATED--}';
+               } else {
                        // Nothing checked!
-                       $MSG = ADMIN_MAILS_NOTHING_CHECKED;
+                       $message = '{--ADMIN_MAILS_NOTHING_CHECKED--}';
                }
 
                // Mails unlocked for mail delivery
-               LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
-       }
-        elseif (isset($_POST['reject']))
-       {
-               if ($SEL > 0)
-               {
+               displayMessage($message);
+       } elseif (isPostRequestElementSet('reject')) {
+               if (ifPostContainsSelections()) {
                        // Reject mail orders
-                       $SW = 2; $OUT = "";
-                       foreach ($_POST['sel'] as $id=>$value)
-                       {
-                               // Secure ID number
+                       $OUT = '';
+                       foreach (postRequestElement('sel') as $id => $value) {
+                               // Secure id number
                                $id = bigintval($id);
 
-                               // Load URL and subject from pool
-                               $result = SQL_QUERY_ESC("SELECT url, subject, sender FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
-                                array($id), __FILE__, __LINE__);
-                               $DATA = SQL_FETCHROW($result);
-                               SQL_FREERESULT($result);
+                               // Get pool data from given id
+                               $content = getPoolDataFromId($id);
 
                                // Load email template and send it away
-                               $msg_user = LOAD_EMAIL_TEMPLATE("order-reject", "", $DATA[2]);
-                               SEND_EMAIL($DATA[2], MEMBER_ORDER_REJECTED, $msg_user);
+                               $message_user = loadEmailTemplate('member_order_rejected', $content, $content['sender']);
+                               sendEmail($content['sender'], '{--MEMBER_ORDER_REJECTED--}', $message_user);
 
                                // If you do not enter an URL to redirect to, your URL will be set!
-                               if ((empty($_POST['redirect'])) || ($_POST['redirect'] == "http://")) $_POST['redirect'] = URL;
+                               if ((!isPostRequestElementSet('redirect')) || (postRequestElement('redirect') == 'http://')) {
+                                       setPostRequestElement('redirect', getUrl());
+                               } // END - if
 
                                // Redirect URL
-                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET url='%s', data_type='NEW' WHERE id=%d LIMIT 1",
-                                array($_POST['redirect'], $id),__FILE__, __LINE__);
+                               updatePoolDataById($id, NULL, array('url' => postRequestElement('redirect'), 'data_type' => 'NEW'));
 
                                // Prepare data for the row template
                                $content = array(
-                                       'sw'  => $SW,
                                        'id'  => $id,
-                                       'url' => $_POST['url'][$id],
+                                       'url' => postRequestElement('url', $id),
                                );
 
                                // Load row template and switch colors
-                               $OUT .= LOAD_TEMPLATE("admin_unlock_emails_redir_row", true, $content);
-                               $SW = 3 - $SW;
-                       }
-                       define('__URL_ROWS', $OUT);
+                               $OUT .= loadTemplate('admin_unlock_emails_redir_row', TRUE, $content);
+                       } // END - foreach
 
                        // Load main template
-                       LOAD_TEMPLATE("admin_unlock_emails_redir");
-               }
-                else
-               {
+                       loadTemplate('admin_unlock_emails_redir', FALSE, $OUT);
+               } else {
                        // Nothing selected
-                       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MAILS_NOTHING_CHECKED);
+                       displayMessage('{--ADMIN_MAILS_NOTHING_CHECKED--}');
                }
-       }
-        elseif ((isset($_POST['lock'])) || ($SEL > 0))
-       {
-               if ($SEL > 0)
-               {
-                       // Lock URLs
-                       foreach ($_POST['sel'] as $id=>$url)
-                       {
-                               $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_url_blist WHERE url='%s' LIMIT 1",
-                                array($url), __FILE__, __LINE__);
-                               if (SQL_NUMROWS($result) == 0)
-                               {
-                                       // Did not find a record so we can add it... :)
-                                       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_url_blist (url, timestamp) VALUES ('%s', UNIX_TIMESTAMP())",
-                                        array($url), __FILE__, __LINE__);
-                               }
-                                else
-                               {
-                                       // Free memory
-                                       SQL_FREERESULT($result);
-                               }
-                       }
-
-                       // Set message
-                       $MSG = ADMIN_URLS_BLOCKED;
-               }
-                else
-               {
-                       // Nothing selected
-                       $MSG = ADMIN_MAILS_NOTHING_CHECKED;
-               }
-               LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
-       }
-        elseif ((empty($_POST['lock'])) && (empty($_POST['accept'])) && (empty($_POST['reject'])))
-       {
+       } elseif ((isFormSent('lock')) && (ifPostContainsSelections()) && (isExtensionActive('blacklist')) && (isUrlBlacklistEnabled())) {
+               // Lock URLs
+               foreach (postRequestElement('sel') as $id => $url) {
+                       // Secure id number
+                       $id = bigintval($id);
+
+                       // Lookup in blacklist
+                       insertUrlInBlacklist($url);
+               } // END - foreach
+
+               // Output message
+               displayMessage('{--ADMIN_URLS_BLOCKED--}');
+       } elseif ((!isFormSent('lock')) && (!isFormSent('accept')) && (!isFormSent('reject'))) {
                // Mail orders are in pool so we can display them
-               $SW = 2; $OUT = "";
-               while (list($id, $sender, $subj, $pay, $time, $url, $tsend, $cat) = SQL_FETCHROW($result_main))
-               {
+               $OUT = '';
+               while ($content = sqlFetchArray($result_main)) {
                        // Prepare data for the template
-                       $content = array(
-                               'sw'        => $SW,
-                               'id'        => $id,
-                               'sender'    => $sender,
-                               'u_link'    => ADMIN_USER_PROFILE_LINK($sender),
-                               'subj'      => COMPILE_CODE($subj),
-                               'tester'    => FRAMETESTER($url),
-                               'url'       => $url,
-                               'cat_title' => str_replace("\"", "&quot;", GET_CATEGORY($cat)),
-                               'cat_link'  => $cat,
-                               'pay_title' => str_replace("\"", "&quot;", GET_PAYMENT($pay, true)),
-                               'pay_link'  => $pay,
-                               'ordered'   => MAKE_DATETIME($time, "2"),
-                               'tsend'     => $tsend,
-                       );
+                       $content['timestamp'] = generateDateTime($content['timestamp'], 2);
 
                        // Load row template and switch colors
-                       $OUT .= LOAD_TEMPLATE("admin_unlock_emails_row", true, $content);
-                       $SW = 3 - $SW;
-               }
+                       $OUT .= loadTemplate('admin_unlock_emails_row', TRUE, $content);
+               } // END - while
 
                // Free memory
-               SQL_FREERESULT($result);
-               define('__UNLOCK_ROWS', $OUT);
+               sqlFreeResult($result_main);
 
-               // Prepare rejection URL
-               $REJECT = "http://";
-               if (GET_EXT_VERSION("other") >= "0.1.6") $REJECT = $_CONFIG['reject_url'];
-               define('__REJECT_URL', $REJECT);
+               // Remember in array
+               $content['rows'] = $OUT;
 
                // Load main template
-               LOAD_TEMPLATE("admin_unlock_emails");
-       }
-        else
-       {
+               loadTemplate('admin_unlock_emails', FALSE, $content);
+       } elseif ((isFormSent('lock')) && ((!isExtensionActive('blacklist')) || (!isUrlBlacklistEnabled()))) {
+               // URL blacklist not activated
+               displayMessage('{--ADMIN_URL_BLACKLIST_DISABLED--}');
+       } else {
                // Wrong call!
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_WRONG_CALL);
+               displayMessage('{--ADMIN_WRONG_CALL--}');
        }
-}
- else
-{
+} else {
        // No mail orders fond
-       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MAILS_IN_POOL);
+       displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
 }
 
-CLOSE_TABLE();
-//
+// [EOF]
 ?>