c52ab321cd6985eef84c98239ecf32a7c42d12a8
[mailer.git] / inc / modules / admin / what-refbanner.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/19/2003 *
4  * ===============                              Last change: 07/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-refbanner.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Manage all referral banner                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Banner fuer die Ref-Links verwalten         *
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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 global $link;
44
45 $SEL = 0;
46 if ((empty($_POST['url'])) || (empty($_POST['alternate'])))
47 {
48         unset($_POST['ok']);
49 }
50 if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']);
51
52 OPEN_TABLE("100%", "admin_content admin_content_align", "");
53 if (isset($_POST['ok']))
54 {
55         // Fix older calls from add-new-banner-form
56         if (empty($_GET['mode'])) $_GET['mode'] = "add";
57         $SQL = "";
58         switch ($_GET['mode'])
59         {
60         case "add":
61                 // Check if banner is already added
62                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_refbanner WHERE url='%s' LIMIT 1",
63                  array($_POST['url']), __FILE__, __LINE__);
64                 if (SQL_NUMROWS($result) == 0)
65                 {
66                         // Add banner
67                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_refbanner (url, alternate, visible)
68 VALUES ('%s', '%s', '%s')",
69  array($_POST['url'], $_POST['alternate'], $_POST['visible']), __FILE__, __LINE__);
70                 }
71                  else
72                 {
73                         // Free memory
74                         SQL_FREERESULT($result);
75                 }
76                 break;
77
78         case "edit": // Update banner
79                 foreach ($_POST['sel'] as $id=>$sel)
80                 {
81                         // Secure ID
82                         $id = bigintval($id);
83
84                         // Update entry
85                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_refbanner SET url='%s', alternate='%s', visible='%s' WHERE id=%d LIMIT 1",
86                          array($_POST['url'][$id], $_POST['alternate'][$id], $_POST['visible'], $id), __FILE__, __LINE__);
87                 }
88                 break;
89         }
90         if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 1)
91         {
92                 $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
93         }
94          else
95         {
96                 $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
97         }
98         LOAD_TEMPLATE("admin_settings_saved", false, $content);
99 }
100  elseif (($SEL > 0) && (isset($_POST['edit'])))
101 {
102         // Edit banner
103         $SW = ""; $OUT = "";
104         foreach ($_POST['sel'] as $id=>$sel)
105         {
106                 // Load data
107                 $result = SQL_QUERY_ESC("SELECT url, alternate, visible FROM "._MYSQL_PREFIX."_refbanner WHERE id=%d LIMIT 1",
108                  array(bigintval($id)), __FILE__, __LINE__);
109                 list($url, $alt, $vis) = SQL_FETCHROW($result);
110                 SQL_FREERESULT($result);
111
112                 // Preapre data for the row
113                 $content = array(
114                         'sw'  => $SW,
115                         'id'  => $id,
116                         'url' => $url,
117                         'alt' => $alt,
118                         'vis' => ADD_SELECTION("yn", $vis   , "visible"),
119                 );
120
121                 // Load row template and switch color
122                 $OUT .= LOAD_TEMPLATE("admin_refbanner_edit_row", true, $content);
123                 $SW = 3 - $SW;
124         }
125         define('__BANNER_ROWS', $OUT);
126
127         // Load main template
128         LOAD_TEMPLATE("admin_refbanner_edit");
129 }
130  else
131 {
132         if (($SEL > 0) && (isset($_POST['del'])))
133         {
134                 // Delete banner
135                 foreach ($_POST['sel'] as $id=>$sel)
136                 {
137                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_refbanner WHERE id=%d LIMIT 1",
138                          array(bigintval($id)), __FILE__, __LINE__);
139                 }
140         }
141
142         // Referral levels
143         $result = SQL_QUERY("SELECT id, url, alternate, visible, counter, clicks FROM "._MYSQL_PREFIX."_refbanner ORDER BY url", __FILE__, __LINE__);
144         if (SQL_NUMROWS($result) > 0)
145         {
146                 // Make referral banner editable and deletable
147                 $SW = 2; $OUT = "";
148                 while (list($id, $url, $alt, $vis, $cntr, $clks) = SQL_FETCHROW($result))
149                 {
150                         // Preapre data for the row
151                         $content = array(
152                                 'sw'  => $SW,
153                                 'id'  => $id,
154                                 'url' => $url,
155                                 'alt' => $alt,
156                                 'vis' => TRANSLATE_YESNO($vis),
157                                 'cnt' => $cntr,
158                                 'clx' => $clks
159                         );
160
161                         // Load row template and switch color
162                         $OUT .= LOAD_TEMPLATE("admin_refbanner_row", true, $content);
163                         $SW = 3 - $SW;
164                 }
165
166                 // Free memory
167                 SQL_FREERESULT($result);
168                 define('__BANNER_ROWS', $OUT);
169
170                 // Load main template
171                 LOAD_TEMPLATE("admin_refbanner");
172         }
173
174         // Form for adding new referral levels
175         LOAD_TEMPLATE("admin_add_banner");
176 }
177 CLOSE_TABLE();
178 //
179 ?>