A lot texts rewritten and exclamation signs removed
[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 - 2009 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         die();
43 } elseif ((!isExtensionActive('order')) && (!isAdmin())) {
44         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('order'));
45         return;
46 } elseif (!isMember()) {
47         // Sorry, no guest access!
48         $URL = 'modules.php?module=index';
49 } elseif (!isGetRequestElementSet('order')) {
50         // You cannot call this module directly!
51         $URL = 'modules.php?module=login&amp;what=order';
52 }
53
54 // When URL is empty nothing bad happend here
55 if (empty($URL)) {
56         // Is the auto-send mechanism active or inactive?
57         if (getConfig('autosend_active') == 'Y') {
58                 // Auto-send is active
59                 $content['admin_autosend']  = getMessage('ADMIN_AUTOSEND_ACTIVE');
60                 $content['member_autosend'] = getMessage('MEMBER_AUTOSEND_ACTIVE');
61                 $type = 'NEW';
62         } else {
63                 // Auto-send is inactive
64                 $content['admin_autosend']  = getMessage('ADMIN_AUTOSEND_INACTIVE');
65                 $content['member_autosend'] = getMessage('MEMBER_AUTOSEND_INACTIVE');
66                 $type = 'ADMIN';
67         }
68
69         // Update sending pool
70         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='%s' WHERE `id`=%s AND `sender`=%s AND `data_type`='TEMP' LIMIT 1",
71                 array($type, bigintval(getRequestElement('order')), getUserId()), __FILE__, __LINE__);
72
73         // Finally is the entry valid?
74         if (SQL_AFFECTEDROWS() == 1) {
75                 // @TODO Unused: 2,4
76                 // Load mail again...              0         1          2             3            4         5       6            7
77                 $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",
78                         array(bigintval(getRequestElement('order')), getUserId()), __FILE__, __LINE__);
79                 $content = merge_array($content, SQL_FETCHARRAY($result));
80                 SQL_FREERESULT($result);
81                 if (empty($content['subject'])) $content['subject'] = getMessage('DEFAULT_SUBJECT_LINE');
82
83                 // Calculate used points
84                 $usedPoints = $content['target_send'] * getPaymentPoints($content['payment_id']);
85
86                 // Update used points
87                 $add = '';
88                 if (getConfig('order_max_full') == 'ORDER') $add = ', mail_orders=mail_orders+1';
89                 subtractPoints('order', getUserId(), $usedPoints);
90
91                 // Compile content
92                 $content['payment']  = getPaymentTitlePrice($content['payment_id']);
93                 $content['category'] = getCategory($content['cat_id']);
94
95                 // Send an email to the user
96                 $message_mem = loadEmailTemplate('order-member', $content, getUserId());
97                 sendEmail(getUserId(), getMessage('MEMBER_NEW_QUEUE'), $message_mem);
98
99                 // Notify admins about this
100                 sendAdminNotification(getMessage('ADMIN_NEW_QUEUE'), 'order-admin', $content, getUserId());
101
102                 // Create new task
103                 createNewTask(
104                         '{--ADMIN_NEW_QUEUE--}',
105                         '<pre>'.loadEmailTemplate('order-admin', $content, getUserId()).'</pre>',
106                         'MEMBER_ORDER',
107                         getUserId(),
108                         0,
109                         false
110                 );
111
112                 // Output back bottom
113                 loadTemplate('member_order-back');
114         } else {
115                 // Matching line not found or already 'placed' in send queue
116                 redirectToUrl('modules.php?module=login');
117         }
118 } else {
119         // Redirect...
120         redirectToUrl($URL);
121 }
122
123 // [EOF]
124 ?>