#!/usr/bin/perl
#  Copyright 2001-2021 Leslie Richardson

use DBI;
use CGI;

my $configpath = '../..'; # go back two to get to etc.


eval require "$configpath/etc/admin.conf";
if ( $@ ) {
    print qq{$lex{Error}: $@<br>\n};
    die qq{$lex{Error}: $@\n};
}

my $q = new CGI;
my %arr = $q->Vars;


my $dbtype = 'mysql';
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);

# my $userid = $ENV{'REMOTE_USER'};

my $sth1 = $dbh->prepare("select * from disc_event where id = ?");
my $sth2 = $dbh->prepare("insert into disc_comment 
			 (eventid, studnum, author, comment) values(?,?,?,?)");


my $sth = $dbh->prepare("select * from disc_ident");
$sth->execute;
if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }

while ( my $ref = $sth->fetchrow_hashref ) {
    my %i = %$ref; # ident table

    # Get the event information.
    $sth1->execute($i{eventid});
    if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
    my $eref = $sth1->fetchrow_hashref;
    my %e = %$eref; # event table

    # add info to the disc_comment table.
    $sth2->execute( $i{eventid}, $i{studnum}, $e{author}, $i{comment} );
    if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; }
    print qq{<div>Copied: $i{eventid} / $i{studnum} / $e{author} / $comment</div>\n};
    
}
