Wernis extension added
[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         global $INC_POOL, $_CONFIG, $CSS;
44
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 (!isSessionVariableSet('mxchange_theme')) {
52                 // Set default theme
53                 set_session("mxchange_theme", $ret, (time() + 60*60*24*365), COOKIE_PATH);
54         } elseif ((isSessionVariableSet('mxchange_theme')) && (GET_EXT_VERSION("sql_patches") >= "0.1.4")) {
55                 // Get theme from cookie
56                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' LIMIT 1", array(get_session('mxchange_theme')), __FILE__, __LINE__);
57                 if (SQL_NUMROWS($result) == 1) {
58                         // Design is valid!
59                         $ret = get_session('mxchange_theme');
60                 }
61
62                 // Free memory
63                 SQL_FREERESULT($result);
64         } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($CSS == true)) && ((!empty($_GET['theme'])) || (!empty($_POST['theme'])))) {
65                 // Prepare FQFN for checking
66                 $theme = sprintf("%stheme/%s/theme.php", PATH, $_GET['theme']);
67
68                 // Installation mode active
69                 if ((!empty($_GET['theme'])) && (file_exists($theme)) && (is_readable($theme))) {
70                         // Set cookie from URL data
71                         set_session("mxchange_theme", $_GET['theme'], (time() + 60*60*24*365), COOKIE_PATH);
72                 } elseif (file_exists(PATH."theme/".$_POST['theme']."/theme.php")) {
73                         // Set cookie from posted data
74                         set_session("mxchange_theme", $_POST['theme'], (time() + 60*60*24*365), COOKIE_PATH);
75                 }
76
77                 // Set return value
78                 $ret = get_session('mxchange_theme');
79         } else {
80                 // Invalid design, reset cookie
81                 set_session("mxchange_theme", $ret, (time() + 60*60*24*365), COOKIE_PATH);
82         }
83
84         // Add (maybe) found theme.php file to inclusion list
85         $theme = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($ret));
86
87         // Try to load the requested include file
88         if ((@file_exists($theme)) && (is_readable($theme))) $INC_POOL[] = $theme;
89
90         // Return theme value
91         return $ret;
92 }
93
94 function THEME_SELECTION_BOX($mod, $act, $wht, $result)
95 {
96         // Construction URL
97         global $CurrTheme;
98         $FORM = URL."/modules.php?module=".$mod;
99         if (!empty($act)) $FORM .= "&amp;action=".$act;
100         if (!empty($wht))   $FORM .= "&amp;what=".$wht;
101         define('__FORM_VALUE', $FORM);
102
103         // Initialize array
104         $THEMES = array(
105                 'theme_unix'   => array(), // Unix name from filesystem
106                 'theme_name'   => array()  // Title
107         );
108
109         // Load all themes
110         while(list($theme) = SQL_FETCHROW($result))
111         {
112                 // Load it's theme.php file
113                 $INC = PATH."theme/".$theme."/theme.php";
114                 if (file_exists($INC))
115                 {
116                         // And save all data in array
117                         include($INC);
118                         $THEMES['theme_unix'][] = $theme;
119                         $THEMES['theme_name'][] = $THEME_NAME;
120                 }
121         }
122
123         // Sort whole array by title
124         array_pk_sort($THEMES, array("theme_name"));
125
126         // Construct selection form for the box template
127         $OUT = "";
128         foreach ($THEMES['theme_unix'] as $key=>$theme)
129         {
130                 $OUT .= "  <OPTION value=\"".$theme."\"";
131                 if ($theme == $CurrTheme) $OUT .= " selected=\"selected\"";
132                 $OUT .= ">".$THEMES['theme_name'][$key]."</OPTION>\n";
133         }
134
135         // Return generated selection
136         define('__THEME_SELECTION_OPTIONS', $OUT);
137         $OUT = LOAD_TEMPLATE("theme_select_form", true);
138         return $OUT;
139 }
140
141 // Initialize variables
142 $CurrTheme = GET_CURR_THEME();
143 if (empty($_POST['new_theme'])) $_POST['new_theme'] = "";
144
145 // Check if new theme is selcted
146 if ((!empty($_POST['new_theme'])) && ($_POST['new_theme'] != $CurrTheme))
147 {
148         // Set new theme for guests
149         $NewTheme = $_POST['new_theme'];
150
151         // Change to new theme
152         set_session("mxchange_theme", $NewTheme, (time() + 60*60*24*365), COOKIE_PATH);
153
154         // Remove current from array and set new
155         $theme = PATH."theme/".$CurrTheme."/theme.php";
156         unset($INC_POOL[array_search($theme, $INC_POOL)]);
157         $INC_POOL[] = PATH."theme/".$NewTheme."/theme.php";
158 }
159
160 // Remove variable again
161 unset($_POST['new_theme']);
162
163 //
164 ?>