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