[Bio] / SubsystemEditor / WebPage / ShowSubsystem.pm Repository:
ViewVC logotype

View of /SubsystemEditor/WebPage/ShowSubsystem.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Fri Feb 15 16:58:13 2008 UTC (11 years, 11 months ago) by bartels
Branch: MAIN
Changes since 1.5: +24 -3 lines
if a user does not still have the right to edit his ss, but his seeduser and
the curator name of the subsystem are the same, he is now automatically granted
the right to edit the subsystem.

This is to solve the problem that the subsystem is created in the old interface,
so that the ppo user does not know about it

CVS

package SubsystemEditor::WebPage::ShowSubsystem;

use strict;
use warnings;
use URI::Escape;
use HTML;
use Data::Dumper;

use FIG;

use base qw( WebPage );

1;

##############################################################
# Method for registering components etc. for the application #
##############################################################
sub init {
  my ( $self ) = @_;

  $self->application->register_component( 'Table', 'sstable'  );
}

#################################
# File where Javascript resides #
#################################
sub require_javascript {

  return [ './Html/showfunctionalroles.js' ];

}

##############################################
# Website content is returned by this method #
##############################################
sub output {
  my ( $self ) = @_;

  use Data::Dumper;

  my $fig = new FIG;
  my $cgi = $self->application->cgi;
  
  # subsystem name and 'nice name' #
  my $name = $cgi->param( 'subsystem' );
  my $ssname = $name;
  $ssname =~ s/\_/ /g;

  # look if someone is logged in and can write the subsystem #
  my $can_alter = 0;
  my $user = $self->application->session->user;

  my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );
  my $ppoapplication = $dbmaster->Backend->init( { name => 'SubsystemEditor' } );
  
  # get a seeduser #
  my $seeduser = '';
  if ( defined( $user ) && ref( $user ) ) {
    my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
							     name => 'SeedUser',
							     application => $ppoapplication } );
    if ( defined( $preferences->[0] ) ) {
      $seeduser = $preferences->[0]->value();
    }
  }

  if ( $user ) {
    if ( $user->has_right( $self->application, 'edit', 'subsystem', $name ) ) {
      $can_alter = 1;
      $fig->set_user( $seeduser );
    }
    else {
      # we might have the problem that the user has not yet got the right for editing the
      # subsystem due to that it was created in the old seed or what do I know where.
      my $curatorOfSS = $fig->subsystem_curator( $name );
      if ( $seeduser eq $curatorOfSS ) {
	# now set the rights... 
	my $right = $dbmaster->Rights->create( { name => 'edit',
						 scope => $user->get_user_scope,
						 data_type => 'subsystem',
						 data_id => $name,
						 granted => 1,
						 delegated => 0 } );
	if ( $right ) {
	  $can_alter = 1;
	  $fig->set_user( $seeduser );
	}
      }
    }
  }

  ######################
  # Construct the menu #
  ######################

  my $menu = $self->application->menu();

  # Build nice tab menu here
  $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$name" );
  $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );
  $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );
  $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );
  $menu->add_category( 'Subsystem Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );
  $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );


  ##############################
  # Construct the page content #
  ##############################
 
  my $content = qq~
<STYLE>
.hideme {
   display: none;
}
.showme {
   display: all;
}
</STYLE>
~;

  $content .= "<H2>Subsystem Info</H2>";
  my $subsystem = new Subsystem( $name, $fig, 0 );

  if ( defined( $cgi->param( 'SUBMIT' ) ) ) {

    # set description and notes
    my $descrp = $cgi->param( 'SSDESC' );
    chomp $descrp;
    $descrp .= "\n";
    $subsystem->set_description( $descrp );
    my $notes = $cgi->param( 'SSNOTES' );
    chomp $notes;
    $notes .= "\n";
    $subsystem->set_notes( $notes );

    my $class1 = '';
    my $class2 = '';

    if ( defined( $cgi->param( 'Classification' ) ) ) {
      if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {      
	if ( defined( $cgi->param( "SUBSYSH1TF" ) ) ) {
	  $class1 = $cgi->param( "SUBSYSH1TF" );
	}
      }
      else {
	if ( defined( $cgi->param( "SUBSYSH1" ) ) ) {
	  $class1 = $cgi->param( "SUBSYSH1" );
	}
      }
    }

    if ( defined( $cgi->param( 'Classification' ) ) ) {
      if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {  
	if ( defined( $cgi->param( "SUBSYSH2TF" ) ) ) {
	  $class2 = $cgi->param( "SUBSYSH2TF" );
	}
      }
      else {
	if ( defined( $cgi->param( "SUBSYSH2" ) ) ) {
	  $class2 = $cgi->param( "SUBSYSH2" );
	}
      }
    }
    $subsystem->set_classification( [ $class1, $class2 ] );

    # here we really edit the files in the subsystem directory #
    $subsystem->incr_version();
    $subsystem->db_sync();
    $subsystem->write_subsystem();
  }
  
  $subsystem = new Subsystem( $name, $fig, 0 );

  $content .= $self->start_form( 'form', { subsystem => $name } );

  my ( $ssversion, $sscurator, $pedigree, $ssroles ) = $fig->subsystem_info( $name );

  my $versionlink = '';

  if ( $can_alter ) {
    $versionlink = " -- <A HREF='".$self->application->url()."?page=ResetSubsystem&subsystem=$name'>Reset to Previous Timestamp</A>";
  }

  my $mod_time = get_mod_time( $name );
  my $class = $fig->subsystem_classification( $name );
  my $ssnotes = $subsystem->get_notes();

  if ( !defined( $ssnotes ) ) {
    $ssnotes = '';
  }
  my $ssdesc = $subsystem->get_description();

  if ( !defined( $ssdesc ) ) {
    $ssdesc = '';
  }

  my $classification_stuff;
  if ( $can_alter ) {
    $classification_stuff = get_classification_boxes( $fig, $cgi, $class->[0], $class->[1] );
  }
  else {
    $classification_stuff = "<TR><TH>Classification:</TH><TD>$class->[0]</TD></TR>";
    $classification_stuff .= "<TR><TH></TH><TD>$class->[1]</TD></TR>";
  }
  
  my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD><TR>";
  $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";
  $infotable .= "<TR><TH>Version:</TH><TD>$ssversion $versionlink</TD></TR>";
  $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";
  if ( $can_alter ) {
    $infotable .= "<TR><TH>Description</TH><TD><TEXTAREA NAME='SSDESC' ROWS=6 STYLE='width: 772px;'>$ssdesc</TEXTAREA></TD></TR>";
    $infotable .= "<TR><TH>Notes</TH><TD><TEXTAREA NAME='SSNOTES' ROWS=6 STYLE='width: 772px;'>$ssnotes</TEXTAREA></TD></TR>";
  }
  else {
    # do a little formating because the notes often contain many many blanks and newlines
    my $ssdesc_brs = $ssdesc;
    $ssdesc_brs =~ s/\n/<BR>/g;
    $ssdesc_brs =~ s/(\n\s)+/\n/g;
    my $ssnotes_brs = $ssnotes;
    $ssnotes_brs =~ s/(\n\s)+/\n/g;
    $ssnotes_brs =~ s/\n/<BR>/g;
    $infotable .= "<TR><TH>Description</TH><TD>$ssdesc_brs</TD></TR>";
    $infotable .= "<TR><TH>Notes</TH><TD>$ssnotes_brs</TD></TR>";
  }
  $infotable .= $classification_stuff;
  $infotable .= "</TABLE>";

  if ( $can_alter ) {
    $infotable .= "<INPUT TYPE=SUBMIT VALUE='Save Changes' ID='SUBMIT' NAME='SUBMIT'>";
  }

  $content .= $infotable;
  $content .= $self->end_form();

  return $content;
}


sub get_mod_time {
  
  my ( $ssa, $fig ) = @_;

  my( $t, @spreadsheets );
  if ( opendir( BACKUP, "$FIG_Config::data/Subsystems/$ssa/Backup" ) ) {

    @spreadsheets = sort { $b <=> $a }
      map { $_ =~ /^spreadsheet.(\d+)/; $1 }
	grep { $_ =~ /^spreadsheet/ } 
	  readdir(BACKUP);
    closedir(BACKUP);

    if ( $t = shift @spreadsheets ) {
      my $last_modified = &FIG::epoch_to_readable( $t );
      return $last_modified;
    }
  }
  return "$FIG_Config::data/Subsystems/$ssa/Backup";
}


sub get_classification_boxes {
  my ( $fig, $cgi, $class1, $class2 ) = @_;
  my $classified = 1;

  my $sdContent = '';
  my $SUBSYSH1 = $class1;
  my $SUBSYSH2 = $class2;

  # variables that monitor if we have selected a box
  my $putinh1 = 0;
  my $putinh2 = 0;

  if ( !defined( $SUBSYSH1 ) ){
    $putinh1 = 1;
  }
  if ( !defined( $SUBSYSH2 ) ){
    $putinh2 = 1;
  }

  my $inh1 = '';
  if ( defined( $cgi->param( 'SUBSYSH1TF' ) ) ) {
    $inh1 = $cgi->param( 'SUBSYSH1TF' );
  }
  elsif ( defined( $SUBSYSH1 ) ) {
    if ( !$putinh1 ) {
      $inh1 = $SUBSYSH1;
    }
  }
  my $inh2 = '';
  if ( defined( $cgi->param( 'SUBSYSH2TF' ) ) ) {
    $inh2 = $cgi->param( 'SUBSYSH2TF' );
  }
  elsif ( defined( $SUBSYSH2 ) ) {
    if ( !$putinh2 ) {
      $inh2 = $SUBSYSH2;
    }
  }

  my @ssclassifications = $fig->all_subsystem_classifications();
  my $ssclass;
  foreach my $ssc ( @ssclassifications ) {
    next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );
    next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );
    next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );
    push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];
  }


  my @options;
  foreach my $firstc ( keys %$ssclass ) {
    my $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='hideme'>";
    my $optstring = '';
    foreach my $secc ( sort @{ $ssclass->{ $firstc } } ) {
      if ( defined( $SUBSYSH2 ) && $SUBSYSH2 eq $secc ) {
	$optstring .= "<OPTION SELECTED VALUE='$secc'>$secc</OPTION>";
	# we have to show the selectbox if there is a selected value
	$opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='showme'>";
	$putinh2 = 1;
      }
      else {
	$optstring .= "<OPTION VALUE='$secc'>$secc</OPTION>";
      }
    }
    $opt .= $optstring;
    $opt .= "</SELECT>";
    push @options, $opt;
  }

  if ( $classified ) {
    $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"Classified\" CHECKED onchange='radioclassification();'>Classification:</TH><TD><SELECT SIZE=5 ID='SUBSYSH1' NAME='SUBSYSH1' STYLE='width: 386px;' onclick='gethiddenoption();'>";
  }
  else {
    $sdContent .= "<TR><TD><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"Classified\" onchange='radioclassification();'>Classification:</TD><TD><SELECT SIZE=5 ID='SUBSYSH1' NAME='SUBSYSH1' STYLE='width: 386px;' onclick='gethiddenoption();' DISABLED=DISABLED>";
  }
  foreach my $firstc ( sort keys %$ssclass ) {
    if ( defined( $SUBSYSH1 ) && $SUBSYSH1 eq $firstc ) {
      $sdContent .= "\n<OPTION SELECTED VALUE='$firstc'>$firstc</OPTION>\n";
      $putinh1 = 1;
    }
    else {
      $sdContent .= "\n<OPTION VALUE='$firstc'>$firstc</OPTION>\n";
    }
  }
  $sdContent .= "</SELECT>";

  foreach my $opt ( @options ) {
    $sdContent .= $opt;
  }

  $sdContent .= "</TD></TR>";
  if ( $classified ) {
    $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"User-defined\" onchange='radioclassification();'>User-defined:</TH><TD><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH1TF' ID='SUBSYSH1TF' VALUE='' DISABLED=\"DISABLED\"><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH2TF' ID='SUBSYSH2TF' VALUE='' DISABLED=DISABLED></TD></TR>";
  }
  else {
    $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"User-defined\" CHECKED onchange='radioclassification();'>User-defined:</TH><TD><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH1TF' ID='SUBSYSH1TF' VALUE='$inh1'><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH2TF' ID='SUBSYSH2TF' VALUE='$inh2'></TD></TR>";
  }


  return $sdContent;
}

sub supported_rights {
  
  return [ [ 'edit', 'subsystem', '*' ] ];

}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3