Another column fix
[mailer.git] / inc / modules / admin / what-theme_import.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/12/2004 *
4  * ================                             Last change: 11/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-theme_import.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Import of new themes                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Importieren von neuen Themes                     *
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')) || (!is_admin())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Switch to testing mode
44 $THEME_MODE = "test";
45
46 // Import selected theme if not present
47 if (!empty($_POST['theme'])) {
48         // Check if theme is there
49         if (!THEME_CHECK_EXIST($_POST['theme'])) {
50                 // Import theme
51                 $file = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($_POST['theme']));
52                 if (FILE_READABLE($file)) {
53                         // Load the theme header file
54                         include($file);
55
56                         // Register it ith the exchange
57                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_themes (theme_path, theme_active, theme_ver, theme_name)
58 VALUES ('%s','N','%s','%s')",
59                                 array($_POST['theme'], $THEME_VERSION, $THEME_NAME), __FILE__, __LINE__);
60
61                         // Destroy cache
62                         REBUILD_CACHE("themes", "them");
63
64                         // Prepare message
65                         $msg = ADMIN_THEME_IMPORTED_1.$_POST['theme'].ADMIN_THEME_IMPORTED_2;
66                 } else {
67                         // Include file not found!
68                         $msg = ADMIN_THEME_INC_404_1.$_POST['theme'].ADMIN_THEME_INC_404_2;
69                 }
70         } else {
71                 // Theme already imported
72                 $msg = ADMIN_THEME_ALREADY_1.$_POST['theme'].ADMIN_THEME_ALREADY_2;
73         }
74
75         // Output message
76         LOAD_TEMPLATE("admin_settings_saved", false, $msg);
77         OUTPUT_HTML("<br />");
78 } // END - if
79
80 // Initialize array
81 $THEMES = array(
82         'theme_unix'   => array(), // Unix name from filesystem
83         'theme_name'   => array(), // Title
84         'theme_author' => array(), // Theme author's name
85         'theme_email'  => array(), // Author's email address
86         'theme_url'    => array(), // URL were you can download it from
87         'theme_ver'    => array(), // Version number of theme
88 );
89
90 // Read directory "themes"
91 $handle = opendir(PATH."theme/") or mxchange_die("Cannot read themes dir!");
92 while ($dir = readdir($handle)) {
93         // Construct absolute theme.php file name
94         $theme = sprintf("%stheme/%s/theme.php", PATH, $dir);
95
96         // Test it...
97         if (($dir != ".") && ($dir != "..") && (FILE_READABLE($theme))) {
98                 // Found a valid directory so let's load it's theme.php file
99                 include($theme);
100
101                 // Add found theme to array
102                 $THEMES['theme_unix'][]   = $dir;
103                 $THEMES['theme_name'][]   = $THEME_NAME;
104                 $THEMES['theme_author'][] = $THEME_AUTHOR;
105                 $THEMES['theme_email'][]  = $THEME_EMAIL;
106                 $THEMES['theme_url'][]    = $THEME_URL;
107                 $THEMES['theme_ver'][]    = $THEME_VERSION;
108         } // END - if
109 } // END - while
110
111 // Close directory
112 closedir($handle);
113
114 // Sort array by Uni* name
115 array_pk_sort($THEMES, array("theme_name"));
116
117 // Generate output lines for the template
118 $OUT = ""; $SW = 2;
119 foreach ($THEMES['theme_unix'] as $key => $unix) {
120         // Check if current theme is already imported or not
121         if (THEME_CHECK_EXIST($unix)) {
122                 // Already installed
123                 $FOUND = "<FONT class=\"admin_note\">".ADMIN_THEME_ALREADY_INSTALLED."</FONT>";
124         } else {
125                 // Theme not installed
126                 $FOUND = "<FORM action=\"".URL."/modules.php?module=admin&amp;what=theme_import\" method=\"POST\">
127   <INPUT type=\"submit\" name=\"ok\" class=\"admin_submit\" value=\"".ADMIN_INSTALL_THEME."\">
128   <INPUT type=\"hidden\" name=\"theme\" value=\"".$unix."\">
129 </FORM>";
130         }
131
132         // Add row
133         $OUT .= "<TR>
134   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\" height=\"30\">".$unix."</TD>
135   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">".$THEMES['theme_name'][$key]."</TD>
136   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
137     <A href=\"mailto:".$THEMES['theme_email'][$key]."?Subject=[Theme:] ".$THEMES['theme_name'][$key]." (".$unix.")"."\">".$THEMES['theme_author'][$key]."</A>
138   </TD>
139   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">
140     <A href=\"".DEREFERER($THEMES['theme_url'][$key])."\" target=\"_blank\">".$THEMES['theme_url'][$key]."</A>
141   </TD>
142   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"center\">v".$THEMES['theme_ver'][$key]."</TD>
143   <TD class=\"switch_sw".$SW." bottom2\" align=\"center\">
144     ".$FOUND."
145   </TD>
146 </TR>\n";
147
148         // Switch color
149         $SW = 3 - $SW;
150 }
151
152 if (empty($OUT)) {
153         // No themes found???
154         $OUT .= "<TR>
155   <TD colspan=\"6\" class=\"bottom2\" height=\"80\">
156     ".LOAD_TEMPLATE("admin_settings_saved", true, ADMIN_NO_THEMES_FOUND)."
157   </TD>
158 </TR>\n";
159 } // END - if
160 define('__THEME_LIST', $OUT);
161
162 // Load template
163 LOAD_TEMPLATE("admin_theme_import");
164
165 //
166 ?>