[Bio] / FigWebServices / assignments.cgi Repository:
ViewVC logotype

View of /FigWebServices/assignments.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Wed Jan 14 20:20:32 2004 UTC (16 years, 4 months ago) by overbeek
Branch: MAIN
synch up Ross

use FIG;
my $fig = new FIG;

use HTML;
use strict;

use CGI;
my $cgi = new CGI;

if (0)
{
    print $cgi->header;
    my @params = $cgi->param;
    print "<pre>\n";
    foreach $_ (@params)
    {
	print "$_\t:",join(",",$cgi->param($_)),":\n";
    }
    exit;
}

my $html = [];

my $request = $cgi->param("request");
$request = defined($request) ? $request : "";

if ($cgi->param('delete checked entries'))
{
    &delete_checked($fig,$cgi,$html);
    &show_initial($fig,$cgi,$html);
}
elsif    ($request eq "edit_set")
{
    &edit_set($fig,$cgi,$html);
}
elsif ($request eq "delete_set")
{
    &delete_set($fig,$cgi,$html);
}
elsif ($request eq "accept_set")
{
    &accept_set($fig,$cgi,$html);
}
else
{
    &show_initial($fig,$cgi,$html);
}

&HTML::show_page($cgi,$html);

sub show_initial {
    my($fig,$cgi,$html) = @_;

    my @sets = &assignment_sets;
    if (@sets == 0)
    {
	push(@$html,$cgi->h1("No Assignment Sets Defined"));
	return;
    }

    my $target = "window$$";
    my $user = $cgi->param('user');
    push(@$html, $cgi->h1('Assignment Sets'),
                 $cgi->start_form(-action => "assignments.cgi",
				  -target => $target,
				  -method => 'post'),
	         $cgi->hidden(-name => 'user', -value => $user),
	 );

    my $col_hdrs = ["Edit/Examine","Delete","Accept All","Set Date","Comment"];
    my $tab      = [];
    my $title    = "Existing Assignment Sets";
    foreach $set (sort { &compare_set_names($a,$b) } @sets)
    {
	$set =~ /(\d+-\d+-\d+:\d+:\d+:\d+)(:(.*))?/;
	$when    = $1;
	$comment = $3;
	push(@$tab,[
		    &edit_link($cgi,$set),
		    &delete_link($cgi,$set),
		    &accept_link($cgi,$set),
		    $when,
		    $comment
		   ]
	     );
    }
    push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
}		  

sub edit_link {
    my($cgi,$set) = @_;

    return $cgi->self_url() . "&request=edit_set&set=$set";
}

sub delete_link {
    my($cgi,$set) = @_;

    return $cgi->self_url() . "&request=delete_set&set=$set";
}

sub accept_link {
    my($cgi,$set) = @_;

    return $cgi->self_url() . "&request=accept_set&set=$set";
}

sub assignment_sets {

    my @sets = ();
    if (opendir(SETS,"$FIG_Config::data/Assignments"))
    {
	@sets = grep { $_ =~ /^\d+-\d+-\d+:\d+:\d+:\d+/ } readdir(SETS);
	closedir(SETS);
    }
    return @sets;
}
	
sub compare_set_names {
    my($a,$b) = @_;
    my(@whenA,@whenB,$i);

    if (($a =~ /^(\d+)-(\d+)-(\d+):(\d+):(\d+):(\d+)(.*)/) && (@whenA = ($3,$1,$2,$4,$5,$6,$7)) &&
	($b =~ /^(\d+)-(\d+)-(\d+):(\d+):(\d+):(\d+)(.*)/) && (@whenB = ($3,$1,$2,$4,$5,$6,$7)))
    {
	for ($i=0; ($i < 6) && ($whenA[$i] == $whenB[$i]); $i++) {}
	if ($i < 6)
	{
	    return ($whenA[$i] <=> $whenB[$i]);
	}
	else
	{
	    returnb ($whenA[6] cmp $whenB[6]);
	}
    }
    return ($a cmp $b);
}

sub edit_set {
    my($fig,$cgi,$html) = @_;
    my($line,$userR,$func1,$func2,$col_hdrs,$tab,$peg,$conf);

    my $user = $cgi->param('user');
    if (! $user)
    {
	push(@$html,$cgi->h1("Sorry, but you need to specify a user to edit assignments"));
	return;
    }
    elsif ($user =~ /^master:/)
    {
	$userR = "master";
    }
    else
    {
	$userR = $user;
    }

    my $set  = $cgi->param('set');
    if (! $set)
    {
	push(@$html,$cgi->h1("Sorry, but you need to specify a set to edit"));
	return;
    }

    my $target = "window$$";
    if (-s "$FIG_Config::data/Assignments/$userR/$set")
    {
	push(@$html, $cgi->h1('Edit Set $set'),
	             $cgi->start_form(-method => 'post',
				      -target => $target,
				      -action => 'edit_checked.cgi'
				      ),
	             $cgi->hidden(-name => 'user', -value => $user),
	             $cgi->hidden(-name => 'set', -value => $set)
	     );

	$col_hdrs = ["delete","PEG","Functions"];
	$tab      = [];
	if (open(SET,"<$FIG_Config::data/Assignments/$userR/$set"))
	{
	    while (defined($line = <SET>))
	    {
		chop $line;
		($peg,$func1,$conf) = split(/\t/,$line);
		if ($conf) { $func1 = "$func1\t$conf" }
		$func2 = &func_of($fig,$peg,$user);
		if ($func1 ne $func2)
		{
		    push(@$tab,[
			        $cgi->checkbox(-name => 'checked', -value => $peg, -checked => 1,-override => 1),
				&HTML::fid_link($cgi,$peg),
				"$func1<br>$func2"
			       ]
			 );
		}
	    }
	    close(SET);
	}
	push(@$html,&HTML::make_table($col_hdrs,$tab,"",["nowrap"]));
	push(@$html,$cgi->submit("delete checked entries"));
    }
}

sub delete_set {
    my($fig,$cgi,$html) = @_;

    my $user = $cgi->param('user');
    my $userR = $user;
    $userR =~ s/^master://;
    my $set  = $cgi->param('set');
    if (-s "$FIG_Config::data/Assignments/$userR/$set")
    {
	unlink("$FIG_Config::data/Assignments/$userR/$set");
	push(@$html,$cgi->h1("Deleted set $set"));
    }
    else
    {
	push(@$html,$cgi->h1("Delete Failed: set $set does not exist"));
    }
}

sub accept_set {
    my($fig,$cgi,$html) = @_;

    my $user = $cgi->param('user');
    my $set  = $cgi->param('set');
    if ($user)
    {
	my $userR = $user;
	$userR =~ s/^master://;
	if (system("fig assign_functionF $user $FIG_Config::data/Assignments/$userR/$set > /dev/null") == 0)
	{
	    push(@$html,$cgi->h1("Made Assignments from $set"));
	}
	else
	{
	    push(@$html,$cgi->h1("Call Support: some error occurred"));
	}
    }
    else
    {
	push(@$html,$cgi->h1("Sorry, but you need to specify a user to accept assignments"));
    }
}
	
sub func_of {
    my($fig,$peg,$user) = @_;
    my $func;

    if ($user =~ /^master:/)
    {
	$func = $fig->function_of($peg,"master");
    }
    else
    {
	$func = $fig->function_of($peg,$user);
    }
    return $func;
}

sub delete_checked {
    my($fig,$cgi,$html) = @_;

    my $user = $cgi->param('user');
    my $set  = $cgi->param('set');
    if ($user)
    {
	my $userR = $user;
	$userR =~ s/^master://;
	if (-s "$FIG_Config::data/Assignments/$userR/$set")
	{
	    @entries = `cat $FIG_Config::data/Assignments/$userR/$set`;
	    
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3