]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/admin_styles.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2_old / admin / admin_styles.php
1 <?php
2 /***************************************************************************
3  *                              admin_styles.php
4  *                            -------------------
5  *   begin                : Thursday, Jul 12, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: admin_styles.php,v 1.27.2.13 2004/07/15 17:57:50 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
14 /***************************************************************************
15  *
16  *   This program is free software; you can redistribute it and/or modify
17  *   it under the terms of the GNU General Public License as published by
18  *   the Free Software Foundation; either version 2 of the License, or
19  *   (at your option) any later version.
20  *
21  ***************************************************************************/
23 define('IN_PHPBB', 1);
25 if( !empty($setmodules) )
26 {
27         $file = basename(__FILE__);
28         $module['Styles']['Add_new'] = "$file?mode=addnew";
29         $module['Styles']['Create_new'] = "$file?mode=create";
30         $module['Styles']['Manage'] = "$file";
31         $module['Styles']['Export'] = "$file?mode=export";
32         return;
33 }
35 //
36 // Load default header
37 //
38 //
39 // Check if the user has cancled a confirmation message.
40 //
41 $phpbb_root_path = "./../";
42 require($phpbb_root_path . 'extension.inc');
44 $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : FALSE;
45 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : FALSE;
47 $no_page_header = (!empty($HTTP_POST_VARS['send_file']) || $cancel) ? TRUE : FALSE;
49 require('./pagestart.' . $phpEx);
51 $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : FALSE;
52 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : FALSE;
54 if ($cancel)
55 {
56         redirect('admin/' . append_sid("admin_styles.$phpEx", true));
57 }
59 if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
60 {
61         $mode = ( isset($HTTP_GET_VARS['mode']) ) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
62         $mode = htmlspecialchars($mode);
63 }
64 else 
65 {
66         $mode = "";
67 }
69 switch( $mode )
70 {
71         case "addnew":
72                 $install_to = ( isset($HTTP_GET_VARS['install_to']) ) ? urldecode($HTTP_GET_VARS['install_to']) : $HTTP_POST_VARS['install_to'];
73                 $style_name = ( isset($HTTP_GET_VARS['style']) ) ? urldecode($HTTP_GET_VARS['style']) : $HTTP_POST_VARS['style'];
74         
75                 if( isset($install_to) )
76                 {
78                         include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
80                         $template_name = $$install_to;
81                         $found = FALSE; 
82                         
83                         for($i = 0; $i < count($template_name) && !$found; $i++)
84                         {
85                                 if( $template_name[$i]['style_name'] == $style_name )
86                                 {
87                                         while(list($key, $val) = each($template_name[$i]))
88                                         {
89                                                 $db_fields[] = $key;
90                                                 $db_values[] = str_replace("\'", "''" , $val);
91                                         }
92                                 }
93                         }
94                                         
95                         $sql = "INSERT INTO " . THEMES_TABLE . " (";
97                         for($i = 0; $i < count($db_fields); $i++)
98                         {
99                                 $sql .= $db_fields[$i];
100                                 if($i != (count($db_fields) - 1))
101                                 {
102                                         $sql .= ", ";
103                                 }
104                                 
105                         }
107                         $sql .= ") VALUES (";
109                         for($i = 0; $i < count($db_values); $i++)
110                         {
111                                 $sql .= "'" . $db_values[$i] . "'";
112                                 if($i != (count($db_values) - 1))
113                                 {
114                                         $sql .= ", ";
115                                 }
116                         }
117                         $sql .= ")";
118                         
119                         if( !$result = $db->sql_query($sql) )
120                         {
121                                 message_die(GENERAL_ERROR, "Could not insert theme data!", "", __LINE__, __FILE__, $sql);
122                         }
123                         
124                         $message = $lang['Theme_installed'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
126                         message_die(GENERAL_MESSAGE, $message);
127                 }
128                 else
129                 {
130                         
131                         $installable_themes = array();
132                         
133                         if( $dir = @opendir($phpbb_root_path. "templates/") )
134                         {
135                                 while( $sub_dir = @readdir($dir) )
136                                 {
137                                         if( !is_file(phpbb_realpath($phpbb_root_path . 'templates/' .$sub_dir)) && !is_link(phpbb_realpath($phpbb_root_path . 'templates/' .$sub_dir)) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" )
138                                         {
139                                                 if( @file_exists(@phpbb_realpath($phpbb_root_path. "templates/" . $sub_dir . "/theme_info.cfg")) )
140                                                 {
141                                                         include($phpbb_root_path. "templates/" . $sub_dir . "/theme_info.cfg");
142                                                         
143                                                         for($i = 0; $i < count($$sub_dir); $i++)
144                                                         {
145                                                                 $working_data = $$sub_dir;
146                                                                 
147                                                                 $style_name = $working_data[$i]['style_name'];
148                                                                                                                 
149                                                                 $sql = "SELECT themes_id 
150                                                                         FROM " . THEMES_TABLE . " 
151                                                                         WHERE style_name = '" . str_replace("\'", "''", $style_name) . "'";
152                                                                 if(!$result = $db->sql_query($sql))
153                                                                 {
154                                                                         message_die(GENERAL_ERROR, "Could not query themes table!", "", __LINE__, __FILE__, $sql);
155                                                                 }
157                                                                 if(!$db->sql_numrows($result))
158                                                                 {
159                                                                         $installable_themes[] = $working_data[$i];
160                                                                 }
161                                                         }
162                                                 }
163                                         }
164                                 }
165                                 
166                                 $template->set_filenames(array(
167                                         "body" => "admin/styles_addnew_body.tpl")
168                                 );
169                                 
170                                 $template->assign_vars(array(
171                                         "L_STYLES_TITLE" => $lang['Styles_admin'],
172                                         "L_STYLES_ADD_TEXT" => $lang['Styles_addnew_explain'],
173                                         "L_STYLE" => $lang['Style'],
174                                         "L_TEMPLATE" => $lang['Template'],
175                                         "L_INSTALL" => $lang['Install'],
176                                         "L_ACTION" => $lang['Action'])
177                                 );
178                                         
179                                 for($i = 0; $i < count($installable_themes); $i++)
180                                 {
181                                         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
182                                         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
183                 
184                                         $template->assign_block_vars("styles", array(
185                                                 "ROW_CLASS" => $row_class,
186                                                 "ROW_COLOR" => "#" . $row_color,
187                                                 "STYLE_NAME" => $installable_themes[$i]['style_name'],
188                                                 "TEMPLATE_NAME" => $installable_themes[$i]['template_name'],
190                                                 "U_STYLES_INSTALL" => append_sid("admin_styles.$phpEx?mode=addnew&amp;style=" . urlencode($installable_themes[$i]['style_name']) . "&amp;install_to=" . urlencode($installable_themes[$i]['template_name'])))
191                                         );
192                                 
193                                 }
194                                 $template->pparse("body");
195                                         
196                         }
197                         closedir($dir);
198                 }
199                 break;
200         
201         case "create":
202         case "edit":
203                 $submit = ( isset($HTTP_POST_VARS['submit']) ) ? TRUE : 0;
204                 
205                 if( $submit )
206                 {
207                         //      
208                         // DAMN! Thats alot of data to validate...
209                         //
210                         $updated['style_name'] = $HTTP_POST_VARS['style_name'];
211                         $updated['template_name'] = $HTTP_POST_VARS['template_name'];
212                         $updated['head_stylesheet'] = $HTTP_POST_VARS['head_stylesheet'];
213                         $updated['body_background'] = $HTTP_POST_VARS['body_background'];
214                         $updated['body_bgcolor'] = $HTTP_POST_VARS['body_bgcolor'];
215                         $updated['body_text'] = $HTTP_POST_VARS['body_text'];
216                         $updated['body_link'] = $HTTP_POST_VARS['body_link'];
217                         $updated['body_vlink'] = $HTTP_POST_VARS['body_vlink'];
218                         $updated['body_alink'] = $HTTP_POST_VARS['body_alink'];
219                         $updated['body_hlink'] = $HTTP_POST_VARS['body_hlink'];
220                         $updated['tr_color1'] = $HTTP_POST_VARS['tr_color1'];
221                         $updated_name['tr_color1_name'] =  $HTTP_POST_VARS['tr_color1_name'];
222                         $updated['tr_color2'] = $HTTP_POST_VARS['tr_color2'];
223                         $updated_name['tr_color2_name'] = $HTTP_POST_VARS['tr_color2_name'];
224                         $updated['tr_color3'] = $HTTP_POST_VARS['tr_color3'];
225                         $updated_name['tr_color3_name'] = $HTTP_POST_VARS['tr_color3_name'];
226                         $updated['tr_class1'] = $HTTP_POST_VARS['tr_class1'];
227                         $updated_name['tr_class1_name'] = $HTTP_POST_VARS['tr_class1_name'];
228                         $updated['tr_class2'] = $HTTP_POST_VARS['tr_class2'];
229                         $updated_name['tr_class2_name'] = $HTTP_POST_VARS['tr_class2_name'];
230                         $updated['tr_class3'] = $HTTP_POST_VARS['tr_class3'];
231                         $updated_name['tr_class3_name'] = $HTTP_POST_VARS['tr_class3_name'];
232                         $updated['th_color1'] = $HTTP_POST_VARS['th_color1'];
233                         $updated_name['th_color1_name'] = $HTTP_POST_VARS['th_color1_name'];
234                         $updated['th_color2'] = $HTTP_POST_VARS['th_color2'];
235                         $updated_name['th_color2_name'] = $HTTP_POST_VARS['th_color2_name'];
236                         $updated['th_color3'] = $HTTP_POST_VARS['th_color3'];
237                         $updated_name['th_color3_name'] = $HTTP_POST_VARS['th_color3_name'];
238                         $updated['th_class1'] = $HTTP_POST_VARS['th_class1'];
239                         $updated_name['th_class1_name'] = $HTTP_POST_VARS['th_class1_name'];
240                         $updated['th_class2'] = $HTTP_POST_VARS['th_class2'];
241                         $updated_name['th_class2_name'] = $HTTP_POST_VARS['th_class2_name'];
242                         $updated['th_class3'] = $HTTP_POST_VARS['th_class3'];
243                         $updated_name['th_class3_name'] = $HTTP_POST_VARS['th_class3_name'];
244                         $updated['td_color1'] = $HTTP_POST_VARS['td_color1'];
245                         $updated_name['td_color1_name'] = $HTTP_POST_VARS['td_color1_name'];
246                         $updated['td_color2'] = $HTTP_POST_VARS['td_color2'];
247                         $updated_name['td_color2_name'] = $HTTP_POST_VARS['td_color2_name'];
248                         $updated['td_color3'] = $HTTP_POST_VARS['td_color3'];
249                         $updated_name['td_color3_name'] = $HTTP_POST_VARS['td_color3_name'];
250                         $updated['td_class1'] = $HTTP_POST_VARS['td_class1'];
251                         $updated_name['td_class1_name'] = $HTTP_POST_VARS['td_class1_name'];
252                         $updated['td_class2'] = $HTTP_POST_VARS['td_class2'];
253                         $updated_name['td_class2_name'] = $HTTP_POST_VARS['td_class2_name'];
254                         $updated['td_class3'] = $HTTP_POST_VARS['td_class3'];
255                         $updated_name['td_class3_name'] = $HTTP_POST_VARS['td_class3_name'];
256                         $updated['fontface1'] = $HTTP_POST_VARS['fontface1'];
257                         $updated_name['fontface1_name'] = $HTTP_POST_VARS['fontface1_name'];
258                         $updated['fontface2'] = $HTTP_POST_VARS['fontface2'];
259                         $updated_name['fontface2_name'] = $HTTP_POST_VARS['fontface2_name'];
260                         $updated['fontface3'] = $HTTP_POST_VARS['fontface3'];
261                         $updated_name['fontface3_name'] = $HTTP_POST_VARS['fontface3_name'];
262                         $updated['fontsize1'] = intval($HTTP_POST_VARS['fontsize1']);
263                         $updated_name['fontsize1_name'] = $HTTP_POST_VARS['fontsize1_name'];
264                         $updated['fontsize2'] = intval($HTTP_POST_VARS['fontsize2']);
265                         $updated_name['fontsize2_name'] = $HTTP_POST_VARS['fontsize2_name'];
266                         $updated['fontsize3'] = intval($HTTP_POST_VARS['fontsize3']);
267                         $updated_name['fontsize3_name'] = $HTTP_POST_VARS['fontsize3_name'];
268                         $updated['fontcolor1'] = $HTTP_POST_VARS['fontcolor1'];
269                         $updated_name['fontcolor1_name'] = $HTTP_POST_VARS['fontcolor1_name'];
270                         $updated['fontcolor2'] = $HTTP_POST_VARS['fontcolor2'];
271                         $updated_name['fontcolor2_name'] = $HTTP_POST_VARS['fontcolor2_name'];
272                         $updated['fontcolor3'] = $HTTP_POST_VARS['fontcolor3'];
273                         $updated_name['fontcolor3_name'] = $HTTP_POST_VARS['fontcolor3_name'];
274                         $updated['span_class1'] = $HTTP_POST_VARS['span_class1'];
275                         $updated_name['span_class1_name'] = $HTTP_POST_VARS['span_class1_name'];
276                         $updated['span_class2'] = $HTTP_POST_VARS['span_class2'];
277                         $updated_name['span_class2_name'] = $HTTP_POST_VARS['span_class2_name'];
278                         $updated['span_class3'] = $HTTP_POST_VARS['span_class3'];
279                         $updated_name['span_class3_name'] = $HTTP_POST_VARS['span_class3_name'];
280                         $style_id = intval($HTTP_POST_VARS['style_id']);
281                         //
282                         // Wheeeew! Thank heavens for copy and paste and search and replace :D
283                         //
284                         
285                         if($mode == "edit")
286                         {
287                                 $sql = "UPDATE " . THEMES_TABLE . " SET ";
288                                 $count = 0;
290                                 while(list($key, $val) = each($updated))
291                                 {
292                                         if($count != 0)
293                                         {
294                                                 $sql .= ", ";
295                                         }
297                                         //
298                                         // I don't like this but it'll keep MSSQL from throwing
299                                         // an error and save me alot of typing
300                                         //
301                                         $sql .= ( stristr($key, "fontsize") ) ? "$key = $val" : "$key = '" . str_replace("\'", "''", $val) . "'";
303                                         $count++;
304                                 }
305                                 
306                                 $sql .= " WHERE themes_id = $style_id";
307                                 
308                                 if(!$result = $db->sql_query($sql))
309                                 {
310                                         message_die(GENERAL_ERROR, "Could not update themes table!", "", __LINE__, __FILE__, $sql);
311                                 }
312                                 
313                                 //
314                                 // Check if there's a names table entry for this style
315                                 //
316                                 $sql = "SELECT themes_id 
317                                         FROM " . THEMES_NAME_TABLE . " 
318                                         WHERE themes_id = $style_id";
319                                 if(!$result = $db->sql_query($sql))
320                                 {
321                                         message_die(GENERAL_ERROR, "Could not get data from themes_name table", "", __LINE__, __FILE__, $sql);
322                                 }
323                                 
324                                 if($db->sql_numrows($result) > 0)
325                                 {
326                                         $sql = "UPDATE " . THEMES_NAME_TABLE . " 
327                                                 SET ";
328                                         $count = 0;
329                                         while(list($key, $val) = each($updated_name))
330                                         {
331                                                 if($count != 0)
332                                                 {
333                                                         $sql .= ", ";
334                                                 }
335                         
336                                                 $sql .= "$key = '$val'";
337                         
338                                                 $count++;
339                                         }
340                                         
341                                         $sql .= " WHERE themes_id = $style_id";
342                                 }
343                                 else
344                                 {
345                                         //
346                                         // Nope, no names entry so we create a new one.
347                                         //
348                                         $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (themes_id, ";
349                                         while(list($key, $val) = each($updated_name))
350                                         {
351                                                 $fields[] = $key;
352                                                 $vals[] = str_replace("\'", "''", $val);
353                                         }
355                                         for($i = 0; $i < count($fields); $i++)
356                                         {
357                                                 if($i > 0)
358                                                 {
359                                                         $sql .= ", ";
360                                                 }
361                                                 $sql .= $fields[$i];
362                                         }
363                                         
364                                         $sql .= ") VALUES ($style_id, ";
365                                         for($i = 0; $i < count($vals); $i++)
366                                         {
367                                                 if($i > 0)
368                                                 {
369                                                         $sql .= ", ";
370                                                 }
371                                                 $sql .= "'" . $vals[$i] . "'";
372                                         }
373                                         
374                                         $sql .= ")";
375                                 }
376                                                                                 
377                                 if(!$result = $db->sql_query($sql))
378                                 {
379                                         message_die(GENERAL_ERROR, "Could not update themes name table!", "", __LINE__, __FILE__, $sql);
380                                 }
381                                                         
382                                 $message = $lang['Theme_updated'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
384                                 message_die(GENERAL_MESSAGE, $message);
385                         }
386                         else
387                         {
388                                 //
389                                 // First, check if we already have a style by this name
390                                 //
391                                 $sql = "SELECT themes_id 
392                                         FROM " . THEMES_TABLE . " 
393                                         WHERE style_name = '" . str_replace("\'", "''", $updated['style_name']) . "'";
394                                 if(!$result = $db->sql_query($sql))
395                                 {
396                                         message_die(GENERAL_ERROR, "Could not query themes table", "", __LINE__, __FILE__, $sql);
397                                 }
398                                 
399                                 if($db->sql_numrows($result))
400                                 {
401                                         message_die(GENERAL_ERROR, $lang['Style_exists'], $lang['Error']);
402                                 }                               
403                                 
404                                 while(list($key, $val) = each($updated))
405                                 {
406                                         $field_names[] = $key;
408                                         if(stristr($key, "fontsize"))
409                                         {
410                                                 $values[] = "$val";
411                                         }
412                                         else
413                                         {
414                                                 $values[] = "'" . str_replace("\'", "''", $val) . "'";
415                                         }
416                                 }
417                                 
418                                 $sql = "INSERT 
419                                         INTO " . THEMES_TABLE . " (";
420                                 for($i = 0; $i < count($field_names); $i++)
421                                 {
422                                         if($i != 0)
423                                         {
424                                                 $sql .= ", ";
425                                         }
426                                         $sql .= $field_names[$i];
427                                 }
428                                 
429                                 $sql .= ") VALUES (";
430                                 for($i = 0; $i < count($values); $i++)
431                                 {
432                                         if($i != 0)
433                                         {
434                                                 $sql .= ", ";
435                                         }
436                                         $sql .= $values[$i];
437                                 }
438                                 $sql .= ")";
439                                 
440                                 if(!$result = $db->sql_query($sql))
441                                 {
442                                         message_die(GENERAL_ERROR, "Could not update themes table!", "", __LINE__, __FILE__, $sql);
443                                 }
444                                 
445                                 $style_id = $db->sql_nextid();
446                                 
447                                 // 
448                                 // Insert names data
449                                 //
450                                 $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (themes_id, ";
451                                 while(list($key, $val) = each($updated_name))
452                                 {
453                                         $fields[] = $key;
454                                         $vals[] = $val;
455                                 }
457                                 for($i = 0; $i < count($fields); $i++)
458                                 {
459                                         if($i > 0)
460                                         {
461                                                 $sql .= ", ";
462                                         }
463                                         $sql .= $fields[$i];
464                                 }
465                                 
466                                 $sql .= ") VALUES ($style_id, ";
467                                 for($i = 0; $i < count($vals); $i++)
468                                 {
469                                         if($i > 0)
470                                         {
471                                         $sql .= ", ";
472                                         }
473                                 $sql .= "'" . $vals[$i] . "'";
474                                 }
475                                 
476                                 $sql .= ")";
477                                                                                 
478                                 if(!$result = $db->sql_query($sql))
479                                 {
480                                         message_die(GENERAL_ERROR, "Could not insert themes name table!", "", __LINE__, __FILE__, $sql);
481                                 }
482                                 
483                                 $message = $lang['Theme_created'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
485                                 message_die(GENERAL_MESSAGE, $message);
486                         }
487                 }
488                 else
489                 {
490                         if($mode == "edit")
491                         {
492                                 $themes_title = $lang['Edit_theme'];
493                                 $themes_explain = $lang['Edit_theme_explain'];
494                                 
495                                 $style_id = intval($HTTP_GET_VARS['style_id']);
496                                 
497                                 $selected_names = array();
498                                 $selected_values = array();
499                                 // 
500                                 // Fetch the Theme Info from the db
501                                 //
502                                 $sql = "SELECT * 
503                                         FROM " . THEMES_TABLE . " 
504                                         WHERE themes_id = $style_id";
505                                 if(!$result = $db->sql_query($sql))
506                                 {
507                                         message_die(GENERAL_ERROR, "Could not get data from themes table", "", __LINE__, __FILE__, $sql);
508                                 }
509                                 
510                                 if ( $selected_values = $db->sql_fetchrow($result) )
511                                 {
512                                         while(list($key, $val) = @each($selected_values))
513                                         {
514                                                 $selected[$key] = $val;
515                                         }
516                                 }
517                                 
518                                 //
519                                 // Fetch the Themes Name data
520                                 //
521                                 $sql = "SELECT * 
522                                         FROM " . THEMES_NAME_TABLE . " 
523                                         WHERE themes_id = $style_id";
524                                 if(!$result = $db->sql_query($sql))
525                                 {
526                                         message_die(GENERAL_ERROR, "Could not get data from themes name table", "", __LINE__, __FILE__, $sql);
527                                 }
528                                 
529                                 if ( $selected_names = $db->sql_fetchrow($result) )
530                                 {
531                                         while(list($key, $val) = @each($selected_names))
532                                         {
533                                                 $selected[$key] = $val;
534                                         }
535                                 }
537                                 $s_hidden_fields = '<input type="hidden" name="style_id" value="' . $style_id . '" />';
538                         }
539                         else
540                         {
541                                 $themes_title = $lang['Create_theme'];
542                                 $themes_explain = $lang['Create_theme_explain'];
543                         }
544                         
545                         $template->set_filenames(array(
546                                 "body" => "admin/styles_edit_body.tpl")
547                         );
548                         
549                         if( $dir = @opendir($phpbb_root_path . 'templates/') )
550                         {       
551                                 $s_template_select = '<select name="template_name">';
552                                 while( $file = @readdir($dir) )
553                                 {       
554                                         if( !is_file(phpbb_realpath($phpbb_root_path . 'templates/' . $file)) && !is_link(phpbb_realpath($phpbb_root_path . 'templates/' . $file)) && $file != "." && $file != ".." && $file != "CVS" )
555                                         {
556                                                 if($file == $selected['template_name'])
557                                                 {
558                                                         $s_template_select .= '<option value="' . $file . '" selected="selected">' . $file . "</option>\n";
559                                                 }
560                                                 else
561                                                 {
562                                                         $s_template_select .= '<option value="' . $file . '">' . $file . "</option>\n";
563                                                 }
564                                         }
565                                 }
566                                 $s_template_select .= '</select>';
567                         }
568                         else
569                         {
570                                 message_die(GENERAL_MESSAGE, $lang['No_template_dir']);
571                         }
573                         $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
575                         $template->assign_vars(array(
576                                 "L_THEMES_TITLE" => $themes_title,
577                                 "L_THEMES_EXPLAIN" => $themes_explain,
578                                 "L_THEME_NAME" => $lang['Theme_name'],
579                                 "L_TEMPLATE" => $lang['Template'],
580                                 "L_THEME_SETTINGS" => $lang['Theme_settings'],
581                                 "L_THEME_ELEMENT" => $lang['Theme_element'],
582                                 "L_SIMPLE_NAME" => $lang['Simple_name'],
583                                 "L_VALUE" => $lang['Value'],
584                                 "L_STYLESHEET" => $lang['Stylesheet'],
585                                 "L_BACKGROUND_IMAGE" => $lang['Background_image'],
586                                 "L_BACKGROUND_COLOR" => $lang['Background_color'],
587                                 "L_BODY_TEXT_COLOR" => $lang['Text_color'],
588                                 "L_BODY_LINK_COLOR" => $lang['Link_color'],
589                                 "L_BODY_VLINK_COLOR" => $lang['VLink_color'],
590                                 "L_BODY_ALINK_COLOR" => $lang['ALink_color'],
591                                 "L_BODY_HLINK_COLOR" => $lang['HLink_color'],
592                                 "L_TR_COLOR1" => $lang['Tr_color1'],
593                                 "L_TR_COLOR2" => $lang['Tr_color2'],
594                                 "L_TR_COLOR3" => $lang['Tr_color3'],
595                                 "L_TR_CLASS1" => $lang['Tr_class1'],
596                                 "L_TR_CLASS2" => $lang['Tr_class2'],
597                                 "L_TR_CLASS3" => $lang['Tr_class3'],
598                                 "L_TH_COLOR1" => $lang['Th_color1'],
599                                 "L_TH_COLOR2" => $lang['Th_color2'],
600                                 "L_TH_COLOR3" => $lang['Th_color3'],
601                                 "L_TH_CLASS1" => $lang['Th_class1'],
602                                 "L_TH_CLASS2" => $lang['Th_class2'],
603                                 "L_TH_CLASS3" => $lang['Th_class3'],
604                                 "L_TD_COLOR1" => $lang['Td_color1'],
605                                 "L_TD_COLOR2" => $lang['Td_color2'],
606                                 "L_TD_COLOR3" => $lang['Td_color3'],
607                                 "L_TD_CLASS1" => $lang['Td_class1'],
608                                 "L_TD_CLASS2" => $lang['Td_class2'],
609                                 "L_TD_CLASS3" => $lang['Td_class3'],
610                                 "L_FONTFACE_1" => $lang['fontface1'],
611                                 "L_FONTFACE_2" => $lang['fontface2'],
612                                 "L_FONTFACE_3" => $lang['fontface3'],
613                                 "L_FONTSIZE_1" => $lang['fontsize1'],
614                                 "L_FONTSIZE_2" => $lang['fontsize2'],
615                                 "L_FONTSIZE_3" => $lang['fontsize3'],
616                                 "L_FONTCOLOR_1" => $lang['fontcolor1'],
617                                 "L_FONTCOLOR_2" => $lang['fontcolor2'],
618                                 "L_FONTCOLOR_3" => $lang['fontcolor3'],
619                                 "L_SPAN_CLASS_1" => $lang['span_class1'],
620                                 "L_SPAN_CLASS_2" => $lang['span_class2'],
621                                 "L_SPAN_CLASS_3" => $lang['span_class3'],
622                                 "L_SAVE_SETTINGS" => $lang['Save_Settings'], 
623                                 "THEME_NAME" => $selected['style_name'],
624                                 "HEAD_STYLESHEET" => $selected['head_stylesheet'],
625                                 "BODY_BACKGROUND" => $selected['body_background'],
626                                 "BODY_BGCOLOR" => $selected['body_bgcolor'],
627                                 "BODY_TEXT_COLOR" => $selected['body_text'],
628                                 "BODY_LINK_COLOR" => $selected['body_link'],
629                                 "BODY_VLINK_COLOR" => $selected['body_vlink'],
630                                 "BODY_ALINK_COLOR" => $selected['body_alink'],
631                                 "BODY_HLINK_COLOR" => $selected['body_hlink'],
632                                 "TR_COLOR1" => $selected['tr_color1'],
633                                 "TR_COLOR2" => $selected['tr_color2'],
634                                 "TR_COLOR3" => $selected['tr_color3'],
635                                 "TR_CLASS1" => $selected['tr_class1'],
636                                 "TR_CLASS2" => $selected['tr_class2'],
637                                 "TR_CLASS3" => $selected['tr_class3'],
638                                 "TH_COLOR1" => $selected['th_color1'],
639                                 "TH_COLOR2" => $selected['th_color2'],
640                                 "TH_COLOR3" => $selected['th_color3'],
641                                 "TH_CLASS1" => $selected['th_class1'],
642                                 "TH_CLASS2" => $selected['th_class2'],
643                                 "TH_CLASS3" => $selected['th_class3'],
644                                 "TD_COLOR1" => $selected['td_color1'],
645                                 "TD_COLOR2" => $selected['td_color2'],
646                                 "TD_COLOR3" => $selected['td_color3'],
647                                 "TD_CLASS1" => $selected['td_class1'],
648                                 "TD_CLASS2" => $selected['td_class2'],
649                                 "TD_CLASS3" => $selected['td_class3'],
650                                 "FONTFACE1" => $selected['fontface1'],
651                                 "FONTFACE2" => $selected['fontface2'],
652                                 "FONTFACE3" => $selected['fontface3'],
653                                 "FONTSIZE1" => $selected['fontsize1'],
654                                 "FONTSIZE2" => $selected['fontsize2'],
655                                 "FONTSIZE3" => $selected['fontsize3'],
656                                 "FONTCOLOR1" => $selected['fontcolor1'],
657                                 "FONTCOLOR2" => $selected['fontcolor2'],
658                                 "FONTCOLOR3" => $selected['fontcolor3'],
659                                 "SPAN_CLASS1" => $selected['span_class1'],
660                                 "SPAN_CLASS2" => $selected['span_class2'],
661                                 "SPAN_CLASS3" => $selected['span_class3'],
663                                 "TR_COLOR1_NAME" => $selected['tr_color1_name'],
664                                 "TR_COLOR2_NAME" => $selected['tr_color2_name'],
665                                 "TR_COLOR3_NAME" => $selected['tr_color3_name'],
666                                 "TR_CLASS1_NAME" => $selected['tr_class1_name'],
667                                 "TR_CLASS2_NAME" => $selected['tr_class2_name'],
668                                 "TR_CLASS3_NAME" => $selected['tr_class3_name'],
669                                 "TH_COLOR1_NAME" => $selected['th_color1_name'],
670                                 "TH_COLOR2_NAME" => $selected['th_color2_name'],
671                                 "TH_COLOR3_NAME" => $selected['th_color3_name'],
672                                 "TH_CLASS1_NAME" => $selected['th_class1_name'],
673                                 "TH_CLASS2_NAME" => $selected['th_class2_name'],
674                                 "TH_CLASS3_NAME" => $selected['th_class3_name'],
675                                 "TD_COLOR1_NAME" => $selected['td_color1_name'],
676                                 "TD_COLOR2_NAME" => $selected['td_color2_name'],
677                                 "TD_COLOR3_NAME" => $selected['td_color3_name'],
678                                 "TD_CLASS1_NAME" => $selected['td_class1_name'],
679                                 "TD_CLASS2_NAME" => $selected['td_class2_name'],
680                                 "TD_CLASS3_NAME" => $selected['td_class3_name'],
681                                 "FONTFACE1_NAME" => $selected['fontface1_name'],
682                                 "FONTFACE2_NAME" => $selected['fontface2_name'],
683                                 "FONTFACE3_NAME" => $selected['fontface3_name'],
684                                 "FONTSIZE1_NAME" => $selected['fontsize1_name'],
685                                 "FONTSIZE2_NAME" => $selected['fontsize2_name'],
686                                 "FONTSIZE3_NAME" => $selected['fontsize3_name'],
687                                 "FONTCOLOR1_NAME" => $selected['fontcolor1_name'],
688                                 "FONTCOLOR2_NAME" => $selected['fontcolor2_name'],
689                                 "FONTCOLOR3_NAME" => $selected['fontcolor3_name'],
690                                 "SPAN_CLASS1_NAME" => $selected['span_class1_name'],
691                                 "SPAN_CLASS2_NAME" => $selected['span_class2_name'],
692                                 "SPAN_CLASS3_NAME" => $selected['span_class3_name'],
693                                 
694                                 "S_THEME_ACTION" => append_sid("admin_styles.$phpEx"),
695                                 "S_TEMPLATE_SELECT" => $s_template_select,
696                                 "S_HIDDEN_FIELDS" => $s_hidden_fields)
697                         );
698                         
699                         $template->pparse("body");
700                 }
701                 break;
703         case "export";
704                 if($HTTP_POST_VARS['export_template'])
705                 {
706                         $template_name = $HTTP_POST_VARS['export_template'];
708                         $sql = "SELECT * 
709                                 FROM " . THEMES_TABLE . " 
710                                 WHERE template_name = '" . str_replace("\'", "''", $template_name) . "'";
711                         if(!$result = $db->sql_query($sql))
712                         {
713                                 message_die(GENERAL_ERROR, "Could not get theme data for selected template", "", __LINE__, __FILE__, $sql);
714                         }
715                         
716                         $theme_rowset = $db->sql_fetchrowset($result);
717                         
718                         if( count($theme_rowset) == 0 )
719                         {
720                                 message_die(GENERAL_MESSAGE, $lang['No_themes']);
721                         }
722                         
723                         $theme_data = '<?php'."\n\n";
724                         $theme_data .= "//\n// phpBB 2.x auto-generated theme config file for $template_name\n// Do not change anything in this file!\n//\n\n";
726                         for($i = 0; $i < count($theme_rowset); $i++)
727                         {
728                                 while(list($key, $val) = each($theme_rowset[$i]))
729                                 {
730                                         if(!intval($key) && $key != "0" && $key != "themes_id")
731                                         {
732                                                 $theme_data .= '$' . $template_name . "[$i]['$key'] = \"" . addslashes($val) . "\";\n";
733                                         }
734                                 }
735                                 $theme_data .= "\n";
736                         }
737                         
738                         $theme_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
739                         
740                         @umask(0111);
742                         $fp = @fopen($phpbb_root_path . 'templates/' . $template_name . '/theme_info.cfg', 'w');
744                         if( !$fp )
745                         {
746                                 //
747                                 // Unable to open the file writeable do something here as an attempt
748                                 // to get around that...
749                                 //
750                                 $s_hidden_fields = '<input type="hidden" name="theme_info" value="' . htmlspecialchars($theme_data) . '" />';
751                                 $s_hidden_fields .= '<input type="hidden" name="send_file" value="1" /><input type="hidden" name="mode" value="export" />';
752                                 
753                                 $download_form = '<form action="' . append_sid("admin_styles.$phpEx") . '" method="post"><input class="mainoption" type="submit" name="submit" value="' . $lang['Download'] . '" />' . $s_hidden_fields;
755                                 $template->set_filenames(array(
756                                         "body" => "message_body.tpl")
757                                 );
759                                 $template->assign_vars(array(
760                                         "MESSAGE_TITLE" => $lang['Export_themes'],
761                                         "MESSAGE_TEXT" => $lang['Download_theme_cfg'] . "<br /><br />" . $download_form)
762                                 );
764                                 $template->pparse('body');
765                                 exit();
766                         }
768                         $result = @fputs($fp, $theme_data, strlen($theme_data));
769                         fclose($fp);
770                         
771                         $message = $lang['Theme_info_saved'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
773                         message_die(GENERAL_MESSAGE, $message);
775                 }
776                 else if($HTTP_POST_VARS['send_file'])
777                 {
778                         
779                         header("Content-Type: text/x-delimtext; name=\"theme_info.cfg\"");
780                         header("Content-disposition: attachment; filename=theme_info.cfg");
782                         echo stripslashes($HTTP_POST_VARS['theme_info']);
783                 }
784                 else
785                 {
786                         $template->set_filenames(array(
787                                 "body" => "admin/styles_exporter.tpl")
788                         );
789                         
790                         if( $dir = @opendir($phpbb_root_path . 'templates/') )
791                         {       
792                                 $s_template_select = '<select name="export_template">';
793                                 while( $file = @readdir($dir) )
794                                 {       
795                                         if( !is_file(phpbb_realpath($phpbb_root_path . 'templates/' . $file)) && !is_link(phpbb_realpath($phpbb_root_path . 'templates/' .$file)) && $file != "." && $file != ".." && $file != "CVS" )
796                                         {
797                                                 $s_template_select .= '<option value="' . $file . '">' . $file . "</option>\n";
798                                         }
799                                 }
800                                 $s_template_select .= '</select>';
801                         }
802                         else
803                         {
804                                 message_die(GENERAL_MESSAGE, $lang['No_template_dir']);
805                         }
806                         
807                         $template->assign_vars(array(
808                                 "L_STYLE_EXPORTER" => $lang['Export_themes'],
809                                 "L_EXPORTER_EXPLAIN" => $lang['Export_explain'],
810                                 "L_TEMPLATE_SELECT" => $lang['Select_template'],
811                                 "L_SUBMIT" => $lang['Submit'], 
813                                 "S_EXPORTER_ACTION" => append_sid("admin_styles.$phpEx?mode=export"),
814                                 "S_TEMPLATE_SELECT" => $s_template_select)
815                         );
816                         
817                         $template->pparse("body");
818                         
819                 }
820                 break;
822         case "delete":
823                 $style_id = ( isset($HTTP_GET_VARS['style_id']) ) ? intval($HTTP_GET_VARS['style_id']) : intval($HTTP_POST_VARS['style_id']);
824                 
825                 if( !$confirm )
826                 {
827                         if($style_id == $board_config['default_style'])
828                         {
829                                 message_die(GENERAL_MESSAGE, $lang['Cannot_remove_style']);
830                         }
831                         
832                         $hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'" /><input type="hidden" name="style_id" value="'.$style_id.'" />';
833                         
834                         //
835                         // Set template files
836                         //
837                         $template->set_filenames(array(
838                                 "confirm" => "confirm_body.tpl")
839                         );
841                         $template->assign_vars(array(
842                                 "MESSAGE_TITLE" => $lang['Confirm'],
843                                 "MESSAGE_TEXT" => $lang['Confirm_delete_style'],
845                                 "L_YES" => $lang['Yes'],
846                                 "L_NO" => $lang['No'],
848                                 "S_CONFIRM_ACTION" => append_sid("admin_styles.$phpEx"),
849                                 "S_HIDDEN_FIELDS" => $hidden_fields)
850                         );
852                         $template->pparse("confirm");
854                 }
855                 else
856                 {
857                         //
858                         // The user has confirmed the delete. Remove the style, the style element
859                         // names and update any users who might be using this style
860                         //
861                         $sql = "DELETE FROM " . THEMES_TABLE . " 
862                                 WHERE themes_id = $style_id";
863                         if(!$result = $db->sql_query($sql, BEGIN_TRANSACTION))
864                         {
865                                 message_die(GENERAL_ERROR, "Could not remove style data!", "", __LINE__, __FILE__, $sql);
866                         }
867                         
868                         //
869                         // There may not be any theme name data so don't throw an error
870                         // if the SQL dosan't work
871                         //
872                         $sql = "DELETE FROM " . THEMES_NAME_TABLE . " 
873                                 WHERE themes_id = $style_id";
874                         $db->sql_query($sql);
876                         $sql = "UPDATE " . USERS_TABLE . " 
877                                 SET user_style = " . $board_config['default_style'] . " 
878                                 WHERE user_style = $style_id";
879                         if(!$result = $db->sql_query($sql, END_TRANSACTION))
880                         {
881                                 message_die(GENERAL_ERROR, "Could not update user style information", "", __LINE__, __FILE__, $sql);
882                         }
883                         
884                         $message = $lang['Style_removed'] . "<br /><br />" . sprintf($lang['Click_return_styleadmin'], "<a href=\"" . append_sid("admin_styles.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
886                         message_die(GENERAL_MESSAGE, $message);
887                 }
888                 break;
890         default:
891                 
892                 $sql = "SELECT themes_id, template_name, style_name 
893                         FROM " . THEMES_TABLE . " 
894                         ORDER BY template_name";
895                 if(!$result = $db->sql_query($sql))
896                 {
897                         message_die(GENERAL_ERROR, "Could not get style information!", "", __LINE__, __FILE__, $sql);
898                 }
899                 
900                 $style_rowset = $db->sql_fetchrowset($result);
901                 
902                 $template->set_filenames(array(
903                         "body" => "admin/styles_list_body.tpl")
904                 );
906                 $template->assign_vars(array(
907                         "L_STYLES_TITLE" => $lang['Styles_admin'],
908                         "L_STYLES_TEXT" => $lang['Styles_explain'],
909                         "L_STYLE" => $lang['Style'],
910                         "L_TEMPLATE" => $lang['Template'],
911                         "L_EDIT" => $lang['Edit'],
912                         "L_DELETE" => $lang['Delete'])
913                 );
914                                         
915                 for($i = 0; $i < count($style_rowset); $i++)
916                 {
917                         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
918                         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
920                         $template->assign_block_vars("styles", array(
921                                 "ROW_CLASS" => $row_class,
922                                 "ROW_COLOR" => $row_color,
923                                 "STYLE_NAME" => $style_rowset[$i]['style_name'],
924                                 "TEMPLATE_NAME" => $style_rowset[$i]['template_name'],
926                                 "U_STYLES_EDIT" => append_sid("admin_styles.$phpEx?mode=edit&amp;style_id=" . $style_rowset[$i]['themes_id']),
927                                 "U_STYLES_DELETE" => append_sid("admin_styles.$phpEx?mode=delete&amp;style_id=" . $style_rowset[$i]['themes_id']))
928                         );
929                 }
930                 
931                 $template->pparse("body");      
932                 break;
935 if (empty($HTTP_POST_VARS['send_file']))
937         include('./page_footer_admin.'.$phpEx);
940 ?>