New naming convention applied to many functions, see #118 for details
[mailer.git] / inc / modules / order.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 $URL = '';
41 if (!defined('__SECURITY')) {
42         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43         require($INC);
44 } elseif ((!EXT_IS_ACTIVE('order')) && (!IS_ADMIN())) {
45         addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), 'order'));
46         return;
47 } elseif (!IS_MEMBER()) {
48         // Sorry, no guest access!
49         $URL = 'modules.php?module=index';
50 } elseif (!REQUEST_ISSET_GET(('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                 define('ADMIN_AUTOSEND',  getMessage('ADMIN_AUTOSEND_ACTIVE'));
61                 define('MEMBER_AUTOSEND', getMessage('MEMBER_AUTOSEND_ACTIVE'));
62                 $type = 'NEW';
63         } else {
64                 // Auto-send is inactive
65                 define('ADMIN_AUTOSEND',  getMessage('ADMIN_AUTOSEND_INACTIVE'));
66                 define('MEMBER_AUTOSEND', getMessage('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(REQUEST_GET('order')), getUserId()), __FILE__, __LINE__);
73
74         // Finally is the entry valid?
75         if (SQL_AFFECTEDROWS() == 1) {
76                 // Load personal data...
77                 $result = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
78                         array(getUserId()), __FILE__, __LINE__);
79                 list($gender, $sname, $fname, $email) = SQL_FETCHROW($result);
80                 SQL_FREERESULT($result);
81
82                 // Load mail again...              0       1        2           3          4      5      6         7
83                 $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",
84                         array(bigintval(REQUEST_GET('order')), getUserId()), __FILE__, __LINE__);
85                 $DATA = SQL_FETCHROW($result);
86                 SQL_FREERESULT($result);
87                 if (empty($DATA[0])) $DATA[0] = getMessage('DEFAULT_SUBJECT_LINE');
88
89                 // Calculate used points
90                 $USED = $DATA[7] * getPaymentPoints($DATA[3]);
91
92                 // Update used points
93                 $add = '';
94                 if (getConfig('order_max_full') == 'ORDER') $add = ', mail_orders=mail_orders+1';
95                 SUB_POINTS('order', getUserId(), $USED);
96
97                 // Prepare content
98                 $content = array(
99                         'blocks'   => getConfig('max_send'),
100                         'subject'  => $DATA[0],
101                         'text'     => $DATA[1],
102                         'payment'  => getPaymentTitlePrice($DATA[3]),
103                         'category' => getCategory($DATA[6]),
104                         'url'      => $DATA[5]
105                 );
106
107                 // Send an email to the user
108                 $msg_mem = LOAD_EMAIL_TEMPLATE('order-member', $content, getUserId());
109                 sendEmail($email, getMessage('MEMBER_NEW_QUEUE'), $msg_mem);
110
111                 // Notify admins about this
112                 sendAdminNotification(getMessage('ADMIN_NEW_QUEUE'), 'order-admin', $content, getUserId());
113
114                 // Output back bottom
115                 LOAD_TEMPLATE('member_order-back', false);
116         } else {
117                 // Matching line not found or already 'placed' in send queue
118                 redirectToUrl('modules.php?module=login');
119         }
120 } else {
121         // Redirect...
122         redirectToUrl($URL);
123 }
124
125 //
126 ?>