#!/usr/bin/perl
#########################################
# import
# escorts ftp'd files into the database
#########################################
use localbucky;
my $pid;
$dbh = DBI->connect ($dsn);
our ($USER, $lastlog) = checkin();
logout() unless ($USER != -1);
if ($input->{c} eq "n")
{
my $valid = 0;
my $thread_id = 0;
if ($DEBUG)
{
header("importing files...");
foreach $k (sort keys %$input) { print "$k => ".$input->{$k}."
"; }
}
foreach my $k (keys %$input)
{
if ($k =~ /^import/)
{ $valid = 1; last; }
}
if ($valid)
{
if ($input->{id} && $input->{id} ne "new")
{
$thread = get_thread($input->{id});
$keyword = get_keyword($thread->{keyword});
if ($thread != -1 && check_privacy($thread, $keyword))
{
$thread_id = $thread->{id};
touch_thread($thread);
}
else
{
error("cannot import into specified thread");
}
}
else
{
if ($input->{title} eq undef || $input->{title} =~ /^\s+$/)
{
error ("No thread title!");
}
else
{
$thread_id = add_thread($input->{title}, $USER->{username}, 0);
}
}
print "thread_id => $thread_id
" if ($DEBUG);
add_comment($thread_id,-1,$USER->{username},$input->{comment}) if ($input->{comment} ne undef);
situate_imports($thread_id, $USER->{username});
if (exists($input->{keyword}))
{
my $k = get_keyword($input->{keyword});
if ($k->{public} || check_op($k))
{
keyword_assign_mechanism($input->{keyword}, $thread_id, $k);
}
}
}
else
{ error("No imports specified!"); }
if ($DEBUG)
{
print qq{this way to your new thread: link!};
footer();
}
redirect("$BUCKY/details/$thread_id");
}
else
{
my ($title, $size, $inc);
my $thread = -1;
my $keyword = -1;
if ($input->{id})
{
# id title username createdate lastmodified size private allowed flagged
$thread = get_thread($input->{id});
$keyword = get_keyword($thread->{keyword});
}
if ($input->{keyword})
{
$keyword = get_keyword($input->{keyword});
}
elsif ($thread->{keyword})
{
$keyword = get_keyword($thread->{keyword});
}
header("ftp import");
menu();
if ($USER->{'username'} eq "asdfasdfadsfadsf")
{
print <<__SORRY__;
Delete some things you've uploaded, then try again.