830df271d38129acfd6562534f0149ac762d339f
[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  * $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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!IS_MEMBER()) {
44         LOAD_URL('modules.php?module=index');
45 } elseif ((!EXT_IS_ACTIVE('theme')) && (!IS_ADMIN())) {
46         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), 'theme');
47         return;
48 }
49
50 // Add description as navigation point
51 ADD_DESCR('member', __FILE__);
52
53 if (REQUEST_ISSET_POST(('member_theme'))) {
54         // Save theme to member's profile
55         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET curr_theme='%s' WHERE userid=%s LIMIT 1",
56                 array(REQUEST_POST('member_theme'), getUserId()), __FILE__, __LINE__);
57
58         // Set new theme for guests
59         $newTheme = SQL_ESCAPE(REQUEST_POST('member_theme'));
60
61         // Change to new theme
62         set_session('mxchange_theme', $newTheme);
63
64         // Theme saved!
65         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('MEMBER_THEME_SAVED'));
66 }
67
68 // Initialize array
69 $THEMES = array(
70         'theme_unix'   => array(), // Unix name from filesystem
71         'theme_name'   => array(), // Title
72         'theme_author' => array(), // Theme author's name
73         'theme_email'  => array(), // Author's email address
74         'theme_url'    => array(), // URL were you can download it from
75         'theme_ver'    => array(), // Version number of theme
76 );
77
78 // Read directory "themes"
79 $handle = opendir(constant('PATH')."theme/") or app_die(__FILE__, __LINE__, "Cannot read themes dir!");
80 while ($entry = readdir($handle)) {
81         // Construct absolute theme.php file name
82         $INC = sprintf("theme/%s/theme.php", $entry);
83
84         if (($entry != ".") && ($entry != "..") && (INCLUDE_READABLE($INC)) && (THEME_IS_ACTIVE($entry))) {
85                 // Found a valid directory so let's load it's theme.php file
86                 LOAD_INC($INC);
87
88                 // Add found theme to array
89                 $THEMES['theme_unix'][]   = $entry;
90                 $THEMES['theme_name'][]   = $GLOBALS['theme_data']['name'];
91                 $THEMES['theme_author'][] = $GLOBALS['theme_data']['author'];
92                 $THEMES['theme_email'][]  = $GLOBALS['theme_data']['email'];
93                 $THEMES['theme_url'][]    = $GLOBALS['theme_data']['url'];
94                 $THEMES['theme_ver'][]    = $GLOBALS['theme_data']['version'];
95         } // END - if
96 } // END - while
97
98 // Close directory
99 closedir($handle);
100
101 // Sort array by Uni* name
102 array_pk_sort($THEMES, array("theme_name"));
103
104 // Generate output lines for the template
105 $OUT = ''; $SW = 2;
106 foreach ($THEMES['theme_unix'] as $key => $unix) {
107         $default = '';
108         if (get_session('mxchange_theme') == $unix) $default = " selected=\"selected\"";
109
110         // Add row
111         $OUT .= "<tr>
112   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">
113     <input type=\"radio\" name=\"member_theme\" class=\"member_normal\" value=\"".$unix."\"".$default." />
114   </td>
115   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</td>
116   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
117     <a href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</a>
118   </td>
119   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
120     <a href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</a>
121   </td>
122   <td class=\"switch_sw".$SW." bottom2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</td>
123 </tr>\n";
124         $SW = 3 - $SW;
125 }
126
127 if (empty($OUT)) {
128         // No themes found???
129         $OUT = "<tr>
130   <td colspan=\"5\" class=\"bottom2\" height=\"80\">
131     ".LOAD_TEMPLATE('admin_settings_saved', true, getMessage('MEMBER_NO_THEMES_FOUND'))."
132   </td>
133 </tr>\n";
134 }
135 define('__THEME_LIST', $OUT);
136
137 // Load template
138 LOAD_TEMPLATE("member_themes");
139
140 //
141 ?>