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