Renamed all SQL-related functions to camel-case notation
[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 - 2013 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 = sqlQueryEscaped("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 (sqlNumRows($result) == 1) {
89                 // Load id and mail type
90                 $data = sqlFetchArray($result);
91         } // END - if
92
93         // Free result
94         sqlFreeResult($result);
95
96         if ($data['data_type'] == 'TEMP') {
97                 /*
98                  * No entry found, so we need to check out the stats table as well...
99                  * :) We have to add that suff here, now we continue WITHOUT checking
100                  * and check the text and subject against some filters
101                  */
102                 $data['url'] = '';
103                 if (!isAllowUrlInTextEnabled()) {
104                         // Test submitted text against some filters (length, URLs in text etc.)
105                         if ((isInStringIgnoreCase('https://', postRequestElement('text'))) || (isInStringIgnoreCase('http://', postRequestElement('text'))) || (isInStringIgnoreCase('www', postRequestElement('text')))) {
106                                 // URL found
107                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('URL_FOUND');
108                         } // END - if
109
110                         // Remove new-line and carriage-return characters
111                         $TEST = str_replace(array(PHP_EOL, chr(13)), array('', ''), postRequestElement('text'));
112
113                         // Text length within allowed length?
114                         if (strlen($TEST) > getMaxTextLength()) {
115                                 // Text is too long!
116                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('OVERLENGTH');
117                         } // END - if
118                 } // END - if
119
120                 // Shall I test the subject line against URLs?
121                 if (!isAllowUrlInSubjectEnabled()) {
122                         // Check the subject line for issues
123                         setPostRequestElement('subject', str_replace(chr(92), '[nl]', substr(postRequestElement('subject'), 0, 200)));
124                         if ((isInStringIgnoreCase('https://', postRequestElement('subject'))) || (isInStringIgnoreCase('http://', postRequestElement('subject'))) || (isInStringIgnoreCase('www', postRequestElement('subject')))) {
125                                 // URL in subject found
126                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('SUBJECT_URL');
127                         } // END - if
128                 } // END - if
129
130                 // And shall I check that his URL is not in the black list?
131                 if ((isExtensionActive('blacklist')) && (isUrlBlacklisted(postRequestElement('url')))) {
132                         // Create redirect-URL
133                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('BLIST_URL') . '&amp;blist=' . $GLOBALS['blacklist_data'][postRequestElement('url')]['timestamp'];
134                 } // END - if
135
136                 // Enougth receivers entered?
137                 if ((postRequestElement('receiver') < getOrderMin()) && (!isAdmin())) {
138                         // Less than allowed receivers entered!
139                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS3');
140                 } // END - if
141
142                 // Validate URL
143                 if (!isUrlValid(postRequestElement('url'))) {
144                         // URL is invalid!
145                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('INVALID_URL');
146                 } // END - if
147
148                 // Probe for HTML extension
149                 if (isExtensionActive('html_mail')) {
150                         // HTML or regular text mail?
151                         if (postRequestElement('html') == 'Y') {
152                                 // Chek for valid HTML tags
153                                 $checked = checkHtmlTags(postRequestElement('text')));
154
155                                 // Maybe invalid tags found?
156                                 if (empty($checked)) {
157                                         // Invalid HTML tags found
158                                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('INVALID_TAGS') . '&amp;id=' . $data['id'];
159                                 } // END - if
160                         } else {
161                                 // Remove any HTML code
162                                 setPostRequestElement('text', str_replace(array('<', '>'), array('{OPEN_HTML}', '{CLOSE_HTML}'), postRequestElement('text')));
163                         }
164                 } // END - if
165
166                 // Is mail type set?
167                 if ((!isPostRequestElementSet('mail_type')) || (postRequestElement('mail_type') < 1)) {
168                         // Not correctly set
169                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_MAIL_TYPE');
170                 } // END - if
171         } elseif (!isAdmin()) {
172                 // He has already sent a mail within a specific time
173                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('URL_TIME_LOCK') . '&amp;id=' . $data['id'];
174         }
175
176         // Still no error?
177         if (empty($data['url'])) {
178                 // Check for userids
179                 $result = sqlQueryEscaped("SELECT
180         `c`.`userid`
181 FROM
182         `{?_MYSQL_PREFIX?}_user_cats` AS `c`
183 INNER JOIN
184         `{?_MYSQL_PREFIX?}_user_data` AS `d`
185 ON
186         `c`.`userid`=`d`.`userid`
187 WHERE
188         `c`.`cat_id`=%s AND
189         `c`.`userid` != %s AND
190         `d`.`status`='CONFIRMED'
191         " . runFilterChain('user_exclusion_sql', ' ') . " AND
192         `d`.`receive_mails` > 0
193 ORDER BY
194         `d`.`{?order_select?}` {?order_mode?}",
195                         array(
196                                 bigintval(postRequestElement('cat')),
197                                 getMemberId()
198                         ), __FILE__, __LINE__);
199
200                 // Are there still receivers left?
201                 if (sqlNumRows($result) >= postRequestElement('receiver')) {
202                         // Load receivers from database
203                         $TEST = array(); $count = '0';
204                         while ($holidayContent = sqlFetchArray($result)) {
205                                 if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
206                                         // Check for his holiday status
207                                         $result_holiday = sqlQueryEscaped("SELECT
208         `id`
209 FROM
210         `{?_MYSQL_PREFIX?}_user_holidays`
211 WHERE
212         `userid`=%s AND
213         `holiday_start` < UNIX_TIMESTAMP() AND
214         `holiday_end` > UNIX_TIMESTAMP()
215 LIMIT 1",
216                                                 array($holidayContent['userid']), __FILE__, __LINE__);
217                                         if (sqlNumRows($result_holiday) == 1) {
218                                                 // Exclude user who are in holiday
219                                                 $holidayContent['userid'] = '0';
220                                         } // END - if
221
222                                         // Free memory
223                                         sqlFreeResult($result_holiday);
224                                 } // END - if
225
226                                 if (isValidId($holidayContent['userid'])) {
227                                         // Add receiver
228                                         array_push($TEST, $holidayContent['userid']);
229                                         $count++;
230                                 } // END - if
231                         } // END - while
232
233                         // Free memory
234                         sqlFreeResult($result);
235
236                         // Implode array into string for the sending pool
237                         $receiver = implode($TEST, ';');
238
239                         // Count array for maximum sent
240                         $content['target_send'] = count($TEST);
241
242                         // Update receiver list
243                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receive_mails`=`receive_mails`-1 WHERE `userid` IN (%s) LIMIT %s",
244                                 array(
245                                         convertReceivers($receiver),
246                                         bigintval($content['target_send'])
247                                 ), __FILE__, __LINE__);
248
249                         // Is calculated max receivers larger than wanted receivers then reset it
250                         if ($content['target_send'] > postRequestElement('receiver')) {
251                                 $content['target_send'] = bigintval(postRequestElement('receiver'));
252                         } // END - if
253
254                         // Calculate used points
255                         $usedPoints = $content['target_send'] * getPaymentPrice(bigintval(postRequestElement('mail_type')));
256
257                         // Fix empty zip code
258                         if (!isPostRequestElementSet('zip')) {
259                                 setPostRequestElement('zip', 0);
260                         } // END - if
261
262                         // Check if he has enougth points for this order and selected more than 0 receivers
263                         if (($usedPoints > 0) && ($usedPoints <= $totalPoints) && ($content['target_send'] > 0)) {
264                                 // Gettings points is okay, so we can add $usedPoints later from
265                                 if ((!isValidId($data['id'])) || ($data['data_type'] != 'TEMP')) {
266                                         // New order, init data array elements
267                                         $data = array(
268                                                 'sender'      => getMemberId(),
269                                                 'subject'     => postRequestElement('subject'),
270                                                 'text'        => postRequestElement('text'),
271                                                 'receivers'   => $receiver
272                                                 'payment_id'  => bigintval(postRequestElement('mail_type')),
273                                                 'data_type'   => 'TEMP',
274                                                 'timestamp'   => 'UNIX_TIMESTAMP()',
275                                                 'url'         => postRequestElement('url'),
276                                                 'cat_id'      => bigintval(postRequestElement('cat')),
277                                                 'target_send' => bigintval($content['target_send']),
278                                                 'zip'         => bigintval(postRequestElement('zip'), TRUE, FALSE),
279                                         );
280
281                                         // Is ext-html_mail active?
282                                         if (isExtensionActive('html_mail')) {
283                                                 // HTML extension is active
284                                                 $data['html_msg'] = postRequestElement('html');
285                                         } // END - if
286
287                                         // Get insert id
288                                         $data['id'] = insertDataIntoPool($data);
289                                 } else {
290                                         // Update this data
291                                         $data = array(
292                                                 'subject'     => postRequestElement('subject'),
293                                                 'text'        => postRequestElement('text'),
294                                                 'receivers'   => $receiver
295                                                 'payment_id'  => bigintval(postRequestElement('mail_type')),
296                                                 'timestamp'   => 'UNIX_TIMESTAMP()',
297                                                 'url'         => postRequestElement('url'),
298                                                 'cat_id'      => bigintval(postRequestElement('cat')),
299                                                 'target_send' => bigintval($content['target_send']),
300                                                 'zip'         => bigintval(postRequestElement('zip'), TRUE, FALSE),
301                                         );
302
303                                         // Is ext-html_mail active?
304                                         if (isExtensionActive('html_mail')) {
305                                                 // HTML extension is active
306                                                 $data['html_msg'] = postRequestElement('html');
307                                         } // END - if
308
309                                         // Update pool data
310                                         updatePoolDataById($data['id'], NULL, $data);
311                                 }
312
313                                 // Make sure only valid id numbers can pass
314                                 assert(isValidId($data['id']));
315
316                                 // Id is received so we can redirect the user, used points will be added when he send's out the mail
317                                 $data['url'] = 'modules.php?module=frametester&amp;order=' . bigintval($data['id']);
318                         } elseif ($content['target_send'] == '0') {
319                                 // Not enougth receivers found which can receive mails
320                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS2');
321                         } else {
322                                 // No enougth points left!
323                                 $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_POINTS');
324                         }
325                 } else {
326                         // Ordered more mails than he can send in this category
327                         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_RECS_LEFT');
328                 }
329         } // END - if
330 } elseif (postRequestElement('receiver') == '0') {
331         // Not enougth receivers selected
332         $data['url'] = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS1');
333 } elseif (($ALLOWED == '0') && (getOrderMaxFull() == 'ORDER')) {
334         // No more mail orders allowed
335         displayMessage('{--MEMBER_ORDER_ALLOWED_EXHAUSTED--}');
336 } elseif (getTotalUnconfirmedMails(getMemberId()) < getConfig('max_unconfirmed')) {
337         // Show only enabled categories to the user ...
338         $whereStatement = " WHERE `visible`='Y'";
339
340         // ... but all to the admin
341         if (isAdmin()) $whereStatement = '';
342
343         // Display order form
344         $result_cats = sqlQuery('SELECT
345         `id`,
346         `cat`
347 FROM
348         `{?_MYSQL_PREFIX?}_cats`
349 ' . $whereStatement . '
350 ORDER BY
351         `sort` ASC', __FILE__, __LINE__);
352
353         // Some categories found?
354         if (!ifSqlHasZeroNums($result_cats)) {
355                 // Enought points left?
356                 if ($totalPoints > 0) {
357                         // Initialize array...
358                         $categories = array(
359                                 'id'      => array(),
360                                 'name'    => array(),
361                                 'userids' => array()
362                         );
363
364                         // Enable HTML checking
365                         // @TODO Rewrite this to a filter
366                         $HTML = ''; $HOL_STRING = '';
367                         if ((isExtensionActive('html_mail')) && (postRequestElement('html') == 'Y')) {
368                                 $HTML = " AND `html`='Y'";
369                         } // END - if
370                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
371                                 // Extension's version is fine
372                                 $HOL_STRING = " AND `holiday_active`='N'";
373                         } // END - if
374
375                         // ... and begin loading stuff
376                         while ($categoriesContent = sqlFetchArray($result_cats)) {
377                                 $categories['id'][]   = bigintval($categoriesContent['id']);
378                                 array_push($categories['name'], $categoriesContent['cat']);
379
380                                 // Select users in current category
381                                 $result_userids = sqlQueryEscaped('SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s AND `userid` != %s ORDER BY `userid` ASC',
382                                         array(bigintval($categoriesContent['id']), getMemberId()), __FILE__, __LINE__);
383
384                                 $userid_cnt = '0';
385                                 while (list($userid) = sqlFetchRow($result_userids)) {
386                                         // Check for holiday system
387                                         $isHolidayActive = FALSE;
388                                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
389                                                 // Check user's holiday status
390                                                 $result_holiday = sqlQueryEscaped("SELECT
391         COUNT(`d`.`userid`) AS `cnt`
392 FROM
393         `{?_MYSQL_PREFIX?}_user_data` AS `d`
394 LEFT JOIN
395         `{?_MYSQL_PREFIX?}_user_holidays` AS `h`
396 ON
397         `d`.`userid`=`h`.`userid`
398 WHERE
399         `d`.`userid`=%s AND
400         `d`.`receive_mails` > 0 AND
401         `d`.`status`='CONFIRMED' AND
402         `d`.`holiday_active`='Y' AND
403         `h`.`holiday_start` < UNIX_TIMESTAMP() AND
404         `h`.`holiday_end` > UNIX_TIMESTAMP()
405 LIMIT 1",
406                                                         array(bigintval($userid)), __FILE__, __LINE__);
407
408                                                 // Fetch entry
409                                                 list($count) = sqlFetchRow($result_holiday);
410
411                                                 // Free memory
412                                                 sqlFreeResult($result_holiday);
413
414                                                 // Is holiday is active?
415                                                 $isHolidayActive = ($count == 1);
416                                         } // END - if
417
418                                         if ($isHolidayActive === FALSE) {
419                                                 // Check if the user want's to receive mails?
420                                                 $result_ver = sqlQueryEscaped("SELECT `zip` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s" . $HTML . " AND `receive_mails` > 0 AND `status`='CONFIRMED' LIMIT 1",
421                                                         array(bigintval($userid)), __FILE__, __LINE__);
422
423                                                 if ((sqlNumRows($result_ver) == 1) && (isPostRequestElementSet('zip')) && (isOrderMultiPageEnabled())) {
424                                                         // Get zip code
425                                                         list($zip) = sqlFetchRow($result_ver);
426                                                         if (substr($zip, 0, strlen(postRequestElement('zip'))) == postRequestElement('zip')) {
427                                                                 // Ok, ZIP code part is found
428                                                                 $userid_cnt++;
429                                                         } // END - if
430                                                 } else {
431                                                         // Count numbers up!
432                                                         $userid_cnt += sqlNumRows($result_ver);
433                                                 }
434
435                                                 // Free result
436                                                 sqlFreeResult($result_ver);
437                                         } // END - if
438                                 } // END - while
439
440                                 // Free memory
441                                 sqlFreeResult($result_userids);
442                                 array_push($categories['userids'], $userid_cnt);
443                         } // END - while
444
445                         // Free memory
446                         sqlFreeResult($result_cats);
447
448                         // Now we need to load the mail types...
449                         $result = sqlQuery("SELECT `id`, `price`, `payment`, `mail_title` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `price` > 0 AND `payment` > 0 ORDER BY `payment` ASC", __FILE__, __LINE__);
450
451                         $payments = array();
452                         if (!ifSqlHasZeroNums($result)) {
453                                 // Is the error code set?
454                                 if (isGetRequestElementSet('code')) {
455                                         // Display error message
456                                         displayMessage(getMessageFromErrorCode(getRequestElement('code')));
457                                 } // END - if
458
459                                 // Load all email types...
460                                 while ($payment = sqlFetchArray($result)) {
461                                         array_push($payments, $payment);
462                                 } // END - while
463
464                                 // Free memory
465                                 sqlFreeResult($result);
466
467                                 // Output user's points
468                                 $content['total_points'] = $totalPoints;
469
470                                 // Check how many mail orders he has placed today and how many he's allowed to send
471                                 switch (getOrderMaxFull()) {
472                                         case 'MAX': // He is allowed to send as much as possible
473                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_MAX--}';
474                                                 break;
475
476                                         case 'ORDER': // He is allowed to send as much as he setup the receiving value
477                                                 $content['order_max_full'] = sprintf(getMessage('MEMBER_ORDER_ALLOWED_RECEIVE'), $ALLOWED, getUserData('receive_mails'));
478                                                 break;
479
480                                         default: // Unknown/invalid
481                                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown order_mas_full config detected.", getOrderMaxFull()));
482                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_UNKNOWN--}';
483                                                 break;
484                                 } // END - switch
485
486                                 // Load final template
487                                 loadTemplate('member_order_points', FALSE, $content);
488
489                                 // Reset variables
490                                 $OLD_ORDER = FALSE;
491                                 $subject = '';
492                                 $text = '';
493                                 $target = '';
494
495                                 // Check if we already have an order placed and make it editable
496                                 $result = sqlQueryEscaped("SELECT
497         `subject`,
498         `text`,
499         `payment_id`,
500         `timestamp`,
501         `url`,
502         `target_send`,
503         `cat_id`,
504         `zip`
505 FROM
506         `{?_MYSQL_PREFIX?}_pool`
507 WHERE
508         `sender`=%s AND
509         `data_type`='TEMP'
510 LIMIT 1",
511                                         array(getMemberId()), __FILE__, __LINE__);
512
513                                 if (sqlNumRows($result) == 1) {
514                                         // Old order found
515                                         $content = merge_array($content, sqlFetchArray($result));
516
517                                         // Fix max receivers when it is too much
518                                         if ((isset($categories['userids'][$content['cat_id']])) && ($content['target_send'] > $categories['userids'][$content['cat_id']])) {
519                                                 // Fix it
520                                                 $content['target_send'] = $categories['userids'][$content['cat_id']];
521                                         } // END - if
522
523                                         // Old order is grabbed
524                                         $OLD_ORDER = TRUE;
525                                 } else {
526                                         // Default output for that your members don't forget it...
527                                         $content['url']         = 'http://';
528                                         $content['target_send'] = '{?order_min?}';
529                                         $content['subject']     = '';
530                                         $content['text']        = '';
531                                 }
532
533                                 // Free result
534                                 sqlFreeResult($result);
535
536                                 if ((isPostRequestElementSet('data')) || ((getOrderMultiPage() != 'Y') && ((!isAdmin()) && (!isExtensionActive('html_mail'))))) {
537                                         // Pre-output categories
538                                         $content['category_selection'] = generateCategoryOptionsList(((isExtensionActive('html_mail')) && (isPostRequestElementSet('html'))) ? postRequestElement('html') : 'N', getMemberId());
539
540                                         // Mail type
541                                         $content['payment_selection'] = '';
542                                         foreach ($payments as $key => $value) {
543                                                 if (is_array($value)) {
544                                                         // Output option line
545                                                         $content['payment_selection'] .= '      <option value="' . $payments[$key]['id'] . '"';
546                                                         if (($OLD_ORDER) && ($content['payment_id'] == $payments[$key]['id'])) $content['payment_selection'] .= ' selected="selected"';
547                                                         $content['payment_selection'] .= '>{%pipe,translateComma=' . $payments[$key]['price'] . '%} {--PER_MAIL--} - ' . $payments[$key]['mail_title'] . ' - ' . round($payments[$key]['payment']) . ' {--PAYMENT--}</option>';
548                                                 } // END - if
549                                         } // END - foreach
550
551                                         // No content is default
552                                         $content['zip_content'] = '';
553
554                                         if (isPostRequestElementSet('zip')) {
555                                                 // Output entered ZIP code
556                                                 $content['zip_content'] = loadTemplate('member_order_zip2', TRUE, postRequestElement('zip'));
557                                         } // END - if
558
559                                         // No HTML extension installed by default
560                                         $content['html_extension'] = '<input type="hidden" name="html" value="N" />';
561
562                                         // HTML extension
563                                         if ((isExtensionActive('html_mail')) && (postRequestElement('html') == 'Y')) {
564                                                 // Extension is active so output valid HTML tags
565                                                 $content['html_extension'] = loadTemplate('member_order_html_ext', TRUE);
566                                         } // END - if
567
568                                         // Output form for page 2
569                                         loadTemplate('member_order_page2', FALSE, $content);
570                                 } else {
571                                         // No HTML extension installed by default
572                                         $content['html_extension'] = '<input type="hidden" name="html" value="N" />';
573
574                                         // Remember maybe entered ZIP code in constant
575                                         if (isExtensionActive('html_mail')) {
576                                                 // Add some content when html extension is active
577                                                 $content['html_extension'] = loadTemplate('member_order_html_intro', TRUE);
578                                         } // END - if
579
580                                         // Default is no ZIP code
581                                         $content['zip_content'] = '';
582
583                                         // Is sending to ZIP code enabled? (logged-in admin can always send to it)
584                                         if ((isOrderMultiPageEnabled()) || (isAdmin())) {
585                                                 // Yes
586                                                 if (postRequestElement('zip') > 0) {
587                                                         $data = array(
588                                                                 'zip' => bigintval(postRequestElement('zip'))
589                                                         );
590                                                 } else {
591                                                         $data = array(
592                                                                 'zip' => ''
593                                                         );
594                                                 }
595                                                 $content['zip_content'] = loadTemplate('member_order_zip1', TRUE, $data);
596                                         } // END - if
597
598                                         // Output form for page 1 (ZIP code or HTML)
599                                         loadTemplate('member_order_page1', FALSE, $content);
600                                 }
601                         } else {
602                                 // No mail types defined
603                                 displayMessage('<span class="bad">{--MEMBER_ORDER_NO_PAYMENTS--}</span>');
604                         }
605                 } else {
606                         // No points left
607                         displayMessage('<span class="bad">{--MEMBER_ORDER_NO_POINTS--}</span>');
608                 }
609         } else {
610                 // No cateogries are defined yet
611                 displayMessage('<span class="bad">{--MEMBER_NO_CATEGORIES--}</span>');
612         }
613 } else {
614         // Please confirm some mails first
615         displayMessage('<span class="notice">{%message,MEMBER_ORDER_LINKS_LEFT=' . getTotalUnconfirmedMails(getMemberId()) . '%}</span>');
616 }
617
618 if (!empty($data['url'])) {
619         // Redirect to requested URL
620         redirectToUrl($data['url']);
621 } // END - if
622
623 // [EOF]
624 ?>