#!/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 OMA;
use REBOOT;
use XSQL;
use HTTP::Date;
use Lists;

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


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

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

	if($in{'username'}) {
		$username = ",username = '$in{'username'}'";
	}

	$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	reboot_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 = '$in{'dc__description__long'}',
				expire = $in{'expire'}
				$username
		WHERE	id=$in{'ID'}
		AND location='$in{'base'}'");

	if($in{'dc__creator'} && $in{'dc__creator__role'}) {
		XSQL::transact("
			INSERT INTO reboot_creator
			VALUES (	$in{'ID'},
						'$REBOOT::HOST',
						'$in{'dc__creator'}',
						'$in{'dc__creator__role'}'
			)
		");
	}
	if($in{'dc__contributor'} && $in{'dc__contributor__role'}) {
		XSQL::transact("
			INSERT INTO reboot_contributor
			VALUES (	$in{'ID'},
						'$REBOOT::HOST',
						'$in{'dc__contributor'}',
						'$in{'dc__contributor__role'}'
			)
		");
	}
	if($in{'dc__relation__type'} && $in{'dc__relation__value'}) {
		XSQL::transact("
			INSERT INTO reboot_relation
			VALUES (	$in{'ID'},
						'$REBOOT::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 reboot_creator
				WHERE	ID=$in{'ID'}
				AND		location='$REBOOT::HOST'
				AND		dc__creator='$creator'
				AND		dc__creator__role='$role'
			");
		}
		if($k =~ /^del_contributor/) {
			local ($del,$contributor,$role) = split(/:/,$in{$k});
			XSQL::transact("
				DELETE FROM reboot_contributor
				WHERE	ID=$in{'ID'}
				AND		location='$REBOOT::HOST'
				AND		dc__contributor='$contributor'
				AND		dc__contributor__role='$role'
			");
		}
		if($k =~ /^del_relation/) {
			local ($del,$type,$value) = split(/:/,$in{$k});
			XSQL::transact("
				DELETE FROM reboot_relation
				WHERE	ID=$in{'ID'}
				AND		location='$REBOOT::HOST'
				AND		dc__relation__type='$type'
				AND		dc__relation__value='$value'
			");
		}
	}

		
	$st = $db->prepare("
		SELECT	*
		FROM	reboot_conn
		WHERE	reboot_conn.reboot_page=$in{'ID'}
		AND		reboot_conn.location='$REBOOT::HOST'
	");
	$st->execute();
	$st->bind_columns(\(@hashrow{@{$st->{NAME_lc}}}));


	$deps = $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
			WHERE	type != 'meta'
			AND		(sid=$hashrow{item_sid}
			AND		link_item=0)
		");
	}
	$st->finish();

	print "DONE.\n";
}





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

sub save {
	local $deps, $ID, $i;

	$ID = time;

	mkdir("$REBOOT::REBOOT_PATH/$ID",0775) or die "Can't create desired directory";
	$in{'dc__format__encoding'} = `file $REBOOT::DOWNLOAD/$ENV{'REMOTE_USER'}/$in{'dc__identifier'}`;
	$in{'dc__format__extent'} = 0;
	system("mv \"$REBOOT::DOWNLOAD/$ENV{'REMOTE_USER'}/$in{'dc__identifier'}\" $REBOOT::REBOOT_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 reboot_page
		VALUES (	$ID,
					'$REBOOT::HOST',
					'$ENV{'REMOTE_USER'}',
					$in{'expire'},
					'$REBOOT::REBOOTDATA',
					'$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 reboot_creator
		VALUES (	$ID,
					'$REBOOT::HOST',
					'$in{'dc__creator'}',
					'$in{'dc__creator__role'}'
		)
	");
	XSQL::transact("
		INSERT INTO reboot_contributor
		VALUES (	$ID,
					'$REBOOT::HOST',
					'$in{'dc__contributor'}',
					'$in{'dc__contributor__role'}'
		)
	");
	XSQL::transact("
		INSERT INTO reboot_relation
		VALUES (	$ID,
					'$REBOOT::HOST',
					'$in{'dc__relation__type'}',
					'$in{'dc__relation__value'}'
		)
	");


	$deps = $in{'department'};
	my $newsid = OMA::nextsid("item_sid");
	XSQL::transact("
		INSERT INTO item
		VALUES (	$newsid,
				$deps,
				'$in{'dc__title'}',
					'reboot',
					0,
					0
		)
	");
	XSQL::transact("
		INSERT INTO reboot_conn
		VALUES (	$newsid,
				$ID,
				'$REBOOT::HOST',
				0,
				$newsid
		)
	");
	print "DONE.\n";
}



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

sub del {
	print "$REBOOT::REBOOT_BODY";
	print "<b>[reboot]</b><p/><p/>";
	print "delete all related with $in{'ID'}\n";
	if(-d "$REBOOT::REBOOT_PATH/$in{'ID'}") {
		system("rm -rf $REBOOT::REBOOT_PATH/$in{'ID'}");	
	}

	$st = $db->prepare("
		SELECT	*
		FROM	reboot_conn
		WHERE	reboot_conn.reboot_page=$in{'ID'}
		AND		reboot_conn.location='$REBOOT::HOST'");
	$st->execute();

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

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

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

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

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

	XSQL::transact("
		DELETE FROM reboot_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);

	$in{'expire'} = 0 if(!$in{'expire'});
	$in{'dc__format__extent'} = 0 if(!$in{'dc__format__extent'});
	
	print "$REBOOT::REBOOT_BODY";
	print "<b>[reboot]</b>";

	if($in{'op2'} ne "delete") {
		$deps = $in{'department'};
		if($deps !~ /^\d+$/) {
			$d = $deps;
			$deps = OMA::getnode($deps);
			if(!$deps) {
				OMA::makebranch($d);
				$deps = OMA::getnode($d);
			}
		}
		$d = OMA::getpath($deps);
	} else {
		$d = OMA::getpath($in{'ID'});
	}
	if((!$in{'dc__identifier'}
	||	!$in{'dc__title'}
	||	!$deps)
	&&	($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>";

	chop($in{'dc__identifier'});

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

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

	print "
Your entry is:
<br>
<i>title:</i> <b>$in{'dc__title'}</b> |
<i>program title:</i> <b>$in{'dc__title__alternative'}</b> |
<i>days to live:</i> <b>$in{'expire'}</b> |
<i>locations:</i> <b>$d ($deps)</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>spatial:</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-
<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=username value="$in{'username'}">
<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";
<br>
<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;
	local $userlist="";
	local $debS="";
	local $lics="";

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

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

		if($ENV{'REMOTE_USER'} eq "admin") {
			$st = $db->prepare("SELECT username FROM users ORDER BY username");
			$st->execute();
			$userlist = "<select name=username>";
			while(@row=$st->fetchrow()) {
				$row[0] =~ s/(\ )*$//;
				if($row[0] eq $hashrow{username}) {
					$userlist .= "<option selected>$row[0]";
				} else {
					$userlist .= "<option>$row[0]";
				}
			}
			$st->finish();
			$userlist .= "</select>";
		}

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



		$st = $db->prepare("
			SELECT	dc__creator,dc__creator__role
			FROM	reboot_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	reboot_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	reboot_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 $REBOOT::DOWNLOAD/$ENV{'REMOTE_USER'}/* 2> /dev/null |");
		while(<P>) {
		        $_ =~ s/$REBOOT::DOWNLOAD\/$ENV{'REMOTE_USER'}\///g;
			$_ = "<OPTION>$_";
			$fileselect .= $_;
    		}
	    close(P);
		$fileselect .= "</select>\n";
		$in{'dc__format__extent'} = 0;
		$in{'extent'} = 0;

	}


	$deps = Lists->getContainers($ENV{'REMOTE_USER'},$depS);
	if(!$deps) {
		$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";
			}
		}
	}

	foreach $i ('', 'Public Domain Dedication', 'The Founders Copyright', 'CC: GNU GPL',
				'CC: GNU LGPL', 'CC: Attribution', 'CC: Attrib.-NoDerivs',
				'CC: Attrib.-NoDerivs-NonCommercial', 'CC: Attrib.-NonCommercial',
				'CC: Attrib.-NonCommercial-ShareAlike', 'CC: Attribution-ShareAlike',
				'CC: NoDerivs', 'CC: NoDerivs-NonCommercial',
				'CC: NonCommercial', 'CC: NonCommercial-ShareAlike', 'CC: ShareAlike') {
		if($hashrow{dc__rights__license}) {
			$lics .= "<option selected>$i</option>";
		} else {
			$lics .= "<option>$i</option>";
		}
	}
	

	{
		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);
			}
		}
	}

	my $languages = Lists->getLangs($hashrow{dc__language});
	my $countries = Lists->getCountries($hashrow{dc__coverage__spatial});
	$hashrow{expire} = $hashrow{expire} + 1;
	$hashrow{expire} = $hashrow{expire} - 1;
	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">
</td><td>
$userlist
</td></tr>

<tr><td align="right" style="color:#cc0000">
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">
Select uploaded file&nbsp;
</td><td>
$fileselect
</td></tr>

<tr><td width="200" align="right" style="color:#cc0000">
Title of the series&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">
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">$lics</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 assistant&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 value=\"\">LANGUANGE LIST</option>
$languages
</select>
</td></tr>

<tr><td align="right">
Reginonal context&nbsp;
</td><td>
<select name="dc__coverage__spatial" style="width:400px">
<option value=\"\">COUNTRY LIST</option>
$countries
</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=base value=$in{'base'}>
<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=hidden name=base value=$in{'base'}>
<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 = REBOOT::opendb();

if($msg=OMA::opallowed($in{'ID'},$in{'base'},'reboot')) {
	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();

