#webliberty::App::Admin.pm (2006/03/26)
#Copyright(C) 2002-2006 Knight, All rights reserved.

package webliberty::App::Admin;

use strict;
use base qw(webliberty::Basis Exporter);
use webliberty::String;
use webliberty::File;
use webliberty::Host;
use webliberty::Cookie;
use webliberty::Lock;
use webliberty::Skin;
use webliberty::Trackback;
use webliberty::Ping;
use webliberty::App::Init;
use webliberty::App::Diary;

our @EXPORT_OK = qw(check_password check_access check regist edit del);

### コンストラクタ
sub new {
	my $class = shift;

	my $self = {
		init    => shift,
		config  => shift,
		query   => shift,
		html    => undef,
		message => undef
	};
	bless $self, $class;

	return $self;
}

### メイン処理
sub run {
	my $self = shift;

	if ($self->check_password) {
		if ($self->{query}->{work} eq 'new') {
			if ($self->{query}->{exec_regist}) {
				$self->check;
				$self->regist;
				$self->output_edit;
			} elsif ($self->{query}->{exec_preview}) {
				$self->check;
				$self->output_preview;
			} else {
				$self->output_form;
			}
		} elsif ($self->{query}->{work} eq 'edit') {
			if ($self->{query}->{exec_regist}) {
				$self->check;
				$self->edit;
			} elsif ($self->{query}->{exec_del}) {
				$self->del;
			}
			if ($self->{query}->{exec_preview}) {
				$self->check;
				$self->output_preview;
			} elsif ($self->{query}->{exec_form}) {
				$self->output_form;
			} elsif ($self->{query}->{exec_confirm}) {
				$self->output_confirm;
			} else {
				$self->output_edit;
			}
		} elsif ($self->{query}->{work} eq 'comment') {
			require webliberty::App::Edit;
			my $app_ins = new webliberty::App::Edit($self->{init}, $self->{config}, $self->{query});
			if ($self->{query}->{exec_regist}) {
				$app_ins->edit;
				$self->{message} = $app_ins->{message};
			} elsif ($self->{query}->{exec_del}) {
				$app_ins->del;
				$self->{message} = $app_ins->{message};
			}
			if ($self->{query}->{exec_preview}) {
				$app_ins->output_preview;
			} elsif ($self->{query}->{exec_form}) {
				$app_ins->output_form;
			} elsif ($self->{query}->{exec_confirm}) {
				$self->output_confirm;
			} else {
				$self->output_comment;
			}
		} elsif ($self->{query}->{work} eq 'trackback') {
			if ($self->{query}->{exec_del}) {
				$self->del_trackback;
			}
			if ($self->{query}->{exec_confirm}) {
				$self->output_confirm;
			} else {
				$self->output_trackback;
			}
		} elsif ($self->{query}->{work} eq 'field') {
			if ($self->{query}->{exec_add}) {
				$self->add_field;
			} elsif ($self->{query}->{exec_edit}) {
				$self->edit_field;
			}
			$self->output_field;
		} elsif ($self->{query}->{work} eq 'env') {
			if ($self->{query}->{exec_env} or $self->{query}->{exec_default}) {
				$self->env;
			}
			$self->output_env;
		} elsif ($self->{query}->{work} eq 'icon') {
			if ($self->{query}->{exec_add}) {
				$self->add_icon;
			} elsif ($self->{query}->{exec_del}) {
				$self->del_icon;
			}
			$self->output_icon;
		} elsif ($self->{query}->{work} eq 'menu') {
			if ($self->{query}->{exec_add}) {
				$self->add_menu;
			} elsif ($self->{query}->{exec_edit}) {
				$self->edit_menu;
			}
			$self->output_menu;
		} elsif ($self->{query}->{work} eq 'link') {
			if ($self->{query}->{exec_add}) {
				$self->add_link;
			} elsif ($self->{query}->{exec_edit}) {
				$self->edit_link;
			}
			$self->output_link;
		} elsif ($self->{query}->{work} eq 'profile') {
			if ($self->{query}->{exec_profile}) {
				$self->profile;
			}
			$self->output_profile;
		} elsif ($self->{query}->{work} eq 'pwd') {
			if ($self->{query}->{exec_pwd}) {
				$self->pwd;
			}
			$self->output_pwd;
		} elsif ($self->{query}->{work} eq 'paint') {
			if ($self->{query}->{exec_del}) {
				$self->del_paint;
			}
			if ($self->{query}->{exec_paint}) {
				$self->output_canvas;
			} elsif ($self->{query}->{exec_view}) {
				$self->output_view;
			} elsif ($self->{query}->{exec_confirm}) {
				$self->output_confirm;
			} else {
				$self->output_paint;
			}
		} elsif ($self->{query}->{work} eq 'build') {
			if ($self->{query}->{exec_build}) {
				$self->build;
			}
			$self->output_build;
		} elsif ($self->{query}->{work} eq 'logout') {
			$self->logout;
			$self->output_login;
		} else {
			$self->output_status;
		}
	} else {
		$self->output_login;
	}

	return;
}

### パスワード認証
sub check_password {
	my $self = shift;

	my $cookie_ins = new webliberty::Cookie($self->{config}->{cookie_admin});

	my %query;
	if ($self->{query}) {
		%query = %{$self->{query}};
	}

	my $admin_pwd;
	if (exists $query{'admin_pwd'}) {
		$admin_pwd = $self->{query}->{admin_pwd};
	} else {
		$admin_pwd = $cookie_ins->get_cookie('admin_pwd');
	}

	my $flag;

	if ($admin_pwd) {
		my %user;

		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_user}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_user}");
		while (<FH>) {
			chomp;
			my($user, $pwd, $authority) = split(/\t/);

			$user{$user} = $pwd;
		}
		close(FH);

		my $pwd_ins = new webliberty::String($admin_pwd);
		if (!$pwd_ins->get_string or !$pwd_ins->check_password($user{'admin'})) {
			return $flag;
		}

		if ($self->{query}->{admin_pwd}) {
			if ($self->{query}->{hold}) {
				$cookie_ins->set_holddays(3650);
			}
			$cookie_ins->set_cookie(
				admin_pwd => $admin_pwd
			);
		}

		$flag = 1;
	}

	return $flag;
}

### アクセスチェック
sub check_access {
	my $self = shift;

	my $flag;

	if ($ENV{'REQUEST_METHOD'} ne 'POST') {
		$flag = 1;
	}
	if ($ENV{'HTTP_REFERER'} and $self->{config}->{base_url} and $ENV{'HTTP_REFERER'} !~ $self->{config}->{base_url}) {
		$flag = 1;
	}
	if (!$self->{config}->{proxy_mode} and ($ENV{'HTTP_VIA'} or $ENV{'HTTP_FORWARDED'} or $ENV{'HTTP_X_FORWARDED_FOR'})) {
		$flag = 1;
	}

	my $host_ins = new webliberty::Host;
	foreach (split(/<>/, $self->{config}->{black_list})) {
		if ($host_ins->get_host =~ /$_/i) {
			$flag = 1;
			last;
		}
	}

	if ($flag) {
		$self->error('不正なアクセスです。');
	}

	return;
}

### 入力内容チェック
sub check {
	my $self = shift;

	my $subj_ins = new webliberty::String($self->{query}->{subj});
	my $text_ins = new webliberty::String($self->{query}->{text});

	my $year_ins   = new webliberty::String($self->{query}->{year});
	my $month_ins  = new webliberty::String($self->{query}->{month});
	my $day_ins    = new webliberty::String($self->{query}->{day});
	my $hour_ins   = new webliberty::String($self->{query}->{hour});
	my $minute_ins = new webliberty::String($self->{query}->{minute});

	my $init_ins = new webliberty::App::Init;
	my %label = %{$init_ins->get_label};

	if (!$subj_ins->get_string) {
		$self->error("$label{'pc_subj'}が入力されていません。");
	}
	if (!$text_ins->get_string) {
		$self->error("$label{'pc_text'}が入力されていません。");
	}

	if (!($year_ins->get_string =~ /^\d\d\d\d$/)) {
		$self->error("$label{'pc_date'}の年が正しく指定されていません。");
	}
	if (!($month_ins->get_string =~ /^\d\d$/)) {
		$self->error("$label{'pc_date'}の月が正しく指定されていません。");
	}
	if (!($day_ins->get_string =~ /^\d\d$/)) {
		$self->error("$label{'pc_date'}の日が正しく指定されていません。");
	}
	if (!($hour_ins->get_string =~ /^\d\d$/)) {
		$self->error("$label{'pc_date'}の時間が正しく指定されていません。");
	}
	if (!($minute_ins->get_string =~ /^\d\d$/)) {
		$self->error("$label{'pc_date'}の分が正しく指定されていません。");
	}

	return;
}

### 新規登録
sub regist {
	my $self = shift;

	$self->check_access;

	my $stat_ins  = new webliberty::String($self->{query}->{stat});
	my $break_ins = new webliberty::String($self->{query}->{break});
	my $comt_ins  = new webliberty::String($self->{query}->{comt});
	my $tb_ins    = new webliberty::String($self->{query}->{tb});
	my $subj_ins  = new webliberty::String($self->{query}->{subj});
	my $text_ins  = new webliberty::String($self->{query}->{text});
	my $icon_ins  = new webliberty::String($self->{query}->{icon});
	my $tburl_ins = new webliberty::String($self->{query}->{tb_url});

	$stat_ins->create_number;
	$break_ins->create_number;
	$comt_ins->create_number;
	$tb_ins->create_number;
	$subj_ins->create_line;
	$text_ins->create_text;
	$icon_ins->create_line;
	$tburl_ins->create_text;

	my $log_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{query}->{year}$self->{query}->{month}\.$self->{init}->{data_ext}";
	my $now      = "$self->{query}->{year}$self->{query}->{month}$self->{query}->{day}$self->{query}->{hour}$self->{query}->{minute}";
	my @logs;

	my $lock_ins = new webliberty::Lock("$self->{init}->{data_dir}$self->{init}->{data_lock}");
	if (!$lock_ins->file_lock) {
		$self->error('ファイルがロックされています。時間をおいてもう一度投稿してください。');
	}

	#記事記録ファイルオープン
	if (-e $log_file) {
		open(FH, $log_file) or $self->error("Read Error : $log_file");
		@logs = <FH>;
		close(FH);
	} else {
		open(FH, ">$log_file") or $self->error("Write Error : $log_file");
		close(FH);

		if ($self->{init}->{chmod_mode}) {
			if ($self->{init}->{suexec_mode}) {
				chmod(0600, "$log_file") or $self->error("Chmod Error : $log_file");
			} else {
				chmod(0606, "$log_file") or $self->error("Chmod Error : $log_file");
			}
		}
	}

	#記録済みデータ読み込み
	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	my @index = <FH>;
	close(FH);

	my @numbers = map { (split(/\t/))[1] } @index;
	@index = @index[sort { $numbers[$b] <=> $numbers[$a] } (0 .. $#numbers)];

	my $new_no   = (split(/\t/, $index[0]))[1] + 1;
	my $host_ins = new webliberty::Host;

	my($new_field, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;

		if ($self->{query}->{field} == ++$i) {
			$new_field = $_;
		}
	}
	close(FH);

	#アップロードファイル保存
	my(%file, $files, $flag);

	foreach (1 .. 5) {
		if ($self->{query}->{'file' . $_} or $self->{query}->{'ext' . $_}) {
			$flag = 1;
		}
	}
	if ($flag) {
		foreach (1 .. 5) {
			if ($self->{query}->{'file' . $_}) {
				my $file_ins = new webliberty::File($self->{query}->{'file' . $_}->{file_name});
				$file{$_} = "$new_no\-$_\." . $file_ins->get_ext;

				open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}");
				binmode(FH);
				print FH $self->{query}->{'file' . $_}->{file_data};
				close(FH);
			} elsif ($self->{query}->{'ext' . $_}) {
				$file{$_} = "$new_no\-$_\.$self->{query}->{'ext' . $_}";
				rename("$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$self->{init}->{data_upfile_tmp}$_", "$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}");
			}
		}

		foreach (1 .. 5) {
			if ($files) {
				$files .= '<>';
			}
			$files .= "$file{$_}";
		}
	}

	#記録用データ作成
	my $diary = "$new_no\t\t" . $stat_ins->get_string . "\t" . $break_ins->get_string . "\t" . $comt_ins->get_string . "\t" . $tb_ins->get_string . "\t$new_field\t$now\t\t" . $subj_ins->get_string . "\t" . $text_ins->get_string . "\t\t" . $icon_ins->get_string . "\t$files\t" . $host_ins->get_host;

	my($new_data, $flag);

	open(FH, $log_file) or $self->error("Read Error : $log_file");
	while (<FH>) {
		chomp;
		my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

		if (!$flag and $now > $date) {
			$new_data .= "$diary\n";
			$flag      = 1;
		}
		$new_data .= "$_\n";
	}
	if (!$flag) {
		$new_data .= "$diary\n";
	}
	close(FH);

	#記事登録
	open(FH, ">$log_file") or $self->error("Write Error : $log_file");
	print FH $new_data;
	close(FH);

	#インデックス用データ作成
	my $index = "$now\t$new_no\t\t" . $stat_ins->get_string . "\t$new_field\t";

	my($new_index, $flag);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if (!$flag and $now > $date) {
			$new_index .= "$index\n";
			$flag       = 1;
		}
		$new_index .= "$_\n";
	}
	if (!$flag) {
		$new_index .= "$index\n";
	}
	close(FH);

	#インデックス登録
	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	print FH $new_index;
	close(FH);

	$lock_ins->file_unlock;

	my $alert_message;

	#トラックバック送信
	if ($tburl_ins->get_string) {
		my $article_url;
		if ($self->{config}->{html_archive_mode}) {
			if ($self->{init}->{archive_dir} =~ /([^\/\\]*\/)$/) {
				$article_url = "$self->{config}->{site_url}$1$new_no\.$self->{init}->{archive_ext}";
			}
		} else {
			if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) {
				$article_url = "$self->{config}->{site_url}$1?no=$new_no";
			}
		}

		my $trackback_ins = new webliberty::Trackback;
		foreach (split(/<br \/>/, $tburl_ins->get_string)) {
			if (!$_) {
				next;
			}
			my($flag, $message) = $trackback_ins->send_trackback(
				trackback_url => $_,
				title         => $subj_ins->get_string,
				url           => $article_url,
				excerpt       => $text_ins->get_string,
				blog_name     => $self->{config}->{site_title}
			);
			if (!$flag) {
				$alert_message .= "<strong>トラックバックの送信に失敗しました。$message</strong>";
			}
		}
	}

	#更新PING送信
	if ($self->{config}->{ping_mode}) {
		my $ping_ins = new webliberty::Ping;
		foreach (split(/<>/, $self->{config}->{ping_list})) {
			if (!$_) {
				next;
			}
			my($flag, $message) = $ping_ins->send_ping(
				ping_url  => $_,
				url       => $self->{config}->{site_url},
				blog_name => $self->{config}->{site_title}
			);
			if (!$flag) {
				$alert_message .= "<strong>更新PINGの送信に失敗しました。$message</strong>";
			}
		}
	}

	#データ更新
	my $dammy;
	$dammy->{query}->{no} = $new_no;

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $dammy->{query});
	$diary_ins->update;

	$self->{message} = '記事を新規に投稿しました。';

	return;
}

### 記事編集
sub edit {
	my $self = shift;

	$self->check_access;

	my $edit_ins  = new webliberty::String($self->{query}->{edit});
	my $stat_ins  = new webliberty::String($self->{query}->{stat});
	my $break_ins = new webliberty::String($self->{query}->{break});
	my $comt_ins  = new webliberty::String($self->{query}->{comt});
	my $tb_ins    = new webliberty::String($self->{query}->{tb});
	my $subj_ins  = new webliberty::String($self->{query}->{subj});
	my $text_ins  = new webliberty::String($self->{query}->{text});
	my $icon_ins  = new webliberty::String($self->{query}->{icon});
	my $tburl_ins = new webliberty::String($self->{query}->{tb_url});

	$edit_ins->create_number;
	$stat_ins->create_number;
	$break_ins->create_number;
	$comt_ins->create_number;
	$tb_ins->create_number;
	$subj_ins->create_line;
	$text_ins->create_text;
	$icon_ins->create_line;
	$tburl_ins->create_text;

	if (!$edit_ins->get_string) {
		$self->error('編集したい記事を選択してください。');
	}

	my $lock_ins = new webliberty::Lock("$self->{init}->{data_dir}$self->{init}->{data_lock}");
	if (!$lock_ins->file_lock) {
		$self->error('ファイルがロックされています。時間をおいてもう一度投稿してください。');
	}

	#記録用データ作成
	my($new_field, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;

		if ($self->{query}->{field} == ++$i) {
			$new_field = $_;
		}
	}
	close(FH);

	my $new_date = "$self->{query}->{year}$self->{query}->{month}$self->{query}->{day}$self->{query}->{hour}$self->{query}->{minute}";

	#インデックス用データ作成
	my(@new_index, $edit_date);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if ($edit_ins->get_string == $no) {
			$edit_date  = $date;
			push(@new_index, "$new_date\t$no\t\t" . $stat_ins->get_string . "\t$new_field\t\n");
		} else {
			push(@new_index, "$_\n");
		}
	}
	close(FH);

	#編集データ検索
	my $edit_file;
	if ($edit_date =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
		$edit_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
	}

	my($new_data, $org_files, $flag);

	open(FH, $edit_file) or $self->error("Read Error : $edit_file");
	while (<FH>) {
		chomp;
		my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

		if ($edit_ins->get_string == $no) {
			$org_files = $file;
			$flag      = 1;
		} else {
			$new_data .= "$_\n";
		}
	}
	close(FH);

	if (!$flag) {
		$self->error('指定された記事は存在しません。');
	}

	#アップロードファイル保存
	my(%file, $files);
	$flag = '';

	foreach (1 .. 5) {
		if ($self->{query}->{'file' . $_} or $self->{query}->{'ext' . $_} or $self->{query}->{'delfile' . $_}) {
			$flag = 1;
		}
	}
	if ($flag) {
		my @org_files = split(/<>/, $org_files);

		foreach (1 .. 5) {
			my $file;

			if ($self->{query}->{'delfile' . $_}) {
				if (-e "$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}" . $org_files[$_ - 1]) {
					unlink("$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}" . $org_files[$_ - 1]);
				}
				unlink("$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}" . $org_files[$_ - 1]);
			} elsif ($self->{query}->{'file' . $_}) {
				if (-e "$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}" . $org_files[$_ - 1]) {
					unlink("$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}" . $org_files[$_ - 1]);
				}

				my $file_ins = new webliberty::File($self->{query}->{'file' . $_}->{file_name});
				$file{$_} = "$self->{query}->{edit}\-$_\." . $file_ins->get_ext;

				open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}");
				binmode(FH);
				print FH $self->{query}->{'file' . $_}->{file_data};
				close(FH);
			} elsif ($self->{query}->{'ext' . $_}) {
				$file{$_} = "$self->{query}->{edit}\-$_\.$self->{query}->{'ext' . $_}";
				rename("$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$self->{init}->{data_upfile_tmp}$_", "$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file{$_}");
			} elsif ($org_files[$_ - 1]) {
				$file{$_} = $org_files[$_ - 1];
			}
		}

		foreach (1 .. 5) {
			if ($files) {
				$files .= '<>';
			}
			$files .= "$file{$_}";
		}
	} else {
		$files = $org_files;
	}

	#編集データ登録
	open(FH, ">$edit_file") or $self->error("Write Error : $edit_file");
	print FH $new_data;
	close(FH);

	#記録用データ作成
	my $host_ins = new webliberty::Host;

	my $diary  = $edit_ins->get_string . "\t\t" . $stat_ins->get_string . "\t" . $break_ins->get_string . "\t" . $comt_ins->get_string . "\t" . $tb_ins->get_string . "\t$new_field\t$new_date\t\t" . $subj_ins->get_string . "\t" . $text_ins->get_string . "\t\t" . $icon_ins->get_string . "\t$files\t" . $host_ins->get_host;
	$edit_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{query}->{year}$self->{query}->{month}\.$self->{init}->{data_ext}";

	if (!-e $edit_file) {
		open(FH, ">$edit_file") or $self->error("Write Error : $edit_file");
		close(FH);

		if ($self->{init}->{chmod_mode}) {
			if ($self->{init}->{suexec_mode}) {
				chmod(0600, "$edit_file") or $self->error("Chmod Error : $edit_file");
			} else {
				chmod(0606, "$edit_file") or $self->error("Chmod Error : $edit_file");
			}
		}
	}

	my $record_data;
	$flag = '';

	open(FH, $edit_file) or $self->error("Read Error : $edit_file");
	while (<FH>) {
		chomp;
		my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

		if (!$flag and (($new_date == $date and $edit_ins->get_string < $no) or $new_date > $date)) {
			$record_data .= "$diary\n";
			$flag         = 1;
		}
		$record_data .= "$_\n";
	}
	if (!$flag) {
		$record_data .= "$diary\n";
	}

	#記事登録
	open(FH, ">$edit_file") or $self->error("Write Error : $edit_file");
	print FH $record_data;
	close(FH);

	#インデックス登録
	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	print FH sort { $b <=> $a } @new_index;
	close(FH);

	$lock_ins->file_unlock;

	my $alert_message;

	#トラックバック送信
	if ($tburl_ins->get_string) {
		my $article_url;
		if ($self->{config}->{html_archive_mode}) {
			if ($self->{init}->{archive_dir} =~ /([^\/\\]*\/)$/) {
				$article_url = "$self->{config}->{site_url}$1" . $edit_ins->get_string . "\.$self->{init}->{archive_ext}";
			}
		} else {
			if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) {
				$article_url = "$self->{config}->{site_url}$1?no=" . $edit_ins->get_string;
			}
		}

		my $trackback_ins = new webliberty::Trackback;
		foreach (split(/<br \/>/, $tburl_ins->get_string)) {
			if (!$_) {
				next;
			}
			my($flag, $message) = $trackback_ins->send_trackback(
				trackback_url => $_,
				title         => $subj_ins->get_string,
				url           => $article_url,
				excerpt       => $text_ins->get_string,
				blog_name     => $self->{config}->{site_title}
			);
			if (!$flag) {
				$alert_message .= "<strong>トラックバックの送信に失敗しました。$message</strong>";
			}
		}
	}

	#更新PING送信
	if ($self->{config}->{ping_mode}) {
		my $ping_ins = new webliberty::Ping;
		foreach (split(/<>/, $self->{config}->{ping_list})) {
			if (!$_) {
				next;
			}
			my($flag, $message) = $ping_ins->send_ping(
				ping_url  => $_,
				url       => $self->{config}->{site_url},
				blog_name => $self->{config}->{site_title}
			);
			if (!$flag) {
				$alert_message .= "<strong>更新PINGの送信に失敗しました。$message</strong>";
			}
		}
	}

	#データ更新
	my $dammy;
	$dammy->{query}->{no} = $edit_ins->get_string;

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $dammy->{query});
	$diary_ins->update;

	$self->{message} = "No." . $edit_ins->get_string . "の記事を編集しました。$alert_message";

	return;
}

### 記事削除
sub del {
	my $self = shift;

	$self->check_access;

	if (!$self->{query}->{del}) {
		$self->error('削除したい記事を選択してください。');
	}

	my $lock_ins = new webliberty::Lock("$self->{init}->{data_dir}$self->{init}->{data_lock}");
	if (!$lock_ins->file_lock) {
		$self->error('ファイルがロックされています。時間をおいてもう一度投稿してください。');
	}

	#削除データ検索
	my($new_index, %del_file);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if ($self->{query}->{del} =~ /(^|\n)$no(\n|$)/) {
			if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
				$del_file{"$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}"} = 1;
			}
		} else {
			$new_index .= "$_\n";
		}
	}
	close(FH);

	#記事削除
	my $flag;

	foreach my $entry (keys %del_file) {
		my $new_data;

		open(FH, $entry) or $self->error("Read Error : $entry");
		while (<FH>) {
			chomp;
			my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

			if ($self->{query}->{del} =~ /(^|\n)$no(\n|$)/) {
				if ($file) {
					foreach my $del_file (split(/<>/, $file)) {
						if ($del_file) {
							if (-e "$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}$del_file") {
								unlink("$self->{init}->{data_dir}$self->{init}->{data_thumbnail_dir}$del_file");
							}
							unlink("$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$del_file");
						}
					}
				}

				$flag = 1;
			} else {
				$new_data .= "$_\n";
			}
		}
		close(FH);

		open(FH, ">$entry") or $self->error("Write Error : $entry");
		print FH $new_data;
		close(FH);
	}

	if (!$flag) {
		$self->error('指定された記事は存在しません。');
	}

	#コメント削除
	if (-e "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{query}->{del}\.$self->{init}->{data_ext}") {
		my $index_data;

		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}");
		while (<FH>) {
			chomp;
			my($no, $pno, $stat, $date, $name, $subj, $host) = split(/\t/);

			if ($self->{query}->{del} != $pno) {
				$index_data .= "$_\n";
			}
		}
		close(FH);

		open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}");
		print FH $index_data;
		close(FH);

		unlink("$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{query}->{del}\.$self->{init}->{data_ext}");
	}
	#トラックバック削除
	if (-e "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{query}->{del}\.$self->{init}->{data_ext}") {
		my $index_data;

		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
		while (<FH>) {
			chomp;
			my($no, $pno, $stat, $date, $blog, $title, $url) = split(/\t/);

			if ($self->{query}->{del} != $pno) {
				$index_data .= "$_\n";
			}
		}
		close(FH);

		open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
		print FH $index_data;
		close(FH);

		unlink("$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{query}->{del}\.$self->{init}->{data_ext}");
	}

	#インデックス登録
	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	print FH $new_index;
	close(FH);

	$lock_ins->file_unlock;

	#データ更新
	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	my $del_list;
	foreach (split(/\n/, $self->{query}->{del})) {
		$del_list .= "No.$_ ";
	}

	if ($self->{config}->{html_archive_mode}) {
		unlink("$self->{init}->{archive_dir}$self->{query}->{del}\.$self->{init}->{archive_ext}");
	}

	$self->{message} = "$del_listの記事を削除しました。";

	return;
}

### トラックバック削除
sub del_trackback {
	my $self = shift;

	$self->check_access;

	if (!$self->{query}->{del}) {
		$self->error('削除したいトラックバックを選択してください。');
	}

	my $lock_ins = new webliberty::Lock("$self->{init}->{data_dir}$self->{init}->{data_lock}");
	if (!$lock_ins->file_lock) {
		$self->error('ファイルがロックされています。時間をおいてもう一度投稿してください。');
	}

	my($new_index, $diary_no, %del_file);

	#削除データ検索
	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $blog, $title, $url) = split(/\t/);

		if ($self->{query}->{del} =~ /(^|\n)$no(\n|$)/) {
			$del_file{"$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$pno\.$self->{init}->{data_ext}"} = 1;
		} else {
			$new_index .= "$_\n";
		}
	}
	close(FH);

	#トラックバック削除
	my $flag;

	foreach my $entry (keys %del_file) {
		my $new_data;

		open(FH, $entry) or $self->error("Read Error : $entry");
		while (<FH>) {
			chomp;
			my($no, $pno, $stat, $date, $blog, $title, $url, $excerpt) = split(/\t/);

			if ($self->{query}->{del} =~ /(^|\n)$no(\n|$)/) {
				$diary_no = $pno;
				$flag = 1;
			} else {
				$new_data .= "$_\n";
			}
		}
		close(FH);

		open(FH, ">$entry") or $self->error("Write Error : $entry");
		print FH $new_data;
		close(FH);
	}

	if (!$flag) {
		$self->error('指定された記事は存在しません。');
	}

	#インデックス登録
	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
	print FH $new_index;
	close(FH);

	$lock_ins->file_unlock;

	#データ更新
	my $dammy;
	$dammy->{query}->{no} = $diary_no;

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $dammy->{query});
	$diary_ins->update;

	my $del_list;
	foreach (split(/\n/, $self->{query}->{del})) {
		$del_list .= "No.$_ ";
	}

	$self->{message} = "$del_listのトラックバックを削除しました。";

	return;
}

### 分類追加
sub add_field {
	my $self = shift;

	$self->check_access;

	my $field_ins  = new webliberty::String($self->{query}->{field});
	my $parent_ins = new webliberty::String($self->{query}->{parent});

	$field_ins->create_line;
	$parent_ins->create_line;

	if ($parent_ins->get_string) {
		my($new_data, $flag);

		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
		while (<FH>) {
			chomp;
			my($field, $child) = split(/<>/);

			if ($parent_ins->get_string eq $field) {
				$flag = 1;
			} elsif ($flag and $parent_ins->get_string ne $field) {
				$new_data .= $parent_ins->get_string . '<>' . $field_ins->get_string . "\n";
				$flag = 0;
			}

			$new_data .= "$_\n";
		}
		if ($flag) {
			$new_data .= $parent_ins->get_string . '<>' . $field_ins->get_string . "\n";
		}
		close(FH);

		open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
		print FH $new_data;
		close(FH);
	} else {
		open(FH, ">>$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
		print FH "$self->{query}->{parent}$self->{query}->{field}\n";
		close(FH);
	}

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = '分類を追加しました。';

	return;
}

### 分類編集
sub edit_field {
	my $self = shift;

	$self->check_access;

	my(@fields, $new_data, $parent);
	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		push(@fields, $_);
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($field, $child) = split(/<>/);

		if ($self->{query}->{from} ne '' and $self->{query}->{to} ne '') {
			if ($self->{query}->{to} == $i) {
				$new_data .= $fields[$self->{query}->{from}];
			}
			if ($self->{query}->{from} != $i) {
				$new_data .= "$_\n";
			}
		} elsif (!$self->{query}->{'del' . $i}) {
			my $field_ins  = new webliberty::String($self->{query}->{'field' . $i});
			my $parent_ins = new webliberty::String($self->{query}->{'parent' . $i});

			$field_ins->create_line;
			$parent_ins->create_line;

			if ($parent and $child) {
				$new_data .= $parent_ins->get_string . "<>" . $field_ins->get_string . "\n";
			} else {
				$parent    = $field_ins->get_string;
				$new_data .= "$parent\n";
			}
		}

		$i++;
	}
	close(FH);

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	print FH $new_data;
	close(FH);

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = '分類を編集しました。';

	return;
}

### 環境設定
sub env {
	my $self = shift;

	$self->check_access;

	my $new_data;
	if ($self->{query}->{exec_default}) {
		my $init_ins = new webliberty::App::Init;
		my %default = %{$init_ins->get_config};

		foreach (keys %default) {
			$new_data .= "$_=$default{$_}\n";
		}
	} else {
		foreach (keys %{$self->{query}}) {
			if ($_ =~ /^env_/) {
				my $key   = $_;
				my $value = $self->{query}->{$_};

				$key   =~ s/^env_//;
				$value =~ s/\r?\n/\r/g;
				$value =~ s/\r/<>/g;

				$new_data .= "$key=$value\n";
			}
		}
	}

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_config}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_config}");
	print FH $new_data;
	close(FH);

	my $config_ins = new webliberty::Configure("$self->{init}->{data_dir}$self->{init}->{data_config}");
	$self->{config} = $config_ins->get_config;

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = '環境設定を実行しました。';
	if ($self->{config}->{html_index_mode} or $self->{config}->{html_archive_mode}) {
		$self->{message} .= '<em>外観に関する設定を変更した場合、サイトの再構築を行ってください。</em>';
	}

	return;
}

### アイコン追加
sub add_icon {
	my $self = shift;

	$self->check_access;

	my $init_ins = new webliberty::App::Init;
	my %label = %{$init_ins->get_label};

	my $file_ins = new webliberty::File($self->{query}->{file}->{file_name});
	my $name_ins = new webliberty::String($self->{query}->{name});

	$name_ins->create_line;

	my $file = $file_ins->get_name . '.' . $file_ins->get_ext;

	open(FILE, ">$self->{init}->{data_dir}$self->{init}->{data_icon_dir}$file") or $self->error("アップロードファイルが保存できません。");
	binmode(FILE);
	print FILE $self->{query}->{file}->{file_data};
	close(FILE);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_icon}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_icon}");
	my @icon = <FH>;
	close(FH);

	push(@icon, "$file\t" . $name_ins->get_string . "\t\t\t\n");

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_icon}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_icon}");
	print FH $self->_sort_icon(@icon);
	close(FH);

	$self->{message} = "$label{'pc_icon'}を新規に登録しました。";

	return;
}

### アイコン削除
sub del_icon {
	my $self = shift;

	$self->check_access;

	my $init_ins = new webliberty::App::Init;
	my %label = %{$init_ins->get_label};

	if (!$self->{query}->{edit}) {
		$self->error("削除したい$label{'pc_icon'}を選択してください。");
	}

	my $new_data;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_icon}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_icon}");
	while (<FH>) {
		chomp;
		my($file, $name, $field, $user, $pwd) = split(/\t/);

		if ($self->{query}->{edit} eq $file) {
			unlink("$self->{init}->{data_dir}$self->{init}->{data_icon_dir}$file") or $self->error('アイコン画像が削除できません。');
		} else {
			$new_data .= "$_\n";
		}
	}
	close(FH);

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_icon}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_icon}");
	print FH $new_data;
	close(FH);

	$self->{message} = "$label{'pc_icon'}$self->{query}->{edit}を削除しました。";

	return;
}

### コンテンツ追加
sub add_menu {
	my $self = shift;

	$self->check_access;

	my $field_ins = new webliberty::String($self->{query}->{field});
	my $name_ins  = new webliberty::String($self->{query}->{name});
	my $url_ins   = new webliberty::String($self->{query}->{url});

	$field_ins->create_line;
	$name_ins->create_line;
	$url_ins->create_line;

	my($new_data, $flag);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	my @menus = <FH>;
	close(FH);

	push(@menus, $field_ins->get_string . "\t" . $name_ins->get_string . "\t" . $url_ins->get_string . "\n");

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	print FH sort { $a cmp $b } @menus;
	close(FH);

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = 'コンテンツを追加しました。';

	return;
}

### コンテンツ編集
sub edit_menu {
	my $self = shift;

	$self->check_access;

	my(@menus, $new_data, $field);
	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	while (<FH>) {
		push(@menus, $_);
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		if ($self->{query}->{from} ne '' and $self->{query}->{to} ne '') {
			if ($self->{query}->{to} == $i) {
				$new_data .= $menus[$self->{query}->{from}];
			}
			if ($self->{query}->{from} != $i) {
				$new_data .= "$_\n";
			}
		} elsif (!$self->{query}->{'del' . $i}) {
			my $field_ins = new webliberty::String($self->{query}->{'field' . $i});
			my $name_ins  = new webliberty::String($self->{query}->{'name' . $i});
			my $url_ins   = new webliberty::String($self->{query}->{'url' . $i});

			$name_ins->create_line;
			$field_ins->create_line;
			$url_ins->create_line;

			$new_data .= $field_ins->get_string . "\t" . $name_ins->get_string . "\t" . $url_ins->get_string . "\n";
		}

		$i++;
	}
	close(FH);

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	print FH $new_data;
	close(FH);

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = 'コンテンツを編集しました。';

	return;
}

### リンク追加
sub add_link {
	my $self = shift;

	$self->check_access;

	my $field_ins = new webliberty::String($self->{query}->{field});
	my $name_ins  = new webliberty::String($self->{query}->{name});
	my $url_ins   = new webliberty::String($self->{query}->{url});

	$field_ins->create_line;
	$name_ins->create_line;
	$url_ins->create_line;

	my($new_data, $flag);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	my @links = <FH>;
	close(FH);

	push(@links, $field_ins->get_string . "\t" . $name_ins->get_string . "\t" . $url_ins->get_string . "\n");

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	print FH sort { $a cmp $b } @links;
	close(FH);

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = 'サイトを追加しました。';

	return;
}

### リンク編集
sub edit_link {
	my $self = shift;

	$self->check_access;

	my(@links, $new_data, $field);
	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	while (<FH>) {
		push(@links, $_);
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		if ($self->{query}->{from} ne '' and $self->{query}->{to} ne '') {
			if ($self->{query}->{to} == $i) {
				$new_data .= $links[$self->{query}->{from}];
			}
			if ($self->{query}->{from} != $i) {
				$new_data .= "$_\n";
			}
		} elsif (!$self->{query}->{'del' . $i}) {
			my $field_ins = new webliberty::String($self->{query}->{'field' . $i});
			my $name_ins  = new webliberty::String($self->{query}->{'name' . $i});
			my $url_ins   = new webliberty::String($self->{query}->{'url' . $i});

			$name_ins->create_line;
			$field_ins->create_line;
			$url_ins->create_line;

			$new_data .= $field_ins->get_string . "\t" . $name_ins->get_string . "\t" . $url_ins->get_string . "\n";
		}

		$i++;
	}
	close(FH);

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	print FH $new_data;
	close(FH);

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config});
	$diary_ins->update;

	$self->{message} = 'リンク集を編集しました。';

	return;
}

### プロフィール設定
sub profile {
	my $self = shift;

	$self->check_access;

	my $name_ins = new webliberty::String($self->{query}->{name});
	my $text_ins = new webliberty::String($self->{query}->{text});

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_profile}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_profile}");
	print FH "admin\t" . $name_ins->create_line . "\t" . $text_ins->create_text . "\n";
	close(FH);

	$self->{message} = 'プロフィールを設定しました。';

	return;
}

### 管理者パスワード設定
sub pwd {
	my $self = shift;

	$self->check_access;

	my $admin_pwd_ins = new webliberty::String($self->{query}->{admin_pwd});
	my $new_pwd_ins   = new webliberty::String($self->{query}->{new_pwd});
	my $cfm_pwd_ins   = new webliberty::String($self->{query}->{cfm_pwd});
	my $pwd_ins       = new webliberty::String($self->{query}->{new_pwd});

	if (!$admin_pwd_ins->get_string) {
		$self->error('以前のパスワードを入力してください。');
	}
	if (!$new_pwd_ins->get_string) {
		$self->error('新しく設定したいパスワードを入力してください。');
	}
	if (!$cfm_pwd_ins->get_string) {
		$self->error('確認用パスワードを入力してください。');
	}
	if ($new_pwd_ins->get_string ne $cfm_pwd_ins->get_string) {
		$self->error('新しいパスワードと確認用パスワードは、同じものを入力してください。');
	}
	if ($new_pwd_ins->check_length < 4) {
		$self->error('管理者用パスワードは4文字以上を指定してください。');
	}

	open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_user}") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_user}");
	print FH "admin\t" . $new_pwd_ins->create_password . "\troot\n";
	close(FH);

	my $cookie_ins = new webliberty::Cookie($self->{config}->{cookie_admin});
	$cookie_ins->set_cookie(
		admin_pwd => $cfm_pwd_ins->get_string
	);

	$self->{message} = 'パスワードを設定しました。';

	return;
}

### イラスト削除
sub del_paint {
	my $self = shift;

	$self->check_access;

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{paint_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{paint_dir}");
	my @files = sort { $a <=> $b } grep { m/\w+\.\w+/g } readdir(DIR);
	close(DIR);

	my $flag;
	foreach (@files) {
		my $file_ins = new webliberty::File("$self->{init}->{data_dir}$self->{init}->{paint_dir}$_");

		if ($self->{query}->{del} eq $file_ins->get_name) {
			unlink("$self->{init}->{data_dir}$self->{init}->{paint_dir}" . $file_ins->get_name . '.' . $file_ins->get_ext);
			$flag = 1;
		}
	}
	if (!$flag) {
		$self->error('指定されたイラストは存在しません。');
	}

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{pch_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{pch_dir}");
	@files = sort { $a <=> $b } grep { m/\w+\.\w+/g } readdir(DIR);
	close(DIR);

	$flag = 0;
	foreach (@files) {
		my $file_ins = new webliberty::File("$self->{init}->{data_dir}$self->{init}->{pch_dir}$_");

		if ($self->{query}->{del} eq $file_ins->get_name) {
			unlink("$self->{init}->{data_dir}$self->{init}->{pch_dir}" . $file_ins->get_name . '.' . $file_ins->get_ext);
			$flag = 1;
		}
	}
	if (!$flag) {
		$self->error('指定されたPCHファイルは存在しません。');
	}

	$self->{message} = "No.$self->{query}->{del}のイラストを削除しました。";

	return;
}

### サイト再構築
sub build {
	my $self = shift;

	$self->check_access;

	require webliberty::App::List;
	my $stdout = *STDOUT;

	#インデックスを構築
	if ($self->{query}->{build} eq 'index' or $self->{query}->{build} eq 'all') {
		open(HTML, ">$self->{init}->{html_file}") or $self->error("Write Error : $self->{init}->{html_file}");
		*STDOUT = *HTML;
		my $app_ins = new webliberty::App::List($self->{init}, $self->{config});
		$app_ins->run;
		close(HTML);
	}
	#アーカイブを構築
	if ($self->{config}->{html_archive_mode} and ($self->{query}->{build} =~ /^\d+$/ or $self->{query}->{build} eq 'all')) {
		my($from, $to);
		if ($self->{query}->{build} =~ /^(\d+)$/) {
			$from = $1;
			$to   = $from + 50 - 1;
		}

		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
		while (<FH>) {
			chomp;
			my($date, $no, $id, $stat, $field, $name) = split(/\t/);

			if ($self->{query}->{build} ne 'all' and ($no < $from or $no > $to)) {
				next;
			}

			my $dammy;
			$dammy->{query}->{no} = $no;

			open(HTML, ">$self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}") or $self->error("Write Error : $self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}");
			*STDOUT = *HTML;
			my $app_ins = new webliberty::App::List($self->{init}, $self->{config}, $dammy->{query});
			$app_ins->run;
			close(HTML);

			if ($self->{init}->{chmod_mode}) {
				if ($self->{init}->{suexec_mode}) {
					chmod(0604, "$self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}") or $self->error("Chmod Error : $self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}");
				} else {
					chmod(0606, "$self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}") or $self->error("Chmod Error : $self->{init}->{archive_dir}$dammy->{query}->{no}\.$self->{init}->{archive_ext}");
				}
			}
		}
	}

	*STDOUT = $stdout;

	$self->{message} = 'サイトを再構築しました。';

	return;
}

### ログアウト
sub logout {
	my $self = shift;

	my $cookie_ins = new webliberty::Cookie($self->{config}->{cookie_admin});
	$cookie_ins->set_cookie(
		admin_pwd => ''
	);

	return;
}

### 投稿フォーム表示
sub output_form {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '記事を入力し、<em>投稿ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_form}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	my(%form, $form_label);

	if ($self->{query}->{work} eq 'edit') {
		if (!$self->{query}->{edit}) {
			$self->error('編集したい記事を選択してください。');
		}

		my $edit_date;
		open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
		while (<FH>) {
			chomp;
			my($date, $no, $id, $stat, $field, $name) = split(/\t/);

			if ($self->{query}->{edit} == $no) {
				$edit_date = $date;

				last;
			}
		}
		close(FH);

		my $edit_file;
		if ($edit_date =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
			$edit_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
		}

		open(FH, "$edit_file") or $self->error("Read Error : $edit_file");
		while (<FH>) {
			chomp;
			my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

			if ($self->{query}->{edit} == $no) {
				%form = $diary_ins->diary_form($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host);
			}
		}
		close(FH);

		$form_label = '記事編集';
	} else {
		my($sec, $min, $hour, $day, $mon, $year) = localtime(time);
		my $date = sprintf("%04d%02d%02d%02d%02d", $year + 1900, $mon + 1, $day, $hour, $min);

		%form = $diary_ins->diary_form('', '', $self->{config}->{default_stat}, $self->{config}->{default_break}, $self->{config}->{default_comt}, $self->{config}->{default_tb}, '', $date, '', '', '', '', '', '', '');

		$form_label = '新規投稿';
	}

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_replace_data(
		'form',
		%form,
		FORM_LABEL => $form_label,
		FORM_WORK  => $self->{query}->{work},
		FORM_EXT1  => '',
		FORM_EXT2  => '',
		FORM_EXT3  => '',
		FORM_EXT4  => '',
		FORM_EXT5  => '',
		FORM_TBURL => $self->{query}->{tb_url}
	);
	print $skin_ins->get_data('footer');

	return;
}

### プレビュー表示
sub output_preview {
	my $self = shift;

	my $date = "$self->{query}->{year}$self->{query}->{month}$self->{query}->{day}$self->{query}->{hour}$self->{query}->{minute}";

	my($new_field, $i);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;

		if ($self->{query}->{field} == ++$i) {
			$new_field = $_;
		}
	}
	close(FH);

	my(%file, %ext, $files, $flag);

	foreach (1 .. 5) {
		if ($self->{query}->{work} eq 'edit' or $self->{query}->{'file' . $_} or $self->{query}->{'ext' . $_}) {
			$flag = 1;
		}
	}

	if ($flag) {
		my $org_files;

		if ($self->{query}->{work} eq 'edit') {
			my $edit_file;
			if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
				$edit_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
			}

			open(FH, $edit_file) or $self->error("Read Error : $edit_file");
			while (<FH>) {
				chomp;
				my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

				if ($self->{query}->{edit} == $no) {
					$org_files = $file;
					last;
				}
			}
			close(FH);
		}

		foreach (1 .. 5) {
			my @org_files = split(/<>/, $org_files);

			if ($self->{query}->{'file' . $_}) {
				my $file_ins = new webliberty::File($self->{query}->{'file' . $_}->{file_name});
				$file{$_} = $self->{init}->{data_upfile_tmp};
				$ext{$_}  = $file_ins->get_ext;

				open(FH, ">$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$self->{init}->{data_upfile_tmp}$_") or $self->error("Write Error : $self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$self->{init}->{data_upfile_tmp}$_");
				binmode(FH);
				print FH $self->{query}->{'file' . $_}->{file_data};
				close(FH);
			} elsif ($self->{query}->{'ext' . $_}) {
				$file{$_} = $self->{init}->{data_upfile_tmp};
				$ext{$_}  = $self->{query}->{'ext' . $_};
			} elsif ($org_files[$_ - 1]) {
				$file{$_} = $org_files[$_ - 1];
			}
		}

		foreach (1 .. 5) {
			if ($files) {
				$files .= '<>';
			}
			$files .= "$file{$_}";
		}
	}

	if (!$self->{message}) {
		$self->{message} = 'この内容で投稿します。よろしければ<em>投稿ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_form}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_diary}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	my $subj_ins = new webliberty::String($self->{query}->{subj});
	my $text_ins = new webliberty::String($self->{query}->{text});

	$subj_ins->create_line;
	$text_ins->create_text;

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_replace_data(
		'form',
		$diary_ins->diary_form($self->{query}->{edit}, '', $self->{query}->{stat}, $self->{query}->{break}, $self->{query}->{comt}, $self->{query}->{tb}, $self->{query}->{field}, $date, '', $subj_ins->get_string, $text_ins->get_string, '', $self->{query}->{icon}, $files, ''),
		FORM_LABEL => 'プレビュー',
		FORM_WORK  => $self->{query}->{work},
		FORM_EXT1  => $ext{'1'},
		FORM_EXT2  => $ext{'2'},
		FORM_EXT3  => $ext{'3'},
		FORM_EXT4  => $ext{'4'},
		FORM_EXT5  => $ext{'5'},
		FORM_TBURL => $self->{query}->{tb_url}
	);
	print $skin_ins->get_data('diary_head');
	print $skin_ins->get_replace_data(
		'diary',
		$diary_ins->diary_article(0, '', $self->{query}->{stat}, $self->{query}->{break}, $self->{query}->{comt}, $self->{query}->{tb}, $new_field, $date, '', $subj_ins->get_string, $text_ins->get_string, '', $self->{query}->{icon}, '', '')
	);
	print $skin_ins->get_data('diary_foot');
	print $skin_ins->get_data('footer');

	return;
}

### 投稿記事一覧表示
sub output_edit {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '記事を選択し、<em>編集ボタン</em>か<em>削除ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_edit}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	$self->{html}->{header}    = $skin_ins->get_data('header');
	$self->{html}->{work_head} = $skin_ins->get_data('work_head');
	$self->{html}->{work}      = $self->work_navi($skin_ins);
	$self->{html}->{work_foot} = $skin_ins->get_data('work_foot');
	$self->{html}->{contents}  = $skin_ins->get_data('contents');

	my($index_size, $index_date, $index_no);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if ($index_size == $self->{query}->{page} * $self->{config}->{page_size}) {
			$index_date = $date;
			$index_no   = $no;
		}

		$index_size++;
	}
	close(FH);

	my $start_file;
	if ($index_date =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
		$start_file = "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$1$2\.$self->{init}->{data_ext}";
	}

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}");
	my @dir = sort { $b <=> $a } readdir(DIR);
	closedir(DIR);

	my($dir_flag, $file_flag, $i);

	$self->{html}->{diary_head} = $skin_ins->get_data('diary_head');
	foreach my $entry (@dir) {
		if ($entry !~ /^\d\d\d\d\d\d\.$self->{init}->{data_ext}$/) {
			next;
		}
		if ($start_file eq "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry") {
			$dir_flag = 1;
		}
		if ($dir_flag) {
			open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$entry");
			while (<FH>) {
				chomp;
				my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/);

				if ($no == $index_no) {
					$file_flag = 1;
				}
				if ($file_flag) {
					$i++;
					if ($i > $self->{config}->{page_size}) {
						$file_flag = 0;
						last;
					}

					$self->{html}->{diary} .= $skin_ins->get_replace_data(
						'diary',
						$diary_ins->diary_article($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host)
					);
				}
			}
			close(FH);
		}
	}
	$self->{html}->{diary_foot} = $skin_ins->get_data('diary_foot');

	my $page_list;
	foreach (0 .. int(($index_size - 1) / $self->{config}->{page_size})) {
		if ($_ == $self->{query}->{page}) {
			$page_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">ページ" . ($_ + 1) . "</option>";
		} else {
			$page_list .= "<option value=\"$_\" lang=\"ja\">ページ" . ($_ + 1) . "</option>";
		}
	}
	$self->{html}->{page} = $skin_ins->get_replace_data(
		'page',
		PAGE_LIST => $page_list
	);

	$self->{html}->{footer} = $skin_ins->get_data('footer');

	print $self->header;
	foreach ($skin_ins->get_list) {
		print $self->{html}->{$_};
	}

	return;
}

### コメント一覧表示
sub output_comment {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'コメントを選択し、<em>編集ボタン</em>か<em>削除ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_comment}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	$self->{html}->{header}    = $skin_ins->get_data('header');
	$self->{html}->{work_head} = $skin_ins->get_data('work_head');
	$self->{html}->{work}      = $self->work_navi($skin_ins);
	$self->{html}->{work_foot} = $skin_ins->get_data('work_foot');
	$self->{html}->{contents}  = $skin_ins->get_data('contents');

	$self->{html}->{diary_head} = $skin_ins->get_data('diary_head');

	my($index_size, $i);

	my $comt_start = $self->{config}->{page_size} * $self->{query}->{page};
	my $comt_end   = $comt_start + $self->{config}->{page_size};

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}");
	while (<FH>) {
		$index_size++;
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $name, $subj, $host) = split(/\t/);

		$i++;
		if ($i <= $comt_start) {
			next;
		} elsif ($i > $comt_end) {
			last;
		}

		$self->{html}->{comment} .= $skin_ins->get_replace_data(
			'comment',
			$diary_ins->comment_article($no, $pno, $stat, $date, $name, '', '', $subj, '', '', '', '', '', '', $host)
		);
	}
	close(FH);

	$self->{html}->{diary_foot} = $skin_ins->get_data('diary_foot');

	my $page_list;
	foreach (0 .. int(($index_size - 1) / $self->{config}->{page_size})) {
		if ($_ == $self->{query}->{page}) {
			$page_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">ページ" . ($_ + 1) . "</option>";
		} else {
			$page_list .= "<option value=\"$_\" lang=\"ja\">ページ" . ($_ + 1) . "</option>";
		}
	}
	$self->{html}->{page} = $skin_ins->get_replace_data(
		'page',
		PAGE_LIST => $page_list
	);

	$self->{html}->{footer} = $skin_ins->get_data('footer');

	print $self->header;
	foreach ($skin_ins->get_list) {
		print $self->{html}->{$_};
	}

	return;
}

### トラックバック一覧表示
sub output_trackback {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'トラックバックを選択し、<em>削除ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_trackback}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	$self->{html}->{header}    = $skin_ins->get_data('header');
	$self->{html}->{work_head} = $skin_ins->get_data('work_head');
	$self->{html}->{work}      = $self->work_navi($skin_ins);
	$self->{html}->{work_foot} = $skin_ins->get_data('work_foot');
	$self->{html}->{contents}  = $skin_ins->get_data('contents');

	$self->{html}->{trackback_head} = $skin_ins->get_data('trackback_head');

	my($index_size, $i);

	my $tb_start = $self->{config}->{page_size} * $self->{query}->{page};
	my $tb_end   = $tb_start + $self->{config}->{page_size};

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
	while (<FH>) {
		$index_size++;
	}
	seek(FH, 0, 0);
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $blog, $title, $url) = split(/\t/);

		$i++;
		if ($i <= $tb_start) {
			next;
		} elsif ($i > $tb_end) {
			last;
		}

		$self->{html}->{trackback} .= $skin_ins->get_replace_data(
			'trackback',
			$diary_ins->trackback_article($no, $pno, $stat, $date, $blog, $title, $url, '')
		);
	}
	close(FH);

	$self->{html}->{trackback_foot} = $skin_ins->get_data('trackback_foot');

	my $page_list;
	foreach (0 .. int(($index_size - 1) / $self->{config}->{page_size})) {
		if ($_ == $self->{query}->{page}) {
			$page_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">ページ" . ($_ + 1) . "</option>";
		} else {
			$page_list .= "<option value=\"$_\" lang=\"ja\">ページ" . ($_ + 1) . "</option>";
		}
	}
	$self->{html}->{page} = $skin_ins->get_replace_data(
		'page',
		PAGE_LIST => $page_list
	);

	$self->{html}->{footer} = $skin_ins->get_data('footer');

	print $self->header;
	foreach ($skin_ins->get_list) {
		print $self->{html}->{$_};
	}

	return;
}

### 削除確認表示
sub output_confirm {
	my $self = shift;

	my($info_heading, $info_delete);
	if ($self->{query}->{work} eq 'comment') {
		$info_heading = 'コメント削除';
		$info_delete  = 'コメント';
	} elsif ($self->{query}->{work} eq 'trackback') {
		$info_heading = 'トラックバック削除';
		$info_delete  = 'トラックバック';
	} elsif ($self->{query}->{work} eq 'paint') {
		$info_heading = 'イラスト削除';
		$info_delete  = 'イラスト';
		$self->{query}->{del} = $self->{query}->{pch};
	} elsif ($self->{query}->{work} eq 'edit') {
		$info_heading = '記事削除';
		$info_delete  = '記事';
	}

	if (!$self->{query}->{del}) {
		$self->error("削除したい$info_deleteを選択してください。");
	}

	if (!$self->{message}) {
		my $del_list;
		foreach (split(/\n/, $self->{query}->{del})) {
			$del_list .= "No.$_ ";
		}

		$self->{message} = "$del_listの$info_deleteを削除します。よろしければ、<em>削除ボタン</em>を押してください。";
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_confirm}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	my $del_list;
	foreach (split(/\n/, $self->{query}->{del})) {
		$del_list .= "<input type=\"hidden\" name=\"del\" value=\"$_\" />";
	}

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	$self->{html}->{header}    = $skin_ins->get_data('header');
	$self->{html}->{work_head} = $skin_ins->get_data('work_head');
	$self->{html}->{work}      = $self->work_navi($skin_ins);
	$self->{html}->{work_foot} = $skin_ins->get_data('work_foot');

	$self->{html}->{contents} = $skin_ins->get_replace_data(
		'contents',
		INFO_HEADING => $info_heading,
		INFO_WORK    => $self->{query}->{work},
		INFO_LIST    => $del_list
	);

	$self->{html}->{footer} = $skin_ins->get_data('footer');

	print $self->header;
	foreach ($skin_ins->get_list) {
		print $self->{html}->{$_};
	}

	return;
}

### 分類設定画面
sub output_field {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '投稿時の記事分類を設定する事ができます。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_field}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');

	my @parents;

	my $form_parent;
	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;
		my($field, $child) = split(/<>/);

		if (!$child) {
			$form_parent .= "<option value=\"$field\" lang=\"ja\">$field</option>";

			push(@parents, $field);
		}
	}
	close(FH);

	print $skin_ins->get_replace_data(
		'contents',
		FORM_PARENT => $form_parent
	);
	print $skin_ins->get_data('field_head');

	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_field}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_field}");
	while (<FH>) {
		chomp;
		my($field, $child) = split(/<>/);

		if ($child) {
			my $field_list;
			foreach (@parents) {
				if ($field eq $_) {
					$field_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">$_</option>";
				} else {
					$field_list .= "<option value=\"$_\" lang=\"ja\">$_</option>";
				}
			}
			$field_list = "<select name=\"parent$i\"><option value=\"\" lang=\"ja\">なし</option>$field_list</select>";

			print $skin_ins->get_replace_data(
				'child',
				FIELD_NAME   => $child,
				FIELD_PARENT => $field_list,
				FIELD_NO     => $i
			);
		} else {
			print $skin_ins->get_replace_data(
				'parent',
				FIELD_NAME => $field,
				FIELD_NO   => $i
			);
		}

		$i++;
	}
	close(FH);

	print $skin_ins->get_data('field_foot');
	print $skin_ins->get_data('footer');

	return;
}

### 環境設定画面表示
sub output_env {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '設定を変更し、<em>設定ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_env}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	my $use_field;
	if ($self->{config}->{use_field} eq '1') {
		$use_field = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$use_field = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $use_icon;
	if ($self->{config}->{use_icon} eq '1') {
		$use_icon = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$use_icon = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $use_file;
	if ($self->{config}->{use_file} eq '1') {
		$use_file = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$use_file = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $use_tburl;
	if ($self->{config}->{use_tburl} eq '1') {
		$use_tburl = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$use_tburl = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $default_stat;
	if ($self->{config}->{default_stat} eq '1') {
		$default_stat = '<option value="1" lang="ja" selected="selected">公開する</option><option value="0" lang="ja">公開しない</option>';
	} else {
		$default_stat = '<option value="1" lang="ja">公開する</option><option value="0" lang="ja" selected="selected">公開しない</option>';
	}

	my $default_break;
	if ($self->{config}->{default_break} eq '1') {
		$default_break = '<option value="1" lang="ja" selected="selected">変換する</option><option value="0" lang="ja">変換しない</option>';
	} else {
		$default_break = '<option value="1" lang="ja">変換する</option><option value="0" lang="ja" selected="selected">変換しない</option>';
	}

	my $default_comt;
	if ($self->{config}->{default_comt} eq '1') {
		$default_comt = '<option value="1" lang="ja" selected="selected">受け付ける</option><option value="0" lang="ja">受け付けない</option>';
	} else {
		$default_comt = '<option value="1" lang="ja">受け付ける</option><option value="0" lang="ja" selected="selected">受け付けない</option>';
	}

	my $default_tb;
	if ($self->{config}->{default_tb} eq '1') {
		$default_tb = '<option value="1" lang="ja" selected="selected">受け付ける</option><option value="0" lang="ja">受け付けない</option>';
	} else {
		$default_tb = '<option value="1" lang="ja">受け付ける</option><option value="0" lang="ja" selected="selected">受け付けない</option>';
	}

	my $autolink_mode;
	if ($self->{config}->{autolink_mode} eq '1') {
		$autolink_mode = '<option value="1" lang="ja" selected="selected">リンクする</option><option value="0" lang="ja">リンクしない</option>';
	} else {
		$autolink_mode = '<option value="1" lang="ja">リンクする</option><option value="0" lang="ja" selected="selected">リンクしない</option>';
	}

	my $thumbnail_mode;
	if ($self->{config}->{thumbnail_mode} eq '1') {
		$thumbnail_mode = '<option value="1" lang="ja" selected="selected">作成する</option><option value="0" lang="ja">作成しない</option>';
	} else {
		$thumbnail_mode = '<option value="1" lang="ja">作成する</option><option value="0" lang="ja" selected="selected">作成しない</option>';
	}

	my $show_calendar;
	if ($self->{config}->{show_calendar} eq '1') {
		$show_calendar = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_calendar = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_field;
	if ($self->{config}->{show_field} eq '1') {
		$show_field = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_field = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_search;
	if ($self->{config}->{show_search} eq '1') {
		$show_search = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_search = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_past;
	if ($self->{config}->{show_past} eq '1') {
		$show_past = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_past = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_menu;
	if ($self->{config}->{show_menu} eq '1') {
		$show_menu = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_menu = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_link;
	if ($self->{config}->{show_link} eq '1') {
		$show_link = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_link = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $show_profile;
	if ($self->{config}->{show_profile} eq '1') {
		$show_profile = '<option value="1" lang="ja" selected="selected">表示する</option><option value="0" lang="ja">表示しない</option>';
	} else {
		$show_profile = '<option value="1" lang="ja">表示する</option><option value="0" lang="ja" selected="selected">表示しない</option>';
	}

	my $sendmail_cmt_mode;
	if ($self->{config}->{sendmail_cmt_mode} eq '1') {
		$sendmail_cmt_mode = '<option value="1" lang="ja" selected="selected">通知する</option><option value="0" lang="ja">通知しない</option>';
	} else {
		$sendmail_cmt_mode = '<option value="1" lang="ja">通知する</option><option value="0" lang="ja" selected="selected">通知しない</option>';
	}

	my $sendmail_tb_mode;
	if ($self->{config}->{sendmail_tb_mode} eq '1') {
		$sendmail_tb_mode = '<option value="1" lang="ja" selected="selected">通知する</option><option value="0" lang="ja">通知しない</option>';
	} else {
		$sendmail_tb_mode = '<option value="1" lang="ja">通知する</option><option value="0" lang="ja" selected="selected">通知しない</option>';
	}

	my $ping_mode;
	if ($self->{config}->{ping_mode} eq '1') {
		$ping_mode = '<option value="1" lang="ja" selected="selected">通知する</option><option value="0" lang="ja">通知しない</option>';
	} else {
		$ping_mode = '<option value="1" lang="ja">通知する</option><option value="0" lang="ja" selected="selected">通知しない</option>';
	}

	my $html_index_mode;
	if ($self->{config}->{html_index_mode} eq '1') {
		$html_index_mode = '<option value="1" lang="ja" selected="selected">ON</option><option value="0" lang="ja">OFF</option>';
	} else {
		$html_index_mode = '<option value="1" lang="ja">ON</option><option value="0" lang="ja" selected="selected">OFF</option>';
	}

	my $html_archive_mode;
	if ($self->{config}->{html_archive_mode} eq '1') {
		$html_archive_mode = '<option value="1" lang="ja" selected="selected">ON</option><option value="0" lang="ja">OFF</option>';
	} else {
		$html_archive_mode = '<option value="1" lang="ja">ON</option><option value="0" lang="ja" selected="selected">OFF</option>';
	}

	my $js_title_mode;
	if ($self->{config}->{js_title_mode} eq '1') {
		$js_title_mode = '<option value="1" lang="ja" selected="selected">ON</option><option value="0" lang="ja">OFF</option>';
	} else {
		$js_title_mode = '<option value="1" lang="ja">ON</option><option value="0" lang="ja" selected="selected">OFF</option>';
	}

	my $js_text_mode;
	if ($self->{config}->{js_text_mode} eq '1') {
		$js_text_mode = '<option value="1" lang="ja" selected="selected">ON</option><option value="0" lang="ja">OFF</option>';
	} else {
		$js_text_mode = '<option value="1" lang="ja">ON</option><option value="0" lang="ja" selected="selected">OFF</option>';
	}

	my $proxy_mode;
	if ($self->{config}->{proxy_mode} eq '1') {
		$proxy_mode = '<option value="1" lang="ja" selected="selected">許可</option><option value="0" lang="ja">禁止</option>';
	} else {
		$proxy_mode = '<option value="1" lang="ja">許可</option><option value="0" lang="ja" selected="selected">禁止</option>';
	}

	my $ng_word = $self->{config}->{ng_word};
	$ng_word =~ s/<>/\n/g;

	my $menu_list = $self->{config}->{menu_list};
	$menu_list =~ s/<>/\n/g;

	my $link_list = $self->{config}->{link_list};
	$link_list =~ s/<>/\n/g;

	my $sendmail_list = $self->{config}->{sendmail_list};
	$sendmail_list =~ s/<>/\n/g;

	my $sendmail_admin = $self->{config}->{sendmail_admin};
	$sendmail_admin =~ s/<>/\n/g;

	my $ping_list = $self->{config}->{ping_list};
	$ping_list =~ s/<>/\n/g;

	my $black_list = $self->{config}->{black_list};
	$black_list =~ s/<>/\n/g;

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_data('contents_head');

	my @envlist = (
		'env_basic',       '基本設定',
		'env_log',         'ログの表示設定',
		'env_form',        '投稿画面の表示設定',
		'env_default',     '投稿記事の初期設定',
		'env_show',        '投稿記事の表示設定',
		'env_upload',      'ファイルアップロードの設定',
		'env_restriction', 'コメント投稿制限の設定',
		'env_layout',      'レイアウトの設定',
		'env_menu',        'コンテンツの設定',
		'env_link',        'リンク集の設定',
		'env_sendmail',    'メール通知の設定',
		'env_ping',        '更新PINGの設定',
		'env_cookie',      'Cookieの設定',
		'env_html',        'HTMLファイル書き出しの設定',
		'env_js',          'JSファイル書き出しの設定',
		'env_access',      'アクセス制限の設定'
	);

	print $skin_ins->get_data('envlist_head');
	my $i = 0;
	foreach (0 .. ($#envlist / 2)) {
		print $skin_ins->get_replace_data(
			'envlist',
			ENV_ID    => $envlist[$i++],
			ENV_TITLE => $envlist[$i++]
		);
	}
	print $skin_ins->get_data('envlist_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => '基本設定',
		ENV_ID    => 'env_basic'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '日記帳タイトル（<em>必ず設定してください</em>）',
		ENV_VALUE => "<input type=\"text\" name=\"env_site_title\" size=\"30\" value=\"$self->{config}->{site_title}\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '日記帳からの戻り先',
		ENV_VALUE => "<input type=\"text\" name=\"env_back_url\" size=\"50\" value=\"$self->{config}->{back_url}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '日記帳タイトル（携帯モード時）',
		ENV_VALUE => "<input type=\"text\" name=\"env_mobile_site_title\" size=\"30\" value=\"$self->{config}->{mobile_site_title}\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '日記帳からの戻り先（携帯モード時）',
		ENV_VALUE => "<input type=\"text\" name=\"env_mobile_back_url\" size=\"50\" value=\"$self->{config}->{mobile_back_url}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'サイトの概要',
		ENV_VALUE => "<input type=\"text\" name=\"env_site_description\" size=\"50\" value=\"$self->{config}->{site_description}\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'サイトのURL（<em>必ず設定してください</em>）',
		ENV_VALUE => "<input type=\"text\" name=\"env_site_url\" size=\"50\" value=\"$self->{config}->{site_url}\" />"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'ログの表示設定',
		ENV_ID    => 'env_log'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '1ページの記事表示件数',
		ENV_VALUE => "<input type=\"text\" name=\"env_page_size\" size=\"5\" value=\"$self->{config}->{page_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着記事の表示件数（0にすると非表示）',
		ENV_VALUE => "<input type=\"text\" name=\"env_list_size\" size=\"5\" value=\"$self->{config}->{list_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着コメントの表示件数（0にすると非表示）',
		ENV_VALUE => "<input type=\"text\" name=\"env_cmtlist_size\" size=\"5\" value=\"$self->{config}->{cmtlist_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着トラックバックの表示件数（0にすると非表示）',
		ENV_VALUE => "<input type=\"text\" name=\"env_tblist_size\" size=\"5\" value=\"$self->{config}->{tblist_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '1ページの記事表示件数（携帯モード時）',
		ENV_VALUE => "<input type=\"text\" name=\"env_mobile_page_size\" size=\"5\" value=\"$self->{config}->{mobile_page_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着コメントの表示件数（携帯モード時）',
		ENV_VALUE => "<input type=\"text\" name=\"env_mobile_cmtlist_size\" size=\"5\" value=\"$self->{config}->{mobile_cmtlist_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着トラックバックの表示件数（携帯モード時）',
		ENV_VALUE => "<input type=\"text\" name=\"env_mobile_tblist_size\" size=\"5\" value=\"$self->{config}->{mobile_tblist_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => '投稿画面の表示設定',
		ENV_ID    => 'env_form'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '分類選択項目の表示',
		ENV_VALUE => "<select name=\"env_use_field\">$use_field</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'アイコン選択項目の表示',
		ENV_VALUE => "<select name=\"env_use_icon\">$use_icon</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'ファイル選択項目の表示',
		ENV_VALUE => "<select name=\"env_use_file\">$use_file</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'トラックバックURL入力項目の表示',
		ENV_VALUE => "<select name=\"env_use_tburl\">$use_tburl</select>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => '投稿記事の初期設定',
		ENV_ID    => 'env_default'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '記事の公開',
		ENV_VALUE => "<select name=\"env_default_stat\">$default_stat</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '改行の変換',
		ENV_VALUE => "<select name=\"env_default_break\">$default_break</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'コメントの受付',
		ENV_VALUE => "<select name=\"env_default_comt\">$default_comt</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'トラックバックの受付',
		ENV_VALUE => "<select name=\"env_default_tb\">$default_tb</select>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => '投稿記事の表示設定',
		ENV_ID    => 'env_show'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '新着マーク表示日数',
		ENV_VALUE => "<input type=\"text\" name=\"env_new_days\" size=\"5\" value=\"$self->{config}->{new_days}\" style=\"ime-mode:disabled;\" />日間"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '本文のURLとメールアドレスに自動的にリンク',
		ENV_VALUE => "<select name=\"env_autolink_mode\">$autolink_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '引用文字色',
		ENV_VALUE => "<input type=\"text\" name=\"env_quotation_color\" size=\"10\" value=\"$self->{config}->{quotation_color}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'ファイルアップロードの設定',
		ENV_ID    => 'env_upload'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'アップロードファイルの最大横幅',
		ENV_VALUE => "<input type=\"text\" name=\"env_img_maxwidth\" size=\"5\" value=\"$self->{config}->{img_maxwidth}\" style=\"ime-mode:disabled;\" />px"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'サムネイル画像を自動的に作成（<em>ImageMagick必須</em>）',
		ENV_VALUE => "<select name=\"env_thumbnail_mode\">$thumbnail_mode</select>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'コメント投稿制限の設定',
		ENV_ID    => 'env_restriction'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '投稿禁止ワード（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_ng_word\" cols=\"30\" rows=\"5\">$ng_word</textarea>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '連続投稿を拒否する時間',
		ENV_VALUE => "<input type=\"text\" name=\"env_wait_time\" size=\"5\" value=\"$self->{config}->{wait_time}\" style=\"ime-mode:disabled;\" />秒"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'レイアウトの設定',
		ENV_ID    => 'env_layout'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'カレンダーの表示',
		ENV_VALUE => "<select name=\"env_show_calendar\">$show_calendar</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '分類一覧の表示',
		ENV_VALUE => "<select name=\"env_show_field\">$show_field</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '検索フォームの表示',
		ENV_VALUE => "<select name=\"env_show_search\">$show_search</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '過去ログ一覧の表示',
		ENV_VALUE => "<select name=\"env_show_past\">$show_past</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'コンテンツの表示',
		ENV_VALUE => "<select name=\"env_show_menu\">$show_menu</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'リンク集の表示',
		ENV_VALUE => "<select name=\"env_show_link\">$show_link</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'プロフィールの表示',
		ENV_VALUE => "<select name=\"env_show_profile\">$show_profile</select>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'コンテンツの設定',
		ENV_ID    => 'env_menu'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'コンテンツの分類（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_menu_list\" cols=\"30\" rows=\"5\">$menu_list</textarea>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'リンク集の設定',
		ENV_ID    => 'env_link'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'リンク集の分類（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_link_list\" cols=\"30\" rows=\"5\">$link_list</textarea>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'メール通知の設定',
		ENV_ID    => 'env_sendmail'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'コメントを受信するとメールで通知',
		ENV_VALUE => "<select name=\"env_sendmail_cmt_mode\">$sendmail_cmt_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'トラックバックを受信するとメールで通知',
		ENV_VALUE => "<select name=\"env_sendmail_tb_mode\">$sendmail_tb_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'Sendmailのパス',
		ENV_VALUE => "<input type=\"text\" name=\"env_sendmail_path\" size=\"30\" value=\"$self->{config}->{sendmail_path}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'メールの通知先（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_sendmail_list\" cols=\"50\" rows=\"5\" style=\"ime-mode:disabled;\">$sendmail_list</textarea>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '通知しないコメント投稿者名（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_sendmail_admin\" cols=\"30\" rows=\"5\">$sendmail_admin</textarea>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => '更新PINGの設定',
		ENV_ID    => 'env_ping'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '更新PINGの送信',
		ENV_VALUE => "<select name=\"env_ping_mode\">$ping_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '更新PINGの通知先（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_ping_list\" cols=\"50\" rows=\"5\" style=\"ime-mode:disabled;\">$ping_list</textarea>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'Cookieの設定',
		ENV_ID    => 'env_cookie'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '投稿者情報Cookieの識別名',
		ENV_VALUE => "<input type=\"text\" name=\"env_cookie_id\" size=\"30\" value=\"$self->{config}->{cookie_id}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '投稿者情報の保存日数',
		ENV_VALUE => "<input type=\"text\" name=\"env_cookie_holddays\" size=\"5\" value=\"$self->{config}->{cookie_holddays}\" style=\"ime-mode:disabled;\" />日間"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '管理者情報Cookieの識別名',
		ENV_VALUE => "<input type=\"text\" name=\"env_cookie_admin\" size=\"30\" value=\"$self->{config}->{cookie_admin}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'HTMLファイル書き出しの設定',
		ENV_ID    => 'env_html'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'トップページをHTMLファイルに書き出し',
		ENV_VALUE => "<select name=\"env_html_index_mode\">$html_index_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '各記事をHTMLファイルに書き出し',
		ENV_VALUE => "<select name=\"env_html_archive_mode\">$html_archive_mode</select>"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'JSファイル書き出しの設定',
		ENV_ID    => 'env_js'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '題名一覧をJSファイルに書き出し',
		ENV_VALUE => "<select name=\"env_js_title_mode\">$js_title_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '題名一覧をJSファイルに書き出す件数',
		ENV_VALUE => "<input type=\"text\" name=\"env_js_title_size\" size=\"5\" value=\"$self->{config}->{js_title_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '最近の記事をJSファイルに書き出し',
		ENV_VALUE => "<select name=\"env_js_text_mode\">$js_text_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '最近の記事をJSファイルに書き出す件数',
		ENV_VALUE => "<input type=\"text\" name=\"env_js_text_size\" size=\"5\" value=\"$self->{config}->{js_text_size}\" style=\"ime-mode:disabled;\" />件"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_replace_data(
		'env_title',
		ENV_TITLE => 'アクセス制限の設定',
		ENV_ID    => 'env_access'
	);
	print $skin_ins->get_data('env_head');
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'アクセス制限対象ホスト（改行区切りで複数指定可能）',
		ENV_VALUE => "<textarea name=\"env_black_list\" cols=\"30\" rows=\"5\" style=\"ime-mode:disabled;\">$black_list</textarea>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => 'Proxy経由のアクセス',
		ENV_VALUE => "<select name=\"env_proxy_mode\">$proxy_mode</select>"
	);
	print $skin_ins->get_replace_data(
		'env',
		ENV_TITLE => '自サイトのURL(このURLを含まないサイトからの投稿を拒否)',
		ENV_VALUE => "<input type=\"text\" name=\"env_base_url\" size=\"50\" value=\"$self->{config}->{base_url}\" style=\"ime-mode:disabled;\" />"
	);
	print $skin_ins->get_data('env_foot');

	print $skin_ins->get_data('contents_foot');
	print $skin_ins->get_data('footer');

	return;
}

### アイコン設定画面表示
sub output_icon {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'アイコンを登録する事ができます。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_icon}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');

	print $skin_ins->get_replace_data(
		'contents',
		FORM_EDIT => '',
		FORM_FILE => '',
		FORM_NAME => '',
		FORM_USER => ''
	);
	print $skin_ins->get_data('icon_head');

	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_icon}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_icon}");
	while (<FH>) {
		chomp;
		my($file, $name, $field, $user, $pwd) = split(/\t/);

		my $image = "<img src=\"$self->{init}->{data_dir}$self->{init}->{data_icon_dir}$file\" alt=\"$file\" />";

		print $skin_ins->get_replace_data(
			'icon',
			ICON_FILE  => $file,
			ICON_IMAGE => $image,
			ICON_NAME  => $name,
			ICON_USER  => $user
		);
	}
	close(FH);

	print $skin_ins->get_data('icon_foot');
	print $skin_ins->get_data('footer');

	return;
}

### コンテンツ設定画面表示
sub output_menu {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'コンテンツを設定する事ができます。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_menu}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');

	my $form_field;
	foreach (split(/<>/, $self->{config}->{menu_list})) {
		$form_field .= "<option value=\"$_\" lang=\"ja\">$_</option>";
	}

	print $skin_ins->get_replace_data(
		'contents',
		FORM_FIELD => $form_field
	);
	print $skin_ins->get_data('menu_head');

	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_menu}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_menu}");
	while (<FH>) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		my $field_list;
		foreach (split(/<>/, $self->{config}->{menu_list})) {
			if ($field eq $_) {
				$field_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">$_</option>";
			} else {
				$field_list .= "<option value=\"$_\" lang=\"ja\">$_</option>";
			}
		}
		$field_list = "<select name=\"field$i\"><option value=\"\" lang=\"ja\">なし</option>$field_list</select>";

		print $skin_ins->get_replace_data(
			'menu',
			MENU_FIELD => $field_list,
			MENU_NAME  => $name,
			MENU_URL   => $url,
			MENU_NO    => $i
		);

		$i++;
	}
	close(FH);

	print $skin_ins->get_data('menu_foot');
	print $skin_ins->get_data('footer');

	return;
}

### リンク集設定画面表示
sub output_link {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'リンク集を設定する事ができます。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_link}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');

	my $form_field;
	foreach (split(/<>/, $self->{config}->{link_list})) {
		$form_field .= "<option value=\"$_\" lang=\"ja\">$_</option>";
	}

	print $skin_ins->get_replace_data(
		'contents',
		FORM_FIELD => $form_field
	);
	print $skin_ins->get_data('link_head');

	my $i = 0;

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_link}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_link}");
	while (<FH>) {
		chomp;
		my($field, $name, $url) = split(/\t/);

		my $field_list;
		foreach (split(/<>/, $self->{config}->{link_list})) {
			if ($field eq $_) {
				$field_list .= "<option value=\"$_\" lang=\"ja\" selected=\"selected\">$_</option>";
			} else {
				$field_list .= "<option value=\"$_\" lang=\"ja\">$_</option>";
			}
		}
		$field_list = "<select name=\"field$i\"><option value=\"\" lang=\"ja\">なし</option>$field_list</select>";

		print $skin_ins->get_replace_data(
			'link',
			LINK_FIELD => $field_list,
			LINK_NAME  => $name,
			LINK_URL   => $url,
			LINK_NO    => $i
		);

		$i++;
	}
	close(FH);

	print $skin_ins->get_data('link_foot');
	print $skin_ins->get_data('footer');

	return;
}

### プロフィール設定画面
sub output_profile {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'プロフィールを設定します。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_profile}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	my(%name, %text);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_profile}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_profile}");
	while (<FH>) {
		chomp;
		my($user, $name, $text) = split(/\t/);

		$name{$user} = $name;
		$text{$user} = $text;
	}
	close(FH);

	my $name_ins = new webliberty::String($name{'admin'});
	my $text_ins = new webliberty::String($text{'admin'});

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_replace_data(
		'contents',
		FORM_NAME => $name_ins->create_plain,
		FORM_TEXT => $text_ins->create_plain
	);
	print $skin_ins->get_data('footer');

	return;
}

### 管理者パスワード設定画面
sub output_pwd {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '管理者用パスワードを設定します。以前のパスワードと新しく設定したいパスワードを入力してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_pwd}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_data('contents');
	print $skin_ins->get_data('footer');

	return;
}

### キャンバス表示
sub output_canvas {
	my $self = shift;

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_paint}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		INFO_RES => $self->{init}->{res_dir},
		$diary_ins->info
	);

	my $pch;
	if ($self->{query}->{pch}) {
		$pch = "$self->{init}->{data_dir}$self->{init}->{pch_dir}$self->{query}->{pch}\.spch";
	} else {
		$pch = '';
	}

	my $cookie_ins = new webliberty::Cookie($self->{config}->{cookie_admin});

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_replace_data(
		'canvas',
		CANVAS_PWD    => $cookie_ins->get_cookie('admin_pwd'),
		CANVAS_NO     => $self->{query}->{pch},
		CANVAS_PCH    => $pch,
		CANVAS_WIDTH  => $self->{query}->{width},
		CANVAS_HEIGHT => $self->{query}->{height}
	);
	print $skin_ins->get_data('footer');

	return;
}

### イラスト表示
sub output_view {
	my $self = shift;

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_image}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info
	);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{paint_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{paint_dir}");
	my @files = sort { $a <=> $b } grep { m/\w+\.\w+/g } readdir(DIR);
	close(DIR);

	my($file_image, $file_name, $file_width, $file_height, $flag);

	foreach (@files) {
		my $file_ins  = new webliberty::File("$self->{init}->{data_dir}$self->{init}->{paint_dir}$_");
		$file_name = $file_ins->get_name . '.' . $file_ins->get_ext;

		if ($self->{query}->{pch} eq $file_ins->get_name) {
			($file_width, $file_height) = $file_ins->get_size;

			$flag = 1;

			last;
		}
	}
	if (!$flag) {
		$self->error('指定されたイラストは存在しません。');
	}

	my $file_image = "<img src=\"$self->{init}->{data_dir}$self->{init}->{paint_dir}$file_name\" alt=\"ペイントファイル $file_name\" width=\"$file_width\" height=\"$file_height\" />";

	print $self->header;
	print $skin_ins->get_replace_data(
		'_all',
		INFO_IMAGE      => $file_image,
		INFO_FILENAME   => $file_name,
		INFO_FILEWIDTH  => $file_width,
		INFO_FILEHEIGHT => $file_height
	);

	return;
}

### イラスト一覧表示
sub output_paint {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = 'イラストを投稿するには、作業対象を選択して<em>ペイントボタン</em>を押してください。';
	}

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{pch_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{pch_dir}");
	my @dir = sort { $b <=> $a } readdir(DIR);
	closedir(DIR);

	my $pch_list;
	foreach my $entry (@dir) {
		if ($entry =~ /^(\d+)\.\w+$/) {
			$pch_list .= "<option value=\"$1\" lang=\"ja\">No.$1のイラスト</option>";
		}
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_paint}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_PCH     => $pch_list,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_data('contents');
	print $skin_ins->get_data('footer');

	return;
}

### 再構築設定表示
sub output_build {
	my $self = shift;

	if (!$self->{message}) {
		$self->{message} = '作業内容を選択し、<em>実行ボタン</em>を押してください。';
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_build}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	my @index = <FH>;
	close(FH);

	my @numbers = map { (split(/\t/))[1] } @index;
	@index = @index[sort { $numbers[$b] <=> $numbers[$a] } (0 .. $#numbers)];
	my $max_no = (split(/\t/, $index[0]))[1];

	my $form_list = "<option value=\"all\" lang=\"ja\">すべてを構築</option><option value=\"index\" lang=\"ja\">インデックスを構築</option>";
	if ($self->{config}->{html_archive_mode}) {
		foreach (0 .. int(($max_no - 1) / 50)) {
			my $from = $_ * 50 + 1;
			my $to;
			if ($_ == int(($max_no - 1) / 50)) {
				$to = $from + ($max_no - 1) % 50;
			} else {
				$to = $from + 50 - 1;
			}
			$form_list .= "<option value=\"$from\" lang=\"ja\">アーカイブ（No.$from～No.$to）を構築</option>";
		}
	}

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');
	print $skin_ins->get_replace_data(
		'contents',
		FORM_LIST => $form_list
	);
	print $skin_ins->get_data('footer');

	return;
}

### ステータス画面
sub output_status {
	my $self = shift;

	my($diary_size, $diary_show_size, $diary_hidden_size);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}$self->{init}->{data_diary_index}");
	while (<FH>) {
		chomp;
		my($date, $no, $id, $stat, $field, $name) = split(/\t/);

		if ($stat) {
			$diary_show_size++;
		} else {
			$diary_hidden_size++;
		}
		$diary_size++;
	}
	close(FH);

	my($comt_size, $comt_show_size, $comt_hidden_size);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}$self->{init}->{data_comt_index}");
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $name, $subj, $host) = split(/\t/);

		if ($stat) {
			$comt_show_size++;
		} else {
			$comt_hidden_size++;
		}
		$comt_size++;
	}
	close(FH);

	my($tb_size, $tb_show_size, $tb_hidden_size);

	open(FH, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}$self->{init}->{data_tb_index}");
	while (<FH>) {
		chomp;
		my($no, $pno, $stat, $date, $blog, $title, $url) = split(/\t/);

		if ($stat) {
			$tb_show_size++;
		} else {
			$tb_hidden_size++;
		}
		$tb_size++;
	}
	close(FH);

	my($diary_file_size, $comt_file_size, $tb_file_size, $upfile_file_size, $archive_file_size, $paint_file_size, $pch_file_size);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_diary_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$diary_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{data_diary_dir}$file");
		}
	}
	closedir(DIR);
	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_comt_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$comt_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{data_comt_dir}$file");
		}
	}
	closedir(DIR);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_tb_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$tb_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{data_tb_dir}$file");
		}
	}
	closedir(DIR);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{data_upfile_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$upfile_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{data_upfile_dir}$file");
		}
	}
	closedir(DIR);

	opendir(DIR, "$self->{init}->{archive_dir}") or $self->error("Read Error : $self->{init}->{archive_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$archive_file_size += (-s "$self->{init}->{archive_dir}$file");
		}
	}
	closedir(DIR);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{paint_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{paint_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$paint_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{paint_dir}$file");
		}
	}
	closedir(DIR);

	opendir(DIR, "$self->{init}->{data_dir}$self->{init}->{pch_dir}") or $self->error("Read Error : $self->{init}->{data_dir}$self->{init}->{pch_dir}");
	foreach my $file (readdir(DIR)) {
		if ($file ne '.' and $file ne '..') {
			$pch_file_size += (-s "$self->{init}->{data_dir}$self->{init}->{pch_dir}$file");
		}
	}
	closedir(DIR);

	$diary_file_size   = sprintf("%.1f", $diary_file_size / 1024);
	$comt_file_size    = sprintf("%.1f", $comt_file_size / 1024);
	$tb_file_size      = sprintf("%.1f", $tb_file_size / 1024);
	$upfile_file_size  = sprintf("%.1f", $upfile_file_size / 1024);
	$archive_file_size = sprintf("%.1f", $archive_file_size / 1024);
	$paint_file_size   = sprintf("%.1f", $paint_file_size / 1024);
	$pch_file_size     = sprintf("%.1f", $pch_file_size / 1024);

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_status}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info,
		INFO_MESSAGE => $self->{message}
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('work_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('work_foot');

	print $skin_ins->get_replace_data(
		'contents',
		STATUS_DIARY_SIZE        => $diary_size || 0,
		STATUS_DIARY_SHOW_SIZE   => $diary_show_size || 0,
		STATUS_DIARY_HIDDEN_SIZE => $diary_hidden_size || 0,
		STATUS_DIARY_FILE_SIZE   => $diary_file_size || 0,
		STATUS_COMT_SIZE         => $comt_size || 0,
		STATUS_COMT_SHOW_SIZE    => $comt_show_size || 0,
		STATUS_COMT_HIDDEN_SIZE  => $comt_hidden_size || 0,
		STATUS_COMT_FILE_SIZE    => $comt_file_size || 0,
		STATUS_TB_SIZE           => $tb_size || 0,
		STATUS_TB_SHOW_SIZE      => $tb_show_size || 0,
		STATUS_TB_HIDDEN_SIZE    => $tb_hidden_size || 0,
		STATUS_TB_FILE_SIZE      => $tb_file_size || 0,
		STATUS_UPFILE_FILE_SIZE  => $upfile_file_size || 0,
		STATUS_ARCHIVE_FILE_SIZE => $archive_file_size || 0,
		STATUS_PAINT_FILE_SIZE   => $paint_file_size || 0,
		STATUS_PCH_FILE_SIZE     => $pch_file_size || 0
	);

	print $skin_ins->get_data('footer');

	return;
}

### 認証画面表示
sub output_login {
	my $self = shift;

	if ($self->{query}->{admin_pwd}) {
		$self->error('パスワードが違います。');
	}

	my $skin_ins = new webliberty::Skin;
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin}");
	$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

	$skin_ins->replace_skin(
		$diary_ins->info
	);

	print $self->header;
	print $skin_ins->get_data('header');
	print $skin_ins->get_data('contents_head');
	print $self->work_navi($skin_ins);
	print $skin_ins->get_data('contents_foot');
	print $skin_ins->get_data('footer');

	return;
}

### 作業内容一覧
sub work_navi {
	my $self     = shift;
	my $skin_ins = shift;

	my $work_data;

	$work_data  = "\t投稿\n";
	$work_data .= "new\t新規投稿\n";
	$work_data .= "edit\t記事編集\n";
	$work_data .= "\tコミュニティ\n";
	$work_data .= "comment\tコメント管理\n";
	$work_data .= "trackback\tトラックバック管理\n";

	$work_data .= "\t各種設定\n";
	if ($self->{config}->{use_field}) {
		$work_data .= "field\t分類設定\n";
	}
	$work_data .= "env\t環境設定\n";
	if ($self->{config}->{use_icon}) {
		$work_data .= "icon\tアイコン設定\n";
	}
	if ($self->{config}->{show_menu}) {
		$work_data .= "menu\tコンテンツ管理\n";
	}
	if ($self->{config}->{show_link}) {
		$work_data .= "link\tリンク集管理\n";
	}
	if ($self->{config}->{show_profile}) {
		$work_data .= "profile\tプロフィール設定\n";
	}
	$work_data .= "pwd\tパスワード設定\n";

	$work_data .= "\tユーティリティ\n";
	if (-e $self->{init}->{paint_jar}) {
		$work_data .= "paint\tイラスト管理\n";
	}
	if ($self->{config}->{html_index_mode} or $self->{config}->{html_archive_mode}) {
		$work_data .= "build\tサイト再構築\n";
	}
	$work_data .= "status\tステータス表示\n";

	my($work_list, $flag);

	foreach (split(/\n/, $work_data)) {
		my($work_id, $work_name) = split(/\t/);

		if ($work_id) {
			if ($self->{query}->{work} eq $work_id) {
				$work_list .= $skin_ins->get_replace_data(
					'work_selected',
					WORK_ID   => $work_id,
					WORK_NAME => $work_name
				);
			} else {
				$work_list .= $skin_ins->get_replace_data(
					'work',
					WORK_ID   => $work_id,
					WORK_NAME => $work_name
				);
			}
		} else {
			if ($flag) {
				$work_list .= $skin_ins->get_data('work_delimiter');
				$flag = 0;
			}

			$work_list .= $skin_ins->get_replace_data(
				'work_title',
				WORK_NAME => $work_name
			);

			$flag = 1;
		}
	}
	if ($flag) {
		$work_list .= $skin_ins->get_data('work_delimiter');
	}

	return $work_list;
}

### エラー出力
sub error {
	my $self    = shift;
	my $message = shift;

	if ($self->{query}->{exec_regist} or $self->{query}->{exec_preview}) {
		$self->{message} = $message;

		my $skin_ins = new webliberty::Skin;
		$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_header}");
		$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_work}");
		$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_admin_form}");
		$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_diary}");
		$skin_ins->parse_skin("$self->{init}->{skin_dir}$self->{init}->{skin_footer}");

		my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});

		$skin_ins->replace_skin(
			$diary_ins->info,
			INFO_MESSAGE => $self->{message}
		);

		my $subj_ins = new webliberty::String($self->{query}->{subj});
		my $text_ins = new webliberty::String($self->{query}->{text});

		$subj_ins->create_line;
		$text_ins->create_text;

		my $date = "$self->{query}->{year}$self->{query}->{month}$self->{query}->{day}$self->{query}->{hour}$self->{query}->{minute}";

		print $self->header;
		print $skin_ins->get_data('header');
		print $skin_ins->get_data('work_head');
		print $self->work_navi($skin_ins);
		print $skin_ins->get_data('work_foot');
		print $skin_ins->get_replace_data(
			'form',
			$diary_ins->diary_form($self->{query}->{edit}, '', $self->{query}->{stat}, $self->{query}->{break}, $self->{query}->{comt}, $self->{query}->{tb}, '', $date, '', $subj_ins->get_string, $text_ins->get_string, '', '', '', ''),
			FORM_LABEL => 'エラー',
			FORM_WORK  => $self->{query}->{work},
			FORM_EXT1  => '',
			FORM_EXT2  => '',
			FORM_EXT3  => '',
			FORM_EXT4  => '',
			FORM_EXT5  => '',
			FORM_TBURL => $self->{query}->{tb_url}
		);
		print $skin_ins->get_data('footer');

		exit;
	}

	my $diary_ins = new webliberty::App::Diary($self->{init}, $self->{config}, $self->{query});
	$diary_ins->error($message);

	exit;
}

### アイコン並び替え
sub _sort_icon {
	my $self = shift;

	my(@normal, @personal, @names);

	foreach (@_) {
		chomp;
		my($file, $name, $field, $user, $pwd) = split(/\t/);

		if ($user) {
			push(@personal, "$_\n");
		} else {
			push(@normal, "$_\n");
		}
	}

	@names  = map { (split(/\t/))[1] } @normal;
	@normal = @normal[sort { $names[$a] cmp $names[$b] } (0 .. $#names)];

	@names    = map { (split(/\t/))[1] } @personal;
	@personal = @personal[sort { $names[$a] cmp $names[$b] } (0 .. $#names)];

	return(@normal, @personal);
}

1;
