2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 06/20/2010 *
4 * =================== Last change: 06/20/2010 *
6 * -------------------------------------------------------------------- *
7 * File : mailid_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for ext-mailid *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer ext-mailid *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Handles the error code from mail confirmation
44 function handleMailIdErrorCode ($errorCode) {
46 if (!empty($errorCode)) {
47 // @TODO Rewrite this to a dynamic include or so
48 switch (getConfig('mailid_error_redirect')) {
49 case 'INDEX': // Redirect to index page
50 redirectToUrl('modules.php?module=index&code=' . $errorCode . '&ext=mailid');
53 case 'REJECT': // Redirect to rejection page
54 if (isExtensionActive('other')) {
55 // Redirect to configured URL
56 redirectToConfiguredUrl('reject_url');
59 redirectToUrl('modules.php?module=index');
64 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
65 redirectToUrl('modules.php?module=index&code=' . getCode('UNKNOWN_REDIRECT') . '&ext=mailid');
71 // Does the "mailid" call-back
72 function doMailIdCallback ($data) {
73 // Load banner generically
74 $data['banner'] = loadTemplate('mailid_banner', TRUE);
76 // Generate call-back function name
77 $callbackName = 'doMailId' . trim(capitalizeUnderscoreString($data['do']));
79 // Is the function there?
80 if (!function_exists($callbackName)) {
82 reportBug(__FILE__, __LINE__, 'Unknown mode ' . $data['do'] . ' detected.');
86 call_user_func($callbackName, $data);
89 //-----------------------------------------------------------------------------
90 // Call-back functions for mailid
91 //-----------------------------------------------------------------------------
93 // Do call-back for 'add'
94 function doMailIdAdd ($data) {
96 // @TODO Rewrite this to a filter
97 switch ($data['link_type']) {
99 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
100 array(bigintval($data['id'])), __FILE__, __LINE__);
102 // Update mediadata as well
103 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
105 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
110 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
111 array(bigintval($data['id'])), __FILE__, __LINE__);
113 // Update mediadata as well
114 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
116 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
120 default: // Unknown type
121 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
125 // Only when user extension = v0.1.2: Update mails-confirmed counter
126 // @TODO Rewrite these blocks to filter
127 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
129 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
130 array(bigintval($data['userid'])), __FILE__, __LINE__);
132 // Update random confirmed as well?
133 if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
134 // Update second counter
135 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
136 array(bigintval($data['userid'])), __FILE__, __LINE__);
140 // Insert stats record
141 insertUserStatsRecord($data['userid'], $data['type'], $data['id']);
143 // Right code entered?
144 if (bigintval(postRequestElement('real_code_check')) == $data['real_code']) {
145 // Set HTTP status to okay
146 setHttpStatus('200 OK');
148 // Add points over referral system is the default
149 $template = 'mailid_points_done';
151 // Right code entered add points and remove entry
152 if (ifUserPointsLocked($data['userid'])) {
153 // Don't add points over the referral system
154 $template = 'mailid_points_locked';
157 // Count down ref_payout value
158 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
159 array(bigintval($data['userid'])), __FILE__, __LINE__);
162 initReferralSystem();
163 addPointsThroughReferralSystem('mailid_okay', $data['userid'], $data['payment']);
165 // Shall I add bonus points for "turbo clickers" ?
166 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
167 // Is an active-rallye running and this is not a notification mail?
168 if ((isBonusRallyeActive()) && ($data['is_notify'] != 'Y')) {
169 // Shall I exclude the webmaster's own userid from the active-rallye?
170 if ((((getBonusUserid() == $data['userid']) && (isBonusIncludeOwnEnabled())) || (getBonusUserid() != $data['userid'])) && (getDefRefid() != $data['userid'])) {
171 // Add points and remember ranking are done in this function....
172 addTurboBonus($data['id'], $data['userid'], $data['type']);
174 // Set template to mailid_points_done2 which contains a link to the ranking list
175 $template = 'mailid_points_done2';
177 // Different template if user has some mails to confirm
178 if (ifUserPointsLocked($data['userid'])) {
179 $template = 'mailid_points_locked2';
186 $data['total_points'] = getTotalPoints($data['userid']);
189 loadTemplate($template, FALSE, $data);
190 } elseif (isValidId($data['sender'])) {
191 // Wrong image code! So add points to sender's account
192 initReferralSystem();
193 addPointsThroughReferralSystem('mailid_payback', $data['sender'], $data['payment']);
196 loadTemplate('mailid_points_failed', FALSE, $data);
199 loadTemplate('mailid_points_failed2', FALSE, $data);
202 // Remove link from table
203 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
204 array(bigintval($data['link_id'])), __FILE__, __LINE__);
207 // Do call-back for 'img'
208 function doMailIdImg ($data) {
209 // Generate image/code
210 generateImageOrCode($data['real_code']);
213 // Do call-back for 'confirm'
214 function doMailIdConfirm ($data) {
216 if ($data['code'] > 0) {
217 // Export data into constants for the template
218 if (getCodeLength() > 0) {
220 $data['image'] = generateCaptchaCode($data['code'], $data['type'], $data['id'], $data['userid']);
221 $templ = 'mailid_enter_code';
224 $data['real_code'] = $realCode;
225 $templ = 'mailid_confirm_buttom';
229 loadTemplate($templ, FALSE, $data);
232 reportBug(__FILE__, __LINE__, 'No code given.');
236 // Do call-back for 'top'
237 function doMailIdTop ($data) {
239 * Ok, all data is valid and loaded. Finally let's output the timer... :-)
240 * Export data into constants for the template
242 $data['tim2'] = strlen($data['time']);
245 loadTemplate('mailid_timer', FALSE, $data);
248 // Call-back for 'frames'
249 function doMailIdFrames ($data) {
251 loadTemplate('mailid_frames', FALSE, $data);