]> git.mxchange.org Git - mailer.git/blob - inc/modules/member/what-order.php
More rewrites to configuration:
[mailer.git] / inc / modules / member / what-order.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
4  * ===================                          Last change: 08/26/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-order.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Order mails here                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Hier koennen Ihre Mitglieder Mails buchen        *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * GNU General Public License for more details.                         *
29  *                                                                      *
30  * You should have received a copy of the GNU General Public License    *
31  * along with this program; if not, write to the Free Software          *
32  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
33  * MA  02110-1301  USA                                                  *
34  ************************************************************************/
35
36 // Some security stuff...
37 if (!defined('__SECURITY')) {
38         exit();
39 } elseif (!isMember()) {
40         redirectToIndexMemberOnlyModule();
41 }
42
43 // Add description as navigation point
44 addYouAreHereLink('member', __FILE__);
45
46 if ((!isExtensionActive('order')) && (!isAdmin())) {
47         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=order%}');
48         return;
49 } // END - if
50
51 // Init data
52 $data = array(
53         'id'        => '0',
54         'data_type' => 'TEMP',
55         'url'       => '',
56 );
57
58 $ALLOWED = getUserData('receive_mails') - getUserData('mail_orders');
59 if (getOrderMaxFull() == 'MAX') $ALLOWED = getUserData('receive_mails');
60
61 // Now check his points amount
62 $totalPoints = getTotalPoints(getMemberId());
63
64 // Admin can always book
65 if ((isExtensionInstalledAndNewer('holiday', '0.1.3')) && (isUserDataEnabled('holiday_active')) && (!isAdmin())) {
66         // Holiday is active!
67         displayMessage('{--MEMBER_HOLIDAY_ORDER_NOT_POSSIBLE--}');
68 } elseif ((isPostRequestElementSet('frametester')) && ($ALLOWED > 0) && (postRequestElement('receiver') > 0)) {
69         // Continue with the frametester, we first need to store the data temporary in the pool
70         //
71         // First we would like to store the data and get it's pool position back...
72         // @TODO Try to move out url_tlock to a filter for extra SQL statements
73         $result = SQL_QUERY_ESC("SELECT
74         `id`,
75         `data_type`
76 FROM
77         `{?_MYSQL_PREFIX?}_pool`
78 WHERE
79         `sender`=%s AND
80         `url`='%s' AND
81         (UNIX_TIMESTAMP() - `timestamp`) >= {?url_tlock?}
82 LIMIT 1",
83                 array(
84                         getMemberId(),
85                         postRequestElement('url')
86                 ), __FILE__, __LINE__);
87
88         if (SQL_NUMROWS($result) == 1) {
89                 // Load id and mail type
90                 $data = SQL_FETCHARRAY($result);
91         } // END - if
92
93         // Free result
94         SQL_FREERESULT($result);
95
96         if ($data['data_type'] == 'TEMP') {
97                 // No entry found, so we need to check out the stats table as well... :)
98                 // We have to add that suff here, now we continue WITHOUT checking and check the text and subject against some filters
99                 $data['url'] = '';
100                 if (getConfig('allow_url_in_text') == 'Y') {
101                         // Test submitted text against some filters (length, URLs in text etc.)
102                         if ((isInStringIgnoreCase('https://', postRequestElement('text'))) || (isInStringIgnoreCase('http://', postRequestElement('text'))) || (isInStringIgnoreCase('www', postRequestElement('text')))) {
103                                 // URL found
104                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('URL_FOUND');
105                         } // END - if
106
107                         // Remove new-line and carriage-return characters
108                         $TEST = str_replace(array(PHP_EOL, chr(13)), array('', ''), postRequestElement('text'));
109
110                         // Text length within allowed length?
111                         if (strlen($TEST) > getMaxTextLength()) {
112                                 // Text is too long!
113                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('OVERLENGTH');
114                         } // END - if
115                 } // END - if
116
117                 // Shall I test the subject line against URLs?
118                 if (getConfig('allow_url_in_subject') == 'Y') {
119                         // Check the subject line for issues
120                         setPostRequestElement('subject', str_replace(chr(92), '[nl]', substr(postRequestElement('subject'), 0, 200)));
121                         if ((isInStringIgnoreCase('https://', postRequestElement('subject'))) || (isInStringIgnoreCase('http://', postRequestElement('subject'))) || (isInStringIgnoreCase('www', postRequestElement('subject')))) {
122                                 // URL in subject found
123                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('SUBJECT_URL');
124                         } // END - if
125                 } // END - if
126
127                 // And shall I check that his URL is not in the black list?
128                 if ((isExtensionActive('blacklist')) && (isUrlBlacklisted(postRequestElement('url')))) {
129                         // Create redirect-URL
130                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('BLIST_URL') . '&amp;blist=' . $GLOBALS['blacklist_data'][postRequestElement('url')]['timestamp'];
131                 } // END - if
132
133                 // Enougth receivers entered?
134                 if ((postRequestElement('receiver') < getConfig('order_min')) && (!isAdmin())) {
135                         // Less than allowed receivers entered!
136                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS3');
137                 } // END - if
138
139                 // Validate URL
140                 if (!isUrlValid(postRequestElement('url'))) {
141                         // URL is invalid!
142                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('INVALID_URL');
143                 } // END - if
144
145                 // Probe for HTML extension
146                 if (isExtensionActive('html_mail')) {
147                         // HTML or regular text mail?
148                         if (postRequestElement('html') == 'Y') {
149                                 // Chek for valid HTML tags
150                                 setPostRequestElement('text', checkHtmlTags(postRequestElement('text')));
151
152                                 // Maybe invalid tags found?
153                                 if (!isPostRequestElementSet('text')) $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('INVALID_TAGS') . '&amp;id=' . $data['id'];
154                         } else {
155                                 // Remove any HTML code
156                                 setPostRequestElement('text', str_replace(array('<', '>'), array('{OPEN_HTML}', '{CLOSE_HTML}'), postRequestElement('text')));
157                         }
158                 } // END - if
159
160                 // Is mail type set?
161                 if ((!isPostRequestElementSet('mail_type')) || (postRequestElement('mail_type') < 1)) {
162                         // Not correctly set
163                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_MAIL_TYPE');
164                 } // END - if
165         } elseif (!isAdmin()) {
166                 // He has already sent a mail within a specific time
167                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('URL_TIME_LOCK') . '&amp;id=' . $data['id'];
168         }
169
170         // Still no error?
171         if (empty($data['url'])) {
172                 // Check for userids
173                 $result = SQL_QUERY_ESC("SELECT
174         `c`.`userid`
175 FROM
176         `{?_MYSQL_PREFIX?}_user_cats` AS `c`
177 INNER JOIN
178         `{?_MYSQL_PREFIX?}_user_data` AS `d`
179 ON
180         `c`.`userid`=`d`.`userid`
181 WHERE
182         `c`.`cat_id`=%s AND
183         `c`.`userid` != %s AND
184         `d`.`status`='CONFIRMED'
185         " . runFilterChain('user_exclusion_sql', ' ') . " AND
186         `d`.`receive_mails` > 0
187 ORDER BY
188         `d`.`{?order_select?}` {?order_mode?}",
189                         array(
190                                 bigintval(postRequestElement('cat')),
191                                 getMemberId()
192                         ), __FILE__, __LINE__);
193
194                 // Are there still receivers left?
195                 if (SQL_NUMROWS($result) >= postRequestElement('receiver')) {
196                         // Load receivers from database
197                         $TEST = array(); $count = '0';
198                         while ($holidayContent = SQL_FETCHARRAY($result)) {
199                                 if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
200                                         // Check for his holiday status
201                                         $result_holiday = SQL_QUERY_ESC("SELECT
202         `id`
203 FROM
204         `{?_MYSQL_PREFIX?}_user_holidays`
205 WHERE
206         `userid`=%s AND
207         `holiday_start` < UNIX_TIMESTAMP() AND
208         `holiday_end` > UNIX_TIMESTAMP()
209 LIMIT 1",
210                                                 array($holidayContent['userid']), __FILE__, __LINE__);
211                                         if (SQL_NUMROWS($result_holiday) == 1) {
212                                                 // Exclude user who are in holiday
213                                                 $holidayContent['userid'] = '0';
214                                         } // END - if
215
216                                         // Free memory
217                                         SQL_FREERESULT($result_holiday);
218                                 } // END - if
219
220                                 if (isValidId($holidayContent['userid'])) {
221                                         // Add receiver
222                                         array_push($TEST, $holidayContent['userid']);
223                                         $count++;
224                                 } // END - if
225                         } // END - while
226
227                         // Free memory
228                         SQL_FREERESULT($result);
229
230                         // Implode array into string for the sending pool
231                         $receiver = implode($TEST, ';');
232
233                         // Count array for maximum sent
234                         $content['target_send'] = count($TEST);
235
236                         // Update receiver list
237                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receive_mails`=`receive_mails`-1 WHERE `userid` IN (%s) LIMIT %s",
238                                 array(
239                                         convertReceivers($receiver),
240                                         bigintval($content['target_send'])
241                                 ), __FILE__, __LINE__);
242
243                         // Is calculated max receivers larger than wanted receivers then reset it
244                         if ($content['target_send'] > postRequestElement('receiver')) {
245                                 $content['target_send'] = bigintval(postRequestElement('receiver'));
246                         } // END - if
247
248                         // Calculate used points
249                         $usedPoints = $content['target_send'] * getPaymentPrice(bigintval(postRequestElement('mail_type')));
250
251                         // Fix empty zip code
252                         if (!isPostRequestElementSet('zip')) {
253                                 setPostRequestElement('zip', 0);
254                         } // END - if
255
256                         // Check if he has enougth points for this order and selected more than 0 receivers
257                         if (($usedPoints > 0) && ($usedPoints <= $totalPoints) && ($content['target_send'] > 0)) {
258                                 // Gettings points is okay, so we can add $usedPoints later from
259                                 if ((!isValidId($data['id'])) || ($data['data_type'] != 'TEMP')) {
260                                         // New order
261                                         $data['id'] = '0';
262                                         if (isExtensionActive('html_mail')) {
263                                                 // HTML extension is active
264                                                 SQL_QUERY_ESC("INSERT INTO
265         `{?_MYSQL_PREFIX?}_pool`
266 (
267         `sender`,
268         `subject`,
269         `text`,
270         `receivers`,
271         `payment_id`,
272         `data_type`,
273         `timestamp`,
274         `url`,
275         `cat_id`,
276         `target_send`,
277         `zip`,
278         `html_msg`
279 ) VALUES (
280         %s,
281         '%s',
282         '%s',
283         '%s',
284         %s,
285         'TEMP',
286         UNIX_TIMESTAMP(),
287         '%s',
288         %s,
289         %s,
290         %s,
291         '%s'
292 )",
293                                                         array(
294                                                                 getMemberId(),
295                                                                 postRequestElement('subject'),
296                                                                 postRequestElement('text'),
297                                                                 $receiver,
298                                                                 bigintval(postRequestElement('mail_type')),
299                                                                 postRequestElement('url'),
300                                                                 bigintval(postRequestElement('cat')),
301                                                                 bigintval($content['target_send']),
302                                                                 bigintval(postRequestElement('zip'), TRUE, FALSE),
303                                                                 postRequestElement('html')
304                                                         ), __FILE__, __LINE__);
305                                         } else {
306                                                 // No HTML extension is active
307                                                 SQL_QUERY_ESC("INSERT INTO
308         `{?_MYSQL_PREFIX?}_pool`
309 (
310         `sender`,
311         `subject`,
312         `text`,
313         `receivers`,
314         `payment_id`,
315         `data_type`,
316         `timestamp`,
317         `url`,
318         `cat_id`,
319         `target_send`,
320         `zip`
321 ) VALUES (
322         %s,
323         '%s',
324         '%s',
325         '%s',
326         %s,
327         'TEMP',
328         UNIX_TIMESTAMP(),
329         '%s',
330         %s,
331         %s,
332         %s
333 )",
334                                                         array(
335                                                                 getMemberId(),
336                                                                 postRequestElement('subject'),
337                                                                 postRequestElement('text'),
338                                                                 $receiver,
339                                                                 bigintval(postRequestElement('mail_type')),
340                                                                 postRequestElement('url'),
341                                                                 bigintval(postRequestElement('cat')),
342                                                                 bigintval($content['target_send']),
343                                                                 bigintval(postRequestElement('zip'), TRUE, FALSE),
344                                                         ), __FILE__, __LINE__);
345                                         }
346
347                                         // Get insert id
348                                         $data['id'] = SQL_INSERTID();
349                                 } else {
350                                         // Change current order
351                                         if (isExtensionActive('html_mail')) {
352                                                 // HTML extension is active
353                                                 SQL_QUERY_ESC("UPDATE
354         `{?_MYSQL_PREFIX?}_pool`
355 SET
356         `subject`='%s',
357         `text`='%s',
358         `receivers`='%s',
359         `payment_id`=%s,
360         `timestamp`=UNIX_TIMESTAMP(),
361         `url`='%s',
362         `cat_id`=%s,
363         `target_send`=%s,
364         `zip`=%s,
365         `html_msg`='%s'
366 WHERE
367         `id`=%s
368 LIMIT 1",
369                                                         array(
370                                                                 postRequestElement('subject'),
371                                                                 postRequestElement('text'),
372                                                                 $receiver,
373                                                                 bigintval(postRequestElement('mail_type')),
374                                                                 postRequestElement('url'),
375                                                                 bigintval(postRequestElement('cat')),
376                                                                 $content['target_send'],
377                                                                 bigintval(postRequestElement('zip')),
378                                                                 postRequestElement('html'),
379                                                                 bigintval($data['id'])
380                                                         ), __FILE__, __LINE__);
381                                         } else {
382                                                 // No HTML extension is active
383                                                 SQL_QUERY_ESC("UPDATE
384         `{?_MYSQL_PREFIX?}_pool`
385 SET
386         `subject`='%s',
387         `text`='%s',
388         `receivers`='%s',
389         `payment_id`=%s,
390         `timestamp`=UNIX_TIMESTAMP(),
391         `url`='%s',
392         `cat_id`=%s,
393         `target_send`=%s,
394         `zip`=%s
395 WHERE
396         `id`=%s
397 LIMIT 1",
398                                                         array(
399                                                                 postRequestElement('subject'),
400                                                                 postRequestElement('text'),
401                                                                 $receiver,
402                                                                 bigintval(postRequestElement('mail_type')),
403                                                                 postRequestElement('url'),
404                                                                 bigintval(postRequestElement('cat')),
405                                                                 $content['target_send'],
406                                                                 bigintval(postRequestElement('zip')),
407                                                                 bigintval($data['id'])
408                                                         ), __FILE__, __LINE__);
409                                         }
410                                 }
411
412                                 // Make sure only valid id numbers can pass
413                                 assert(isValidId($data['id']));
414
415                                 // Id is received so we can redirect the user, used points will be added when he send's out the mail
416                                 $data['url'] = 'modules.php?module=frametester&amp;order=' . $data['id'];
417                         } elseif ($content['target_send'] == '0') {
418                                 // Not enougth receivers found which can receive mails
419                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS2');
420                         } else {
421                                 // No enougth points left!
422                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_POINTS');
423                         }
424                 } else {
425                         // Ordered more mails than he can send in this category
426                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_RECS_LEFT');
427                 }
428         } // END - if
429 } elseif (postRequestElement('receiver') == '0') {
430         // Not enougth receivers selected
431         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS1');
432 } elseif (($ALLOWED == '0') && (getOrderMaxFull() == 'ORDER')) {
433         // No more mail orders allowed
434         displayMessage('{--MEMBER_ORDER_ALLOWED_EXHAUSTED--}');
435 } elseif (getTotalUnconfirmedMails(getMemberId()) < getConfig('max_unconfirmed')) {
436         // Show only enabled categories to the user ...
437         $whereStatement = " WHERE `visible`='Y'";
438
439         // ... but all to the admin
440         if (isAdmin()) $whereStatement = '';
441
442         // Display order form
443         $result_cats = SQL_QUERY('SELECT
444         `id`,
445         `cat`
446 FROM
447         `{?_MYSQL_PREFIX?}_cats`
448 ' . $whereStatement . '
449 ORDER BY
450         `sort` ASC', __FILE__, __LINE__);
451
452         // Some categories found?
453         if (!SQL_HASZERONUMS($result_cats)) {
454                 // Enought points left?
455                 if ($totalPoints > 0) {
456                         // Initialize array...
457                         $categories = array(
458                                 'id'      => array(),
459                                 'name'    => array(),
460                                 'userids' => array()
461                         );
462
463                         // Enable HTML checking
464                         // @TODO Rewrite this to a filter
465                         $HTML = ''; $HOL_STRING = '';
466                         if ((isExtensionActive('html_mail')) && (postRequestElement('html') == 'Y')) {
467                                 $HTML = " AND `html`='Y'";
468                         } // END - if
469                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
470                                 // Extension's version is fine
471                                 $HOL_STRING = " AND `holiday_active`='N'";
472                         } // END - if
473
474                         // ... and begin loading stuff
475                         while ($categoriesContent = SQL_FETCHARRAY($result_cats)) {
476                                 $categories['id'][]   = bigintval($categoriesContent['id']);
477                                 array_push($categories['name'], $categoriesContent['cat']);
478
479                                 // Select users in current category
480                                 $result_userids = SQL_QUERY_ESC('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s AND `userid` != %s ORDER BY `userid` ASC',
481                                         array(bigintval($categoriesContent['id']), getMemberId()), __FILE__, __LINE__);
482
483                                 $userid_cnt = '0';
484                                 while (list($userid) = SQL_FETCHROW($result_userids)) {
485                                         // Check for holiday system
486                                         $isHolidayActive = FALSE;
487                                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
488                                                 // Check user's holiday status
489                                                 $result_holiday = SQL_QUERY_ESC("SELECT
490         COUNT(`d`.`userid`) AS `cnt`
491 FROM
492         `{?_MYSQL_PREFIX?}_user_data` AS `d`
493 LEFT JOIN
494         `{?_MYSQL_PREFIX?}_user_holidays` AS `h`
495 ON
496         `d`.`userid`=`h`.`userid`
497 WHERE
498         `d`.`userid`=%s AND
499         `d`.`receive_mails` > 0 AND
500         `d`.`status`='CONFIRMED' AND
501         `d`.`holiday_active`='Y' AND
502         `h`.`holiday_start` < UNIX_TIMESTAMP() AND
503         `h`.`holiday_end` > UNIX_TIMESTAMP()
504 LIMIT 1",
505                                                         array(bigintval($userid)), __FILE__, __LINE__);
506
507                                                 // Fetch entry
508                                                 list($count) = SQL_FETCHROW($result_holiday);
509
510                                                 // Free memory
511                                                 SQL_FREERESULT($result_holiday);
512
513                                                 // Is holiday is active?
514                                                 $isHolidayActive = ($count == 1);
515                                         } // END - if
516
517                                         if ($isHolidayActive === FALSE) {
518                                                 // Check if the user want's to receive mails?
519                                                 $result_ver = SQL_QUERY_ESC("SELECT `zip` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s" . $HTML . " AND `receive_mails` > 0 AND `status`='CONFIRMED' LIMIT 1",
520                                                         array(bigintval($userid)), __FILE__, __LINE__);
521
522                                                 if ((SQL_NUMROWS($result_ver) == 1) && (isPostRequestElementSet('zip')) && (isOrderMultiPageEnabled())) {
523                                                         // Get zip code
524                                                         list($zip) = SQL_FETCHROW($result_ver);
525                                                         if (substr($zip, 0, strlen(postRequestElement('zip'))) == postRequestElement('zip')) {
526                                                                 // Ok, ZIP code part is found
527                                                                 $userid_cnt++;
528                                                         } // END - if
529                                                 } else {
530                                                         // Count numbers up!
531                                                         $userid_cnt += SQL_NUMROWS($result_ver);
532                                                 }
533
534                                                 // Free result
535                                                 SQL_FREERESULT($result_ver);
536                                         } // END - if
537                                 } // END - while
538
539                                 // Free memory
540                                 SQL_FREERESULT($result_userids);
541                                 array_push($categories['userids'], $userid_cnt);
542                         } // END - while
543
544                         // Free memory
545                         SQL_FREERESULT($result_cats);
546
547                         // Now we need to load the mail types...
548                         $result = SQL_QUERY("SELECT `id`, `price`, `payment`, `mail_title` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `price` > 0 AND `payment` > 0 ORDER BY `payment` ASC", __FILE__, __LINE__);
549
550                         $payments = array();
551                         if (!SQL_HASZERONUMS($result)) {
552                                 // Is the error code set?
553                                 if (isGetRequestElementSet('code')) {
554                                         // Display error message
555                                         displayMessage(getMessageFromErrorCode(getRequestElement('code')));
556                                 } // END - if
557
558                                 // Load all email types...
559                                 while ($payment = SQL_FETCHARRAY($result)) {
560                                         array_push($payments, $payment);
561                                 } // END - while
562
563                                 // Free memory
564                                 SQL_FREERESULT($result);
565
566                                 // Output user's points
567                                 $content['total_points'] = $totalPoints;
568
569                                 // Check how many mail orders he has placed today and how many he's allowed to send
570                                 switch (getOrderMaxFull()) {
571                                         case 'MAX': // He is allowed to send as much as possible
572                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_MAX--}';
573                                                 break;
574
575                                         case 'ORDER': // He is allowed to send as much as he setup the receiving value
576                                                 $content['order_max_full'] = sprintf(getMessage('MEMBER_ORDER_ALLOWED_RECEIVE'), $ALLOWED, getUserData('receive_mails'));
577                                                 break;
578
579                                         default: // Unknown/invalid
580                                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown order_mas_full config detected.", getOrderMaxFull()));
581                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_UNKNOWN--}';
582                                                 break;
583                                 } // END - switch
584
585                                 // Load final template
586                                 loadTemplate('member_order_points', FALSE, $content);
587
588                                 // Reset variables
589                                 $OLD_ORDER = FALSE;
590                                 $subject = '';
591                                 $text = '';
592                                 $target = '';
593
594                                 // Check if we already have an order placed and make it editable
595                                 $result = SQL_QUERY_ESC("SELECT
596         `subject`,
597         `text`,
598         `payment_id`,
599         `timestamp`,
600         `url`,
601         `target_send`,
602         `cat_id`,
603         `zip`
604 FROM
605         `{?_MYSQL_PREFIX?}_pool`
606 WHERE
607         `sender`=%s AND
608         `data_type`='TEMP'
609 LIMIT 1",
610                                         array(getMemberId()), __FILE__, __LINE__);
611
612                                 if (SQL_NUMROWS($result) == 1) {
613                                         // Old order found
614                                         $content = merge_array($content, SQL_FETCHARRAY($result));
615
616                                         // Fix max receivers when it is too much
617                                         if ((isset($categories['userids'][$content['cat_id']])) && ($content['target_send'] > $categories['userids'][$content['cat_id']])) {
618                                                 // Fix it
619                                                 $content['target_send'] = $categories['userids'][$content['cat_id']];
620                                         } // END - if
621
622                                         // Old order is grabbed
623                                         $OLD_ORDER = TRUE;
624                                 } else {
625                                         // Default output for that your members don't forget it...
626                                         $content['url']         = 'http://';
627                                         $content['target_send'] = '{?order_min?}';
628                                         $content['subject']     = '';
629                                         $content['text']        = '';
630                                 }
631
632                                 // Free result
633                                 SQL_FREERESULT($result);
634
635                                 if ((isPostRequestElementSet('data')) || ((getOrderMultiPage() != 'Y') && ((!isAdmin()) && (!isExtensionActive('html_mail'))))) {
636                                         // Pre-output categories
637                                         $content['category_selection'] = generateCategoryOptionsList(((isExtensionActive('html_mail')) && (isPostRequestElementSet('html'))) ? postRequestElement('html') : 'N', getMemberId());
638
639                                         // Mail type
640                                         $content['payment_selection'] = '';
641                                         foreach ($payments as $key => $value) {
642                                                 if (is_array($value)) {
643                                                         // Output option line
644                                                         $content['payment_selection'] .= '      <option value="' . $payments[$key]['id'] . '"';
645                                                         if (($OLD_ORDER) && ($content['payment_id'] == $payments[$key]['id'])) $content['payment_selection'] .= ' selected="selected"';
646                                                         $content['payment_selection'] .= '>{%pipe,translateComma=' . $payments[$key]['price'] . '%} {--PER_MAIL--} - ' . $payments[$key]['mail_title'] . ' - ' . round($payments[$key]['payment']) . ' {--PAYMENT--}</option>';
647                                                 } // END - if
648                                         } // END - foreach
649
650                                         // No content is default
651                                         $content['zip_content'] = '';
652
653                                         if (isPostRequestElementSet('zip')) {
654                                                 // Output entered ZIP code
655                                                 $content['zip_content'] = loadTemplate('member_order_zip2', TRUE, postRequestElement('zip'));
656                                         } // END - if
657
658                                         // No HTML extension installed by default
659                                         $content['html_extension'] = '<input type="hidden" name="html" value="N" />';
660
661                                         // HTML extension
662                                         if ((isExtensionActive('html_mail')) && (postRequestElement('html') == 'Y')) {
663                                                 // Extension is active so output valid HTML tags
664                                                 $content['html_extension'] = loadTemplate('member_order_html_ext', TRUE);
665                                         } // END - if
666
667                                         // Output form for page 2
668                                         loadTemplate('member_order_page2', FALSE, $content);
669                                 } else {
670                                         // No HTML extension installed by default
671                                         $content['html_extension'] = '<input type="hidden" name="html" value="N" />';
672
673                                         // Remember maybe entered ZIP code in constant
674                                         if (isExtensionActive('html_mail')) {
675                                                 // Add some content when html extension is active
676                                                 $content['html_extension'] = loadTemplate('member_order_html_intro', TRUE);
677                                         } // END - if
678
679                                         // Default is no ZIP code
680                                         $content['zip_content'] = '';
681
682                                         // Is sending to ZIP code enabled? (logged-in admin can always send to it)
683                                         if ((isOrderMultiPageEnabled()) || (isAdmin())) {
684                                                 // Yes
685                                                 if (postRequestElement('zip') > 0) {
686                                                         $data = array(
687                                                                 'zip' => bigintval(postRequestElement('zip'))
688                                                         );
689                                                 } else {
690                                                         $data = array(
691                                                                 'zip' => ''
692                                                         );
693                                                 }
694                                                 $content['zip_content'] = loadTemplate('member_order_zip1', TRUE, $data);
695                                         } // END - if
696
697                                         // Output form for page 1 (ZIP code or HTML)
698                                         loadTemplate('member_order_page1', FALSE, $content);
699                                 }
700                         } else {
701                                 // No mail types defined
702                                 displayMessage('<span class="bad">{--MEMBER_ORDER_NO_PAYMENTS--}</span>');
703                         }
704                 } else {
705                         // No points left
706                         displayMessage('<span class="bad">{--MEMBER_ORDER_NO_POINTS--}</span>');
707                 }
708         } else {
709                 // No cateogries are defined yet
710                 displayMessage('<span class="bad">{--MEMBER_NO_CATEGORIES--}</span>');
711         }
712 } else {
713         // Please confirm some mails first
714         displayMessage('<span class="notice">{%message,MEMBER_ORDER_LINKS_LEFT=' . getTotalUnconfirmedMails(getMemberId()) . '%}</span>');
715 }
716
717 if (!empty($data['url'])) {
718         // Redirect to requested URL
719         redirectToUrl($data['url']);
720 } // END - if
721
722 // [EOF]
723 ?>