Renamed all SQL-related functions to camel-case notation
[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 - 2013 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         $sql = '';
53         switch (getRequestElement('do')) {
54                 case 'add':
55                         // Check if banner is already added
56                         $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `url`='%s' LIMIT 1",
57                                 array(postRequestElement('url')), __FILE__, __LINE__);
58
59                         // Was the banner found?
60                         if (ifSqlHasZeroNums($result)) {
61                                 // Add banner
62                                 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (`url`, `alternate`, `visible`)
63 VALUES ('%s','%s','%s')",
64                                         array(
65                                                 postRequestElement('url'),
66                                                 postRequestElement('alternate'),
67                                                 postRequestElement('visible')
68                                         ), __FILE__, __LINE__);
69                         } // END - if
70
71                         // Free memory
72                         sqlFreeResult($result);
73                         break;
74
75                 case 'edit': // Update banner
76                         foreach (postRequestElement('sel') as $id => $sel) {
77                                 // Secure id
78                                 $id = bigintval($id);
79
80                                 // Update entry
81                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `url`='%s',`alternate`='%s',`visible`='%s' WHERE `id`=%s LIMIT 1",
82                                         array(
83                                                 postRequestElement('url', $id),
84                                                 postRequestElement('alternate', $id),
85                                                 postRequestElement('visible'),
86                                                 $id
87                                         ), __FILE__, __LINE__);
88                         }
89                         break;
90         } // END - switch
91
92         // Check if we have saved (updated)
93         if (!ifSqlHasZeroAffectedRows()) {
94                 // Updated!
95                 $content = '{--SETTINGS_SAVED--}';
96         } else {
97                 // Nothing has been updated
98                 $content = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
99         }
100
101         // Display message
102         displayMessage($content);
103 } elseif ((ifPostContainsSelections()) && (isFormSent('edit'))) {
104         // Edit banner
105         $OUT = '';
106         foreach (postRequestElement('sel') as $id => $sel) {
107                 // Load data
108                 $result = sqlQueryEscaped("SELECT `id`, `url`, `alternate`, `visible` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
109                         array(bigintval($id)), __FILE__, __LINE__);
110                 $content = sqlFetchArray($result);
111                 sqlFreeResult($result);
112
113                 // Preapre data for the row
114                 $content['visible'] = addSelectionBox('yn', $content['visible'], 'visible');
115
116                 // Load row template and switch color
117                 $OUT .= loadTemplate('admin_edit_refbanner_row', TRUE, $content);
118         } // END - foreach
119
120         // Load main template
121         loadTemplate('admin_edit_refbanner', FALSE, $OUT);
122 } else {
123         if ((ifPostContainsSelections()) && (isFormSent('delete'))) {
124                 // Delete banner
125                 foreach (postRequestElement('sel') as $id => $sel) {
126                         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
127                         array(bigintval($id)), __FILE__, __LINE__);
128                 } // END - foreach
129         } // END - if
130
131         // Referral levels
132         $result = sqlQuery('SELECT `id`, `url`, `alternate`, `visible`, `counter`, `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY `url` ASC', __FILE__, __LINE__);
133
134         // Entries found?
135         if (!ifSqlHasZeroNums($result)) {
136                 // Make referral banner editable and deletable
137                 $OUT = '';
138                 while ($content = sqlFetchArray($result)) {
139                         // Load row template and switch color
140                         $OUT .= loadTemplate('admin_list_refbanner_row', TRUE, $content);
141                 } // END - while
142
143                 // Free memory
144                 sqlFreeResult($result);
145
146                 // Load main template
147                 loadTemplate('admin_list_refbanner', FALSE, $OUT);
148         } // END - if
149
150         // Form for adding new referral levels
151         loadTemplate('admin_add_refbanner');
152 }
153
154 // [EOF]
155 ?>