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