Large code 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 referral 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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Some sanity-check
47 if ((!isPostRequestElementSet('url')) || (!isPostRequestElementSet('alternate'))) {
48         unsetPostRequestElement('ok');
49 } // END - if
50
51 if (isFormSent()) {
52         // Fix older calls from add-new-banner-form
53         if (!isGetRequestElementSet('mode')) setGetRequestElement('mode', 'add');
54         $sql = '';
55         switch (getRequestElement('mode')) {
56                 case 'add':
57                         // Check if banner is already added
58                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `url`='%s' LIMIT 1",
59                                 array(postRequestElement('url')), __FILE__, __LINE__);
60
61                         // Was the banner found?
62                         if (SQL_HASZERONUMS($result)) {
63                                 // Add banner
64                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (`url`,`alternate`,`visible`)
65 VALUES ('%s','%s','%s')",
66                                         array(
67                                                 postRequestElement('url'),
68                                                 postRequestElement('alternate'),
69                                                 postRequestElement('visible')
70                                         ), __FILE__, __LINE__);
71                         } // END - if
72
73                         // Free memory
74                         SQL_FREERESULT($result);
75                         break;
76
77                 case 'edit': // Update banner
78                         foreach (postRequestElement('sel') as $id => $sel) {
79                                 // Secure id
80                                 $id = bigintval($id);
81
82                                 // Update entry
83                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `url`='%s',`alternate`='%s',`visible`='%s' WHERE `id`=%s LIMIT 1",
84                                         array(
85                                                 postRequestElement('url', $id),
86                                                 postRequestElement('alternate', $id),
87                                                 postRequestElement('visible'),
88                                                 $id
89                                         ), __FILE__, __LINE__);
90                         }
91                         break;
92         } // END - switch
93
94         // Check if we have saved (updated)
95         if (!SQL_HASZEROAFFECTED()) {
96                 // Updated!
97                 $content = '{--SETTINGS_SAVED--}';
98         } else {
99                 // Nothing has been updated
100                 $content = '<span class="notice">{--SETTINGS_NOT_SAVED--}</span>';
101         }
102
103         // Display message
104         displayMessage($content);
105 } elseif ((ifPostContainsSelections()) && (isFormSent('edit'))) {
106         // Edit banner
107         $OUT = '';
108         foreach (postRequestElement('sel') as $id => $sel) {
109                 // Load data
110                 $result = SQL_QUERY_ESC("SELECT `id`,`url`,`alternate`,`visible` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
111                         array(bigintval($id)), __FILE__, __LINE__);
112                 $content = SQL_FETCHARRAY($result);
113                 SQL_FREERESULT($result);
114
115                 // Preapre data for the row
116                 $content['visible'] = addSelectionBox('yn', $content['visible'], 'visible');
117
118                 // Load row template and switch color
119                 $OUT .= loadTemplate('admin_edit_refbanner_row', true, $content);
120         } // END - foreach
121
122         // Load main template
123         loadTemplate('admin_edit_refbanner', false, $OUT);
124 } else {
125         if ((ifPostContainsSelections()) && (isFormSent('delete'))) {
126                 // Delete banner
127                 foreach (postRequestElement('sel') as $id => $sel) {
128                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
129                         array(bigintval($id)), __FILE__, __LINE__);
130                 } // END - foreach
131         } // END - if
132
133         // Referral levels
134         $result = SQL_QUERY('SELECT `id`,`url`,`alternate`,`visible`,`counter`,`clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY `url` ASC', __FILE__, __LINE__);
135
136         // Entries found?
137         if (!SQL_HASZERONUMS($result)) {
138                 // Make referral banner editable and deletable
139                 $OUT = '';
140                 while ($content = SQL_FETCHARRAY($result)) {
141                         // Load row template and switch color
142                         $OUT .= loadTemplate('admin_list_refbanner_row', true, $content);
143                 } // END - while
144
145                 // Free memory
146                 SQL_FREERESULT($result);
147
148                 // Load main template
149                 loadTemplate('admin_list_refbanner', false, $OUT);
150         } // END - if
151
152         // Form for adding new referral levels
153         loadTemplate('admin_add_refbanner');
154 }
155
156 // [EOF]
157 ?>