#!/usr/bin/perl -w

use strict;

my $doc_root =  "/var/www/html/qr";

if ( -d $doc_root )
  {
    print STDERR "Found Scotty Doc root\n";
  }
else
  {
    $doc_root = "/opt/bitnami/apache2/htdocs/qr";
    if ( -d $doc_root )
      {
	print STDERR "Found media.wgvc.com Doc root\n";
      }
    else
      {
	die "Couldn't find a sane doc root";
      }
  }


open EVENTCODE, "<event-code.txt" or die "Failed to open event-code.txt ($!)";

while (<EVENTCODE>) {
  chomp;
  my ($code, $div) = split /\|/;
  my $event;
  ($event, $div) = split( /\//, $div );

  print "$code $event $div\n";

  if ( ! -d "$doc_root/$code" )
  {
    mkdir "$doc_root/$code" or die "Failed to mkdir $doc_root/$code ($!)";
  }
  chdir "$doc_root/$code" or die "Failed to chdir $doc_root/$code ($!)";
    unlink ( "../../tsh/$event/html/tsh.css",
	       "./tsh.css");
    unlink ( "../../tsh/$event/html/logowiki-83x83.gif",
	       "./logowiki-83x83.gif");
    unlink ( "../../tsh/$event/html/pix",
	       "./pix");
    symlink ( "../../tsh/$event/html/tsh.css",
	       "./tsh.css");
    symlink ( "../../tsh/$event/html/logowiki-83x83.gif",
	       "./logowiki-83x83.gif");
    symlink ( "../../tsh/$event/html/pix",
	       "./pix");

  for (my $i = 1; $i <= 199 ; $i++) {
    unlink  sprintf( "./%d", $i);
    symlink ( sprintf( "../../tsh/$event/html/$div-CSC-%d.html", $i),
	      sprintf( "./%d", $i) );
  }
}
