Even more fixes/improvements for rallye
[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 - 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 // Init variable
48 $SEL = 0;
49
50 // Some sanity-check
51 if ((!isPostRequestElementSet('url')) || (!isPostRequestElementSet(('alternate')))) {
52         unsetPostRequestElement('ok');
53 }
54
55 // Check selection count
56 if (isPostRequestElementSet('sel')) $SEL = countPostSelection();
57
58 if (isFormSent()) {
59         // Fix older calls from add-new-banner-form
60         if (!isGetRequestElementSet('mode')) setRequestGetElement('mode', 'add');
61         $sql = '';
62         switch (getRequestElement('mode')) {
63                 case 'add':
64                         // Check if banner is already added
65                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE url='%s' LIMIT 1",
66                         array(postRequestElement('url')), __FILE__, __LINE__);
67                         if (SQL_NUMROWS($result) == 0) {
68                                 // Add banner
69                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (url, alternate, visible)
70 VALUES ('%s','%s','%s')",
71                                 array(postRequestElement('url'), postRequestElement('alternate'), postRequestElement('visible')), __FILE__, __LINE__);
72                         } else {
73                                 // Free memory
74                                 SQL_FREERESULT($result);
75                         }
76                         break;
77
78                 case 'edit': // Update banner
79                         foreach (postRequestElement('sel') as $id => $sel) {
80                                 // Secure id
81                                 $id = bigintval($id);
82
83                                 // Update entry
84                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET url='%s', alternate='%s', `visible`='%s' WHERE `id`=%s LIMIT 1",
85                                 array(
86                                 postRequestElement('url', $id),
87                                 postRequestElement('alternate', $id),
88                                 postRequestElement('visible'),
89                                 $id
90                                 ), __FILE__, __LINE__);
91                         }
92                         break;
93         }
94
95         if (SQL_AFFECTEDROWS() == 1) {
96                 $content = getMessage('SETTINGS_SAVED');
97         } else {
98                 $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
99         }
100         loadTemplate('admin_settings_saved', false, $content);
101 } elseif (($SEL > 0) && (isPostRequestElementSet('edit'))) {
102         // Edit banner
103         $SW = 2; $OUT = '';
104         foreach (postRequestElement('sel') as $id => $sel) {
105                 // Load data
106                 $result = SQL_QUERY_ESC("SELECT url, alternate, visible FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
107                 array(bigintval($id)), __FILE__, __LINE__);
108                 list($url, $alt, $vis) = SQL_FETCHROW($result);
109                 SQL_FREERESULT($result);
110
111                 // Preapre data for the row
112                 $content = array(
113                         'sw'  => $SW,
114                         'id'  => $id,
115                         'url' => $url,
116                         'alt' => $alt,
117                         'vis' => addSelectionBox('yn', $vis   , 'visible'),
118                 );
119
120                 // Load row template and switch color
121                 $OUT .= loadTemplate('admin_refbanner_edit_row', true, $content);
122                 $SW = 3 - $SW;
123         }
124
125         // Load main template
126         loadTemplate('admin_refbanner_edit', false, $OUT);
127 } else {
128         if (($SEL > 0) && (isPostRequestElementSet('del'))) {
129                 // Delete banner
130                 foreach (postRequestElement('sel') as $id => $sel) {
131                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
132                         array(bigintval($id)), __FILE__, __LINE__);
133                 } // END - foreach
134         } // END - if
135
136         // Referal levels
137         $result = SQL_QUERY("SELECT id, url, alternate, visible, counter, clicks FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY url", __FILE__, __LINE__);
138
139         // Entries found?
140         if (SQL_NUMROWS($result) > 0) {
141                 // Make referal banner editable and deletable
142                 $OUT = ''; $SW = 2;
143                 while ($content = SQL_FETCHARRAY($result)) {
144                         // Preapre data for the row
145                         // @TODO Rewritings: alt->alternate,cnt->counter,clx->clicks in template
146                         $content = array(
147                                 'sw'  => $SW,
148                                 'id'  => $content['id'],
149                                 'url' => $content['url'],
150                                 'alt' => $content['alternate'],
151                                 'vis' => translateYesNo($content['visible']),
152                                 'cnt' => $content['counter'],
153                                 'clx' => $content['clicks']
154                         );
155
156                         // Load row template and switch color
157                         $OUT .= loadTemplate('admin_refbanner_row', true, $content);
158                         $SW = 3 - $SW;
159                 }
160
161                 // Free memory
162                 SQL_FREERESULT($result);
163
164                 // Load main template
165                 loadTemplate('admin_refbanner', false, $OUT);
166         }
167
168         // Form for adding new referal levels
169         loadTemplate('admin_add_banner');
170 }
171
172 // [EOF]
173 ?>