Updated copyright notice as there are changes in this year
[mailer.git] / inc / libs / mailid_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/20/2010 *
4  * ===================                          Last change: 06/20/2010 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mailid_functions.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for ext-mailid                         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer ext-mailid                       *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Handles the error code from mail confirmation
44 function handleMailIdErrorCode ($errorCode) {
45         // Is an error set?
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&amp;code=' . $errorCode . '&amp;ext=mailid');
51                                 break;
52
53                         case 'REJECT': // Redirect to rejection page
54                                 if (isExtensionActive('other')) {
55                                         // Redirect to configured URL
56                                         redirectToConfiguredUrl('reject_url');
57                                 } else {
58                                         // Redirect to index
59                                         redirectToUrl('modules.php?module=index');
60                                 }
61                                 break;
62
63                         default:
64                                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected in mailid_error_redirect.", getConfig('mailid_error_redirect')));
65                                 redirectToUrl('modules.php?module=index&amp;code=' . getCode('UNKNOWN_REDIRECT') . '&amp;ext=mailid');
66                                 break;
67                 } // END - switch
68         } // END - if
69 }
70
71 // Does the "mailid" call-back
72 function doMailIdCallback ($data) {
73         // Generate call-back function name
74         $callbackName = 'doMailId' . trim(capitalizeUnderscoreString($data['do']));
75
76         // Is the function there?
77         if (!function_exists($callbackName)) {
78                 // Not found
79                 reportBug(__FILE__, __LINE__, 'Unknown mode ' . $data['do'] . ' detected.');
80         } // END - if
81
82         // Do the call-back
83         call_user_func($callbackName, $data);
84 }
85
86 //-----------------------------------------------------------------------------
87 //                         Call-back functions for mailid
88 //-----------------------------------------------------------------------------
89
90 // Do call-back for 'add'
91 function doMailIdAdd ($data) {
92         // Count clicks
93         // @TODO Rewrite this to a filter
94         switch ($data['link_type']) {
95                 case 'NORMAL':
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__);
98
99                         // Update mediadata as well
100                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
101                                 // Update database
102                                 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
103                         } // END - if
104                         break;
105
106                 case 'BONUS':
107                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
108                                 array(bigintval($data['id'])), __FILE__, __LINE__);
109
110                         // Update mediadata as well
111                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
112                                 // Update database
113                                 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
114                         } // END - if
115                         break;
116
117                 default: // Unknown type
118                         reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
119                         break;
120         } // END - switch
121
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')) {
125                 // Update counter
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__);
128
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__);
134                 } // END - if
135         } // END - if
136
137         // Insert stats record
138         insertUserStatsRecord($data['userid'], $data['type'], $data['id']);
139
140         // Right code entered?
141         if (bigintval(postRequestElement('real_code_check')) == $data['real_code']) {
142                 // Set HTTP status to okay
143                 setHttpStatus('200 OK');
144
145                 // Add points over referral system is the default
146                 $template = 'mailid_points_done';
147
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';
152                 } // END - if
153
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__);
157
158                 // Add points
159                 initReferralSystem();
160                 addPointsThroughReferralSystem('mailid_okay', $data['userid'], $data['payment']);
161
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']);
170
171                                         // Set template to mailid_points_done2 which contains a link to the ranking list
172                                         $template = 'mailid_points_done2';
173
174                                         // Different template if user has some mails to confirm
175                                         if (ifUserPointsLocked($data['userid'])) {
176                                                 $template = 'mailid_points_locked2';
177                                         } // END - if
178                                 } // END - if
179                         } // END - if
180                 } // END - if
181
182                 // Load total points
183                 $data['total_points']  = getTotalPoints($data['userid']);
184
185                 // Load template
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']);
191
192                 // Load template
193                 loadTemplate('mailid_points_failed', FALSE, $data);
194         } else {
195                 // Load template
196                 loadTemplate('mailid_points_failed2', FALSE, $data);
197         }
198
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__);
202 }
203
204 // Do call-back for 'img'
205 function doMailIdImg ($data) {
206         // Generate image/code
207         generateImageOrCode($data['real_code']);
208 }
209
210 // Do call-back for 'confirm'
211 function doMailIdConfirm ($data) {
212         // Is code valid?
213         if ($data['code'] > 0) {
214                 // Export data into constants for the template
215                 if (getCodeLength() > 0) {
216                         // Generate Code
217                         $data['image'] = generateCaptchaCode($data['code'], $data['type'], $data['id'], $data['userid']);
218                         $templ = 'mailid_enter_code';
219                 } else {
220                         // Disabled code
221                         $data['real_code'] = $realCode;
222                         $templ = 'mailid_confirm_buttom';
223                 }
224
225                 // Load template
226                 loadTemplate($templ, FALSE, $data);
227         } else {
228                 // Cannot confirm!
229                 reportBug(__FILE__, __LINE__, 'No code given.');
230         }
231 }
232
233 // Do call-back for 'top'
234 function doMailIdTop ($data) {
235         /*
236          * Ok, all data is valid and loaded. Finally let's output the timer... :-)
237          * Export data into constants for the template
238          */
239         $data['tim2']   = strlen($data['time']);
240
241         // Load template
242         loadTemplate('mailid_timer', FALSE, $data);
243 }
244
245 // Call-back for 'frames'
246 function doMailIdFrames ($data) {
247         // Load template
248         loadTemplate('mailid_frames', FALSE, $data);
249 }
250
251 // [EOF]
252 ?>