#!]2;jean-luc (pjdev)]1;jean-luc (pjdev)/usr/local/bin/perl
#
# Remove a project.

$installdir = "/httpd/bin/PJDev";
$hthome = "/www/Projects";


open(CONF,"< $installdir/Projects.conf");

while (<CONF>) {
    next if (/^$/||/^\#/);
    m/^(\S+) (.*)$/;
    $variable = $1;
    $value = $2;
    eval "\$$variable = \"$value\"";
}

print "Please enter the project code to remove\n";
print "> ";
$deadpj = <STDIN>;
chop $deadpj;
$deadpj =~ tr/[a-z]/[A-Z]/;

print "Are you sure you want to remove $deadpj (Y/N): ";
$yn = <STDIN>;
chop $yn;
$yn =~ tr/[a-z]/[A-Z]/;
if (!($yn =~ /Y/)) {
    print "Aborting\n";
    exit;
}

$sesame = open (KILLME,"$userlistfile");
open (TMP,"> $$.tmp");
$killing = 0;
$gotit = 0;

while (<KILLME>) {
    $killing = 0 if (/&&/);
    if (/^$deadpj&&/) {
	print "$_ Started my killing\n";
	$killing = 1;
	$gotit = 1;
    }
    print TMP if(!$killing);
}
print TMP "\n";

close TMP;
close KILLME;

if ($gotit == 0) {
    print "$deadpj does not seem to be a current project";
    exit;
}

unlink ("$userlistfile");
link ("$$.tmp","$userlistfile");
unlink("$$.tmp");


while (<KILLME>) {
    if (m/^\<b\>From\:\<\/b\>/) {
	$FromLine = $'; #'
	$FromLine = m/\b(\S+\@\S+)\b/;
	$killedemail = $1;
	print "ORIGINATED BY $killedemail\n";
    }
    last if (/\<hr\>/);
}


# Open the index and strip out any references to this project
open (IND, "< $hthome/index.html" ) || die "no index $hthome/$index.html";

    
open (NEWIN, "> $hthome/tmp.new" ) || die "no output";
while (<IND>) {
    print NEWIN if (!(m/\<a href=\"$deadpj\"\>/));  #"
}
close IND;
close NEWIN;
unlink("$hthome/index.html");
link("$hthome/tmp.new","$hthome/index.html");
unlink ("$hthome/tmp.new");
# Clean up
system("/bin/rm $hthome/$deadpj/*");
system("/bin/rmdir $hthome/$deadpj");
print "\n$deadpj Succesfully Removed\n";
