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