More EL used, this has fixed double calls of translateComma() in various places
[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, 2010 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 addMenuDescription('member', __FILE__);
45
46 if ((!isExtensionActive('order')) && (!isAdmin())) {
47         loadTemplate('admin_settings_saved', false, 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')) && (getUserData('holiday_active') == 'Y')) {
63         // Holiday is active!
64         loadTemplate('admin_settings_saved', false, '{--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         `timestamp` > (UNIX_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                 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 ((strpos(strtolower(postRequestParameter('text')), 'https://') > -1) || (strpos(strtolower(postRequestParameter('text')), 'http://') > -1) || (strpos(strtolower(postRequestParameter('text')), "www") > -1)) {
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("\n", '', str_replace("\r", '', postRequestParameter('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                         setPostRequestParameter('subject', str_replace("\\", '[nl]', substr(postRequestParameter('subject'), 0, 200)));
116                         if ((strpos(strtolower(postRequestParameter('subject')), 'http://') > -1) || (strpos(strtolower(postRequestParameter('subject')), "www") > -1)) {
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 (isUrlBlaskEnabled()) {
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(postRequestParameter('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 ((postRequestParameter('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(postRequestParameter('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 (postRequestParameter('html') == 'Y') {
156                                 // Chek for valid HTML tags
157                                 setPostRequestParameter('text', checkHtmlTags(postRequestParameter('text')));
158
159                                 // Maybe invalid tags found?
160                                 if (!isPostRequestParameterSet('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                                 setPostRequestParameter('text', str_replace('<', '{OPEN_HTML}', str_replace('>', '{CLOSE_HTML}', postRequestParameter('text'))));
164                         }
165                 } // END - if
166
167                 // Is mail type set?
168                 if ((!isPostRequestParameterSet('mail_type')) || (postRequestParameter('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 if category and number of receivers is okay
180                 $add = '';
181                 if ((getConfig('order_multi_page') == 'Y') && (isPostRequestParameterSet('zip')) && (postRequestParameter('zip') != '')) {
182                         // Choose recipients by ZIP code
183                         $add = sprintf(" AND d.zip LIKE '%s%%'",
184                                 bigintval(postRequestParameter('zip'))
185                         );
186                 } // END - if
187
188                 // Check for userids
189                 $result = SQL_QUERY_ESC("SELECT
190         c.userid
191 FROM
192         `{?_MYSQL_PREFIX?}_user_cats` AS c
193 LEFT JOIN
194         `{?_MYSQL_PREFIX?}_user_data` AS d
195 ON
196         c.userid=d.userid
197 WHERE
198         c.cat_id=%s AND
199         c.userid != '%s' AND
200         d.`status`='CONFIRMED' AND
201         d.receive_mails > 0
202         ".$add."
203 ORDER BY
204         d.{?order_select?} {?order_mode?}",
205                         array(
206                                 bigintval(postRequestParameter('cat')),
207                                 getMemberId()
208                         ), __FILE__, __LINE__);
209
210                 // Do we enougth receivers left?
211                 if (SQL_NUMROWS($result) >= postRequestParameter('receiver')) {
212                         // Load receivers from database
213                         $TEST = array(); $cnt = '0';
214                         while ($holidayContent = SQL_FETCHARRAY($result)) {
215                                 if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
216                                         // Check for his holiday status
217                                         $result_holiday = SQL_QUERY_ESC("SELECT
218         `id`
219 FROM
220         `{?_MYSQL_PREFIX?}_user_holidays`
221 WHERE
222         `userid`=%s AND `holiday_start` < UNIX_TIMESTAMP() AND `holiday_end` > UNIX_TIMESTAMP()
223 LIMIT 1",
224                                                 array($holidayContent['userid']), __FILE__, __LINE__);
225                                         if (SQL_NUMROWS($result_holiday) == 1) $holidayContent['userid'] = '0'; // Exclude user who are in holiday
226
227                                         // Free memory
228                                         SQL_FREERESULT($result_holiday);
229                                 } // END - if
230
231                                 if ($holidayContent['userid'] > 0) {
232                                         // Add receiver
233                                         $TEST[] = $holidayContent['userid'];
234                                         $cnt++;
235                                 } // END - if
236                         } // END - while
237
238                         // Free memory
239                         SQL_FREERESULT($result);
240
241                         // Implode array into string for the sending pool
242                         $receiver = implode($TEST, ';');
243
244                         // Count array for maximum sent
245                         $content['target_send'] = count($TEST);
246
247                         // Update receiver list
248                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receive_mails`=`receive_mails`-1 WHERE `userid` IN (%s) LIMIT %s",
249                                 array(
250                                         convertReceivers($receiver),
251                                         $content['target_send']
252                                 ), __FILE__, __LINE__);
253
254                         // Is calculated max receivers larger than wanted receivers then reset it
255                         if ($content['target_send'] > postRequestParameter('receiver')) $content['target_send'] = bigintval(postRequestParameter('receiver'));
256
257                         // Calculate used points
258                         $USED = $content['target_send'] * getPaymentPoints(bigintval(postRequestParameter('mail_type')));
259
260                         // Fix empty zip code
261                         if (!isPostRequestParameterSet('zip')) setPostRequestParameter('zip', 0);
262
263                         // Check if he has enougth points for this order and selected more than 0 receivers
264                         if (($USED > 0) && ($USED <= $total) && ($content['target_send'] > 0)) {
265                                 // Gettings points is okay, so we can add $USED 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 `{?_MYSQL_PREFIX?}_pool` (`sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `zip`, `html_msg`)
272 VALUES (%s,'%s','%s','%s','%s','TEMP',UNIX_TIMESTAMP(),'%s',%s,%s,%s,'%s')",
273                                                         array(
274                                                                 getMemberId(),
275                                                                 postRequestParameter('subject'),
276                                                                 postRequestParameter('text'),
277                                                                 $receiver,
278                                                                 bigintval(postRequestParameter('mail_type')),
279                                                                 postRequestParameter('url'),
280                                                                 bigintval(postRequestParameter('cat')),
281                                                                 $content['target_send'],
282                                                                 bigintval(postRequestParameter('zip'), true, false),
283                                                                 postRequestParameter('html')
284                                                         ), __FILE__, __LINE__);
285                                         } else {
286                                                 // No HTML extension is active
287                                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_pool` (`sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `zip`)
288 VALUES (%s,'%s','%s','%s','%s','TEMP',UNIX_TIMESTAMP(),'%s',%s,%s,%s)",
289                                                         array(
290                                                                 getMemberId(),
291                                                                 postRequestParameter('subject'),
292                                                                 postRequestParameter('text'),
293                                                                 $receiver,
294                                                                 bigintval(postRequestParameter('mail_type')),
295                                                                 postRequestParameter('url'),
296                                                                 bigintval(postRequestParameter('cat')),
297                                                                 $content['target_send'],
298                                                                 bigintval(postRequestParameter('zip'), true, false),
299                                                         ), __FILE__, __LINE__);
300                                         }
301                                 } else {
302                                         // Change current order
303                                         if (isExtensionActive('html_mail')) {
304                                                 // HTML extension is active
305                                                 SQL_QUERY_ESC("UPDATE
306         `{?_MYSQL_PREFIX?}_pool`
307 SET
308         `subject`='%s',
309         `text`='%s',
310         `receivers`='%s',
311         `payment_id`=%s,
312         `timestamp`=UNIX_TIMESTAMP(),
313         `url`='%s',
314         `cat_id`=%s,
315         `target_send`=%s,
316         `zip`=%s,
317         `html_msg`='%s'
318 WHERE
319         `id`=%s
320 LIMIT 1",
321                                                         array(
322                                                                 postRequestParameter('subject'),
323                                                                 postRequestParameter('text'),
324                                                                 $receiver,
325                                                                 bigintval(postRequestParameter('mail_type')),
326                                                                 postRequestParameter('url'),
327                                                                 bigintval(postRequestParameter('cat')),
328                                                                 $content['target_send'],
329                                                                 bigintval(postRequestParameter('zip')),
330                                                                 postRequestParameter('html'),
331                                                                 bigintval($id)
332                                                         ), __FILE__, __LINE__);
333                                         } else {
334                                                 // No HTML extension is active
335                                                 SQL_QUERY_ESC("UPDATE
336         `{?_MYSQL_PREFIX?}_pool`
337 SET
338         `subject`='%s',
339         `text`='%s',
340         `receivers`='%s',
341         `payment_id`=%s,
342         `timestamp`=UNIX_TIMESTAMP(),
343         `url`='%s',
344         `cat_id`=%s,
345         `target_send`=%s,
346         `zip`=%s
347 WHERE
348         `id`=%s
349 LIMIT 1",
350                                                         array(
351                                                                 postRequestParameter('subject'),
352                                                                 postRequestParameter('text'),
353                                                                 $receiver,
354                                                                 bigintval(postRequestParameter('mail_type')),
355                                                                 postRequestParameter('url'),
356                                                                 bigintval(postRequestParameter('cat')),
357                                                                 $content['target_send'],
358                                                                 bigintval(postRequestParameter('zip')),
359                                                                 bigintval($id)
360                                                         ), __FILE__, __LINE__);
361                                         }
362                                 }
363
364                                 // Do we need to get the id number?
365                                 if ($id == '0') {
366                                         // Order is placed as temporary. We need to get it's id for the frametester
367                                         $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",
368                                                 array(
369                                                         getMemberId(),
370                                                         postRequestParameter('subject'),
371                                                         bigintval(postRequestParameter('mail_type'))
372                                                 ), __FILE__, __LINE__);
373
374                                         // Get pool id
375                                         list($id) = SQL_FETCHROW($result);
376
377                                         // Free result
378                                         SQL_FREERESULT($result);
379                                 } // END - if
380
381                                 // id is received so we can redirect the user, used points will be added when he send's out the mail
382                                 $url = 'modules.php?module=frametester&amp;order=' . $id;
383                         } elseif ($content['target_send'] == '0') {
384                                 // Not enougth receivers found which can receive mails
385                                 $url = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS2');
386                         } else {
387                                 // No enougth points left!
388                                 $url = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_POINTS');
389                         }
390                 } else {
391                         // Ordered more mails than he can send in this category
392                         $url = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('NO_RECS_LEFT');
393                 }
394         } // END - if
395 } elseif (postRequestParameter('receiver') == '0') {
396         // Not enougth receivers selected
397         $url = 'modules.php?module=login&amp;what=order&amp;code=' . getCode('MORE_RECEIVERS1');
398 } elseif (($ALLOWED == '0') && (getConfig('order_max_full') == 'ORDER')) {
399         // No more mail orders allowed
400         loadTemplate('admin_settings_saved', false, '{--MEMBER_ORDER_ALLOWED_EXHAUSTED--}');
401 } elseif ($links < getConfig('unconfirmed')) {
402         // Show only enabled categories to the user ...
403         $whereStatement = " WHERE `visible`='Y'";
404
405         // ... but all to the admin
406         if (isAdmin()) $whereStatement = '';
407
408         // Display order form
409         $result_cats = SQL_QUERY("SELECT
410         `id`, `cat`
411 FROM
412         `{?_MYSQL_PREFIX?}_cats`
413 ".$whereStatement."
414 ORDER BY
415         `sort` ASC", __FILE__, __LINE__);
416         if (!SQL_HASZERONUMS($result_cats)) {
417                 if ($total > 0) {
418                         // Initialize array...
419                         $categories = array(
420                                 'id'      => array(),
421                                 'name'    => array(),
422                                 'userids' => array()
423                         );
424
425                         // Enable HTML checking
426                         // @TODO Rewrite this to a filter
427                         $HTML = ''; $HOL_STRING = '';
428                         if ((isExtensionActive('html_mail')) && (postRequestParameter('html') == 'Y')) $HTML = " AND `html`='Y'";
429                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
430                                 // Extension's version is fine
431                                 $HOL_STRING = " AND `holiday_active`='N'";
432                         } // END - if
433
434                         // ... and begin loading stuff
435                         while ($categoriesContent = SQL_FETCHARRAY($result_cats)) {
436                                 $categories['id'][]   = bigintval($categoriesContent['id']);
437                                 $categories['name'][] = $categoriesContent['cat'];
438
439                                 // Select users in current category
440                                 $result_userids = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s AND `userid` != '%s' ORDER BY `userid` ASC",
441                                         array(bigintval($categoriesContent['id']), getMemberId()), __FILE__, __LINE__);
442
443                                 $userid_cnt = '0';
444                                 while (list($ucat) = SQL_FETCHROW($result_userids)) {
445                                         // Check for holiday system
446                                         $isHolidayActive = false;
447                                         if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
448                                                 // Check user's holiday status
449                                                 $result_holiday = SQL_QUERY_ESC("SELECT
450         COUNT(d.userid) AS `cnt`
451 FROM
452         `{?_MYSQL_PREFIX?}_user_data` AS d
453 LEFT JOIN
454         `{?_MYSQL_PREFIX?}_user_holidays` AS h
455 ON
456         d.userid=h.userid
457 WHERE
458         d.userid=%s AND
459         d.receive_mails > 0 AND
460         d.`status`='CONFIRMED' AND
461         d.`holiday_active`='Y' AND
462         h.holiday_start < UNIX_TIMESTAMP() AND
463         h.holiday_end > UNIX_TIMESTAMP()
464 LIMIT 1",
465                                                         array(bigintval($ucat)), __FILE__, __LINE__);
466
467                                                 // Fetch entry
468                                                 list($cnt) = SQL_FETCHROW($result_holiday);
469
470                                                 // Free memory
471                                                 SQL_FREERESULT($result_holiday);
472
473                                                 // Is holiday is active?
474                                                 $isHolidayActive = ($cont == 1);
475                                         } // END - if
476
477                                         if ($isHolidayActive === false) {
478                                                 // Check if the user want's to receive mails?
479                                                 $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",
480                                                         array(bigintval($ucat)), __FILE__, __LINE__);
481
482                                                 if ((SQL_NUMROWS($result_ver) == 1) && (isPostRequestParameterSet('zip')) && (getConfig('order_multi_page') == 'Y')) {
483                                                         // Get zip code
484                                                         list($zip) = SQL_FETCHROW($result_ver);
485                                                         if (substr($zip, 0, strlen(postRequestParameter('zip'))) == postRequestParameter('zip')) {
486                                                                 // Ok, ZIP part is found
487                                                                 $userid_cnt++;
488                                                         } // END - if
489                                                 } else {
490                                                         // Count numbers up!
491                                                         $userid_cnt += SQL_NUMROWS($result_ver);
492                                                 }
493
494                                                 // Free result
495                                                 SQL_FREERESULT($result_ver);
496                                         } // END - if
497                                 } // END - while
498
499                                 // Free memory
500                                 SQL_FREERESULT($result_userids);
501                                 $categories['userids'][] = $userid_cnt;
502                         } // END - while
503
504                         // Free memory
505                         SQL_FREERESULT($result_cats);
506
507                         // Now we need to load the mail types...
508                         $result = SQL_QUERY("SELECT `id`, `price`, `payment`, `mail_title` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `payment` ASC", __FILE__, __LINE__);
509
510                         $types = array();
511                         if (!SQL_HASZERONUMS($result)) {
512                                 // Check for message id in URL
513                                 $message = getMessageFromErrorCode(getRequestParameter('code'));
514
515                                 if (!empty($message)) {
516                                         // We got system message so we drop it out to the user
517                                         loadTemplate('admin_settings_saved', false, $message);
518                                 } // END - if
519
520                                 // Load all email types...
521                                 while ($types[] = SQL_FETCHROW($result)) {
522                                         // Nothing to do here... ;-)
523                                 } // END - while
524
525                                 // Free memory
526                                 SQL_FREERESULT($result);
527
528                                 // Output user's points
529                                 $content['total'] = $total;
530
531                                 // Check how many mail orders he has placed today and how many he's allowed to send
532                                 switch (getConfig('order_max_full')) {
533                                         case 'MAX': // He is allowed to send as much as possible
534                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_MAX--}';
535                                                 break;
536
537                                         case 'ORDER': // He is allowed to send as much as he setup the receiving value
538                                                 $content['order_max_full'] = sprintf(getMessage('MEMBER_ORDER_ALLOWED_RECEIVE'), $ALLOWED, getUserData('receive_mails'));
539                                                 break;
540
541                                         default: // Unknown/invalid
542                                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown order_mas_full config detected.", getConfig('order_max_full')));
543                                                 $content['order_max_full'] = '{--MEMBER_ORDER_ALLOWED_UNKNOWN--}';
544                                                 break;
545                                 } // END - switch
546
547                                 // Load final template
548                                 loadTemplate('member_order_points', false, $content);
549
550                                 // Reset variables
551                                 $OLD_ORDER = false;
552                                 $subject = '';
553                                 $text = '';
554                                 $target = '';
555
556                                 // Check if we already have an order placed and make it editable
557                                 $result = SQL_QUERY_ESC("SELECT
558         `subject`, `text`, `payment_id`, `timestamp`, `url`, `target_send`, `cat_id`, `zip`
559 FROM
560         `{?_MYSQL_PREFIX?}_pool`
561 WHERE
562         `sender`=%s AND
563         `data_type`='TEMP'
564 LIMIT 1",
565                                         array(getMemberId()), __FILE__, __LINE__);
566
567                                 if (SQL_NUMROWS($result) == 1) {
568                                         // Old order found
569                                         $content = merge_array($content, SQL_FETCHARRAY($result));
570
571                                         // Fix max receivers when it is too much
572                                         if ((isset($categories['userids'][$content['cat_id']])) && ($content['target_send'] > $categories['userids'][$content['cat_id']])) {
573                                                 // Fix it
574                                                 $content['target_send'] = $categories['userids'][$content['cat_id']];
575                                         } // END - if
576
577                                         // Old order is grabbed
578                                         $OLD_ORDER = true;
579                                 } else {
580                                         // Default output for that your members don't forget it...
581                                         $content['url']         = 'http://';
582                                         $content['target_send'] = '{?order_min?}';
583                                         $content['subject']     = '{--ORDER_DEFAULT_SUBJECT--}';
584                                         $content['text']        = '{--ORDER_DEFAULT_TEXT--}';
585                                 }
586
587                                 // Free result
588                                 SQL_FREERESULT($result);
589
590                                 if ((isPostRequestParameterSet('data')) || ((getConfig('order_multi_page') != 'Y') && ((!isAdmin()) && (!isExtensionActive('html_mail'))))) {
591                                         // Pre-output categories
592                                         $content['category_selection'] = '';
593                                         foreach ($categories['id'] as $key => $value) {
594                                                 $content['category_selection'] .= '      <option value="' . $value . '"';
595                                                 if (($OLD_ORDER) && ($content['cat_id'] == $value)) $content['category_selection'] .= ' selected="selected"';
596                                                 $content['category_selection'] .= '>' . $categories['name'][$key]." (".$categories['userids'][$key] . ' {--USER_IN_CAT--})</option>';
597                                         } // END - foreach
598
599                                         // Mail type
600                                         $content['type_selection'] = '';
601                                         foreach ($types as $key => $value) {
602                                                 if (is_array($value)) {
603                                                         // Output option line
604                                                         $content['type_selection'] .= '      <option value="' . $types[$key][0] . '"';
605                                                         if (($OLD_ORDER) && ($content['payment_id'] == $types[$key][0])) $content['type_selection'] .= ' selected="selected"';
606                                                         $content['type_selection'] .= '>{%pipe,translateComma=' . $types[$key][1] . '%} {--PER_MAIL--} - ' . $types[$key][3] . ' - ' . round($types[$key][2]) . ' {--PAYMENT--}</option>';
607                                                 } // END - if
608                                         } // END - foreach
609
610                                         // No content is default
611                                         $content['zip_content'] = '';
612
613                                         if (isPostRequestParameterSet('zip')) {
614                                                 // Output entered ZIP code
615                                                 $content['zip_content'] = loadTemplate('member_order-zip2', true, postRequestParameter('zip'));
616                                         } // END - if
617
618                                         // HTML extension
619                                         if ((isExtensionActive('html_mail')) && (postRequestParameter('html') == 'Y')) {
620                                                 // Extension is active so output valid HTML tags
621                                                 $content['html_extension'] = loadTemplate('member_order-html_ext', true, addValidHtmlTags());
622                                         } else {
623                                                 // Extension not active and/or class not uploaded
624                                                 $content['html_extension'] = '<tr><td colspan="3"><input type="hidden" name="html" value="N" /></td></tr>';
625                                         }
626
627                                         // Output form for page 2
628                                         loadTemplate('member_order_page2', false, $content);
629                                 } else {
630                                         // Remember maybe entered ZIP code in constant
631                                         if (isExtensionActive('html_mail')) {
632                                                 // Add some content when html extension is active
633                                                 $content['html_extension'] = loadTemplate('member_order-html_intro', true);
634                                         } else {
635                                                 // No HTML extension installed
636                                                 $content['html_extension'] = '<tr><td colspan="3"><input type="hidden" name="html" value="N" /></td></tr>';
637                                         }
638
639                                         // Default is no ZIP code
640                                         $content['zip_content'] = '';
641
642                                         // Do we want ZIP code or not?
643                                         if ((getConfig('order_multi_page') == 'Y') || (isAdmin())) {
644                                                 // Yes
645                                                 if (postRequestParameter('zip') > 0) {
646                                                         $data = array(
647                                                                 'zip' => bigintval(postRequestParameter('zip'))
648                                                         );
649                                                 } else {
650                                                         $data = array(
651                                                                 'zip' => ''
652                                                         );
653                                                 }
654                                                 $content['zip_content'] = loadTemplate('member_order-zip1', true, $data);
655                                         } // END - if
656
657                                         // Output form for page 1 (ZIP code or HTML)
658                                         loadTemplate('member_order_page1', false, $content);
659                                 }
660                         } else {
661                                 // No mail types defined
662                                 loadTemplate('admin_settings_saved', false, '<span class="notice">{--MEMBER_NO_PAYMENTS--}</span>');
663                         }
664                 } else {
665                         // No points left
666                         loadTemplate('admin_settings_saved', false, '<span class="notice">{--MEMBER_NO_POINTS--}</span>');
667                 }
668         } else {
669                 // No cateogries are defined yet
670                 loadTemplate('admin_settings_saved', false, '<span class="notice">{--MEMBER_NO_CATEGORIES--}</span>');
671         }
672 } else {
673         // Please confirm some mails first
674         loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_LINKS_LEFT'), $links);
675 }
676
677 if (!empty($url)) {
678         // Redirect to requested URL
679         redirectToUrl($url);
680 } // END - if
681
682 // [EOF]
683 ?>