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