#!perl
# Gets WebPub info from config files.
# Called by importInfo.
#
BEGIN {
    @INC = ( '../../perl' );
}
use Cgi;
use BinUtil;
use ES40lnf;

$isNT = -d '\\';
my %pkgList = BinUtil::getPkgList($ENV{'NETSITE_ROOT'});

print "<!-- Start Form -->\n";
# web publishing section
ES40lnf::print_subheader("Document Root");
print "<TABLE CELLPADDING=\"5\">\n";
print "  <TR>\n";
ES40lnf::print_OpenTD();
print "   Please select a document root.\n";
print "   If you do not use the old server's document root, the documents on the\n";
print "   old server will not be visible from the migrated server.\n";
print "   Should you wish to revert back to the old server's document root, you can\n";
print "   always set the primary document root to the old server's document root from\n";
print "   the Content Management tab in the Web Server Administration Server.\n";
if (!$isNT && $pkgList{'webpub'}) {
    print "   <P>\n";
    print "   Note that if you use the old server's document root, you may encounter\n";
    print "   problems using the Web Publishing component if the primary document\n";
    print "   directory and the files under it are not owned by old server's user.\n";
}
print "   <P>\n";
print "   <TABLE>\n";
print "     <TR>\n";
print "      <TD VALIGN=\"top\">${ES40lnf::dfltFont}Document Root:</TD>\n";
ES40lnf::print_OpenTD();
print '      <INPUT TYPE="radio" NAME="docroot" VALUE="old" CHECKED>';
print "Use the same document root as the old server<BR>\n";
print '      <INPUT TYPE="radio" NAME="docroot" VALUE="new">';
print "Use the new server's document root\n";
print "      </TD>\n";
print "     <TR>\n";
print "   </TABLE>\n";
print "   </TD>\n  </TR>\n</TABLE>\n";

if ($pkgList{'webpub'}) {
    my $gotSearch = 0;
    $searchDir = "$cgiVars{'dir'}/$cgiVars{'server'}/search";
    my $x = 0;

    # web publishing
    if (-d "$searchDir/collections/web_htm") {
	print "\n<P>\n";
        ES40lnf::print_subheader("Web Publishing");
	print "<TABLE CELLPADDING=\"5\">\n  <TR>\n";
        ES40lnf::print_OpenTD();
	print "Metadata for the web publishing system exists in the old server.\n";
	print "Note that this metadata is associated with the documents in the old\n";
	print "server's document root.  If you migrate the metadata and do not use\n";
	print "the old server's document root, some of the migrated metadata may be invalid.\n";
	print "   <P>\n";
	print "   <TABLE CELLPADDING=\"0\" CELLSPACING=\"0\">\n";
	print "     <TR>\n ";
        ES40lnf::print_OpenTD();
	print "Migrate Web Publishing Metadata:";
        ES40lnf::print_CloseTD();
        ES40lnf::print_OpenTD();
	$x++;
	print "<INPUT TYPE=\"radio\" NAME=\"collection$x\" VALUE=\"web_htm\" CHECKED> Yes\n";
	print "<INPUT TYPE=\"radio\" NAME=\"collection$x\" VALUE=\"IGNORE\"> No\n";
        ES40lnf::print_CloseTD();
	print "     </TR>\n";
	print "   </TABLE>\n";
	print "   </TD>\n  </TR>\n</TABLE>\n";
    }
    # search collections
    opendir(SEARCHDIR, "$searchDir/collections") or 
	die "<FONT COLOR=\"red\">[Error]</FONT> Cannot open $searchDir/collections: $!.\n";
    while ($dir = readdir(SEARCHDIR)) {
	next if ($dir =~ /^\.$/ || $dir =~ /^\.\.$/ || $dir =~ /^web_htm$/ ||
		 $dir =~ /^html_doc$/ || $dir =~ /^link_mgr$/);
	if (-d "$searchDir/collections/$dir") {
	    if (!$gotSearch) {
		print "\n<P>\n";
	        ES40lnf::print_subheader("Search Collections");
		print "<TABLE CELLPADDING=\"5\">\n  <TR>\n";
	        ES40lnf::print_OpenTD();
		print "   Select the collections you would like to migrate:\n";
		print "   <TABLE CELLPADDING=\"0\" CELLSPACING=\"0\">\n";
		$gotSearch = 1;
	    }
	    print "     <TR>\n";
	  ES40lnf::print_OpenTD();
	    $x++;
	    print "&nbsp;<INPUT TYPE=\"checkbox\" NAME=\"collection$x\" VALUE=\"$dir\">$dir</TD>\n";
	    print "     </TR>\n";
	}
    }
    closedir SEARCHDIR;
    if ($x) {
	print "<INPUT TYPE=\"hidden\" NAME=\"search\" VALUE=\"$x\">\n";
	print "   </TABLE>\n";
	print "   </TD>\n  </TR>\n</TABLE>\n";
    }
    # search pattern files
    if ($gotSearch) {
        ES40lnf::print_subheader("Search Pattern Files");
	print "<TABLE CELLPADDING=\"5\">\n";
	print "  <TR>\n";
	ES40lnf::print_OpenTD();
	print "   Search pattern files allow the search interface to be customized.\n";
	print "   If the old server has customized pattern files, they can be migrated\n";
	print "   to the new server.  Do <I>not</I> migrate the old server's pattern\n";
	print "   files unless they have been customized.\n";
	print "   <P>\n";
	print "   <TABLE CELLPADDING=\"0\" CELLSPACING=\"0\">\n";
	print "     <TR>\n ";
        ES40lnf::print_OpenTD();
	print "Migrate Search Pattern Files:";
        ES40lnf::print_CloseTD();
        ES40lnf::print_OpenTD();
	print "<INPUT TYPE=\"radio\" NAME=\"search-pat\" VALUE=\"1\"> Yes\n";
	print "<INPUT TYPE=\"radio\" NAME=\"search-pat\" VALUE=\"0\" CHECKED> No\n";
        ES40lnf::print_CloseTD();
	print "     </TR>\n";
	print "   </TABLE>\n";
	print "   </TD>\n  </TR>\n</TABLE>\n";
    }
}
print "<!-- End Form -->\n";
