Deprecated variables for templates removed, mor EL-rewrites, getMessage() rewritten:
[mailer.git] / inc / fix_menu.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * 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')) {
42         die();
43 } // END - if
44
45 // Get all menus
46 foreach (array('guest','member','admin') as $menu) {
47         // Query it
48         $result = SQL_QUERY_ESC("SELECT `action`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` ORDER BY `action` ASC, `what` ASC",
49                 array($menu), __FILE__, __LINE__);
50
51         // Init array
52         $menus = array();
53
54         // Load all entries
55         while ($entry = SQL_FETCHARRAY($result)) {
56                 // Is the menu entry set?
57                 if (!isset($menus['menu'][$entry['action']][$entry['what']])) {
58                         // Not found
59                         $menus['menu'][$entry['action']][$entry['what']] = 1;
60                 } else {
61                         // Double entry, so get count
62                         if (is_null($entry['what'])) {
63                                 // Main menu
64                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, " AND `what` IS NULL");
65                         } else {
66                                 // Sub menu
67                                 $entries = countSumTotalData($entry['action'], $menu . '_menu', 'action', 'action', true, sprintf(" AND `what`='%s'", $entry['what']));
68                         }
69                         //* DEBUG: */ debugOutput('menu='.$menu.',action='.$entry['action'].',what='.$entry['what'].',entries='.$entries);
70
71                         // Only remove if we have at least 2 entries from same menu
72                         if ($entries > 1) {
73                                 // Remove all except one
74                                 if (is_null($entry['what'])) {
75                                         // Main menu is double
76                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` IS NULL LIMIT %s",
77                                                 array(
78                                                         $menu,
79                                                         $entry['action'],
80                                                         ($entries - 1)
81                                                 ), __FILE__, __LINE__);
82                                 } else {
83                                         // Sub menu is double
84                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s' LIMIT %s",
85                                                 array(
86                                                         $menu,
87                                                         $entry['action'],
88                                                         $entry['what'],
89                                                         ($entries - 1)
90                                                 ), __FILE__, __LINE__);
91                                 }
92                         } // END - if
93                 }
94         } // END - while
95
96         // Free result
97         SQL_FREERESULT($result);
98
99         // Init sqls
100         initSqls();
101
102         // Now insert our unqiue key for action-what combination
103         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `action_what`", $menu));
104         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `action_what` (`action` , `what`)", $menu));
105
106         // Now insert our unqiue key for what
107         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `what`", $menu));
108         addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE `what` (`what`)", $menu));
109
110         // And run all
111         runFilterChain('run_sqls');
112 } // END - foreach
113
114 // [EOF]
115 ?>