Next wave of lesser getMessage() usage and more EL
[mailer.git] / inc / modules / order.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/29/2003 *
4  * ===================                          Last change: 01/06/2006 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : order.php                                        *
8  * -------------------------------------------------------------------- *
9  * Short description : Submits your order to the administrators         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sendet die Buchung an die Administratoren        *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 $url = '';
42 if (!defined('__SECURITY')) {
43         die();
44 } elseif ((!isExtensionActive('order')) && (!isAdmin())) {
45         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('order'));
46         return;
47 } elseif (!isMember()) {
48         // Sorry, no guest access!
49         $url = 'modules.php?module=index';
50 } elseif (!isGetRequestParameterSet('order')) {
51         // You cannot call this module directly!
52         $url = 'modules.php?module=login&amp;what=order';
53 }
54
55 // When URL is empty nothing bad happend here
56 if (empty($url)) {
57         // Is the auto-send mechanism active or inactive?
58         if (getConfig('autosend_active') == 'Y') {
59                 // Auto-send is active
60                 $content['admin_autosend']  = '{--ADMIN_AUTOSEND_ACTIVE--}';
61                 $content['member_autosend'] = '{--MEMBER_AUTOSEND_ACTIVE--}';
62                 $type = 'NEW';
63         } else {
64                 // Auto-send is inactive
65                 $content['admin_autosend']  = '{--ADMIN_AUTOSEND_INACTIVE--}';
66                 $content['member_autosend'] = '{--MEMBER_AUTOSEND_INACTIVE--}';
67                 $type = 'ADMIN';
68         }
69
70         // Update sending pool
71         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='%s' WHERE `id`=%s AND `sender`=%s AND `data_type`='TEMP' LIMIT 1",
72                 array($type, bigintval(getRequestParameter('order')), getMemberId()), __FILE__, __LINE__);
73
74         // Finally is the entry valid?
75         if (SQL_AFFECTEDROWS() == 1) {
76                 // @TODO Unused: 2,4
77                 // Load mail again...              0         1          2             3            4         5       6            7
78                 $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",
79                         array(bigintval(getRequestParameter('order')), getMemberId()), __FILE__, __LINE__);
80
81                 // Merge arrays
82                 $content = merge_array($content, SQL_FETCHARRAY($result));
83
84                 // Free result
85                 SQL_FREERESULT($result);
86
87                 // Fix empty subject line
88                 if (empty($content['subject'])) $content['subject'] = '{--DEFAULT_SUBJECT_LINE--}';
89
90                 // Calculate used points
91                 $usedPoints = $content['target_send'] * getPaymentPoints($content['payment_id']);
92
93                 // Update used points
94                 $add = '';
95                 if (getConfig('order_max_full') == 'ORDER') $add = ', mail_orders=mail_orders+1';
96                 subtractPoints('order', getMemberId(), $usedPoints);
97
98                 // Compile content
99                 $content['payment']  = getPaymentTitlePrice($content['payment_id']);
100                 $content['category'] = getCategory($content['cat_id']);
101
102                 // Send an email to the user
103                 $message_mem = loadEmailTemplate('order-member', $content, getMemberId());
104                 sendEmail(getMemberId(), getMessage('MEMBER_NEW_QUEUE'), $message_mem);
105
106                 // Notify admins about this
107                 sendAdminNotification(getMessage('ADMIN_NEW_QUEUE'), 'order-admin', $content, getMemberId());
108
109                 // Create new task
110                 createNewTask(
111                         '{--ADMIN_NEW_QUEUE--}',
112                         '<pre>'.loadEmailTemplate('order-admin', $content, getMemberId()).'</pre>',
113                         'MEMBER_ORDER',
114                         getMemberId(),
115                         0,
116                         false
117                 );
118
119                 // Output back bottom
120                 loadTemplate('member_order-back');
121         } else {
122                 // Matching line not found or already 'placed' in send queue
123                 redirectToUrl('modules.php?module=login');
124         }
125 } else {
126         // Redirect...
127         redirectToUrl($url);
128 }
129
130 // [EOF]
131 ?>