#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


use DBI;
use CGI;
use OMA;
use OTA;
use XSQL;
use HTTP::Date;
use Unicode::String qw(utf8 latin1 utf16);

local (%in, @row, $st, , $trans);
undef(%in);
undef(@row);
undef($trans);


                   ###            ##
                    ##            ##
 ##  ## ## ###   #####   ####    #####    ####
 ##  ##  ##  ## ##  ##      ##    ##     ##  ##
 ##  ##  ##  ## ##  ##   #####    ##     ######
 ##  ##  #####  ##  ##  ##  ##    ## ##  ##
  #####  ##      ### ##  ### ##    ###    ####
        ####
sub update {
	local @deps;
	local (%hashrow, %hashrow2);
	local ($st, $nst);
	local @row;

	foreach $k (keys %in) {
		$in{$k} =~ s/'/\'/g;
		$in{$k} =~ s/"/&quot;/g;
	}
	$in{'expire'} = 0 if(!$in{'expire'});

	$in{'dc__date__created'}=str2time("$in{created_yy}-$in{created_mm}-$in{created_dd}","GMT");

#				dc__date__issued = '$in{'dc__date__issued'}',
#				dc__format__extent = $in{'dc__format__extent'},
#				dc__format__medium = '$in{'dc__format__medium'}',
#				dc__format__encoding = '$in{'dc__format__encoding'}',
#				dc__date__digitized = '$in{'dc__date__digitized'}',
	XSQL::transact("
		UPDATE	ota_page
		SET		dc__title = '$in{'dc__title'}',
				dc__title__alternative = '$in{'dc__title__alternative'}',
				dc__publisher = '$in{'dc__publisher'}',
				dc__type = '$in{'dc__type'}',
				dc__subject = '$in{'dc__subject'}',
				dc__language = '$in{'dc__language'}',
				dc__coverage__spatial = '$in{'dc__coverage__spatial'}',
				dc__coverage__temporal = '$in{'dc__coverage__temporal'}',
				dc__date__created = $in{'dc__date__created'},
				dc__source = '$in{'dc__source'}',
				dc__rights = '$in{'dc__rights'}',
				dc__rights__license = '$in{'dc__rights__license'}',
				dc__description__toc = '$in{'dc__description__toc'}',
				dc__description__abstract = '$in{'dc__description__abstract'}',
				dc__description__long = '". utf8($in{'dc__description__long'}) ."',
				expire = $in{'expire'}
		WHERE	id=$in{'ID'}
--		AND location='$in{'base'}'");

	if($in{'dc__creator'} && $in{'dc__creator__role'}) {
		XSQL::transact("
			INSERT INTO ota_creator
			VALUES (	$in{'ID'},
						'$OTA::HOST',
						'$in{'dc__creator'}',
						'$in{'dc__creator__role'}'
			)
		");
	}
	if($in{'dc__contributor'} && $in{'dc__contributor__role'}) {
		XSQL::transact("
			INSERT INTO ota_contributor
			VALUES (	$in{'ID'},
						'$OTA::HOST',
						'$in{'dc__contributor'}',
						'$in{'dc__contributor__role'}'
			)
		");
	}
	if($in{'dc__relation__type'} && $in{'dc__relation__value'}) {
		XSQL::transact("
			INSERT INTO ota_relation
			VALUES (	$in{'ID'},
						'$OTA::HOST',
						'$in{'dc__relation__type'}',
						'$in{'dc__relation__value'}'
			)
		");
	}


	foreach $k (keys %in) {
		if($k =~ /^del_creator/) {
			local ($del,$creator,$role) = split(/:/,$in{$k});
			XSQL::transact("
				DELETE FROM ota_creator
				WHERE	ID=$in{'ID'}
				AND		location='$in{'base'}'
				AND		dc__creator='$creator'
				AND		dc__creator__role='$role'
			");
		}
		if($k =~ /^del_contributor/) {
			local ($del,$contributor,$role) = split(/:/,$in{$k});
			XSQL::transact("
				DELETE FROM ota_contributor
				WHERE	ID=$in{'ID'}
				AND		location='$in{'base'}'
				AND		dc__contributor='$contributor'
				AND		dc__contributor__role='$role'
			");
		}
		if($k =~ /^del_relation/) {
			local ($del,$type,$value) = split(/:/,$in{$k});
			XSQL::transact("
				DELETE FROM ota_relation
				WHERE	ID=$in{'ID'}
				AND		location='$in{'base'}'
				AND		dc__relation__type='$type'
				AND		dc__relation__value='$value'
			");
		}
	}

		
	$st = $db->prepare("
		SELECT	*
		FROM	ota_conn
		WHERE	ota_conn.ota_page=$in{'ID'}
		AND		ota_conn.location='$in{'base'}'
	");
	$st->execute();
	$st->bind_columns(\(@hashrow{@{$st->{NAME_lc}}}));


	@deps = split(/\000/,$in{'department'});

	while(@row = $st->fetchrow()) {
		XSQL::transact("
			UPDATE	item
			SET		description = '$in{'dc__title'}'
			WHERE	type != 'meta'
			AND		(sid=$hashrow{item_sid}
			OR		link_item=$hashrow{item_sid})
		");
		XSQL::transact("
			UPDATE	item
			SET		node_sid = $deps[0]
			WHERE	type != 'meta'
			AND		(sid=$hashrow{item_sid}
			AND		link_item=0)
		");
	}
	$st->finish();

	print "DONE.\n";
}





  ####   ####    ##  ##   ####
 ##         ##   ##  ##  ##  ##
  ####   #####   ##  ##  ######
     ## ##  ##    ####   ##
 #####   ### ##    ##     ####

sub save {
	local @deps, $ID, $i;
	undef(@deps);

	$ID = time;

	if(0) {
	mkdir("$OTA::OTA_PATH/$ID",0775) or die "Can't create desired directory ($OTA::OTA_PATH/$ID)";
	$in{'dc__format__encoding'} = `file $OTA::DOWNLOAD/$ENV{'REMOTE_USER'}/$in{'dc__identifier'}`;
	$in{'dc__format__extent'} = 0;
	system("mv \"$OTA::DOWNLOAD/$ENV{'REMOTE_USER'}/$in{'dc__identifier'}\" $OTA::OTA_PATH/$ID") if($in{'dc__identifier'});
	}

	foreach $k (keys %in) {
		$in{$k} =~ s/'/\'/g;
		$in{$k} =~ s/"/&quot;/g;
	}
	
	$in{'expire'} = 0 if(!$in{'expire'});
	$in{'dc__format__extent'} = 0 if(!$in{'dc__format__extent'});
	$in{'dc__date__created'}=str2time("$in{created_yy}-$in{created_mm}-$in{created_dd}","GMT");
	$in{'dc__date__issued'} = 0;

	XSQL::transact("
		INSERT INTO ota_page
		VALUES (	$ID,
					'$OTA::HOST',
					'$ENV{'REMOTE_USER'}',
					$in{'expire'},
					'$OTA::OTADATA',
					'$in{'dc__title'}',
					'$in{'dc__title__alternative'}',
					'archive.reboot.fm',
					$in{'dc__date__issued'},
					$in{'dc__date__created'},
					$ID,
					$in{'dc__format__extent'},
					'$in{'dc__format__medium'}',
					'$in{'dc__format__encoding'}',
					'$in{'dc__identifier'}',
					'$in{'dc__source'}',
					'$in{'dc__rights'}',
					'$in{'dc__rights__license'}',
					'$in{'dc__description__toc'}',
					'$in{'dc__description__abstract'}',
					'$in{'dc__description__long'}',
					'$in{'dc__type'}',
					'$in{'dc__subject'}',
					'$in{'dc__language'}',
					'$in{'dc__coverage__spatial'}',
					'$in{'dc__coverage__temporal'}'
		)
	");

	XSQL::transact("
		INSERT INTO ota_creator
		VALUES (	$ID,
					'$OTA::HOST',
					'$in{'dc__creator'}',
					'$in{'dc__creator__role'}'
		)
	");
	XSQL::transact("
		INSERT INTO ota_contributor
		VALUES (	$ID,
					'$OTA::HOST',
					'$in{'dc__contributor'}',
					'$in{'dc__contributor__role'}'
		)
	");
	XSQL::transact("
		INSERT INTO ota_relation
		VALUES (	$ID,
					'$OTA::HOST',
					'$in{'dc__relation__type'}',
					'$in{'dc__relation__value'}'
		)
	");

	@deps = split(/\000/,$in{'department'});
	for($i=0;$i<=$#deps;$i++) {
		my $newsid = OMA::nextsid("item_sid");
		XSQL::transact("
			INSERT INTO item
			VALUES (	$newsid,
						$deps[$i],
						'$in{'dc__title'}',
						'ota',
						0,
						0
			)
		");
		XSQL::transact("
			INSERT INTO ota_conn
			VALUES (	$newsid,
						$ID,
						'$OTA::HOST',
						0,
						$newsid
			)
		");
	}
	print "DONE.\n";
}



   ###            ###
    ##             ##
 #####    ####     ##
##  ##   ##  ##    ##
##  ##   ######    ##
##  ##   ##        ##
 ### ##   ####    ####

sub del {
	print "delete all related with $in{'ID'}\n";
	if(-d "$OTA::OTA_PATH/$in{'ID'}") {
		system("rm -rf $OTA::OTA_PATH/$in{'ID'}");	
	}

	$st = $db->prepare("
		SELECT	*
		FROM	ota_conn
		WHERE	ota_conn.ota_page=$in{'ID'}
		AND		ota_conn.location='$in{'base'}'");
	$st->execute();

	while(@row=$st->fetchrow()) {
		XSQL::transact("DELETE FROM item WHERE item.sid = $row[0] AND item.type='ota'");
	}
	$st->finish();

	XSQL::transact("
		DELETE FROM ota_conn
		WHERE	ota_conn.ota_page=$in{'ID'}
		AND		ota_conn.location='$in{'base'}'
	");

	XSQL::transact("
		DELETE FROM ota_page
		WHERE	id=$in{'ID'}
		AND		location='$in{'base'}'
	");

	XSQL::transact("
		DELETE FROM ota_relation
		WHERE	id=$in{'ID'}
		AND		location='$in{'base'}'
	");

	XSQL::transact("
		DELETE FROM ota_contributor
		WHERE	id=$in{'ID'}
		AND		location='$in{'base'}'
	");

	XSQL::transact("
		DELETE FROM ota_creator
		WHERE	id=$in{'ID'}
		AND		location='$in{'base'}'
	");
}



                        ###                     ###
                         ##                      ##
  #####   ####           #####   ####     ####   ##  ##
 ##  ##  ##  ##          ##  ##     ##   ##  ##  ## ##
 ##  ##  ##  ##          ##  ##  #####   ##      ####
  #####  ##  ##          ##  ## ##  ##   ##  ##  ## ##
     ##   ####          ## ###   ### ##   ####  ###  ##
 #####          ########
sub go_back {
	print "You did not enter something in the field <b>$_[0]</b>.
Please <a href=javascript:this.back()>switch back</a> to correct this.

";
}



                                   ###
                                  ## ##
## ###  ## ###    ####    ####    ##
 ##  ##  ### ##  ##  ##  ##  ##  ####
 ##  ##  ##      ##  ##  ##  ##   ##
 #####   ##      ##  ##  ##  ##   ##
 ##     ####      ####    ####   ####
####
sub proof {
	local (@deps, $d="", $i, $op);
	undef(@deps);

	$in{'expire'} = 0 if(!$in{'expire'});
	$in{'dc__format__extent'} = 0 if(!$in{'dc__format__extent'});
	
	print "$OTA::OTA_BODY";
	print "<b>[ota]</b>";

	if((!$in{'dc__title'}
	||	!$in{'department'})
	&&	($in{'op2'} ne "delete")) {
		print "SORRY! YOU FORGET TO SELECT MEDIA FILE OR ENTER A TITLE OR SELECT A NODE\n";
		exit;
	}
	print "<table><tr><td><form method=post>";
	@deps = split(/\000/,$in{'department'});
	for($i=0;$i<=$#deps;$i++) {
		$d .= OMA::getpath($deps[$i]). ", ";
#		print "<input type=hidden name=department value=\"$deps[$i]\">";
	}

	print "<input type=hidden name=department value=\"$in{'department'}\">";
	$op = "<input type=hidden name=op value=save>";
	$op = "<input type=hidden name=op value=update> <input type=hidden name=ID value=$in{'ID'}>" if($in{'op2'} eq "update");
	$op = "<input type=hidden name=op value=delete> <input type=hidden name=ID value=$in{'ID'}>" if($in{'op2'} eq "delete");

$in{'abstract'} =~ s/"/&quot;/g;

    print "
Your entry is:
<i>title</i> <b>$in{'dc__title'}</b> |
<i>program title: $in{'dc__title__program_title'}</b> |
<i>days to live</i> <b>$in{'expire'}</b> |
<i>locations</i> <b>$d</b> |
<i>file</i> <b>$in{'dc__identifier'}</b> |
<i>publisher</i> <b>$in{'dc__publisher'}</b> |
<i>type</i> <b>$in{'dc__type'}</b> |
<i>subject</i> <b>$in{'dc__subject'}</b> |
<i>language</i> <b>$in{'dc__language'}</b> |
<i>spacial</i> <b>$in{'dc__coverage__spatial'}</b> |
<i>temporal</i> <b>$in{'dc__coverage__temporal'}</b> |
<i>issued</i> <b>$in{'dc__date__issued'}</b> |
<i>created</i> <b>$in{'dc__date__created'}</b> |
<i>digitized</i> <b>$in{'dc__date__digitized'}</b> |
<i>extent</i> <b>$in{'dc__format__extent'}</b> |
<i>medium</i> <b>$in{'dc__format__medium'}</b> |
<i>encoding</i> <b>$in{'dc__format__encoding'}</b> |
<i>source</i> <b>$in{'dc__source'}</b> |
<i>rights</i> <b>$in{'dc__rights'}</b> |
<i>license</i> <b>$in{'dc__rights__license'}</b> |
<i>creator</i> <b>$in{'dc__creator__role'} - $in{'dc__creator'}</b> |
<i>contributor</i> <b>$in{'dc__contributor__role'} - $in{'dc__contributor'}</b> |
<i>relation</i> <b>$in{'dc__relation__type'} - $in{'dc__relation__value'}</b> 
<br>
description-
<br>
<i>TOC :</i><br>
$in{'dc__description__toc'}
<p>
<i>abstract :</i><br>
$in{'dc__description__abstract'}
<p>
<i>long :</i><br>
$in{'dc__description__long'}
<p>
";

	foreach $k (keys %in) {
		$in{$k} =~ s/'/\\'/g;
		$in{$k} =~ s/"/&quot;/g;
		if($k =~ /del_/) {
			print "<input type=hidden name=\"$k\" value=\"$k\">";
		}
	}

	print <<"EOT";
<input type=hidden name=dc__title value="$in{'dc__title'}">
<input type=hidden name=dc__title__alternative value="$in{'dc__title__alternative'}">
<input type=hidden name=expire value="$in{'expire'}">
<input type=hidden name=dc__identifier value="$in{'dc__identifier'}">
<input type=hidden name=dc__publisher value="$in{'dc__publisher'}">
<input type=hidden name=dc__type value="$in{'dc__type'}">
<input type=hidden name=dc__subject value="$in{'dc__subject'}">
<input type=hidden name=dc__language value="$in{'dc__language'}">
<input type=hidden name=dc__coverage__spatial value="$in{'dc__coverage__spatial'}">
<input type=hidden name=dc__coverage__temporal value="$in{'dc__coverage__temporal'}">
<input type=hidden name=dc__date__issued value="$in{'dc__date__issued'}">
<input type=hidden name=dc__date__created value="$in{'dc__date__created'}">
<input type=hidden name=dc__date__digitized value="$in{'dc__date__digitized'}">
<input type=hidden name=dc__format__extent value="$in{'dc__format__extent'}">
<input type=hidden name=dc__format__medium value="$in{'dc__format__medium'}">
<input type=hidden name=dc__format__encoding value="$in{'dc__format__encoding'}">
<input type=hidden name=dc__source value="$in{'dc__source'}">
<input type=hidden name=dc__rights value="$in{'dc__rights'}">
<input type=hidden name=dc__rights__license value="$in{'dc__rights__license'}">
<input type=hidden name=dc__description__toc value="$in{'dc__description__toc'}">
<input type=hidden name=dc__description__abstract value="$in{'dc__description__abstract'}">
<input type=hidden name=dc__description__long value="$in{'dc__description__long'}">
<input type=hidden name=dc__creator value="$in{'dc__creator'}">
<input type=hidden name=dc__creator__role value="$in{'dc__creator__role'}">
<input type=hidden name=dc__contributor value="$in{'dc__contributor'}">
<input type=hidden name=dc__contributor__role value="$in{'dc__contributor__role'}">
<input type=hidden name=dc__relation__type value="$in{'dc__relation__type'}">
<input type=hidden name=dc__relation__value value="$in{'dc__relation__value'}">
<input type=hidden name=created_yy value="$in{'created_yy'}">
<input type=hidden name=created_mm value="$in{'created_mm'}">
<input type=hidden name=created_dd value="$in{'created_dd'}">

$op
EOT

	go_back("dc__identifier") if(!$in{'dc__identifier'});
	go_back("dc__title") if(!$in{'dc__title'});

	print <<"EOT";
<input type=submit value=\"I am responsible.\">
</form>
EOT
}



                                ###
                                 ##
  ####   ## ##   ####     ####   ##  ##
 ##  ## #######     ##   ##      ## ##
 ###### ## # ##  #####    ####   ####
 ##     ## # ## ##  ##       ##  ## ##
  ####  ##   ##  ### ##  #####  ###  ##

sub emask {
	local $deps;
	local @row;
	local $abstract;
	local %deps_s;
	local %hashrow;
	local $op2;
	local $relation;
	local $creator;
	local $contributor;
	local ($created_yy, $created_mm, $created_dd);
	local $fileselect;

	undef(@row);
	undef(%deps_s);
	undef(%hashrow);
	undef(@abstract);
	$deps = "";

	#UPDATE
	if($in{'ID'}) {
		$st = $db->prepare("
				SELECT	*
				FROM	ota_page
				WHERE	id=$in{'ID'}
				AND		location='$in{'base'}'
		");
		$st->execute();
		$st->bind_columns(\(@hashrow{@{$st->{NAME_lc}}}));
		@row = $st->fetchrow();
		$st->finish();

		$deps="";
		$st = $db->prepare("
			SELECT	ota_conn.ota_page,item.node_sid
			FROM	ota_conn, item
 			WHERE	ota_conn.item_sid = item.sid
		 	AND		ota_conn.ota_page=$in{'ID'}
			AND		ota_conn.location='$in{'base'}'
			AND		item.link_item=0
			AND		item.type <> 'meta'
		");
		$st->execute();
		while(@row=$st->fetchrow()) {
		 	$deps_s{$row[1]} = $row[0];
 		}
 		$st->finish();
		$op2 = "<input type=hidden name=op2 value=update>";



		$st = $db->prepare("
			SELECT	dc__creator,dc__creator__role
			FROM	ota_creator
 			WHERE	ID=$in{'ID'}
			AND		location='$in{'base'}'
		");
		$st->execute();
		while(@row=$st->fetchrow()) {
			$creator .= "<input type=checkbox name=\"del_creator:$row[0]:$row[1]\" value=\"del_creator:$row[0]:$row[1]\">delete $row[0] as an $row[1]<br/>";
		}
		$st->finish();



		$st = $db->prepare("
			SELECT	dc__contributor,dc__contributor__role
			FROM	ota_contributor
 			WHERE	ID=$in{'ID'}
			AND		location='$in{'base'}'
		");
		$st->execute();
		while(@row=$st->fetchrow()) {
			$contributor .= "<input type=checkbox name=\"del_contributor:$row[0]:$row[1]\" value=\"del_contributor:$row[0]:$row[1]\">delete $row[0] as an $row[1]<br>";
		}
		$st->finish();



		$st = $db->prepare("
			SELECT	dc__relation__type,dc__relation__value
			FROM	ota_relation
 			WHERE	ID=$in{'ID'}
			AND		location='$in{'base'}'
		");
		$st->execute();
		while(@row=$st->fetchrow()) {
			$relation .= "<input type=checkbox name=\"del_relation:$row[0]:$row[1]\" value=\"del_relation:$row[0]:$row[1]\">relation: $row[1], is: $row[0]<br>";
		}
		$st->finish();

		{
			my @t = split(/\//,$hashrow{'dc__identifier'});
			$fileselect = $t[$#t];
		}

	} else {

	#NEW ENTRY
		$fileselect = "<select name=dc__identifier style=\"width:400px\">\n";
		open(P,"/bin/ls $OTA::DOWNLOAD/$ENV{'REMOTE_USER'}/* 2> /dev/null |");
		while(<P>) {
	        $_ =~ s/$OTA::DOWNLOAD\/$ENV{'REMOTE_USER'}\///g;
			$_ = "<OPTION> $_";
			$fileselect .= $_;
    	}
	    close(P);
		$fileselect .= "</select>\n";
		$in{'dc__format__extent'} = 0;
		$in{'extent'} = 0;

	}


	$st = $db->prepare("SELECT * FROM treemap ORDER BY node");
	$st->execute();
	while(@row=$st->fetchrow()) {
		if($deps_s{$row[0]}) {
			$deps .= "<option value=$row[0] selected>$row[1]\n";
		}
		else {
			$deps .= "<option value=$row[0]>$row[1]\n";
		}
	}

	{
		my @lt;
		$created_yy = $created_mm = $created_dd = "";
		if($hashrow{dc__date__created}>0) {
			@lt = gmtime($hashrow{dc__date__created});
		} else {
			@lt = gmtime(time());
		}
			
		for($i=1970;$i<=2033;$i++) {
			if($i == $lt[5]+1900) {
				$created_yy .= "<option selected>$i";
			} else {
				$created_yy .= "<option>$i";
			}
		}
		for($i=1;$i<=12;$i++) {
			if($i == $lt[4]+1) {
				$created_mm .= sprintf("<option selected>%02d",$i);
			} else {
				$created_mm .= sprintf("<option>%02d",$i);
			}
		}
		for($i=1;$i<=31;$i++) {
			if($i == $lt[3]) {
				$created_dd .= sprintf("<option selected>%02d",$i);
			} else {
				$created_dd .= sprintf("<option>%02d",$i);
			}
		}
	}

	print <<"EOT";

<style>
body { font-family:arial; font-weight:bold; font-size:11px; color:#606060; background:#e0e0e0; }
td { font-family:arial; font-weight:bold; font-size:11px; }
input,textarea,select { font-family:arial; font-weight:bold; font-size:11px; background:#e0e0e0; }
</style>

<span style="font-family:helvetica">

<table border="0" cellpadding="0" cellspacing="0">

<form method="post">

<tr><th colspan="2" align="center">
About this transmission:
</th>
</tr>


<tr><td align="right" style="color:#cc0000">
Title&nbsp;
</td><td>
<input type="text" name="dc__title" style="width:400px" value="$hashrow{dc__title}"/>
</td></tr>


<tr><td align="right" style="color:#cc0000">
Select uploaded file&nbsp;
</td><td>
$fileselect
</td></tr>

<tr><td width="200" align="right" style="color:#cc0000">
Alternative title&nbsp;
</td><td>
<input type="text" name="dc__title__alternative"/ style="width:400px" value="$hashrow{dc__title__alternative}">
</td></tr>

<tr><td align="right" style="color:#cc0000">
Type of transmission&nbsp;
</td><td>
<select name="department" style="width:400px">$deps</select>
</td></tr>


<tr><td align="right">
Creation date (yyyy-mm-dd)&nbsp;
</td><td>
<select name="created_yy" style="width:184px">$created_yy</select>-
<select name="created_mm" style="width:100px">$created_mm</select>-
<select name="created_dd" style="width:100px">$created_dd</select>
</td></tr>

<tr><td align="right">
License holder&nbsp;
</td><td>
<input type="text" name="dc__rights" style="width:180px" value="$hashrow{dc__rights}"/> License <select name="dc__rights__license" style="width:176px">
<option></option>
<option>GPL</option>
</select>
</td></tr>

<tr><td align="right" valign="top">
Name of an executive person&nbsp;
</td><td>
<input type="text" name="dc__creator" style="width:180px" value="$hashrow{dc__creator}"/> Role <select name="dc__creator__role" style="width:192px">
<option></option>
<option>Artist</option>
<option>Author</option>
<option>Journalist</option>
<option>Cooperator</option>
<option>Editor</option>
<option>Group</option>
<option>Collective</option>
<option>Moderator</option>
</select>
<br/>
$creator
</td></tr>

<tr><td align="right" valign="top">
Name of an helper person&nbsp;
</td><td>
<input type="text" name="dc__contributor" style="width:180px" value="$hashrow{dc__ontributor}"/> Role <select name="dc__contributor__role" style="width:192px">
<option></option>
<option>Editor</option>
<option>Artist</option>
<option>Author</option>
<option>Support</option>
<option>Label</option>
<option>Club</option>
<option>Group</option>
<option>Collective</option>
<option>Guest</option>
</select>
<br/>
$contributor
</td></tr>

<tr><td colspan="2"><br/></td></tr>

<tr><td>
Brief description or subtitle&nbsp;
</td></tr>

<tr><td colspan="2">
<textarea cols="80" rows="3" name="dc__description__abstract" style="width:600px">$hashrow{dc__description__abstract}</textarea>
</td></tr>

<tr><td colspan="2">
Table of content or playlist (artist, title, album, label, length)&nbsp;
</td></tr>

<tr><td colspan="2">
<textarea cols="80" rows="9" name="dc__description__toc" style="width:600px">$hashrow{dc__description__toc}</textarea>
</td></tr>

<tr><td colspan="2">
Long description&nbsp;
</td></tr>

<tr><td colspan="2">
<textarea cols="80" rows="9" name="dc__description__long" style="width:600px">$hashrow{dc__description__long}</textarea>
</td></tr>

<tr><td colspan="2">
Keywords, may be build either from the title or description entry&nbsp;
</td></tr>

<tr><td colspan="2">
<input type="text" name="dc__subject"/ style="width:600px" value="$hashrow{dc__subject}">
</td></tr>

<tr><td colspan="2"><br/></td></tr>

<tr><td align="right">
Mostly used language&nbsp;
</td><td>
<select name="dc__language" style="width:400px">
<option></option>
<option>(sprachen)</option>
</select>
</td></tr>

<tr><td align="right">
Reginonal context&nbsp;
</td><td>
<select name="dc__coverage__spatial" style="width:400px">
<option></option>
<option>(staedteliste)</option>
</select>
</td></tr>

<tr><td align="right">
Related time period&nbsp;
</td><td>
<input type="text" name="dc__coverage__temporal"/ style="width:400px" value="$hashrow{dc__coverage__temporal}">
</td></tr>

<tr><td align="right">
Days to stay in archive (0=forever)&nbsp;
</td><td>
<input type="text" name="expire"/ style="width:400px" value="$hashrow{expire}">
</td></tr>

<tr>
<td colspan="2">
<br/>
<input type="submit" value="OK! Save this entry" style="font-size:16px; height:22px; width:600px; color:#008800; background:#e0e0e0;">
<br/>
<br/>
<br/>
<input type=hidden name=dc__identifier value="$hashrow{'dc__identifier'}">
<input type=hidden name=op value=proof>
$op2
<input type=hidden name=ID value=$in{'ID'}>
</form>
</td></tr>

<tr><td colspan="2">
<form method=post>
<input type=hidden name=op value=proof>
<input type=hidden name=op2 value=delete>
<input type=hidden name=ID value=$in{'ID'}>
<input type="submit" value="DELETE ! ! ? Delete it from the archive." style="font-size:16px; height:22px; width:600px; color:#880000; background:#e0e0e0;">
</form>

</td></tr>
</table>

</span>

<!--
     relation : <select name=dc__relation__type>
<option>IsVersionOf
<option>HasVersion
<option>IsReplacedBy
<option>Replaces
<option>IsRequiredBy
<option>Requires
<option>IsPartOf
<option>HasPart
<option>IsReferencedB
<option>References
<option>IsFormatOf
</select> relation: <input type=text name=dc__relation__value><br>
$relation
-->

EOT
}


##   ##            ##            ######         ##   ##
### ###           ####             ##           ###  ##
#######          ##  ##            ##           #### ##
#######          ##  ##            ##           ## ####
## # ##          ######            ##           ##  ###
##   ##          ##  ##            ##           ##   ##
##   ##          ##  ##          ######         ##   ##

CGI::ReadParse();
$db = OTA::opendb();
if($msg=OMA::opallowed($in{'ID'},$in{'base'},'ota')) {
    print $msg;
    exit;
}

XSQL::transopen();

del() if($in{'op'} eq "delete");
update() if($in{'op'} eq "update");
save() if($in{'op'} eq "save");
proof() if($in{'op'} eq "proof");
emask() if($in{'op'} eq "correct");
emask() if($in{'op'} eq "" || !defined($in{'op'}));

XSQL::transclose();

