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