removed
[mailer.git] / inc / theme-manager.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 12/03/2004 *
4  * ===============                              Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : theme-manager.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Theme manager                                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Themen-Manager                                   *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 //
42 function GET_CURR_THEME()
43 {
44         global $_COOKIE, $INC_POOL, $CONFIG, $_GET, $_POST, $CSS;
45         // The default theme is 'default'... ;-)
46         $ret = "default";
47
48         // Load default theme if not empty from configuration
49         if (!empty($CONFIG['default_theme'])) $ret = $CONFIG['default_theme'];
50
51         if (empty($_COOKIE['mxchange_theme']))
52         {
53                 // Set default theme
54                 @setcookie("mxchange_theme", $ret, (time() + 60*60*24*365), COOKIE_PATH);
55         }
56          elseif ((!empty($_COOKIE['mxchange_theme'])) && (GET_EXT_VERSION("sql_patches") >= "0.1.4"))
57         {
58                 // Get theme from cookie
59                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' LIMIT 1", array($_COOKIE['mxchange_theme']), __FILE__, __LINE__);
60                 if (SQL_NUMROWS($result) == 1)
61                 {
62                         // Design is valid!
63                         $ret = $_COOKIE['mxchange_theme'];
64                 }
65
66                 // Free memory
67                 SQL_FREERESULT($result);
68         }
69          elseif ((!mxchange_installed) && ((mxchange_installing) || ($CSS == true)) && ((!empty($_GET['theme'])) || (!empty($_POST['theme']))))
70         {
71                 // Installation mode active
72                 if ((!empty($_GET['theme'])) && (file_exists(PATH."theme/".$_GET['theme']."/theme.php")))
73                 {
74                         // Set cookie from URL data
75                         @setcookie("mxchange_theme", $_GET['theme'], (time() + 60*60*24*365), COOKIE_PATH);
76                         $_COOKIE['mxchange_theme'] = $_GET['theme'];
77                 }
78                  elseif (file_exists(PATH."theme/".$_POST['theme']."/theme.php"))
79                 {
80                         // Set cookie from posted data
81                         @setcookie("mxchange_theme", $_POST['theme'], (time() + 60*60*24*365), COOKIE_PATH);
82                         $_COOKIE['mxchange_theme'] = $_POST['theme'];
83                 }
84
85                 // Set return value
86                 $ret = $_COOKIE['mxchange_theme'];
87         }
88          else
89         {
90                 // Invalid design, reset cookie
91                 @setcookie("mxchange_theme", $ret, (time() + 60*60*24*365), COOKIE_PATH);
92         }
93
94         // Add (maybe) found theme.php file to inclusion list
95         $theme = PATH."theme/".$ret."/theme.php";
96         if (@file_exists($theme)) $INC_POOL[] = $theme;
97
98         // Return theme value
99         return $ret;
100 }
101
102 function THEME_SELECTION_BOX($mod, $act, $wht, $result)
103 {
104         // Construction URL
105         global $CurrTheme;
106         $FORM = URL."/modules.php?module=".$mod;
107         if (!empty($act)) $FORM .= "&amp;action=".$act;
108         if (!empty($wht))   $FORM .= "&amp;what=".$wht;
109         define('__FORM_VALUE', $FORM);
110
111         // Initialize array
112         $THEMES = array(
113                 'theme_unix'   => array(), // Unix name from filesystem
114                 'theme_name'   => array()  // Title
115         );
116
117         // Load all themes
118         while(list($theme) = SQL_FETCHROW($result))
119         {
120                 // Load it's theme.php file
121                 $INC = PATH."theme/".$theme."/theme.php";
122                 if (file_exists($INC))
123                 {
124                         // And save all data in array
125                         include($INC);
126                         $THEMES['theme_unix'][] = $theme;
127                         $THEMES['theme_name'][] = $THEME_NAME;
128                 }
129         }
130
131         // Sort whole array by title
132         array_pk_sort($THEMES, array("theme_name"));
133
134         // Construct selection form for the box template
135         $OUT = "";
136         foreach ($THEMES['theme_unix'] as $key=>$theme)
137         {
138                 $OUT .= "  <OPTION value=\"".$theme."\"";
139                 if ($theme == $CurrTheme) $OUT .= " selected=\"selected\"";
140                 $OUT .= ">".$THEMES['theme_name'][$key]."</OPTION>\n";
141         }
142
143         // Return generated selection
144         define('__THEME_SELECTION_OPTIONS', $OUT);
145         $OUT = LOAD_TEMPLATE("theme_select_form", true);
146         return $OUT;
147 }
148
149 // Initialize variables
150 $CurrTheme = GET_CURR_THEME();
151 if (empty($_POST['new_theme'])) $_POST['new_theme'] = "";
152
153 // Check if new theme is selcted
154 if ((!empty($_POST['new_theme'])) && ($_POST['new_theme'] != $CurrTheme))
155 {
156         // Set new theme for guests
157         $NewTheme = $_POST['new_theme'];
158
159         // Change to new theme
160         @setcookie("mxchange_theme", $NewTheme, (time() + 60*60*24*365), COOKIE_PATH);
161
162         // Remove current from array and set new
163         $theme = PATH."theme/".$CurrTheme."/theme.php";
164         unset($INC_POOL[array_search($theme, $INC_POOL)]);
165         $INC_POOL[] = PATH."theme/".$NewTheme."/theme.php";
166 }
167
168 // Remove variable again
169 unset($_POST['new_theme']);
170
171 //
172 ?>