diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index a0519e0ab0..ccad70c00f 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -28,19 +28,40 @@ if (!$auth->acl_get('a_styles')) trigger_error($user->lang['NO_ADMIN']); } -// + +// Get and set some vars $mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : ''; -$action = (isset($_REQUEST['action'])) ? htmlspecialchars($_REQUEST['action']) : ''; - - + +if (isset($_REQUEST['action'])) +{ + $action = htmlspecialchars($_REQUEST['action']); +} +else +{ + if (isset($_POST['add'])) + { + $action = 'add'; + } + else if (isset($_POST['preview'])) + { + $action = 'preview'; + } + else + { + $action = ''; + } +} + +$error = array(); +// What shall we do today then? switch ($mode) { case 'styles': - $style_id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : ''; + $style_id = (isset($_REQUEST['id'])) ? intval($_REQUEST['id']) : ''; switch ($action) { @@ -53,24 +74,103 @@ switch ($mode) $db->sql_query($sql); break; + case 'delete': + break; + + case 'export': + break; + + case 'add': case 'edit': if (isset($_POST['update'])) { + $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; + $style_copyright = (isset($_POST['style_copyright'])) ? stripslashes(htmlspecialchars($_POST['style_copyright'])) : ''; + + $style_active = (!empty($_POST['style_active'])) ? 1 : 0; + + $template_id = (!empty($_POST['template_id'])) ? intval($_POST['template_id']) : 0; + $theme_id = (!empty($_POST['theme_id'])) ? intval($_POST['theme_id']) : 0; + $imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; + + if (empty($style_name)) + { + $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; + } + + if (strlen($style_name) > 30) + { + $error[] = $user->lang['STYLE_ERR_NAME_LONG']; + } + + if (strlen($style_copyright) > 60) + { + $error[] = $user->lang['STYLE_ERR_COPY_LONG']; + } + + if (!$template_id || !$theme_id || !$imageset_id) + { + $error[] = $user->lang['STYLE_ERR_NO_IDS']; + } + + if ($action == 'add') + { + $sql = 'SELECT style_name + FROM ' . STYLES_TABLE . " + WHERE style_name = '" . $db->sql_escape($style_name) . "'"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; + } + $db->sql_freeresult($result); + } + + if (!sizeof($error)) + { + $sql_ary = array( + 'style_name' => $style_name, + 'style_copyright' => $style_copyright, + 'template_id' => $template_id, + 'theme_id' => $theme_id, + 'imageset_id' => $imageset_id, + ); + + $sql = ($action == 'add') ? 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary) : 'UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE style_id = $style_id"; + $db->sql_query($sql); + + $log = ($action == 'add') ? 'LOG_ADD_STYLE' : 'LOG_EDIT_STYLE'; + add_log('admin', $log, addslashes($style_name)); + + $message = ($action == 'add') ? 'STYLED_ADDED' : 'STYLE_EDITED'; + trigger_error($user->lang[$message]); + } } - if ($style_id) + if (!sizeof($error)) { - $sql = 'SELECT * - FROM ' . STYLES_TABLE . " - WHERE style_id = $style_id"; - $result = $db->sql_query($sql); - - if (!extract($db->sql_fetchrow($result))) + if ($style_id) { - die("ERROR"); + $sql = 'SELECT * + FROM ' . STYLES_TABLE . " + WHERE style_id = $style_id"; + $result = $db->sql_query($sql); + + if (!extract($db->sql_fetchrow($result))) + { + die("ERROR"); + } + $db->sql_freeresult($result); + } + else + { + $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; + $style_copyright = ''; + $style_active = 1; + $template_id = $theme_id = $imageset_id = 0; } - $db->sql_freeresult($result); } $style_options = array(); @@ -81,6 +181,7 @@ switch ($mode) FROM $table ORDER BY {$field}_id"; $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { $selected = ($row[$field . '_id'] == ${$field . '_id'}) ? ' selected="selected"' : ''; @@ -103,15 +204,29 @@ switch ($mode)