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