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