Fixes for broken order page and themes
[mailer.git] / inc / fix_menu.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/22/2009 *
4  * ===============                              Last change: 10/22/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : fix_menu.php                                     *
8  * -------------------------------------------------------------------- *
9  * Short description : Fixes dublicate entries in filters table         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Repariert doppelte Eintraege in filters-Tabelle  *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Get all menus
45 foreach (array('guest','member','admin') as $menu) {
46         // Query it
47         $result = SQL_QUERY_ESC("SELECT `action`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` ORDER BY `action` ASC, `what` ASC",
48                 array($menu), __FILE__, __LINE__);
49
50         // Init array
51         $menus = array();
52
53         // Load all entries
54         while ($entry = SQL_FETCHARRAY($result)) {
55                 // Is the menu entry set?
56                 if (!isset($menus['menu'][$entry['action']][$entry['what']])) {
57                         // Not found
58                         $menus['menu'][$entry['action']][$entry['what']] = 1;
59                 } else {
60                         // Double entry, so get count
61                         if (is_null($entry['what'])) {
62                                 // Main menu
63                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, " AND `what` IS NULL");
64                         } else {
65                                 // Sub menu
66                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, sprintf(" AND `what`='%s'", $entry['what']));
67                         }
68                         //* DEBUG: */ print 'menu='.$menu.',action='.$entry['action'].',what='.$entry['what'].',entries='.$entries.'<br />';
69
70                         // Only remove if we have at least 2 entries from same menu
71                         if ($entries > 1) {
72                                 // Remove all except one
73                                 if (is_null($entry['what'])) {
74                                         // Main menu is double
75                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` IS NULL LIMIT %s",
76                                                 array($menu, $entry['action'], ($entries - 1)), __FILE__, __LINE__);
77                                 } else {
78                                         // Sub menu is double
79                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s' LIMIT %s",
80                                                 array($menu, $entry['action'], $entry['what'], ($entries - 1)), __FILE__, __LINE__);
81                                 }
82                         } // END - if
83                 }
84         } // END - while
85
86         // Free result
87         SQL_FREERESULT($result);
88
89         // Now insert our unqiue key for action-what combination
90         SQL_QUERY_ESC("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `action_what`",
91                 array($menu), __FILE__, __LINE__);
92         SQL_QUERY_ESC("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `action_what` (`action` , `what`)",
93                 array($menu), __FILE__, __LINE__);
94
95         // Now insert our unqiue key for what
96         SQL_QUERY_ESC("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `what`",
97                 array($menu), __FILE__, __LINE__);
98         SQL_QUERY_ESC("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `what` (`what`)",
99                 array($menu), __FILE__, __LINE__);
100 } // END - foreach
101
102 // [EOF]
103 ?>