Some fixes for surfbar extension (#123), double->single, misc cleanups/fixes
[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 referal banner                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Banner fuer die Ref-Links verwalten         *
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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 // Init variable
49 $SEL = 0;
50
51 // Some sanity-check
52 if ((!REQUEST_ISSET_POST('url')) || (!REQUEST_ISSET_POST(('alternate')))) {
53         REQUEST_UNSET_POST('ok');
54 }
55
56 // Check selection count
57 if (REQUEST_ISSET_POST('sel')) $SEL = countPostSelection();
58
59 if (isFormSent()) {
60         // Fix older calls from add-new-banner-form
61         if (!REQUEST_ISSET_GET('mode')) REQUEST_SET_GET('mode', 'add');
62         $sql = '';
63         switch (REQUEST_GET('mode'))
64         {
65                 case 'add':
66                         // Check if banner is already added
67                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_refbanner` WHERE url='%s' LIMIT 1",
68                         array(REQUEST_POST('url')), __FILE__, __LINE__);
69                         if (SQL_NUMROWS($result) == 0) {
70                                 // Add banner
71                                 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_refbanner` (url, alternate, visible)
72 VALUES ('%s','%s','%s')",
73                                 array(REQUEST_POST('url'), REQUEST_POST('alternate'), REQUEST_POST('visible')), __FILE__, __LINE__);
74                         } else {
75                                 // Free memory
76                                 SQL_FREERESULT($result);
77                         }
78                         break;
79
80                 case 'edit': // Update banner
81                         foreach (REQUEST_POST('sel') as $id => $sel) {
82                                 // Secure ID
83                                 $id = bigintval($id);
84
85                                 // Update entry
86                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_refbanner` SET url='%s', alternate='%s', `visible`='%s' WHERE `id`=%s LIMIT 1",
87                                 array(
88                                 REQUEST_POST('url', $id),
89                                 REQUEST_POST('alternate', $id),
90                                 REQUEST_POST('visible'),
91                                 $id
92                                 ), __FILE__, __LINE__);
93                         }
94                         break;
95         }
96
97         if (SQL_AFFECTEDROWS() == 1) {
98                 $content = getMessage('SETTINGS_SAVED');
99         } else {
100                 $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
101         }
102         LOAD_TEMPLATE('admin_settings_saved', false, $content);
103 } elseif (($SEL > 0) && (REQUEST_ISSET_POST('edit'))) {
104         // Edit banner
105         $SW = 2; $OUT = '';
106         foreach (REQUEST_POST('sel') as $id => $sel) {
107                 // Load data
108                 $result = SQL_QUERY_ESC("SELECT url, alternate, visible FROM `{!_MYSQL_PREFIX!}_refbanner` WHERE `id`=%s LIMIT 1",
109                 array(bigintval($id)), __FILE__, __LINE__);
110                 list($url, $alt, $vis) = SQL_FETCHROW($result);
111                 SQL_FREERESULT($result);
112
113                 // Preapre data for the row
114                 $content = array(
115                         'sw'  => $SW,
116                         'id'  => $id,
117                         'url' => $url,
118                         'alt' => $alt,
119                         'vis' => ADD_SELECTION('yn', $vis   , "visible"),
120                 );
121
122                 // Load row template and switch color
123                 $OUT .= LOAD_TEMPLATE("admin_refbanner_edit_row", true, $content);
124                 $SW = 3 - $SW;
125         }
126
127         // @TODO Rewrite this constant
128         define('__BANNER_ROWS', $OUT);
129
130         // Load main template
131         LOAD_TEMPLATE("admin_refbanner_edit");
132 } else {
133         if (($SEL > 0) && (REQUEST_ISSET_POST('del'))) {
134                 // Delete banner
135                 foreach (REQUEST_POST('sel') as $id => $sel) {
136                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_refbanner` WHERE `id`=%s LIMIT 1",
137                         array(bigintval($id)), __FILE__, __LINE__);
138                 }
139         }
140
141         // Referal levels
142         $result = SQL_QUERY("SELECT id, url, alternate, visible, counter, clicks FROM `{!_MYSQL_PREFIX!}_refbanner` ORDER BY url",
143         __FILE__, __LINE__);
144         if (SQL_NUMROWS($result) > 0) {
145                 // Make referal banner editable and deletable
146                 $OUT = ''; $SW = 2;
147                 while ($content = SQL_FETCHARRAY($result)) {
148                         // Preapre data for the row
149                         // @TODO Rewritings: alt->alternate,cnt->counter,clx->clicks in template
150                         $content = array(
151                                 'sw'  => $SW,
152                                 'id'  => $content['id'],
153                                 'url' => $content['url'],
154                                 'alt' => $content['alternate'],
155                                 'vis' => translateYesNo($content['visible']),
156                                 'cnt' => $content['counter'],
157                                 'clx' => $content['clicks']
158                         );
159
160                         // Load row template and switch color
161                         $OUT .= LOAD_TEMPLATE("admin_refbanner_row", true, $content);
162                         $SW = 3 - $SW;
163                 }
164
165                 // Free memory
166                 SQL_FREERESULT($result);
167
168                 // @TODO Rewrite this constant
169                 define('__BANNER_ROWS', $OUT);
170
171                 // Load main template
172                 LOAD_TEMPLATE("admin_refbanner");
173         }
174
175         // Form for adding new referal levels
176         LOAD_TEMPLATE("admin_add_banner");
177 }
178
179 //
180 ?>