Fix in CREATE_EXTENSION_DEACTIVATION_TASK() and coding-style updated
[mailer.git] / inc / modules / member / what-themes.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 03/20/2005 *
4  * ================                             Last change: 03/20/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-themes.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Theme selection for members                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Design-Auswahl fuer Mitglieder                   *
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 (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("theme")) && (!IS_ADMIN())) {
41         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "theme");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", __FILE__);
47
48 if (!empty($_POST['member_theme'])) {
49         // Save theme to member's profile
50         SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET curr_theme='%s' WHERE userid=%s LIMIT 1",
51                 array($_POST['member_theme'], $GLOBALS['userid']), __FILE__, __LINE__);
52
53         // Set new theme for guests
54         $newTheme = SQL_ESCAPE($_POST['member_theme']);
55
56         // Change to new theme
57         set_session("mxchange_theme", $newTheme);
58
59         // Theme saved!
60         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_THEME_SAVED);
61 }
62
63 // Initialize array
64 $THEMES = array(
65         'theme_unix'   => array(), // Unix name from filesystem
66         'theme_name'   => array(), // Title
67         'theme_author' => array(), // Theme author's name
68         'theme_email'  => array(), // Author's email address
69         'theme_url'    => array(), // URL were you can download it from
70         'theme_ver'    => array(), // Version number of theme
71 );
72
73 // Read directory "themes"
74 $handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
75 while ($entry = readdir($handle)) {
76         // Construct absolute theme.php file name
77         $theme = sprintf("%stheme/%s/theme.php", PATH, $entry);
78
79         if (($entry != ".") && ($entry != "..") && (FILE_READABLE($theme)) && (THEME_IS_ACTIVE($entry))) {
80                 // Found a valid directory so let's load it's theme.php file
81                 include($theme);
82
83                 // Add found theme to array
84                 $THEMES['theme_unix'][]   = $entry;
85                 $THEMES['theme_name'][]   = $THEME_NAME;
86                 $THEMES['theme_author'][] = $THEME_AUTHOR;
87                 $THEMES['theme_email'][]  = $THEME_EMAIL;
88                 $THEMES['theme_url'][]    = $THEME_URL;
89                 $THEMES['theme_ver'][]    = $THEME_VERSION;
90         } // END - if
91 } // END - while
92
93 // Close directory
94 closedir($handle);
95
96 // Sort array by Uni* name
97 array_pk_sort($THEMES, array("theme_name"));
98
99 // Generate output lines for the template
100 $OUT = ""; $SW = 2;
101 foreach ($THEMES['theme_unix'] as $key => $unix) {
102         $default = "";
103         if (get_session('mxchange_theme') == $unix) $default = " checked selected";
104
105         // Add row
106         $OUT .= "<TR>
107   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">
108     <INPUT type=\"radio\" name=\"member_theme\" class=\"member_normal\" value=\"".$unix."\"".$default.">
109   </TD>
110   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</TD>
111   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
112     <A href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</A>
113   </TD>
114   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
115     <A href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</A>
116   </TD>
117   <TD class=\"switch_sw".$SW." bottom2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</TD>
118 </TR>\n";
119         $SW = 3 - $SW;
120 }
121
122 if (empty($OUT)) {
123         // No themes found???
124         $OUT = "<TR>
125   <TD colspan=\"5\" class=\"bottom2\" height=\"80\">
126     ".LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_THEMES_FOUND)."
127   </TD>
128 </TR>\n";
129 }
130 define('__THEME_LIST', $OUT);
131
132 // Load template
133 LOAD_TEMPLATE("member_themes");
134
135 //
136 ?>