DIR : /home/kozerus/public_html/go/dgs/forum/edit_tag.php
/home/kozerus/public_html/go/dgs/forum
<?php
/*
Dragon Go Server
Copyright (C) 2001- Jens-Uwe Gaspar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$TranslateGroups[] = "Forum";
chdir('..');
require_once 'include/std_functions.php';
require_once 'include/form_functions.php';
require_once 'forum/forum_functions.php';
$GLOBALS['ThePage'] = new Page('TagEdit');
{
connect2mysql();
$logged_in = who_is_logged( $player_row);
if ( !$logged_in )
error('login_if_not_logged_in', 'edit_tag');
if ( !ENABLE_FORUM_TAGS )
error('feature_disabled', 'tags');
$my_id = $player_row['ID'];
if ( $my_id <= GUESTS_ID_MAX )
error('not_allowed_for_guest', 'edit_tag');
/* Actual REQUEST calls used:
(no args) : add new tag
tag= : edit existing tag
preview&tag= : preview for tag-save
save&tag= : save new/updated tag
delete&tag= : remove existing tag (need confirmation)
delete&confirm=1&tag= : remove tag (confirmed)
cancel : cancel remove-confirmation
*/
if ( @$_REQUEST['cancel'] ) // cancel delete
jump_to("forum/tags.php");
$tag_id = (int) get_request_arg('tag');
if ( $tag_id < 0 ) $tag_id = 0;
$is_delete = @$_REQUEST['delete'];
// init new tag
if ( $tag_id > 0 )
{
$tag = Tag::load_tag($tag_id);
if ( is_null($tag) )
error('unknown_tag', "edit_tag.check.load_tag($tag_id)");
}
else
$tag = Tag::new_tag();
if ( $tag_id && $is_delete && @$_REQUEST['confirm'] )
{
Tag::delete_cache_tags("edit_tag.delete_tag($my_id,$tag_id)", $my_id);
$tag->delete();
jump_to("forum/tags.php?sysmsg=". urlencode(T_('Tag removed!')) );
}
// check + parse edit-form
list( $vars, $edits, $errors ) = parse_edit_form( $tag );
// save tag-object with values from edit-form
if ( @$_REQUEST['save'] && !@$_REQUEST['preview'] && count($errors) == 0 )
{
$tag->persist();
Tag::delete_cache_tags("edit_tag.add_tag($my_id,{$tag->ID})", $my_id);
jump_to("forum/tags.php?sysmsg=". urlencode(T_('Tag saved!')) );
}
$page = "edit_tag.php";
if ( $tag_id )
$title = ($is_delete) ? T_('Delete tag') : T_('Edit tag');
else
$title = T_('New Tag');
// ---------- Tag EDIT form -------------------------------------
$tform = new Form( 'tagEdit', $page, FORM_GET );
$tform->add_hidden( 'tag', $tag_id );
if ( count($errors) )
{
$tform->add_row( array(
'DESCRIPTION', T_('Error'),
'TEXT', buildErrorListString(T_('There are some errors'), $errors) ));
$tform->add_empty_row();
}
$tform->add_row( array(
'DESCRIPTION', T_('Name'),
'TEXTINPUT', 'name', 40, 64, $vars['name'] ));
$tform->add_row( array(
'DESCRIPTION', T_('Background color'),
'TEXTINPUT', 'col_bg', 6, 10, $vars['col_bg'] ));
$tform->add_row( array(
'DESCRIPTION', T_('Text color'),
'TEXTINPUT', 'col_fg', 6, 10, $vars['col_fg'] ));
$tform->add_row( array(
'DESCRIPTION', T_('Unsaved edits'),
'TEXT', span('TWarning', implode(', ', $edits), '[%s]'), ));
if ( $tag_id && $is_delete )
{
$tform->add_hidden( 'confirm', 1 );
$tform->add_empty_row();
$tform->add_row( array(
'CELL', 2, '',
'TEXT', T_('Please confirm deletion of tag') . ':', ));
$tform->add_row( array(
'SUBMITBUTTON', 'delete', T_('Confirm delete'),
'SUBMITBUTTON', 'cancel', T_('Cancel') ));
}
else
{
$tform->add_row( array(
'TAB', 'CELL', 1, '', // align submit-buttons
'SUBMITBUTTON', 'save', T_('Save tag'),
'TEXT', SMALL_SPACING,
'SUBMITBUTTON', 'preview', T_('Preview'),
));
}
if ( @$_REQUEST['preview'] || $is_delete || $tag->Name != '' || $tag_id > 0 )
{
$preview_row_fmt = '<td class="Preview %s">[%s] ' .
sprintf( '%s: %s%s%s:%s</td>',
T_('Active#tag'), $tag->render_tag(), SMALL_SPACING, T_('Inactive#tag'), $tag->render_tag( 'Inactive' ) );
$tform->add_empty_row();
$tform->add_row( array(
'DESCRIPTION', T_('Preview'),
'OWNHTML', sprintf( $preview_row_fmt, 'ForumTagsBG', T_('Forum posts') ), ));
$tform->add_row( array(
'TAB',
'OWNHTML', sprintf($preview_row_fmt, 'SearchTagsBG', T_('Forum search') ), ));
}
start_page( $title, true, $logged_in, $player_row);
echo "<h3 class=Header>$title</h3>\n";
$tform->echo_string();
$menu_array = array();
$menu_array[T_('Tags')] = "forum/tags.php";
if ( $tag_id > 0 )
$menu_array[T_('Add new tag')] = 'forum/' . $page;
end_page(@$menu_array);
}//main
// return [ vars-hash, edits-arr, errorlist ]
function parse_edit_form( Tag &$tag )
{
$edits = array();
$errors = array();
$is_posted = ( @$_REQUEST['save'] || @$_REQUEST['preview'] );
// read from props or set defaults
$vars = array(
'name' => $tag->Name,
'col_bg' => $tag->ColorBG,
'col_fg' => $tag->ColorFG,
);
$old_vals = array() + $vars; // copy to determine edit-changes
// read URL-vals into vars
foreach ( $vars as $key => $val )
$vars[$key] = get_request_arg( $key, $val );
// parse URL-vars
if ( $is_posted )
{
$new_value = trim($vars['name']);
if ( strlen($new_value) == 0 )
$errors[] = T_('Missing tag name');
elseif ( strlen($new_value) > 64 )
$errors[] = sprintf( T_('Tag name too long (max. %s chars allowed).'), 64 );
else
$tag->Name = $new_value;
$new_value = $vars['col_bg'];
if ( !preg_match("/^[0-9a-f]{6}$/i", $new_value ) )
$errors[] = sprintf( T_('Invalid background color [%s] (must be 6 hex-chars).'), $new_value );
else
$tag->ColorBG = $new_value;
$new_value = $vars['col_fg'];
if ( !preg_match("/^[0-9a-f]{6}$/i", $new_value ) )
$errors[] = sprintf( T_('Invalid text color [%s] (must be 6 hex-chars).'), $new_value );
else
$tag->ColorFG = $new_value;
// determine edits
if ( $old_vals['name'] != $tag->Name ) $edits[] = T_('Name');
if ( $old_vals['col_bg'] != $tag->ColorBG ) $edits[] = T_('Background color');
if ( $old_vals['col_fg'] != $tag->ColorFG ) $edits[] = T_('Text color');
}
return array( $vars, array_unique($edits), $errors );
}//parse_edit_form
?>
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer