3655fd58ac44d3d000f26d6fbb0e330eae6c5b67
[mailer.git] / surfbar.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/05/2008 *
4  * ===============                              Last change: 09/05/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : surfbar.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : The surfbar itself                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Die Surfbar selbst                               *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require_once("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 global $what, $action, $startTime, $SURFBAR_CACHE;
39 $SURFBAR_CACHE = array();
40 $GLOBALS['startTime'] = microtime(true);
41 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
42
43 // Set module
44 $GLOBALS['module'] = "surfbar";
45 $GLOBALS['refid']  = 0;
46 $CSS = 0;
47 $msg = null;
48
49 // Load the required file(s)
50 require ("inc/config.php");
51
52 // Is the script installed?
53 if (defined('mxchange_installed') && (isBooleanConstantAndTrue('mxchange_installed'))) {
54         // Only logged in users may use this surfbar!
55         if (!IS_LOGGED_IN()) {
56                 // Redirect
57                 LOAD_URL(URL."/modules.php?module=index");
58         } elseif (!EXT_IS_ACTIVE("surfbar")) {
59                 // Surfbar deactivated
60                 LOAD_URL(URL."/modules.php?module=login&msg=".CODE_EXTENSION_PROBLEM);
61         }
62
63         // Is there a check value?
64         if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isset($_GET['frame'])) && (in_array($_GET['frame'], array("stop", "stop2", "stats", "textlinks"))))) {
65                 // Reload-lock is full, surfbar stopped so...
66                 // Load header
67                 require_once(PATH."inc/header.php");
68
69                 // Load template
70                 if (((isset($_GET['frame'])) && ($_GET['frame'] == "stop")) || (!isset($_GET['frame']))) {
71                         // Load template for "start" page
72                         LOAD_TEMPLATE("surfbar_frame_start");
73
74                         // Load banner
75                         OUTPUT_HTML("<br />");
76                         LOAD_TEMPLATE("surfbar_start_banner");
77
78                         // This makes the footer appear again
79                         unset($_GET['frame']);
80                 } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "stats")) {
81                         // Get total points amount
82                         $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
83
84                         // Prepare content
85                         $content = array(
86                                 'points'   => TRANSLATE_COMMA($points),
87                                 'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
88                                 'reload'   => ($_CONFIG['surfbar_stats_reload'] * 1000),
89                                 'c_total'  => TRANSLATE_COMMA($_CONFIG['surfbar_total_counter']),
90                                 'c_today'  => TRANSLATE_COMMA($_CONFIG['surfbar_daily_counter']),
91                                 'c_yester' => TRANSLATE_COMMA($_CONFIG['surfbar_yester_counter']),
92                                 'c_week'   => TRANSLATE_COMMA($_CONFIG['surfbar_weekly_counter']),
93                                 'c_month'  => TRANSLATE_COMMA($_CONFIG['surfbar_monthly_counter']),
94                         );
95
96                         // Load template for "stats" page
97                         LOAD_TEMPLATE("surfbar_frame_stats", false, $content);
98                 } else {
99                         // Prepare content
100                         $content = array(
101                                 'restart'   => $_CONFIG['surfbar_restart_time'],
102                                 'start'     => str_repeat("X", strlen($_CONFIG['surfbar_restart_time'])),
103                                 'autostart' => ($_CONFIG['surfbar_autostart'] == "Y") ? "true" : "false"
104                         );
105
106                         // Load template for stopped surfbar
107                         LOAD_TEMPLATE("surfbar_stopped", false, $content);
108                 }
109         } elseif ((isset($_GET['check'])) && (isset($_GET['id'])) && (isset($_GET['salt']))) {
110                 // Dummy next id get
111                 SURFBAR_GET_NEXT_ID($_GET['id']);
112
113                 // Check reload lock and validation code
114                 if ((!SURFBAR_CHECK_RELOAD_LOCK($_GET['id'])) && (SURFBAR_CHECK_VALIDATION_CODE($_GET['id'], $_GET['check'], $_GET['salt']))) {
115                         // Lock the URL (id) down
116                         SURFBAR_LOCKDOWN_ID($_GET['id']);
117
118                         // Code is valid so pay points here
119                         SURFBAR_PAY_POINTS($_GET['id']);
120
121                         // Check if reload is full
122                         if (SURFBAR_CHECK_RELOAD_FULL()) {
123                                 // Then load waiting page
124                                 LOAD_URL("surfbar.php?frame=stop");
125                         } // END - if
126                 } else {
127                         // Reload to stop frame!
128                         LOAD_URL("surfbar.php?frame=stop");
129                 }
130
131                 // All done, so fix notice for footer.php
132                 $footer = 1;
133         } else {
134                 // Prepare content
135                 $content = "";
136
137                 // Determine template name
138                 $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
139
140                 // Frame "top" set?
141                 if ((isset($_GET['frame'])) && ($_GET['frame'] == "top")) {
142                         // Determine next id
143                         $nextId = SURFBAR_GET_NEXT_ID();
144
145                         // Is there a valid id?
146                         if ($nextId > 0) {
147                                 // Then prepare other content
148                                 $content = array(
149                                         'id'          => $nextId,
150                                         'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
151                                         'salt'        => SURFBAR_GET_SALT(),
152                                         'reward'      => TRANSLATE_COMMA(SURFBAR_GET_REWARD($nextId)),
153                                         'url'         => SURFBAR_GET_URL($nextId),
154                                         'curr_reload' => SURFBAR_GET_USER_RELOAD_LOCK(),
155                                         'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
156                                         'reload'      => SURFBAR_GET_RELOAD_TIME($nextId)
157                                 );
158
159                                 // Update salt (double-call lock!) and statistics
160                                 SURFBAR_UPDATE_SALT_STATS();
161                         } else {
162                                 // Load new URL
163                                 LOAD_URL("surfbar.php?frame=stop2");
164                         }
165                 } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "start")) {
166                         // Starter frame found so let the footer display
167                         unset($_GET['frame']);
168                 } else {
169                         // Load header in frameset mode
170                         $isFrameset = true;
171                 }
172
173                 // Load header
174                 require_once(PATH."inc/header.php");
175
176                 // Load that template
177                 //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
178                 LOAD_TEMPLATE($templateName, false, $content);
179         }
180
181         // Load footer
182         require_once(PATH."inc/footer.php");
183 } else {
184         // You have to configure first!
185         LOAD_URL("install.php");
186 }
187
188 // Close any open database connection here
189 SQL_CLOSE($link, __FILE__, __LINE__);
190
191 // Really all done here... ;-)
192 ?>