Continue link added, contributed by profi-concept. Partly resolves #3
[mailer.git] / inc / modules / member / what-order.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("order")) && (!IS_ADMIN())) {
41         addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "order");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
47
48 $URL = ""; $id = 0;
49 $whereStatement = " WHERE `visible`='Y'";
50
51 // Set undefined array elements
52 if (empty($_GET['msg']))       $_GET['msg']       = "";
53 if (empty($_POST['zip']))      $_POST['zip']      = "";
54 if (empty($_POST['html']))     $_POST['html']     = "";
55 if (empty($_POST['receiver'])) $_POST['receiver'] = "";
56 if (IS_ADMIN()) $whereStatement = "";
57
58 // Minimum mails / order
59 define('__MIN_VALUE', getConfig('order_min'));
60
61 // Count unconfirmed mails
62 $links = GET_TOTAL_DATA($GLOBALS['userid'], "user_links", "id", "userid", true);
63
64 // Does the user has more than 0 mails per day set?
65 $HOLIDAY = "userid";
66 if (GET_EXT_VERSION("holiday") >= "0.1.3") {
67         // Fetch also holiday activation data
68         $HOLIDAY = "holiday_active";
69 } // END - if
70
71 $result_mmails = SQL_QUERY_ESC("SELECT userid, receive_mails, mail_orders, ".$HOLIDAY."
72 FROM `{!_MYSQL_PREFIX!}_user_data`
73 WHERE userid=%s AND max_mails > 0 LIMIT 1",
74         array($GLOBALS['userid']), __FILE__, __LINE__);
75
76 $mmails = SQL_NUMROWS($result_mmails);
77 list($DMY, $MAXI, $ORDERS, $HOLIDAY) = SQL_FETCHROW($result_mmails);
78 SQL_FREERESULT($result_mmails);
79 if ($HOLIDAY == $DMY) $HOLIDAY='N';
80
81 $ALLOWED = $MAXI - $ORDERS;
82 if (getConfig('order_max_full') == "MAX") $ALLOWED = $MAXI;
83
84 // Now check his points amount
85 $TOTAL = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");;
86
87 if (($HOLIDAY == "Y") && (GET_EXT_VERSION("holiday") >= "0.1.3")) {
88         // Holiday is active!
89         LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_ORDER_NOT_POSSIBLE);
90 } elseif ((!empty($_POST['frametester'])) && ($ALLOWED > 0) && ($_POST['receiver'] > 0)) {
91         // Continue with the frametester, we first need to store the data temporary in the pool
92         //
93         // First we would like to store the data and get it's pool position back...
94         $result = SQL_QUERY_ESC("SELECT id, data_type
95 FROM `{!_MYSQL_PREFIX!}_pool`
96 WHERE sender=%s AND url='%s' AND timestamp > (UNIX_TIMESTAMP() - %s) LIMIT 1",
97                 array($GLOBALS['userid'], $_POST['url'], getConfig('url_tlock')), __FILE__, __LINE__);
98
99         $type = "TEMP"; $id = 0;
100         if (SQL_NUMROWS($result) == 1) {
101                 // Load id and mail type
102                 list($id, $type) = SQL_FETCHROW($result);
103         } // END - if
104
105         // Free result
106         SQL_FREERESULT($result);
107
108         if ($type == "TEMP") {
109                 // No entry found, so we need to check out the stats table as well... :)
110                 // We have to add that suff here, now we continue WITHOUT checking and check the text and subject against some filters
111                 $URL = "";
112                 if (getConfig('test_text') == "Y") {
113                         // Test submitted text against some filters (length, URLs in text etc.)
114                         if ((strpos(strtolower($_POST['text']), "https://") > -1) || (strpos(strtolower($_POST['text']), "http://") > -1) || (strpos(strtolower($_POST['text']), "www") > -1)) {
115                                 // URL found!
116                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_URL_FOUND');
117                         } // END - if
118
119                         // Remove new-line and carriage-return characters
120                         $TEST = str_replace("\n", "", str_replace("\r", "", $_POST['text']));
121
122                         // Text length within allowed length?
123                         if (strlen($TEST) > getConfig('max_tlength')) {
124                                 // Text is too long!
125                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_OVERLENGTH');
126                         } // END - if
127                 } // END - if
128
129                 // Shall I test the subject line against URLs?
130                 if (getConfig('test_subj') == "Y") {
131                         // Check the subject line for issues
132                         $_POST['subject'] = str_replace("\\", "[nl]", substr($_POST['subject'], 0, 200));
133                         if ((strpos(strtolower($_POST['subject']), "http://") > -1) || (strpos(strtolower($_POST['subject']), "www") > -1)) {
134                                 // URL in subject found
135                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_SUBJ_URL');
136                         } // END - if
137                 } // END - if
138
139                 // And shall I check that his URL is not in the black list?
140                 if (getConfig('url_blacklist') == "Y") {
141                         // Ok, I do that for you know...
142                         $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`timestamp`) AS tstamp FROM `{!_MYSQL_PREFIX!}_url_blacklist` WHERE `url`='%s' LIMIT 1",
143                                 array($_POST['url']), __FILE__, __LINE__);
144
145                         if (SQL_NUMROWS($result) == 1) {
146                                 // Jupp, we got one listed
147                                 list($blist) = SQL_FETCHROW($result);
148
149                                 // Create redirect-URL
150                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_BLIST_URL')."&blist=".$blist;
151                         } // END - if
152
153                         // Free result
154                         SQL_FREERESULT($result);
155                 } // END - if
156
157                 // Enougth receivers entered?
158                 if (($_POST['receiver'] < getConfig('order_min')) && (!IS_ADMIN())) {
159                         // Less than allowed receivers entered!
160                         $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_MORE_RECEIVERS3');
161                 } // END - if
162
163                 // Validate URL
164                 if (!VALIDATE_URL($_POST['url'])) {
165                         // URL is invalid!
166                         $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_INVALID_URL');
167                 } // END - if
168
169                 // Probe for HTML extension
170                 if (EXT_IS_ACTIVE("html_mail")) {
171                         // HTML or regular text mail?
172                         if ($_POST['html'] == "Y") {
173                                 // Chek for valid HTML tags
174                                 $_POST['text'] = HTML_CHECK_TAGS($_POST['text']);
175
176                                 // Maybe invalid tags found?
177                                 if (empty($_POST['text'])) $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_INVALID_TAGS')."&amp;id=".$id;
178                         } else {
179                                 // Remove any HTML code
180                                 $_POST['text'] = str_replace("<", "{OPEN_HTML}", str_replace(">", "{CLOSE_HTML}", $_POST['text']));
181                         }
182                 }
183         } elseif (!IS_ADMIN()) {
184                 // He has already sent a mail within a specific time
185                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_URL_TLOCK')."&amp;id=".$id;
186         }
187
188         // Still no error?
189         if (empty($URL)) {
190                 // Check if category and number of receivers is okay
191                 $ADD = "";
192                 if ((getConfig('order_multi_page') == "Y") && (!empty($_POST['zip']))) {
193                         // Choose recipients by ZIP code
194                         $ADD = " AND d.zip LIKE '".bigintval($_POST['zip'])."{PER}'";
195                 } // END - if
196
197                 // Check for userids
198                 $result = SQL_QUERY_ESC("SELECT DISTINCT c.userid FROM `{!_MYSQL_PREFIX!}_user_cats` AS c
199 LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
200 ON c.userid=d.userid
201 WHERE c.cat_id=%s AND c.userid != '%s' AND d.`status`='CONFIRMED' AND d.receive_mails > 0".$ADD."
202 ORDER BY d.%s %s",
203  array(
204         bigintval($_POST['cat']),
205         $GLOBALS['userid'],
206         getConfig('order_select'),
207         getConfig('order_mode'),
208  ), __FILE__, __LINE__);
209
210                 // Do we enougth receivers left?
211                 if (SQL_NUMROWS($result) >= $_POST['receiver']) {
212                         // Check for holiday extensions
213                         $HOLIDAY = false;
214                         if (GET_EXT_VERSION("holiday") >= "0.1.3") {
215                                 // Include checking for users in holiday
216                                 $HOLIDAY = true;
217                         } // END - if
218
219                         // Load receivers from database
220                         $TEST = array(); $cnt = 0;
221                         while (list($REC) = SQL_FETCHROW($result)) {
222                                 if ($HOLIDAY) {
223                                         // Check for his holiday status
224                                         $result_holiday = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_holidays`
225 WHERE userid=%s AND holiday_start < UNIX_TIMESTAMP() AND holiday_end > UNIX_TIMESTAMP() LIMIT 1",
226  array(bigintval($REC)), __FILE__, __LINE__);
227                                         if (SQL_NUMROWS($result_holiday) == 1) $REC = 0; // Exclude user who are in holiday
228
229                                         // Free memory
230                                         SQL_FREERESULT($result_holiday);
231                                 } // END - if
232
233                                 if ($REC > 0) {
234                                         // Add receiver
235                                         $TEST[] = $REC;
236                                         $cnt++;
237                                 } // END - if
238                         } // END - while
239
240                         // Free memory
241                         SQL_FREERESULT($result);
242
243                         // Implode array into string for the sending pool
244                         $RECEIVER = implode($TEST, ";");
245
246                         // Count array for maximum sent
247                         $MAX_SEND = count($TEST);
248
249                         // Update receiver list
250                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET receive_mails=receive_mails-1 WHERE userid IN (%s) LIMIT %s",
251                                 array(str_replace(";", ", ", $RECEIVER), $MAX_SEND), __FILE__, __LINE__);
252
253                         // Is calculated max receivers larger than wanted receivers then reset it
254                         if ($MAX_SEND > $_POST['receiver']) $MAX_SEND = $_POST['receiver'];
255
256                         // Calculate used points
257                         $USED = $MAX_SEND * GET_PAY_POINTS(bigintval($_POST['type']));
258
259                         // Fix empty zip code
260                         if (empty($_POST['zip'])) $_POST['zip'] = "0";
261
262                         // Check if he has enougth points for this order and selected more than 0 receivers
263                         if (($USED > 0) && ($USED <= $TOTAL) && ($MAX_SEND > 0)) {
264                                 // Gettings points is okay, so we can add $USED later from
265                                 $TIME = time();
266                                 if (($id == "0") || ($type != "TEMP")) {
267                                         // New order
268                                         $id = 0;
269                                         if (EXT_IS_ACTIVE("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','%s','%s','%s','%s','%s','%s')",
273 array(
274         $GLOBALS['userid'],
275         $_POST['subject'],
276         $_POST['text'],
277         $RECEIVER,
278         bigintval($_POST['type']),
279         $TIME,
280         $_POST['url'],
281         bigintval($_POST['cat']),
282         $MAX_SEND,
283         bigintval($_POST['zip']),
284         $_POST['html']
285 ), __FILE__, __LINE__);
286                                         } else {
287                                                 // No HTML extension is active
288                                                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_pool` (sender, subject, text, receivers, payment_id, data_type, timestamp, url, cat_id, target_send, zip)
289  VALUES ('%s','%s','%s','%s','%s','TEMP','%s','%s','%s','%s','%s')",
290 array(
291         $GLOBALS['userid'],
292         $_POST['subject'],
293         $_POST['text'],
294         $RECEIVER,
295         bigintval($_POST['type']),
296         $TIME,
297         $_POST['url'],
298         bigintval($_POST['cat']),
299         $MAX_SEND,
300         bigintval($_POST['zip']),
301 ), __FILE__, __LINE__);
302                                         }
303                                 } else {
304                                         // Change current order
305                                         if (EXT_IS_ACTIVE("html_mail")) {
306                                                 // HTML extension is active
307                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` 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 id=%s LIMIT 1",
319 array(
320         $_POST['subject'],
321         $_POST['text'],
322         $RECEIVER,
323         bigintval($_POST['type']),
324         $_POST['url'],
325         bigintval($_POST['cat']),
326         $MAX_SEND,
327         bigintval($_POST['zip']),
328         $_POST['html'],
329         bigintval($id)
330 ), __FILE__, __LINE__);
331                                         } else {
332                                                 // No HTML extension is active
333                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET
334 subject='%s',
335 text='%s',
336 receivers='%s',
337 payment_id=%s,
338 timestamp=UNIX_TIMESTAMP(),
339 url='%s',
340 cat_id=%s,
341 target_send=%s,
342 zip=%s
343 WHERE id=%s LIMIT 1",
344 array(
345         $_POST['subject'],
346         $_POST['text'],
347         $RECEIVER,
348         bigintval($_POST['type']),
349         $_POST['url'],
350         bigintval($_POST['cat']),
351         $MAX_SEND,
352         bigintval($_POST['zip']),
353         bigintval($id)
354 ), __FILE__, __LINE__);
355                                         }
356                                 }
357
358                                 // Do we need to get the ID number?
359                                 if ($id == 0) {
360                                         // Order is placed as temporary. We need to get it's id for the frametester
361                                         $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=%s LIMIT 1",
362                                         array(
363                                                 $GLOBALS['userid'],
364                                                 $_POST['subject'],
365                                                 bigintval($_POST['type']),
366                                                 $TIME
367                                         ), __FILE__, __LINE__);
368
369                                         list($id) = SQL_FETCHROW($result);
370                                         SQL_FREERESULT($result);
371                                 }
372
373                                 // ID is received so we can redirect the user, used points will be added when he send's out the mail
374                                 $URL = "modules.php?module=frametester&amp;order=".$id."";
375                         } elseif ($MAX_SEND == 0) {
376                                 // Not enougth receivers found which can receive mails
377                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_MORE_RECEIVERS2');
378                         } else {
379                                 // No enougth points left!
380                                 $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_MORE_POINTS');
381                         }
382                 } else  {
383                         // Ordered more mails than he can send in this category
384                         $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_NO_RECS_LEFT');
385                 }
386         }
387 } elseif ($_POST['receiver'] == "0") {
388         // Not enougth receivers selected
389         $URL = "modules.php?module=login&amp;what=order&amp;msg=".constant('CODE_MORE_RECEIVERS1');
390 } elseif (($ALLOWED == 0) && (getConfig('order_max_full') == "ORDER")) {
391         // No more mail orders allowed
392         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_ORDER_ALLOWED_EXHAUSTED'));
393 } elseif (($links < getConfig('unconfirmed')) && ($mmails == "1")) {
394         // Display order form
395         $result_cats = SQL_QUERY("SELECT id, cat FROM `{!_MYSQL_PREFIX!}_cats`".$whereStatement." ORDER BY `sort`", __FILE__, __LINE__);
396         if (SQL_NUMROWS($result_cats) > 0) {
397                 if ($TOTAL > 0) {
398                         // Initialize array...
399                         $CATS = array(
400                                 'id'   => array(),
401                                 'name' => array(),
402                                 'uids' => array()
403                         );
404
405                         // Enable HTML checking
406                         $HTML = ""; $HOLIDAY = false; $HOL_STRING = "";
407                         if ((EXT_IS_ACTIVE("html_mail")) && ($_POST['html'] == "Y")) $HTML = " AND html='Y'";
408                         if (GET_EXT_VERSION("holiday") >= "0.1.3") {
409                                 // Extension's version is fine
410                                 $HOLIDAY = true; $HOL_STRING = " AND holiday_active='N'";
411                         } // END - if
412
413                         // ... and begin loading stuff
414                         while (list($id, $cat) = SQL_FETCHROW($result_cats)) {
415                                 $CATS['id'][]   = bigintval($id);
416                                 $CATS['name'][] = $cat;
417
418                                 // Select users in current category
419                                 $result_uids = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s AND userid != '%s' ORDER BY userid",
420                                         array(bigintval($id), $GLOBALS['userid']), __FILE__, __LINE__);
421
422                                 $uid_cnt = 0;
423                                 while (list($ucat) = SQL_FETCHROW($result_uids)) {
424                                         // Check for holiday system
425                                         $HOL_ACTIVE = false;
426                                         if ($HOLIDAY) {
427                                                 // Check user's holiday status
428                                                 $result_holiday = SQL_QUERY_ESC("SELECT DISTINCT d.userid FROM `{!_MYSQL_PREFIX!}_user_data` AS d
429 LEFT JOIN `{!_MYSQL_PREFIX!}_user_holidays` AS h
430 ON d.userid=h.userid
431 WHERE d.userid=%s AND d.receive_mails > 0 AND d.`status`='CONFIRMED' AND d.holiday_active='Y'
432 AND h.holiday_start < UNIX_TIMESTAMP() AND h.holiday_end > UNIX_TIMESTAMP()
433 LIMIT 1", array(bigintval($ucat)), __FILE__, __LINE__);
434                                                 if (SQL_NUMROWS($result_holiday) == 1) {
435                                                         // Holiday is active!
436                                                         $HOL_ACTIVE = true;
437                                                 } // END - if
438
439                                                 // Free memory
440                                                 SQL_FREERESULT($result_holiday);
441                                         } // END - if
442
443                                         if (!$HOL_ACTIVE) {
444                                                 // Check if the user want's to receive mails?
445                                                 $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",
446                                                         array(bigintval($ucat)), __FILE__, __LINE__);
447
448                                                 if ((SQL_NUMROWS($result_ver) == 1) && (!empty($_POST['zip'])) && (getConfig('order_multi_page') == "Y")) {
449                                                         list($zip) = SQL_FETCHROW($result_ver);
450                                                         SQL_FREERESULT($result_ver);
451                                                         if (substr($zip, 0, strlen($_POST['zip'])) == $_POST['zip']) {
452                                                                 // Ok, ZIP part is found
453                                                                 $uid_cnt++;
454                                                         } // END - if
455                                                 } else {
456                                                         // Count numbers up!
457                                                         $uid_cnt += SQL_NUMROWS($result_ver);
458                                                 }
459                                         } // END - if
460                                 } // END - while
461
462                                 // Free memory
463                                 SQL_FREERESULT($result_uids);
464                                 $CATS['uids'][] = $uid_cnt;
465                         } // END - while
466
467                         // Free memory
468                         SQL_FREERESULT($result_cats);
469
470                         // Now we need to load the mail types...
471                         $result = SQL_QUERY("SELECT id, price, payment, mail_title FROM `{!_MYSQL_PREFIX!}_payments` ORDER BY payment", __FILE__, __LINE__);
472
473                         $typeS = array();
474                         if (SQL_NUMROWS($result) > 0) {
475                                 // Check for message ID in URL
476                                 $MSG = "";
477                                 switch ($_GET['msg'])
478                                 {
479                                 case constant('CODE_URL_TLOCK'):
480                                         $result = SQL_QUERY_ESC("SELECT timestamp FROM `{!_MYSQL_PREFIX!}_pool` WHERE id=%s LIMIT 1",
481                                          array(bigintval($_GET['id'])), __FILE__, __LINE__);
482
483                                         // Load timestamp from last order
484                                         list($LORDER) = SQL_FETCHROW($result);
485                                         $LORDER = MAKE_DATETIME($LORDER, "1");
486
487                                         // Free memory
488                                         SQL_FREERESULT($result);
489
490                                         // Calculate hours...
491                                         $STD = round(getConfig('url_tlock') / 60 / 60);
492
493                                         // Minutes...
494                                         $MIN = round((getConfig('url_tlock') - $STD * 60 * 60) / 60);
495
496                                         // And seconds
497                                         $SEC = getConfig('url_tlock') - $STD * 60 * 60 - $MIN * 60;
498
499                                         // Finally contruct the message
500                                         // @TODO Rewrite this old lost code to a template
501                                         $MSG = "{!MEMBER_URL_TIME_LOCK!}<br />{!CONFIG_URL_TLOCK!} ".$STD."
502                                                 {!_HOURS!}, ".$MIN." {!_MINUTES!} {!_AND!} ".$SEC." {!_SECONDS!}<br />
503                                                 {!MEMBER_LAST_TLOCK!}: ".$LORDER;
504                                         break;
505
506                                 case constant('CODE_OVERLENGTH'):
507                                         $MSG = getMessage('MEMBER_TEXT_OVERLENGTH');
508                                         break;
509
510                                 case constant('CODE_URL_FOUND'):
511                                         $MSG = getMessage('MEMBER_TEXT_CONTAINS_URL');
512                                         break;
513
514                                 case constant('CODE_SUBJ_URL'):
515                                         $MSG = getMessage('MEMBER_SUBJ_CONTAINS_URL');
516                                         break;
517
518                                 case constant('CODE_BLIST_URL'):
519                                         $MSG = "{!MEMBER_URL_BLACK_LISTED!}<br />\n{!MEMBER_BLIST_TIME!}: ".MAKE_DATETIME($_GET['blist'], "0");
520                                         break;
521
522                                 case constant('CODE_NO_RECS_LEFT'):
523                                         $MSG = getMessage('MEMBER_SELECTED_MORE_RECS');
524                                         break;
525
526                                 case constant('CODE_INVALID_TAGS'):
527                                         $MSG = getMessage('MEMBER_HTML_INVALID_TAGS');
528                                         break;
529
530                                 case constant('CODE_MORE_POINTS'):
531                                         $MSG = getMessage('MEMBER_MORE_POINTS_NEEDED');
532                                         break;
533
534                                 case constant('CODE_MORE_RECEIVERS1'):
535                                         $MSG = getMessage('MEMBER_ENTER_MORE_RECEIVERS');
536                                         break;
537
538                                 case constant('CODE_MORE_RECEIVERS2'):
539                                         $MSG = getMessage('MEMBER_NO_MORE_RECEIVERS_FOUND');
540                                         break;
541
542                                 case constant('CODE_MORE_RECEIVERS3'):
543                                         $MSG = "{!MEMBER_ENTER_MORE_MIN_RECEIVERS_1!}".getConfig('order_min')."{!MEMBER_ENTER_MORE_MIN_RECEIVERS_2!}";
544                                         break;
545
546                                 case constant('CODE_INVALID_URL'):
547                                         $MSG = getMessage('MEMBER_ENTER_INVALID_URL');
548                                         break;
549
550                                 case "": // When no error code is included in the URL we do not need to output an error message as well...
551                                         break;
552
553                                 default:
554                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown error code %s detected.", $_GET['msg']));
555                                         $MSG = "{!UNKNOWN_CODE_1!}".$_GET['msg']."{!UNKNOWN_CODE_2!}";
556                                         break;
557                                 }
558
559                                 if (!empty($MSG)) {
560                                         // We got system message so we drop it out to the user
561                                         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
562                                 } // END - if
563
564                                 // Load all email types...
565                                 while ($typeS[] = SQL_FETCHROW($result)) {
566                                         // Nothing to do here... ;-)
567                                 } // END - while
568
569                                 // Free memory
570                                 SQL_FREERESULT($result);
571
572                                 // Output user's points
573                                 $TOTAL = TRANSLATE_COMMA($TOTAL);
574
575                                 // Check how many mail orders he has placed today and how many he's allowed to send
576                                 switch (getConfig('order_max_full'))
577                                 {
578                                 case "MAX": // He is allowed to send as much as possible
579                                         define('ORDER_MAX_VALUE', getMessage('ORDER_ALLOWED_MAX'));
580                                         break;
581
582                                 case "ORDER": // He is allowed to send as much as he setup the receiving value
583                                         define('ORDER_MAX_VALUE', ORDER_ALLOWED_RECEIVE_1.$ALLOWED.ORDER_ALLOWED_RECEIVE_2.$MAXI.ORDER_ALLOWED_RECEIVE_3);
584                                         break;
585
586                                 default: // Unknown/invalid
587                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown order_mas_full config detected.", getConfig('order_max_full')));
588                                         define('ORDER_MAX_VALUE', getMessage('ORDER_ALLOWED_UNKNOWN'));
589                                         break;
590                                 }
591
592                                 // Load final template
593                                 LOAD_TEMPLATE("member_order_points", false, $TOTAL);
594
595                                 // Reset variables
596                                 $OLD_ORDER = false; $subject = ""; $text = ""; $target = "";
597
598                                 // Check if we already have an order placed and make it editable
599                                 $result = SQL_QUERY_ESC("SELECT subject, text, payment_id, timestamp, url, target_send, cat_id, zip FROM `{!_MYSQL_PREFIX!}_pool` WHERE sender=%s AND data_type='TEMP' LIMIT 1",
600                                  array($GLOBALS['userid']), __FILE__, __LINE__);
601
602                                 if (SQL_NUMROWS($result) == 1) {
603                                         // Old order found
604                                         list($subject, $text, $payment, $tstamp, $url, $target, $cat, $zip) = SQL_FETCHROW($result);
605
606                                         // Fix max receivers when it is too much
607                                         if ((isset($CATS['uids'][$cat])) && ($target > $CATS['uids'][$cat])) $target = $CATS['uids'][$cat];
608
609                                         // Old order is grabbed
610                                         $OLD_ORDER = true;
611                                 } else {
612                                         // Default output for that your members don't forget it...
613                                         $url = "http://";
614                                 }
615
616                                 // Free result
617                                 SQL_FREERESULT($result);
618
619                                 // 01      2              21    12                                   2    23         443    3          3210
620                                 if ((!empty($_POST['data'])) || ((getConfig('order_multi_page') == "N") && ((!IS_ADMIN()) && (!EXT_IS_ACTIVE("html_mail"))))) {
621                                         // Pre-output categories
622                                         $CAT = "";
623                                         foreach ($CATS['id'] as $key => $value) {
624                                                 $CAT .= "      <option value=\"".$value."\"";
625                                                 if (($OLD_ORDER) && ($cat == $value)) $CAT .= " selected=\"selected\"";
626                                                 $CAT .= ">".$CATS['name'][$key]." (".$CATS['uids'][$key]." {!USER_IN_CAT!})</option>\n";
627                                         } // END - foreach
628
629                                         // Mail type
630                                         $type = "";
631                                         foreach ($typeS as $key => $value) {
632                                                 $P = TRANSLATE_COMMA($typeS[$key][1]);
633                                                 if (is_array($value)) {
634                                                         // Output option line
635                                                         $type .= "      <option value=\"".$typeS[$key][0]."\"";
636                                                         if (($OLD_ORDER) && ($payment == $typeS[$key][0])) $type .= " selected=\"selected\"";
637                                                         $type .= ">".$P." {!PER_MAIL!} - ".$typeS[$key][3]." - ".round($typeS[$key][2])." {!PAYMENT!}</option>\n";
638                                                 } // END - if
639                                         } // END - foreach
640
641                                         // Put all in constants for the template
642                                         define('CATEGORY_SELECTION', $CAT);
643                                         define('TYPE_SELECTION', $type);
644                                         define('TARGET', $target);
645                                         define('SUBJECT', $subject);
646                                         define('TEXT', COMPILE_CODE($text));
647                                         define('T_URL', $url);
648
649                                         if (!empty($_POST['zip'])) {
650                                                 // Output entered ZIP code
651                                                 define('ZIP_OUTPUT', LOAD_TEMPLATE("member_order-zip2", true, $_POST['zip']));
652                                         } else {
653                                                 define('ZIP_OUTPUT', "<tr><td colspan=\"5\" height=\"5\" class=\"seperator\">&nbsp;</td></tr>");
654                                         }
655
656                                         // HTML extension
657                                         if ((EXT_IS_ACTIVE("html_mail")) && ($_POST['html'] == "Y")) {
658                                                 // Extension is active so output valid HTML tags
659                                                 define('MEMBER_HTML_EXTENSION', LOAD_TEMPLATE("member_order-html_ext", true, HTML_ADD_VALID_TAGS()));
660                                         } else {
661                                                 // Extension not active and/or class not uploaded
662                                                 define('MEMBER_HTML_EXTENSION', "<tr><td colspan=\"5\"><input type=\"hidden\" name=\"html\" value=\"N\"> /</td></tr>");
663                                         }
664
665                                         // Output form for page 2
666                                         LOAD_TEMPLATE("member_order_page2");
667                                 } else {
668                                         // Remember maybe entered ZIP code in constant
669                                         $ADD = "";
670                                         if (EXT_IS_ACTIVE("html_mail")) {
671                                                 // Add some content when html extension is active
672                                                 if ((getConfig('order_multi_page') == "Y") || (IS_ADMIN())) $ADD = "<tr><td colspan=\"2\" class=\"seperator bottom2\" height=\"5\">&nbsp;</td></tr>\n";
673                                                 define('MEMBER_HTML_EXTENSION', LOAD_TEMPLATE("member_order-html_intro", true));
674                                         } else {
675                                                 // No HTML extension installed
676                                                 define('MEMBER_HTML_EXTENSION', "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"html\" value=\"N\" /></td></tr>");
677                                         }
678
679                                         // Do we want ZIP code or not?
680                                         if ((getConfig('order_multi_page') == "Y") || (IS_ADMIN())) {
681                                                 // Yes
682                                                 if ($_POST['zip'] > 0) {
683                                                         $content = array(
684                                                                 'zip' => bigintval($_POST['zip']),
685                                                                 'add' => $ADD
686                                                         );
687                                                 } else {
688                                                         $content = array(
689                                                                 'zip' => "",
690                                                                 'add' => $ADD
691                                                         );
692                                                 }
693                                                 define('MEMBER_ZIP_CONTENT', LOAD_TEMPLATE("member_order-zip1", true, $content));
694                                         } else {
695                                                 // No
696                                                 define('MEMBER_ZIP_CONTENT', "");
697                                         }
698
699                                         // Output form for page 1 (ZIP code or HTML)
700                                         LOAD_TEMPLATE("member_order_page1");
701                                 }
702                         } else {
703                                 // No mail types defined
704                                 LOAD_TEMPLATE("admin_settings_saved", false, "<span class=\"member_failed\">{!MEMBER_NO_PAYMENTS!}</span>");
705                         }
706                 } else {
707                         // No points left!
708                         LOAD_TEMPLATE("admin_settings_saved", false, "<span class=\"member_failed\">{!MEMBER_NO_POINTS!}</span>");
709                 }
710         } else {
711                 // No cateogries are defined yet
712                 LOAD_TEMPLATE("admin_settings_saved", false, "<span class=\"member_failed\">{!MEMBER_NO_CATS!}</span>");
713         }
714 } elseif ($mmails == "0") {
715         // Please set more than 0 mails per day!
716         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_HAS_ZERO_MMAILS'));
717 } else {
718         // Please confirm some mails first!
719         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_LINKS_LEFT_1.$links.MEMBER_LINKS_LEFT_2.getConfig('unconfirmed').MEMBER_LINKS_LEFT_3);
720 }
721
722 if (!empty($URL)) {
723         // Redirect to requested URL
724         LOAD_URL($URL);
725 } // END - if
726
727 //
728 ?>