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 - 2013 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 // Generate call-back function name
74 $callbackName = 'doMailId' . trim(capitalizeUnderscoreString($data['do']));
76 // Is the function there?
77 if (!function_exists($callbackName)) {
79 reportBug(__FILE__, __LINE__, 'Unknown mode ' . $data['do'] . ' detected.');
83 call_user_func($callbackName, $data);
86 //-----------------------------------------------------------------------------
87 // Call-back functions for mailid
88 //-----------------------------------------------------------------------------
90 // Do call-back for 'add'
91 function doMailIdAdd ($data) {
93 // @TODO Rewrite this to a filter
94 switch ($data['link_type']) {
96 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
97 array(bigintval($data['id'])), __FILE__, __LINE__);
99 // Update mediadata as well
100 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
102 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
107 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
108 array(bigintval($data['id'])), __FILE__, __LINE__);
110 // Update mediadata as well
111 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
113 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
117 default: // Unknown type
118 reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
122 // Only when user extension = v0.1.2: Update mails-confirmed counter
123 // @TODO Rewrite these blocks to filter
124 if (isExtensionInstalledAndNewer('user', '0.1.2')) {
126 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
127 array(bigintval($data['userid'])), __FILE__, __LINE__);
129 // Update random confirmed as well?
130 if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
131 // Update second counter
132 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
133 array(bigintval($data['userid'])), __FILE__, __LINE__);
137 // Insert stats record
138 insertUserStatsRecord($data['userid'], $data['type'], $data['id']);
140 // Right code entered?
141 if (bigintval(postRequestElement('real_code_check')) == $data['real_code']) {
142 // Set HTTP status to okay
143 setHttpStatus('200 OK');
145 // Add points over referral system is the default
146 $template = 'mailid_points_done';
148 // Right code entered add points and remove entry
149 if (ifUserPointsLocked($data['userid'])) {
150 // Don't add points over the referral system
151 $template = 'mailid_points_locked';
154 // Count down ref_payout value
155 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
156 array(bigintval($data['userid'])), __FILE__, __LINE__);
159 initReferralSystem();
160 addPointsThroughReferralSystem('mailid_okay', $data['userid'], $data['payment']);
162 // Shall I add bonus points for "turbo clickers" ?
163 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
164 // Is an active-rallye running and this is not a notification mail?
165 if ((isBonusRallyeActive()) && ($data['is_notify'] != 'Y')) {
166 // Shall I exclude the webmaster's own userid from the active-rallye?
167 if ((((getBonusUserid() == $data['userid']) && (isBonusIncludeOwnEnabled())) || (getBonusUserid() != $data['userid'])) && (getDefRefid() != $data['userid'])) {
168 // Add points and remember ranking are done in this function....
169 addTurboBonus($data['id'], $data['userid'], $data['type']);
171 // Set template to mailid_points_done2 which contains a link to the ranking list
172 $template = 'mailid_points_done2';
174 // Different template if user has some mails to confirm
175 if (ifUserPointsLocked($data['userid'])) {
176 $template = 'mailid_points_locked2';
183 $data['total_points'] = getTotalPoints($data['userid']);
186 loadTemplate($template, FALSE, $data);
187 } elseif (isValidId($data['sender'])) {
188 // Wrong image code! So add points to sender's account
189 initReferralSystem();
190 addPointsThroughReferralSystem('mailid_payback', $data['sender'], $data['payment']);
193 loadTemplate('mailid_points_failed', FALSE, $data);
196 loadTemplate('mailid_points_failed2', FALSE, $data);
199 // Remove link from table
200 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
201 array(bigintval($data['link_id'])), __FILE__, __LINE__);
204 // Do call-back for 'img'
205 function doMailIdImg ($data) {
206 // Generate image/code
207 generateImageOrCode($data['real_code']);
210 // Do call-back for 'confirm'
211 function doMailIdConfirm ($data) {
213 if ($data['code'] > 0) {
214 // Export data into constants for the template
215 if (getCodeLength() > 0) {
217 $data['image'] = generateCaptchaCode($data['code'], $data['type'], $data['id'], $data['userid']);
218 $templ = 'mailid_enter_code';
221 $data['real_code'] = $realCode;
222 $templ = 'mailid_confirm_buttom';
226 loadTemplate($templ, FALSE, $data);
229 reportBug(__FILE__, __LINE__, 'No code given.');
233 // Do call-back for 'top'
234 function doMailIdTop ($data) {
236 * Ok, all data is valid and loaded. Finally let's output the timer... :-)
237 * Export data into constants for the template
239 $data['tim2'] = strlen($data['time']);
242 loadTemplate('mailid_timer', FALSE, $data);
245 // Call-back for 'frames'
246 function doMailIdFrames ($data) {
248 loadTemplate('mailid_frames', FALSE, $data);