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