IS_LOGGED_IN() renamed to IS_MEMBER(), some HTML fixes
[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 (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  elseif (!IS_MEMBER())
41 {
42         LOAD_URL("modules.php?module=index");
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("member", basename(__FILE__));
47
48 if (!empty($_POST['member_theme']))
49 {
50         // Save theme to member's profile
51         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET curr_theme='%s' WHERE userid=%s LIMIT 1",
52           array($_POST['member_theme'], $GLOBALS['userid']), __FILE__, __LINE__);
53
54         // Set new theme for guests
55         $NewTheme = $_POST['member_theme'];
56
57         // Change to new theme
58         set_session("mxchange_theme", $NewTheme);
59
60         // Theme saved!
61         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_THEME_SAVED);
62 }
63
64 // Initialize array
65 $THEMES = array(
66         'theme_unix'   => array(), // Unix name from filesystem
67         'theme_name'   => array(), // Title
68         'theme_author' => array(), // Theme author's name
69         'theme_email'  => array(), // Author's email address
70         'theme_url'    => array(), // URL were you can download it from
71         'theme_ver'    => array(), // Version number of theme
72 );
73
74 // Read directory "themes"
75 $handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
76 while ($dir = readdir($handle)) {
77         // Construct absolute theme.php file name
78         $theme = sprintf("%stheme/%s/theme.php", PATH, $dir);
79
80         // Test it...
81         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_themes WHERE theme_path='%s' AND theme_active='Y' LIMIT 1",
82          array($dir), __FILE__, __LINE__);
83
84         if (($dir != ".") && ($dir != "..") && (FILE_READABLE($theme)) && (SQL_NUMROWS($result) == 1)) {
85                 // Free memory
86                 SQL_FREERESULT($result);
87
88                 // Found a valid directory so let's load it's theme.php file
89                 include($theme);
90
91                 // Add found theme to array
92                 $THEMES['theme_unix'][]   = $dir;
93                 $THEMES['theme_name'][]   = $THEME_NAME;
94                 $THEMES['theme_author'][] = $THEME_AUTHOR;
95                 $THEMES['theme_email'][]  = $THEME_EMAIL;
96                 $THEMES['theme_url'][]    = $THEME_URL;
97                 $THEMES['theme_ver'][]    = $THEME_VERSION;
98         } // END - if
99 } // END - while
100
101 // Close directory
102 closedir($handle);
103
104 // Sort array by Uni* name
105 array_pk_sort($THEMES, array("theme_name"));
106
107 // Generate output lines for the template
108 $OUT = ""; $SW = 2;
109 foreach ($THEMES['theme_unix'] as $key=>$unix)
110 {
111         $default = "";
112         if (get_session('mxchange_theme') == $unix) $default = " checked selected";
113
114         // Add row
115         $OUT .= "<TR>
116   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">
117     <INPUT type=\"radio\" name=\"member_theme\" class=\"member_normal\" value=\"".$unix."\"".$default.">
118   </TD>
119   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</TD>
120   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
121     <A href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</A>
122   </TD>
123   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
124     <A href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</A>
125   </TD>
126   <TD class=\"switch_sw".$SW." bottom2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</TD>
127 </TR>\n";
128         $SW = 3 - $SW;
129 }
130 if (empty($OUT))
131 {
132         // No themes found???
133         $OUT = "<TR>
134   <TD colspan=\"5\" class=\"bottom2\" height=\"80\">
135     ".LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_THEMES_FOUND)."
136   </TD>
137 </TR>\n";
138 }
139 define('__THEME_LIST', $OUT);
140
141 // Load template
142 LOAD_TEMPLATE("member_themes");
143
144 //
145 ?>