Naming inconsistencies for userid fixed
[mailer.git] / inc / modules / member / what-reflinks.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/19/2003 *
4  * ===============                              Last change: 09/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-reflinks.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Referal links                                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Referal-Links                                    *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 // Load current referal clicks
50 if (!fetchUserData(getMemberId())) {
51         // Something really bad happened
52         debug_report_bug('No user account ' . getMemberId() . ' found.');
53 } // END - if
54
55 // Prepare some data
56 $content['ref_clicks'] = getUserData('ref_clicks');
57 $content['userid']     = getMemberId();
58
59 // @TODO Move this into a filter
60 if (isExtensionActive('nickname')) {
61         // Add nickname link when nickname is entered
62         $nick = getNickname(getMemberId());
63
64         if (!empty($nick)) {
65                 // Display nickname link
66                 $content['nickname_content'] = loadTemplate('member_reflink_nickname', true, $nick);
67         } else {
68                 // Display link to nickname form
69                 $content['nickname_content'] = loadTemplate('member_reflink_no_nickname', true);
70         }
71 } // END - if
72
73 $whereStatement = " WHERE `visible`='Y'";
74 if (isAdmin()) $whereStatement = '';
75 $result = SQL_QUERY("SELECT `id`, `url`, `alternate`, `counter`, `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner`", __FILE__, __LINE__);
76
77 if (SQL_NUMROWS($result) > 0) {
78         // List available ref banners
79         $OUT = ''; $SW = 2;
80         while ($row = SQL_FETCHARRAY($result)) {
81                 $test = str_replace(getConfig('URL'), getConfig('PATH'), $row['url']); $size = 0;
82                 if ($test == $row['url']) {
83                         // Download banner (I hope you keep the banner on same server???)
84                         $fp = sendGetRequest($row['url']); $bannerContent = '';
85                         if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0)) {
86                                 // Loads only found banner, when there is a 404 error this foreach() command
87                                 // will cause an "Invalid argument supplied for foreach()" error
88                                 foreach ($fp as $f) {
89                                         $bannerContent .= $f;
90                                 } // END - foreach
91                         } // END - if
92                         $size = strlen($bannerContent);
93                 } elseif (isFileReadable($test)) {
94                         $size = filesize($test);
95                 }
96
97                 // Empty alternative text?
98                 if (empty($row['alternate'])) {
99                         // Then set default
100                         $row['alternate'] = '{?MAIN_TITLE?} - {?SLOGAN?}';
101                 } // END - if
102
103                 if ($size > 0) $row['alternate'] .= ' ('  .translateComma(round($size / 102.4) / 10) . ' {--KBYTES--})';
104
105                 // Add some more data
106                 $row['sw']     = $SW;
107                 $row['userid'] = getMemberId();
108
109                 // Add row
110                 $OUT .= loadTemplate('member_reflinks_row', true, $row);
111
112                 // Switchcolors
113                 $SW = 3 - $SW;
114         } // END - while
115
116         // Load final template
117         $content['refbanner_content'] = loadTemplate('member_reflinks_table', true, $OUT);
118 } else {
119         // No refbanner found!
120         $content['refbanner_content'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_REFBANNER_FOUND'));
121 }
122
123 // Free result
124 SQL_FREERESULT($result);
125
126 // Load main template
127 loadTemplate('member_reflink', false, $content);
128
129 // [EOF]
130 ?>