2d0917b5035147cef43e5a29e899345ca25244c5
[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         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', 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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_MORE_RECEIVERS3;
161                 } // END - if
162
163                 // Validate URL
164                 if (!VALIDATE_URL($_POST['url'])) {
165                         // URL is invalid!
166                         $URL = URL."/modules.php?module=login&amp;what=order&amp;msg=".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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_INVALID_TAGS."&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 = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_URL_TLOCK."&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                         $result = 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                                                 $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)
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                                                 $result = 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                                                 $result = 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                                                 $result = 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 = URL."/modules.php?module=frametester&amp;order=".$id."";
375                         } elseif ($MAX_SEND == 0) {
376                                 // Not enougth receivers found which can receive mails
377                                 $URL = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_MORE_RECEIVERS2;
378                         } else {
379                                 // No enougth points left!
380                                 $URL = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_MORE_POINTS;
381                         }
382                 } else  {
383                         // Ordered more mails than he can send in this category
384                         $URL = URL."/modules.php?module=login&amp;what=order&amp;msg=".CODE_NO_RECS_LEFT;
385                 }
386         }
387 } elseif ($_POST['receiver'] == "0") {
388         // Not enougth receivers selected
389         $URL = URL."/modules.php?module=login&amp;what=order&amp;msg=".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, 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 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                                         $MSG = MEMBER_URL_TIME_LOCK."<br />".CONFIG_URL_TLOCK." ".$STD." ".
501                                                 _HOURS.", ".$MIN." "._MINUTES." "._AND." ".$SEC." "._SECONDS."<br />".
502                                                 MEMBER_LAST_TLOCK.": ".$LORDER;
503                                         break;
504
505                                 case CODE_OVERLENGTH:
506                                         $MSG = MEMBER_TEXT_OVERLENGTH;
507                                         break;
508
509                                 case CODE_URL_FOUND:
510                                         $MSG = MEMBER_TEXT_CONTAINS_URL;
511                                         break;
512
513                                 case CODE_SUBJ_URL:
514                                         $MSG = MEMBER_SUBJ_CONTAINS_URL;
515                                         break;
516
517                                 case CODE_BLIST_URL:
518                                         $MSG = MEMBER_URL_BLACK_LISTED."<br />\n".MEMBER_BLIST_TIME.": ".MAKE_DATETIME($_GET['blist'], "0");
519                                         break;
520
521                                 case CODE_NO_RECS_LEFT:
522                                         $MSG = MEMBER_SELECTED_MORE_RECS;
523                                         break;
524
525                                 case CODE_INVALID_TAGS:
526                                         $MSG = MEMBER_HTML_INVALID_TAGS;
527                                         break;
528
529                                 case CODE_MORE_POINTS:
530                                         $MSG = MEMBER_MORE_POINTS_NEEDED;
531                                         break;
532
533                                 case CODE_MORE_RECEIVERS1:
534                                         $MSG = MEMBER_ENTER_MORE_RECEIVERS;
535                                         break;
536
537                                 case CODE_MORE_RECEIVERS2:
538                                         $MSG = MEMBER_NO_MORE_RECEIVERS_FOUND;
539                                         break;
540
541                                 case CODE_MORE_RECEIVERS3:
542                                         $MSG = MEMBER_ENTER_MORE_MIN_RECEIVERS_1.getConfig('order_min').MEMBER_ENTER_MORE_MIN_RECEIVERS_2;
543                                         break;
544
545                                 case CODE_INVALID_URL:
546                                         $MSG = MEMBER_ENTER_INVALID_URL;
547                                         break;
548
549                                 case "": // When no error code is included in the URL we do not need to output an error message as well...
550                                         break;
551
552                                 default:
553                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown error code %s detected.", $_GET['msg']));
554                                         $MSG = UNKNOWN_CODE_1.$_GET['msg'].UNKNOWN_CODE_2;
555                                         break;
556                                 }
557
558                                 if (!empty($MSG)) {
559                                         // We got system message so we drop it out to the user
560                                         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
561                                 } // END - if
562
563                                 // Load all email types...
564                                 while ($typeS[] = SQL_FETCHROW($result)) {
565                                         // Nothing to do here... ;-)
566                                 } // END - while
567
568                                 // Free memory
569                                 SQL_FREERESULT($result);
570
571                                 // Output user's points
572                                 $TOTAL = TRANSLATE_COMMA($TOTAL);
573
574                                 // Check how many mail orders he has placed today and how many he's allowed to send
575                                 switch (getConfig('order_max_full'))
576                                 {
577                                 case "MAX": // He is allowed to send as much as possible
578                                         define('ORDER_MAX_VALUE', ORDER_ALLOED_MAX);
579                                         break;
580
581                                 case "ORDER": // He is allowed to send as much as he setup the receiving value
582                                         define('ORDER_MAX_VALUE', ORDER_ALLOWED_RECEIVE_1.$ALLOWED.ORDER_ALLOWED_RECEIVE_2.$MAXI.ORDER_ALLOWED_RECEIVE_3);
583                                         break;
584
585                                 default: // Unknown/invalid
586                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown order_mas_full config detected.", getConfig('order_max_full')));
587                                         define('ORDER_MAX_VALUE', ORDER_ALLOED_UNKNOWN);
588                                         break;
589                                 }
590
591                                 // Load final template
592                                 LOAD_TEMPLATE("member_order_points", false, $TOTAL);
593
594                                 // Reset variables
595                                 $OLD_ORDER = false; $subject = ""; $text = ""; $target = "";
596
597                                 // Check if we already have an order placed and make it editable
598                                 $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",
599                                  array($GLOBALS['userid']), __FILE__, __LINE__);
600
601                                 if (SQL_NUMROWS($result) == 1) {
602                                         // Old order found
603                                         list($subject, $text, $payment, $tstamp, $url, $target, $cat, $zip) = SQL_FETCHROW($result);
604                                         SQL_FREERESULT($result);
605
606                                         // Fix max receivers when it is too much
607                                         if ($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                                 // 01      2              21    12                                   2    23         443    3          3210
617                                 if ((!empty($_POST['data'])) || ((getConfig('order_multi_page') == "N") && ((!IS_ADMIN()) && (!EXT_IS_ACTIVE("html_mail"))))) {
618                                         // Pre-output categories
619                                         $CAT = "";
620                                         foreach ($CATS['id'] as $key => $value) {
621                                                 $CAT .= "      <OPTION value=\"".$value."\"";
622                                                 if (($OLD_ORDER) && ($cat == $value)) $CAT .= " selected=\"selected\"";
623                                                 $CAT .= ">".$CATS['name'][$key]." (".$CATS['uids'][$key]." ".USER_IN_CAT.")</OPTION>\n";
624                                         } // END - foreach
625
626                                         // Mail type
627                                         $type = "";
628                                         foreach ($typeS as $key => $value) {
629                                                 $P = TRANSLATE_COMMA($typeS[$key][1]);
630                                                 if (is_array($value)) {
631                                                         // Output option line
632                                                         $type .= "      <OPTION value=\"".$typeS[$key][0]."\"";
633                                                         if (($OLD_ORDER) && ($payment == $typeS[$key][0])) $type .= " selected=\"selected\"";
634                                                         $type .= ">".$P." ".PER_MAIL." - ".$typeS[$key][3]." - ".round($typeS[$key][2])." ".PAYMENT."</OPTION>\n";
635                                                 } // END - if
636                                         } // END - foreach
637
638                                         // Put all in constants for the template
639                                         define('CATEGORY_SELECTION', $CAT);
640                                         define('TYPE_SELECTION', $type);
641                                         define('TARGET', $target);
642                                         define('SUBJECT', $subject);
643                                         define('TEXT', COMPILE_CODE($text));
644                                         define('T_URL', $url);
645
646                                         if (!empty($_POST['zip'])) {
647                                                 // Output entered ZIP code
648                                                 define('ZIP_OUTPUT', LOAD_TEMPLATE("member_order-zip2", true, $_POST['zip']));
649                                         } else {
650                                                 define('ZIP_OUTPUT', "<TR><TD colspan=\"5\" height=\"5\" class=\"seperator\">&nbsp;</TD></TR>");
651                                         }
652
653                                         // HTML extension
654                                         if ((EXT_IS_ACTIVE("html_mail")) && ($_POST['html'] == "Y")) {
655                                                 // Extension is active so output valid HTML tags
656                                                 define('MEMBER_HTML_EXTENSION', LOAD_TEMPLATE("member_order-html_ext", true, HTML_ADD_VALID_TAGS()));
657                                         } else {
658                                                 // Extension not active and/or class not uploaded
659                                                 define('MEMBER_HTML_EXTENSION', "<TR><TD colspan=\"5\"><INPUT type=\"hidden\" name=\"html\" value=\"N\"></TD></TR>");
660                                         }
661
662                                         // Output form for page 2
663                                         LOAD_TEMPLATE("member_order_page2");
664                                 } else {
665                                         // Remember maybe entered ZIP code in constant
666                                         $ADD = "";
667                                         if (EXT_IS_ACTIVE("html_mail")) {
668                                                 // Add some content when html extension is active
669                                                 if ((getConfig('order_multi_page') == "Y") || (IS_ADMIN())) $ADD = "<TR><TD colspan=\"2\" class=\"seperator bottom2\" height=\"5\">&nbsp;</TD></TR>\n";
670                                                 define('MEMBER_HTML_EXTENSION', LOAD_TEMPLATE("member_order-html_intro", true));
671                                         } else {
672                                                 // No HTML extension installed
673                                                 define('MEMBER_HTML_EXTENSION', "<TR><TD colspan=\"2\"><INPUT type=\"hidden\" name=\"html\" value=\"N\"></TD></TR>");
674                                         }
675
676                                         // Do we want ZIP code or not?
677                                         if ((getConfig('order_multi_page') == "Y") || (IS_ADMIN())) {
678                                                 // Yes
679                                                 if ($_POST['zip'] > 0) {
680                                                         $content = array(
681                                                                 'zip' => bigintval($_POST['zip']),
682                                                                 'add' => $ADD
683                                                         );
684                                                 } else {
685                                                         $content = array(
686                                                                 'zip' => "",
687                                                                 'add' => $ADD
688                                                         );
689                                                 }
690                                                 define('MEMBER_ZIP_CONTENT', LOAD_TEMPLATE("member_order-zip1", true, $content));
691                                         } else {
692                                                 // No
693                                                 define('MEMBER_ZIP_CONTENT', "");
694                                         }
695
696                                         // Output form for page 1 (ZIP code or HTML)
697                                         LOAD_TEMPLATE("member_order_page1");
698                                 }
699                         } else {
700                                 // No mail types defined
701                                 OUTPUT_HTML("<STRONG><SPAN class=\"member_failed\">".MEMBER_NO_PAYMENTS."</SPAN></STRONG>");
702                         }
703                 } else {
704                         // No points left!
705                         OUTPUT_HTML("<STRONG><SPAN class=\"member_failed\">".MEMBER_NO_POINTS."</SPAN></STRONG>");
706                 }
707         } else {
708                 // No cateogries are defined yet
709                 OUTPUT_HTML("<STRONG><SPAN class=\"member_failed\">".MEMBER_NO_CATS."</SPAN></STRONG>");
710         }
711 } elseif ($mmails == "0") {
712         // Please set more than 0 mails per day!
713         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_HAS_ZERO_MMAILS);
714 } else {
715         // Please confirm some mails first!
716         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_LINKS_LEFT_1.$links.MEMBER_LINKS_LEFT_2.getConfig('unconfirmed').MEMBER_LINKS_LEFT_3);
717 }
718
719 if (!empty($URL)) {
720         // Redirect to requested URL
721         LOAD_URL($URL);
722 } // END - if
723
724 //
725 ?>