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