Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[mailer.git] / inc / modules / order.php
index ee40a2149eaf0829dadf1f4964b5c12b6ec5ff7e..915500d4d7aba0bf78abef0429f65ad1d269ac77 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/29/2003 *
- * ===============                              Last change: 01/06/2006 *
+ * Mailer v0.2.1-FINAL                                Start: 10/29/2003 *
+ * ===================                          Last change: 01/06/2006 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : order.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 - 2012 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...
-$URL = "";
+$url = '';
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-} elseif ((!EXT_IS_ACTIVE("order")) && (!IS_ADMIN())) {
-       addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "order");
+       exit();
+} elseif ((!isExtensionActive('order')) && (!isAdmin())) {
+       displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=order%}');
        return;
-} elseif (!IS_MEMBER()) {
+} elseif (!isMember()) {
        // Sorry, no guest access!
-       $URL = "modules.php?module=index";
-} elseif (!REQUEST_ISSET_GET(('order'))) {
+       $url = 'modules.php?module=index';
+} elseif (!isGetRequestElementSet('order')) {
        // You cannot call this module directly!
-       $URL = "modules.php?module=login&amp;what=order";
+       $url = 'modules.php?module=login&amp;what=order';
 }
 
 // When URL is empty nothing bad happend here
-if (empty($URL)) {
+if (empty($url)) {
+       // Auto-send is inactive
+       $content['admin_autosend']  = '{--ADMIN_AUTOSEND_INACTIVE--}';
+       $content['member_autosend'] = '{--MEMBER_AUTOSEND_INACTIVE--}';
+       $type = 'ADMIN';
+
        // Is the auto-send mechanism active or inactive?
-       if (getConfig('autosend_active') == "Y") {
+       if (getConfig('autosend_active') == 'Y') {
                // Auto-send is active
-               define('ADMIN_AUTOSEND',  getMessage('ADMIN_AUTOSEND_ACTIVE'));
-               define('MEMBER_AUTOSEND', getMessage('MEMBER_AUTOSEND_ACTIVE'));
-               $type = "NEW";
-       } else {
-               // Auto-send is inactive
-               define('ADMIN_AUTOSEND',  getMessage('ADMIN_AUTOSEND_INACTIVE'));
-               define('MEMBER_AUTOSEND', getMessage('MEMBER_AUTOSEND_INACTIVE'));
-               $type = "ADMIN";
-       }
+               $content['admin_autosend']  = '{--ADMIN_AUTOSEND_ACTIVE--}';
+               $content['member_autosend'] = '{--MEMBER_AUTOSEND_ACTIVE--}';
+               $type = 'NEW';
+       } // END - if
 
        // Update sending pool
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET data_type='%s' WHERE id=%s AND sender=%s AND data_type='TEMP' LIMIT 1",
-               array($type, bigintval(REQUEST_GET('order')), getUserId()), __FILE__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='%s' WHERE `id`=%s AND `sender`=%s AND `data_type`='TEMP' LIMIT 1",
+               array(
+                       $type,
+                       bigintval(getRequestElement('order')),
+                       getMemberId()
+               ), __FILE__, __LINE__);
 
        // Finally is the entry valid?
-       if (SQL_AFFECTEDROWS() == 1) {
-               // Load personal data...
-               $result = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                       array(getUserId()), __FILE__, __LINE__);
-               list($gender, $sname, $fname, $email) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+       if (!SQL_HASZEROAFFECTED()) {
+               // @TODO Unused: 2,4
+               // Load mail again...              0         1          2             3            4         5       6            7
+               $result = SQL_QUERY_ESC("SELECT `subject`,`text`,`receivers`,`payment_id`,`timestamp`,`url`,`cat_id`,`target_send` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s AND `sender`=%s LIMIT 1",
+                       array(
+                               bigintval(getRequestElement('order')),
+                               getMemberId()
+                       ), __FILE__, __LINE__);
+
+               // Merge arrays
+               $content = merge_array($content, SQL_FETCHARRAY($result));
 
-               // Load mail again...              0       1        2           3          4      5      6         7
-               $result = SQL_QUERY_ESC("SELECT subject, text, receivers, payment_id, timestamp, url, cat_id, target_send FROM `{!_MYSQL_PREFIX!}_pool` WHERE id=%s AND sender=%s LIMIT 1",
-                       array(bigintval(REQUEST_GET('order')), getUserId()), __FILE__, __LINE__);
-               $DATA = SQL_FETCHROW($result);
+               // Free result
                SQL_FREERESULT($result);
-               if (empty($DATA[0])) $DATA[0] = getMessage('DEFAULT_SUBJECT_LINE');
+
+               // Fix empty subject line
+               if (empty($content['subject'])) {
+                       $content['subject'] = '{--DEFAULT_SUBJECT_LINE--}';
+               } // END - if
 
                // Calculate used points
-               $USED = $DATA[7] * GET_PAY_POINTS($DATA[3]);
+               $content['payed_points'] = $content['target_send'] * getPaymentData($content['payment_id']);
+
+               // Subtract them from the user's account and ignore return status
+               subtractPoints('order', getMemberId(), $content['payed_points']);
 
                // Update used points
-               $ADD = "";
-               if (getConfig('order_max_full') == "ORDER") $ADD = ", mail_orders=mail_orders+1";
-               SUB_POINTS("order", getUserId(), $USED);
-
-               // Prepare content
-               $content = array(
-                       'blocks'   => getConfig('max_send'),
-                       'subject'  => $DATA[0],
-                       'text'     => $DATA[1],
-                       'payment'  => GET_PAYMENT($DATA[3]),
-                       'category' => GET_CATEGORY($DATA[6]),
-                       'url'      => $DATA[5]
-               );
+               $add = '';
+               if ((isExtensionInstalledAndNewer('order', '0.1.1')) && (getConfig('order_max_full') == 'ORDER')) {
+                       $add = ',`mail_orders`=`mail_orders`+1';
+               } // END - if
 
                // Send an email to the user
-               $msg_mem = LOAD_EMAIL_TEMPLATE("order-member", $content, getUserId());
-               SEND_EMAIL($email, getMessage('MEMBER_NEW_QUEUE'), $msg_mem);
+               $message_mem = loadEmailTemplate('member_order_normal', $content, getMemberId());
+               sendEmail(getMemberId(), '{--MEMBER_NEW_QUEUE--}', $message_mem);
 
                // Notify admins about this
-               SEND_ADMIN_NOTIFICATION(getMessage('ADMIN_NEW_QUEUE'), "order-admin", $content, getUserId());
+               sendAdminNotification('{--ADMIN_NEW_QUEUE--}', 'admin_order_normal', $content, getMemberId());
+
+               // Create new task (we ignore the task id here)
+               createNewTask(
+                       '{--ADMIN_NEW_QUEUE--}',
+                       '<pre>' . loadEmailTemplate('admin_order_normal', $content, getMemberId()) . '</pre>',
+                       'MEMBER_ORDER',
+                       getMemberId(),
+                       0,
+                       false
+               );
 
                // Output back bottom
-               LOAD_TEMPLATE("member_order-back", false);
+               loadTemplate('member_order_thanks');
        } else {
-               // Matching line not found or already "placed" in send queue
-               LOAD_URL("modules.php?module=login");
+               // Matching line not found or already 'placed' in send queue
+               redirectToUrl('modules.php?module=login');
        }
 } else {
        // Redirect...
-       LOAD_URL($URL);
+       redirectToUrl($url);
 }
 
-//
+// [EOF]
 ?>