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