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