sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not insert theme data!", "Error", __LINE__, __FILE__, $sql);
}
message_die(GENERAL_MESSAGE, $lang['Theme_installed'], $lang['Success']);
}
else
{
$installable_themes = array();
if($dir = opendir($phpbb_root_dir . "templates/"))
{
while($sub_dir = readdir($dir))
{
if($sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS")
{
if(file_exists($phpbb_root_dir . "templates/" . $sub_dir . "/theme_info.cfg"))
{
include($phpbb_root_dir . "templates/" . $sub_dir . "/theme_info.cfg");
for($i = 0; $i < count($$sub_dir); $i++)
{
$working_data = $$sub_dir;
$style_name = $working_data[$i]['style_name'];
$sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name = '$style_name'";
if(!$result = $db->sql_query($sql))
{
message_die(GENREAL_ERROR, "Could not query themes table!", "Error", __LINE__, __FILE__, $sql);
}
if(!$db->sql_numrows($result))
{
$installable_themes[] = $working_data[$i];
}
}
}
}
}
$template->set_filenames(array(
"body" => "admin/styles_addnew_body.tpl")
);
$template->assign_vars(array(
"L_STYLES_TITLE" => $lang['Styles_admin'],
"L_STYLES_ADD_TEXT" => $lang['Styles_addnew_explain'],
"L_STYLE" => $lang['Style'],
"L_TEMPLATE" => $lang['Template'],
"L_INSTALL" => $lang['Install'],
"L_ACTION" => $lang['Action'])
);
for($i = 0; $i < count($installable_themes); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars("styles", array(
"STYLE_NAME" => $installable_themes[$i]['style_name'],
"TEMPLATE_NAME" => $installable_themes[$i]['template_name'],
"ROW_CLASS" => $row_class,
"ROW_COLOR" => $row_color,
"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'])))
);
}
$template->pparse("body");
}
closedir($dir);
}
break;
case "create":
case "edit":
$submit = (isset($HTTP_POST_VARS['submit'])) ? 1 : 0;
if($submit)
{
//
// DAMN! Thats alot of data to validate...
//
$updated['style_name'] = $HTTP_POST_VARS['style_name'];
$updated['template_name'] = $HTTP_POST_VARS['template_name'];
$updated['head_stylesheet'] = $HTTP_POST_VARS['head_stylesheet'];
$updated['body_background'] = $HTTP_POST_VARS['body_background'];
$updated['body_bgcolor'] = $HTTP_POST_VARS['body_bgcolor'];
$updated['body_link'] = $HTTP_POST_VARS['body_link'];
$updated['body_vlink'] = $HTTP_POST_VARS['body_vlink'];
$updated['body_alink'] = $HTTP_POST_VARS['body_alink'];
$updated['body_hlink'] = $HTTP_POST_VARS['body_hlink'];
$updated['tr_color1'] = $HTTP_POST_VARS['tr_color1'];
$updated_name['tr_color1_name'] = $HTTP_POST_VARS['tr_color1_name'];
$updated['tr_color2'] = $HTTP_POST_VARS['tr_color2'];
$updated_name['tr_color2_name'] = $HTTP_POST_VARS['tr_color2_name'];
$updated['tr_color3'] = $HTTP_POST_VARS['tr_color3'];
$updated_name['tr_color3_name'] = $HTTP_POST_VARS['tr_color3_name'];
$updated['tr_class1'] = $HTTP_POST_VARS['tr_class1'];
$updated_name['tr_class1_name'] = $HTTP_POST_VARS['tr_class1_name'];
$updated['tr_class2'] = $HTTP_POST_VARS['tr_class2'];
$updated_name['tr_class2_name'] = $HTTP_POST_VARS['tr_class2_name'];
$updated['tr_class3'] = $HTTP_POST_VARS['tr_class3'];
$updated_name['tr_class3_name'] = $HTTP_POST_VARS['tr_class3_name'];
$updated['th_color1'] = $HTTP_POST_VARS['th_color1'];
$updated_name['th_color1_name'] = $HTTP_POST_VARS['th_color1_name'];
$updated['th_color2'] = $HTTP_POST_VARS['th_color2'];
$updated_name['th_color2_name'] = $HTTP_POST_VARS['th_color2_name'];
$updated['th_color3'] = $HTTP_POST_VARS['th_color3'];
$updated_name['th_color3_name'] = $HTTP_POST_VARS['th_color3_name'];
$updated['th_class1'] = $HTTP_POST_VARS['th_class1'];
$updated_name['th_class1_name'] = $HTTP_POST_VARS['th_class1_name'];
$updated['td_color1'] = $HTTP_POST_VARS['td_color1'];
$updated_name['td_color1_name'] = $HTTP_POST_VARS['td_color1_name'];
$updated['td_color2'] = $HTTP_POST_VARS['td_color2'];
$updated_name['td_color2_name'] = $HTTP_POST_VARS['td_color2_name'];
$updated['td_color3'] = $HTTP_POST_VARS['td_color3'];
$updated_name['td_color3_name'] = $HTTP_POST_VARS['td_color3_name'];
$updated['td_class1'] = $HTTP_POST_VARS['td_class1'];
$updated_name['td_class1_name'] = $HTTP_POST_VARS['td_class1_name'];
$updated['td_class2'] = $HTTP_POST_VARS['td_class2'];
$updated_name['td_class2_name'] = $HTTP_POST_VARS['td_class2_name'];
$updated['td_class3'] = $HTTP_POST_VARS['td_class3'];
$updated_name['td_class3_name'] = $HTTP_POST_VARS['td_class3_name'];
$updated['fontface1'] = $HTTP_POST_VARS['fontface1'];
$updated_name['fontface1_name'] = $HTTP_POST_VARS['fontface1_name'];
$updated['fontface2'] = $HTTP_POST_VARS['fontface2'];
$updated_name['fontface2_name'] = $HTTP_POST_VARS['fontface2_name'];
$updated['fontface3'] = $HTTP_POST_VARS['fontface3'];
$updated_name['fontface3_name'] = $HTTP_POST_VARS['fontface3_name'];
$updated['fontsize1'] = intval($HTTP_POST_VARS['fontsize1']);
$updated_name['fontsize1_name'] = $HTTP_POST_VARS['fontsize1_name'];
$updated['fontsize2'] = intval($HTTP_POST_VARS['fontsize2']);
$updated_name['fontsize2_name'] = $HTTP_POST_VARS['fontsize2_name'];
$updated['fontsize3'] = intval($HTTP_POST_VARS['fontsize3']);
$updated_name['fontsize3_name'] = $HTTP_POST_VARS['fontsize3_name'];
$updated['fontcolor1'] = $HTTP_POST_VARS['fontcolor1'];
$updated_name['fontcolor1_name'] = $HTTP_POST_VARS['fontcolor1_name'];
$updated['fontcolor2'] = $HTTP_POST_VARS['fontcolor2'];
$updated_name['fontcolor2_name'] = $HTTP_POST_VARS['fontcolor2_name'];
$updated['fontcolor3'] = $HTTP_POST_VARS['fontcolor3'];
$updated_name['fontcolor3_name'] = $HTTP_POST_VARS['fontcolor3_name'];
$updated['span_class1'] = $HTTP_POST_VARS['span_class1'];
$updated_name['span_class1_name'] = $HTTP_POST_VARS['span_class1_name'];
$updated['span_class2'] = $HTTP_POST_VARS['span_class2'];
$updated_name['span_class2_name'] = $HTTP_POST_VARS['span_class2_name'];
$updated['span_class3'] = $HTTP_POST_VARS['span_class3'];
$updated_name['span_class3_name'] = $HTTP_POST_VARS['span_class3_name'];
$style_id = intval($HTTP_POST_VARS['style_id']);
//
// Wheeeew! Thank heavens for copy and paste and search and replace :D
//
if($mode == "edit")
{
$sql = "UPDATE " . THEMES_TABLE . " SET ";
$count = 0;
while(list($key, $val) = each($updated))
{
if($count != 0)
{
$sql .= ", ";
}
// I don't like this but it'll keep MSSQL from throwing an error and save me alot of typing
if(stristr($key, "fontsize"))
{
$sql .= "$key = $val";
}
else
{
$sql .= "$key = '$val'";
}
$count++;
}
$sql .= " WHERE themes_id = $style_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not update themes table!", "Error", __LINE__, __FILE__, $sql);
}
//
// Check if there's a names table entry for this style
//
$sql = "SELECT themes_id FROM " . THEMES_NAME_TABLE . " WHERE themes_id = $style_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not get data from themes_name table", "Error", __LINE__, __FILE__, $sql);
}
if($db->sql_numrows($result) > 0)
{
$sql = "UPDATE " . THEMES_NAME_TABLE . " SET ";
$count = 0;
while(list($key, $val) = each($updated_name))
{
if($count != 0)
{
$sql .= ", ";
}
$sql .= "$key = '$val'";
$count++;
}
$sql .= " WHERE themes_id = $style_id";
}
else
{
// Nope, no names entry so we create a new one.
$sql = "INSERT INTO " . THEMES_NAME_TABLE . " (themes_id, ";
while(list($key, $val) = each($updated_name))
{
$fields[] = $key;
$vals[] = $val;
}
for($i = 0; $i < count($fields); $i++)
{
if($i > 0)
{
$sql .= ", ";
}
$sql .= $fields[$i];
}
$sql .= ") VALUES ($style_id, ";
for($i = 0; $i < count($vals); $i++)
{
if($i > 0)
{
$sql .= ", ";
}
$sql .= "'" . $vals[$i] . "'";
}
$sql .= ")";
}
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not update themes name table!", "Error", __LINE__, __FILE__, $sql);
}
message_die(GENERAL_MESSAGE, $lang['Theme_updated'], $lang['Success']);
}
else
{
while(list($key, $val) = each($updated))
{
$field_names[] = $key;
if(stristr($key, "fontsize"))
{
$values[] = "$val";
}
else
{
$values[] = "'$val'";
}
}
$sql = "INSERT INTO " . THEMES_TABLE . " (";
for($i = 0; $i < count($field_names); $i++)
{
if($i != 0)
{
$sql .= ", ";
}
$sql .= $field_names[$i];
}
$sql .= ") VALUES (";
for($i = 0; $i < count($values); $i++)
{
if($i != 0)
{
$sql .= ", ";
}
$sql .= $values[$i];
}
$sql .= ")";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not update themes table!", "Error", __LINE__, __FILE__, $sql);
}
$style_id = $db->sql_nextid();
//
// Insert names data
//
$sql = "INSERT INTO " . THEMES_NAME_TABLE . " (themes_id, ";
while(list($key, $val) = each($updated_name))
{
$fields[] = $key;
$vals[] = $val;
}
for($i = 0; $i < count($fields); $i++)
{
if($i > 0)
{
$sql .= ", ";
}
$sql .= $fields[$i];
}
$sql .= ") VALUES ($style_id, ";
for($i = 0; $i < count($vals); $i++)
{
if($i > 0)
{
$sql .= ", ";
}
$sql .= "'" . $vals[$i] . "'";
}
$sql .= ")";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not insert themes name table!", "Error", __LINE__, __FILE__, $sql);
}
message_die(GENERAL_MESSAGE, $lang['Theme_created'], $lang['Success']);
}
}
else
{
if($mode == "edit")
{
$themes_title = $lang['Edit_theme'];
$themes_explain = $lang['Edit_theme_explain'];
$style_id = $HTTP_GET_VARS['style_id'];
//
// Fetch the Theme Info from the db
//
$sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id = $style_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not get data from themes table", "Error", __LINE__, __FILE__, $sql);
}
$selected_values = $db->sql_fetchrow($result);
//
// Fetch the Themes Name data
//
$sql = "SELECT * FROM " . THEMES_NAME_TABLE . " WHERE themes_id = $style_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not get data from themes name table", "Error", __LINE__, __FILE__, $sql);
}
$selected_names = $db->sql_fetchrow($result);
$selected = array_merge($selected_values, $selected_names);
$s_hidden_fields = '';
}
else
{
$themes_title = $lang['Create_theme'];
$themes_explain = $lang['Create_theme_explain'];
}
$template->set_filenames(array(
"body" => "admin/styles_edit_body.tpl")
);
if($dir = opendir($phpbb_root_path . 'templates/'))
{
$s_template_select = '