-<?php
-/************************************************************************
- * Mailer v0.2.1-FINAL Start: 10/22/2009 *
- * =================== Last change: 10/22/2009 *
- * *
- * -------------------------------------------------------------------- *
- * File : fix_menu.php *
- * -------------------------------------------------------------------- *
- * Short description : Fixes dublicate entries in filters table *
- * -------------------------------------------------------------------- *
- * Kurzbeschreibung : Repariert doppelte Eintraege in filters-Tabelle *
- * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2016 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 *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
- * MA 02110-1301 USA *
- ************************************************************************/
-
-// Some security stuff...
-if (!defined('__SECURITY')) {
- die();
-} // END - if
-
-// Get all menus
-foreach (array('guest','member','admin') as $menu) {
- // Query it
- $result = sqlQueryEscaped("SELECT `action`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` ORDER BY `action` ASC,`what` ASC",
- array($menu), __FILE__, __LINE__);
-
- // Init array
- $menus = array();
-
- // Load all entries
- while ($entry = sqlFetchArray($result)) {
- // Is the menu entry set?
- if (!isset($menus['menu'][$entry['action']][$entry['what']])) {
- // Not found
- $menus['menu'][$entry['action']][$entry['what']] = 1;
- } else {
- // Double entry, so get count
- if (is_null($entry['what'])) {
- // Main menu
- $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', TRUE, ' AND `what` IS NULL');
- } else {
- // Sub menu
- $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', TRUE, sprintf(" AND `what`='%s'", $entry['what']));
- }
- //* DEBUG: */ debugOutput('menu='.$menu.',action='.$entry['action'].',what='.$entry['what'].',entries='.$entries);
-
- // Only remove if we have at least 2 entries from same menu
- if ($entries > 1) {
- // Remove all except one
- if (is_null($entry['what'])) {
- // Main menu is double
- sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` IS NULL LIMIT %s",
- array(
- $menu,
- $entry['action'],
- ($entries - 1)
- ), __FILE__, __LINE__);
- } else {
- // Sub menu is double
- sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s' LIMIT %s",
- array(
- $menu,
- $entry['action'],
- $entry['what'],
- ($entries - 1)
- ), __FILE__, __LINE__);
- }
- } // END - if
- }
- } // END - while
-
- // Free result
- sqlFreeResult($result);
-
- // Init sqls
- initSqls();
-
- // Now insert our unqiue key for action-what combination
- addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `action_what`', $menu));
- addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `action_what` (`action`, `what`)', $menu));
-
- // Now insert our unqiue key for what
- addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `what`', $menu));
- addSql(sprintf('ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `what` (`what`)', $menu));
-
- // And run all
- runFilterChain('run_sqls');
-} // END - foreach
-
-// [EOF]
-?>