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