#!/usr/local/bin/perl 
# Copyright 1994-2000, Cunningham & Cunningham, Inc.
# Open Source for personal use only.
# ... and then only
# with the understanding that the owner(s) cannot be
# responsible for any behavior of the program or
# any damages that it may cause. See LICENSE.TXT

# EDIT.PL - редактирование текста ВикиВики
# use strict;
$|++;
$WikiDB = "../db/pustwiki.txt";


print "Content-type: text/html\n\n";

open (TEXT,"$WikiDB") or die "Couldn't open for reading \n";
my %kees = ();	
while (<TEXT>) {
        ($name,$descript,$time) = split("#") ;
     $kees{$name} = $descript ;
	# OR push ( @{$kees{$name}},$descript) ;
		}
close TEXT ;

my $mark = "\263";
my $pomark = "\265";



my $query=&urldecode($ENV{'QUERY_STRING'}) ;

my $page = $query =~ /^(\S+\_\S+(\_\S+)?)$/
 ? $1
 : "Вики_Вики";  # $& is the last match

my $text = "";

if ( exists($kees{$page} )) {
	$_ = $kees{$page} ;
	s/&/&amp;/g;
	s/</&lt;/g;
	s/>/&gt;/g;
	s/$pomark/\n/g;
	$text = $_;
}

my %par;
$par{title} = "Edit $page";
$par{page} = $page;
$par{body} = <<ST  ;
	<form method=post action="save.pl?$page">
	<textarea name=Text rows=18 cols=60 wrap=virtual>$text</textarea>
	<p><input type="submit" value=" Save ">
      <input type="hidden" name="mode" value="$mode">
	</form>
ST


open(T, '../p_template.html') or die "template.html: $!";
undef $/;
$_ = <T>;
close(T);
s/\$(\w+)/defined($par{$1}) ? $par{$1} : ''/geo;
print;
$/ = "\n";


# == --  Russian Subs

sub urldecode{
 local($val)=@_;
 $val=~s/\+/ /g;
 $val=~s/%([0-9a-hA-H]{2})/pack('C',hex($1))/ge;
 return $val;
 }


