A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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  *                                                                      *
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 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 }
41
42 // Add description as navigation point
43 ADD_DESCR("member", __FILE__);
44
45 // Load current referal clicks
46 $result = SQL_QUERY_ESC("SELECT ref_clicks FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
47         array($GLOBALS['userid']), __FILE__, __LINE__);
48 list($c) = SQL_FETCHROW($result);
49 SQL_FREERESULT($result);
50
51 OUTPUT_HTML("<div class=\"tiny\">{--YOUR_PERSONAL_REFLINK--}:<br />
52 <strong><a href=\"{!URL!}/ref.php?refid=".$GLOBALS['userid']."\" target=\"_blank\">{!URL!}/ref.php?ref=".$GLOBALS['userid']."</a></strong><br />
53 <br />");
54
55 if (EXT_IS_ACTIVE("nickname")) {
56         // Add nickname link when nickname is entered
57         $nick = NICKNAME_GET_NICK($GLOBALS['userid']);
58
59         if (!empty($nick)) {
60                 // Display nickname link
61                 OUTPUT_HTML("{--NICKNAME_YOUR_REFLINK--}:<br />
62 <strong><a href=\"{!URL!}/ref.php?ref=".$nick."\" target=\"_blank\">{!URL!}/ref.php?ref=".$nick."</a></strong><br />
63 <br />");
64         } else {
65                 // Display link to nickname form
66                 OUTPUT_HTML("<div class=\"guest_note\">{--NO_NICKNAME_SET--}</strong><br />
67 <a class=\"tiny\" href=\"{!URL!}/modules.php?module=login&amp;what=nickname\">{--PLEASE_CLICK_NICKNAME_FORM--}</a>");
68         }
69 }
70
71 // Clicks on your reflink
72 OUTPUT_HTML("{--YOUR_REFCLICKS--}: <strong>".$c."</strong> {--CLICKS--}</div><br /><br />");
73 $whereStatement = " WHERE `visible`='Y'";
74 if (IS_ADMIN()) $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 ($content = SQL_FETCHARRAY($result)) {
81                 $test = str_replace(constant('URL'), constant('PATH'), $content['url']); $size = 0;
82                 if ($test == $content['url']) {
83                         // Download banner (I hope you keep the banner on same server???)
84                         $fp = GET_URL($content['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                                 }
91                         }
92                         $size = strlen($bannerContent);
93                 } elseif (FILE_READABLE($test)) {
94                         $size = filesize($test);
95                 }
96
97                 if ($size > 0) $content['alternate'] .= " (".TRANSLATE_COMMA(round($size/102.4)/10)." {--KBYTES--})";
98
99                 // Load banner data
100                 // @TODO Rewritings: alt->alternate,cnt->counter,cks->clicks,uid->userid in template
101                 $content = array(
102                         'sw'  => $SW,
103                         'url' => $content['url'],
104                         'alt' => $content['alternate'],
105                         'cnt' => $content['counter'],
106                         'cks' => $content['clicks'],
107                         'uid' => $GLOBALS['userid'],
108                         'id'  => $content['id'],
109                 );
110
111                 // Add row
112                 $OUT .= LOAD_TEMPLATE("member_reflinks_row", true, $content);
113
114                 // Switchcolors
115                 $SW = 3 - $SW;
116         }
117
118         define('__REFLINKS_ROWS', $OUT);
119
120         // Load final template
121         LOAD_TEMPLATE("member_reflinks_table", false, $GLOBALS['userid']);
122 } else {
123         // No refbanner found!
124         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_NO_REFBANNER_FOUND'));
125 }
126
127 // Free result
128 SQL_FREERESULT($result);
129
130 //
131 ?>