Bad things are now 'classified' as bad (CSS class 'bad' is being used instead of...
[mailer.git] / inc / modules / admin / what-refbanner.php
index 33a3ff3933000c68ad343dc56bb11cfec0587f61..e8754f6ba2eb3b28ab48ec4d24dd0344f1914e55 100644 (file)
@@ -6,7 +6,7 @@
  * -------------------------------------------------------------------- *
  * File              : what-refbanner.php                               *
  * -------------------------------------------------------------------- *
- * Short description : Manage all referal banner                        *
+ * Short description : Manage all referral banner                       *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Alle Banner fuer die Ref-Links verwalten         *
  * -------------------------------------------------------------------- *
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
 // Some security stuff...
 if ((!defined('__SECURITY')) || (!isAdmin())) {
        die();
-}
+} // END - if
 
 // Add description as navigation point
-addMenuDescription('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
 // Some sanity-check
-if ((!isPostRequestElementSet('url')) || (!isPostRequestElementSet(('alternate')))) {
+if ((!isPostRequestElementSet('url')) || (!isPostRequestElementSet('alternate'))) {
        unsetPostRequestElement('ok');
-}
+} // END - if
 
 if (isFormSent()) {
        // Fix older calls from add-new-banner-form
@@ -56,17 +55,23 @@ if (isFormSent()) {
        switch (getRequestElement('mode')) {
                case 'add':
                        // Check if banner is already added
-                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE url='%s' LIMIT 1",
-                       array(postRequestElement('url')), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == '0') {
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `url`='%s' LIMIT 1",
+                               array(postRequestElement('url')), __FILE__, __LINE__);
+
+                       // Was the banner found?
+                       if (SQL_HASZERONUMS($result)) {
                                // Add banner
-                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (url, alternate, visible)
+                               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refbanner` (`url`,`alternate`,`visible`)
 VALUES ('%s','%s','%s')",
-                               array(postRequestElement('url'), postRequestElement('alternate'), postRequestElement('visible')), __FILE__, __LINE__);
-                       } else {
-                               // Free memory
-                               SQL_FREERESULT($result);
-                       }
+                                       array(
+                                               postRequestElement('url'),
+                                               postRequestElement('alternate'),
+                                               postRequestElement('visible')
+                                       ), __FILE__, __LINE__);
+                       } // END - if
+
+                       // Free memory
+                       SQL_FREERESULT($result);
                        break;
 
                case 'edit': // Update banner
@@ -75,7 +80,7 @@ VALUES ('%s','%s','%s')",
                                $id = bigintval($id);
 
                                // Update entry
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET url='%s', alternate='%s', `visible`='%s' WHERE `id`=%s LIMIT 1",
+                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `url`='%s',`alternate`='%s',`visible`='%s' WHERE `id`=%s LIMIT 1",
                                        array(
                                                postRequestElement('url', $id),
                                                postRequestElement('alternate', $id),
@@ -84,42 +89,40 @@ VALUES ('%s','%s','%s')",
                                        ), __FILE__, __LINE__);
                        }
                        break;
-       }
+       } // END - switch
 
-       if (SQL_AFFECTEDROWS() == 1) {
-               $content = getMessage('SETTINGS_SAVED');
+       // Check if we have saved (updated)
+       if (!SQL_HASZEROAFFECTED()) {
+               // Updated!
+               $content = '{--SETTINGS_SAVED--}';
        } else {
-               $content = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
+               // Nothing has been updated
+               $content = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
        }
-       loadTemplate('admin_settings_saved', false, $content);
-} elseif ((countPostSelection() > 0) && (isPostRequestElementSet('edit'))) {
+
+       // Display message
+       displayMessage($content);
+} elseif ((ifPostContainsSelections()) && (isFormSent('edit'))) {
        // Edit banner
-       $SW = 2; $OUT = '';
+       $OUT = '';
        foreach (postRequestElement('sel') as $id => $sel) {
                // Load data
-               $result = SQL_QUERY_ESC("SELECT url, alternate, visible FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
-               array(bigintval($id)), __FILE__, __LINE__);
-               list($url, $alt, $vis) = SQL_FETCHROW($result);
+               $result = SQL_QUERY_ESC("SELECT `id`,`url`,`alternate`,`visible` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)), __FILE__, __LINE__);
+               $content = SQL_FETCHARRAY($result);
                SQL_FREERESULT($result);
 
                // Preapre data for the row
-               $content = array(
-                       'sw'  => $SW,
-                       'id'  => $id,
-                       'url' => $url,
-                       'alt' => $alt,
-                       'vis' => addSelectionBox('yn', $vis   , 'visible'),
-               );
+               $content['visible'] = addSelectionBox('yn', $content['visible'], 'visible');
 
                // Load row template and switch color
-               $OUT .= loadTemplate('admin_refbanner_edit_row', true, $content);
-               $SW = 3 - $SW;
-       }
+               $OUT .= loadTemplate('admin_edit_refbanner_row', true, $content);
+       } // END - foreach
 
        // Load main template
-       loadTemplate('admin_refbanner_edit', false, $OUT);
+       loadTemplate('admin_edit_refbanner', false, $OUT);
 } else {
-       if ((countPostSelection() > 0) && (isPostRequestElementSet('del'))) {
+       if ((ifPostContainsSelections()) && (isFormSent('delete'))) {
                // Delete banner
                foreach (postRequestElement('sel') as $id => $sel) {
                        SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1",
@@ -127,40 +130,27 @@ VALUES ('%s','%s','%s')",
                } // END - foreach
        } // END - if
 
-       // Referal levels
-       $result = SQL_QUERY("SELECT id, url, alternate, visible, counter, clicks FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY url", __FILE__, __LINE__);
+       // Referral levels
+       $result = SQL_QUERY('SELECT `id`,`url`,`alternate`,`visible`,`counter`,`clicks` FROM `{?_MYSQL_PREFIX?}_refbanner` ORDER BY `url` ASC', __FILE__, __LINE__);
 
        // Entries found?
-       if (SQL_NUMROWS($result) > 0) {
-               // Make referal banner editable and deletable
-               $OUT = ''; $SW = 2;
+       if (!SQL_HASZERONUMS($result)) {
+               // Make referral banner editable and deletable
+               $OUT = '';
                while ($content = SQL_FETCHARRAY($result)) {
-                       // Preapre data for the row
-                       // @TODO Rewritings: alt->alternate,cnt->counter,clx->clicks in template
-                       $content = array(
-                               'sw'  => $SW,
-                               'id'  => $content['id'],
-                               'url' => $content['url'],
-                               'alt' => $content['alternate'],
-                               'vis' => translateYesNo($content['visible']),
-                               'cnt' => $content['counter'],
-                               'clx' => $content['clicks']
-                       );
-
                        // Load row template and switch color
-                       $OUT .= loadTemplate('admin_refbanner_row', true, $content);
-                       $SW = 3 - $SW;
-               }
+                       $OUT .= loadTemplate('admin_list_refbanner_row', true, $content);
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
 
                // Load main template
-               loadTemplate('admin_refbanner', false, $OUT);
-       }
+               loadTemplate('admin_list_refbanner', false, $OUT);
+       } // END - if
 
-       // Form for adding new referal levels
-       loadTemplate('admin_add_banner');
+       // Form for adding new referral levels
+       loadTemplate('admin_add_refbanner');
 }
 
 // [EOF]