]> git.mxchange.org Git - mailer.git/blob - inc/libs/mailid_functions.php
da8cd7350ac4f413848e16dbb08b1c68ddeb99d9
[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 - 2012 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         // Load banner generically
74         $data['banner'] = loadTemplate('mailid_banner', TRUE);
75
76         // Generate call-back function name
77         $callbackName = 'doMailId' . trim(capitalizeUnderscoreString($data['do']));
78
79         // Is the function there?
80         if (!function_exists($callbackName)) {
81                 // Not found
82                 reportBug(__FILE__, __LINE__, 'Unknown mode ' . $data['do'] . ' detected.');
83         } // END - if
84
85         // Do the call-back
86         call_user_func($callbackName, $data);
87 }
88
89 //-----------------------------------------------------------------------------
90 //                         Call-back functions for mailid
91 //-----------------------------------------------------------------------------
92
93 // Do call-back for 'add'
94 function doMailIdAdd ($data) {
95         // Count clicks
96         // @TODO Rewrite this to a filter
97         switch ($data['link_type']) {
98                 case 'NORMAL':
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__);
101
102                         // Update mediadata as well
103                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
104                                 // Update database
105                                 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
106                         } // END - if
107                         break;
108
109                 case 'BONUS':
110                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
111                                 array(bigintval($data['id'])), __FILE__, __LINE__);
112
113                         // Update mediadata as well
114                         if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
115                                 // Update database
116                                 updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
117                         } // END - if
118                         break;
119
120                 default: // Unknown type
121                         reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
122                         break;
123         } // END - switch
124
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')) {
128                 // Update counter
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__);
131
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__);
137                 } // END - if
138         } // END - if
139
140         // Insert stats record
141         insertUserStatsRecord($data['userid'], $data['type'], $data['id']);
142
143         // Right code entered?
144         if (bigintval(postRequestElement('real_code_check')) == $data['real_code']) {
145                 // Set HTTP status to okay
146                 setHttpStatus('200 OK');
147
148                 // Add points over referral system is the default
149                 $template = 'mailid_points_done';
150
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';
155                 } // END - if
156
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__);
160
161                 // Add points
162                 initReferralSystem();
163                 addPointsThroughReferralSystem('mailid_okay', $data['userid'], $data['payment']);
164
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']);
173
174                                         // Set template to mailid_points_done2 which contains a link to the ranking list
175                                         $template = 'mailid_points_done2';
176
177                                         // Different template if user has some mails to confirm
178                                         if (ifUserPointsLocked($data['userid'])) {
179                                                 $template = 'mailid_points_locked2';
180                                         } // END - if
181                                 } // END - if
182                         } // END - if
183                 } // END - if
184
185                 // Load total points
186                 $data['total_points']  = getTotalPoints($data['userid']);
187
188                 // Load template
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']);
194
195                 // Load template
196                 loadTemplate('mailid_points_failed', FALSE, $data);
197         } else {
198                 // Load template
199                 loadTemplate('mailid_points_failed2', FALSE, $data);
200         }
201
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__);
205 }
206
207 // Do call-back for 'img'
208 function doMailIdImg ($data) {
209         // Generate image/code
210         generateImageOrCode($data['real_code']);
211 }
212
213 // Do call-back for 'confirm'
214 function doMailIdConfirm ($data) {
215         // Is code valid?
216         if ($data['code'] > 0) {
217                 // Export data into constants for the template
218                 if (getCodeLength() > 0) {
219                         // Generate Code
220                         $data['image'] = generateCaptchaCode($data['code'], $data['type'], $data['id'], $data['userid']);
221                         $templ = 'mailid_enter_code';
222                 } else {
223                         // Disabled code
224                         $data['real_code'] = $realCode;
225                         $templ = 'mailid_confirm_buttom';
226                 }
227
228                 // Load template
229                 loadTemplate($templ, FALSE, $data);
230         } else {
231                 // Cannot confirm!
232                 reportBug(__FILE__, __LINE__, 'No code given.');
233         }
234 }
235
236 // Do call-back for 'top'
237 function doMailIdTop ($data) {
238         /*
239          * Ok, all data is valid and loaded. Finally let's output the timer... :-)
240          * Export data into constants for the template
241          */
242         $data['tim2']   = strlen($data['time']);
243
244         // Load template
245         loadTemplate('mailid_timer', FALSE, $data);
246 }
247
248 // Call-back for 'frames'
249 function doMailIdFrames ($data) {
250         // Load template
251         loadTemplate('mailid_frames', FALSE, $data);
252 }
253
254 // [EOF]
255 ?>