#!]2;jean-luc (pjdev)]1;jean-luc (pjdev)/usr/local/bin/perl
#-*-perl-*-

$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\"";
}

# Makes a new project

print "=============================\n";
print "    CREATE A NEW PROJECT     \n";
print "=============================\n";
print "\n";
print "Enter Project Code : ";
$newpj = <STDIN>;
chop $newpj;
$newpj =~ tr/[a-z]/[A-Z]/;

# Make sure the project doesnt already exist.
open(LIST, "< $userlistfile") || die "CONFIGURATION ERROR: list file\n";
while (<LIST>) {
    if (/\&\&/) {
	($apj) = split ('\&\&');
	if ($newpj eq $apj) {
	    print "$newpj exists\n";
	}
    }
}


print "Enter Description  : ";
$desc = <STDIN>;
chop $desc;


print "Enter 1 to allow posting only from users and domain names,\n";
print "  0 for a Free for all   : ";
$at = <STDIN>;
chop $at;


print "Enter 1 to send all posts to all usernames on project list,\n";
print "  0 to disable this feature for this project   : ";
$bi = <STDIN>;
chop $bi;print "$desc\n";



print "Enter Valid Users and Domain Names with a blank like to terminate\n";
print "> ";
$currline = <STDIN>;
chop $currline;
$users = $currline;
while (!($currline =~ m/^$/)) {
    print "> ";
    $currline = <STDIN>;
    chop $currline;
    $users .= " ".$currline;
}

# Output to and Close the list file
print "LIST FILE ENTRY:\n";
$DATE = `date`;
($wkday, $mo, $day, $time, $j, $yr) = split(' ', $DATE);
print  "\n\n\# $newpj added $wkday $mo $day, $yr\n";
print  "$newpj&&$at&&$bi&&$desc\n";
foreach $USER (split(' ',$users)) {
    print  "   $USER\n";
}


print "\nAdd this Entry [y/n]  : ";
$yn = <stdin>;
$yn =~ tr/[A-Z]/[a-z]/;
chop $yn;


if ($yn =~ /y/) {
    open(LIST, ">> $userlistfile") || die "CONFIGURATION ERROR: list file\n";
    print LIST "\n\n\# $newpj added $wkday $mo $day, $yr\n";
    print LIST "$newpj&&$at&&$bi&&$desc\n";
    foreach $USER (split(' ',$users)) {
	print LIST "   $USER\n";
    }
    close LIST;
    #  Create directory for Project
    system ("mkdir -p $hthome/$newpj");
    system ("chmod 755 $hthome/$newpj");

    open(LIST,"< $hthome/index.html");
    open(TMP, "> $hthome/$$.html");
    while (<LIST>) {
	print TMP if (!(/<\/UL>/));
	tr/[a-z]/[A-Z]/;
	print TMP "<LI><a href=\"$newpj\">$newpj<\/a> $desc\n<\/UL>\n" 
	    if /\<\/UL\>/;
    }
    close LIST;
    close TMP;
    unlink ("$hthome/index.html");
    link ("$hthome/$$.html","$hthome/index.html");
    unlink("$hthome/$$.html");
    system ("chmod 644 $hthome/index.html");
    
    open(PROJECT,"> $hthome/$newpj/index.html");
    
    print PROJECT <<NEWPJ;
<html>
<title>$desc</title>
<h1>$desc</h1>
Projects Page with code $newpj
<hr>
<ul>
</ul>
<hr>
$organization Projects Page

NEWPJ
    

    # Go Home
    print " === $newpj Successfully Added ===\n";
} else {
    print " === $newpj addition aborted ===\n";
}


