More double quotes to single rewritten, CSS/HTML cleanups
[mailer.git] / inc / modules / admin / what-refbanner.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 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')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Some sanity-check
48 if ((!isPostRequestParameterSet('url')) || (!isPostRequestParameterSet(('alternate')))) {
49         unsetPostRequestParameter('ok');
50 }
51
52 if (isFormSent()) {
53         // Fix older calls from add-new-banner-form
54         if (!isGetRequestParameterSet('mode')) setGetRequestParameter('mode', 'add');
55         $sql = '';
56         switch (getRequestParameter('mode')) {
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(postRequestParameter('url')), __FILE__, __LINE__);
61                         if (SQL_NUMROWS($result) == '0') {
62                                 // Add banner
63                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (url, alternate, visible)
64 VALUES ('%s','%s','%s')",
65                                 array(postRequestParameter('url'), postRequestParameter('alternate'), postRequestParameter('visible')), __FILE__, __LINE__);
66                         } else {
67                                 // Free memory
68                                 SQL_FREERESULT($result);
69                         }
70                         break;
71
72                 case 'edit': // Update banner
73                         foreach (postRequestParameter('sel') as $id => $sel) {
74                                 // Secure id
75                                 $id = bigintval($id);
76
77                                 // Update entry
78                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET url='%s', alternate='%s', `visible`='%s' WHERE `id`=%s LIMIT 1",
79                                         array(
80                                                 postRequestParameter('url', $id),
81                                                 postRequestParameter('alternate', $id),
82                                                 postRequestParameter('visible'),
83                                                 $id
84                                         ), __FILE__, __LINE__);
85                         }
86                         break;
87         }
88
89         // Check if we have saved (updated)
90         if (SQL_AFFECTEDROWS() == 1) {
91                 // Updated!
92                 $content = getMessage('SETTINGS_SAVED');
93         } else {
94                 // Nothing has been updated
95                 $content = '<span class="admin_failed">{--SETTINGS_NOT_SAVED--}</span>';
96         }
97
98         // Display message
99         loadTemplate('admin_settings_saved', false, $content);
100 } elseif ((countPostSelection() > 0) && (isPostRequestParameterSet('edit'))) {
101         // Edit banner
102         $SW = 2; $OUT = '';
103         foreach (postRequestParameter('sel') as $id => $sel) {
104                 // Load data
105                 $result = SQL_QUERY_ESC("SELECT url, alternate, visible FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
106                 array(bigintval($id)), __FILE__, __LINE__);
107                 list($url, $alt, $vis) = SQL_FETCHROW($result);
108                 SQL_FREERESULT($result);
109
110                 // Preapre data for the row
111                 $content = array(
112                         'sw'  => $SW,
113                         'id'  => $id,
114                         'url' => $url,
115                         'alt' => $alt,
116                         'vis' => addSelectionBox('yn', $vis   , 'visible'),
117                 );
118
119                 // Load row template and switch color
120                 $OUT .= loadTemplate('admin_refbanner_edit_row', true, $content);
121                 $SW = 3 - $SW;
122         }
123
124         // Load main template
125         loadTemplate('admin_refbanner_edit', false, $OUT);
126 } else {
127         if ((countPostSelection() > 0) && (isPostRequestParameterSet('del'))) {
128                 // Delete banner
129                 foreach (postRequestParameter('sel') as $id => $sel) {
130                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
131                         array(bigintval($id)), __FILE__, __LINE__);
132                 } // END - foreach
133         } // END - if
134
135         // Referal levels
136         $result = SQL_QUERY("SELECT id, url, alternate, visible, counter, clicks FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY url", __FILE__, __LINE__);
137
138         // Entries found?
139         if (SQL_NUMROWS($result) > 0) {
140                 // Make referal banner editable and deletable
141                 $OUT = ''; $SW = 2;
142                 while ($content = SQL_FETCHARRAY($result)) {
143                         // Preapre data for the row
144                         // @TODO Rewritings: alt->alternate,cnt->counter,clx->clicks in template
145                         $content = array(
146                                 'sw'  => $SW,
147                                 'id'  => $content['id'],
148                                 'url' => $content['url'],
149                                 'alt' => $content['alternate'],
150                                 'vis' => translateYesNo($content['visible']),
151                                 'cnt' => $content['counter'],
152                                 'clx' => $content['clicks']
153                         );
154
155                         // Load row template and switch color
156                         $OUT .= loadTemplate('admin_refbanner_row', true, $content);
157                         $SW = 3 - $SW;
158                 }
159
160                 // Free memory
161                 SQL_FREERESULT($result);
162
163                 // Load main template
164                 loadTemplate('admin_refbanner', false, $OUT);
165         }
166
167         // Form for adding new referal levels
168         loadTemplate('admin_add_banner');
169 }
170
171 // [EOF]
172 ?>