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