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