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