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

Annotation of /SubsystemEditor/WebPage/ShowSubsystem.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (view) (download) (as text)

1 : bartels 1.1 package SubsystemEditor::WebPage::ShowSubsystem;
2 :    
3 :     use strict;
4 :     use warnings;
5 :     use URI::Escape;
6 :     use HTML;
7 :     use Data::Dumper;
8 :    
9 :     use FIG;
10 :    
11 :     use base qw( WebPage );
12 :    
13 :     1;
14 :    
15 : bartels 1.2 ##############################################################
16 :     # Method for registering components etc. for the application #
17 :     ##############################################################
18 : bartels 1.1 sub init {
19 :     my ( $self ) = @_;
20 :    
21 : bartels 1.2 $self->application->register_component( 'Table', 'sstable' );
22 :     }
23 :    
24 :     #################################
25 :     # File where Javascript resides #
26 :     #################################
27 :     sub require_javascript {
28 :    
29 :     return [ './Html/showfunctionalroles.js' ];
30 :    
31 : bartels 1.1 }
32 :    
33 :     ##############################################
34 :     # Website content is returned by this method #
35 :     ##############################################
36 :     sub output {
37 :     my ( $self ) = @_;
38 : bartels 1.2
39 : bartels 1.1 my $fig = new FIG;
40 :     my $cgi = $self->application->cgi;
41 :    
42 : bartels 1.2 # subsystem name and 'nice name' #
43 : bartels 1.1 my $name = $cgi->param( 'subsystem' );
44 :     my $ssname = $name;
45 :     $ssname =~ s/\_/ /g;
46 :    
47 : bartels 1.2 # look if someone is logged in and can write the subsystem #
48 :     my $can_alter = 0;
49 :     my $user = $self->application->session->user;
50 : bartels 1.4
51 :     my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );
52 :     my $ppoapplication = $dbmaster->Backend->init( { name => 'SubsystemEditor' } );
53 :    
54 :     # get a seeduser #
55 :     my $seeduser = '';
56 :     if ( defined( $user ) && ref( $user ) ) {
57 :     my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
58 :     name => 'SeedUser',
59 :     application => $ppoapplication } );
60 :     if ( defined( $preferences->[0] ) ) {
61 :     $seeduser = $preferences->[0]->value();
62 :     }
63 :     }
64 :    
65 : bartels 1.6 if ( $user ) {
66 :     if ( $user->has_right( $self->application, 'edit', 'subsystem', $name ) ) {
67 :     $can_alter = 1;
68 :     $fig->set_user( $seeduser );
69 :     }
70 :     else {
71 :     # we might have the problem that the user has not yet got the right for editing the
72 :     # subsystem due to that it was created in the old seed or what do I know where.
73 :     my $curatorOfSS = $fig->subsystem_curator( $name );
74 : bartels 1.7 my $su = lc( $seeduser );
75 :     my $cu = lc( $curatorOfSS );
76 :     if ( $su eq $cu ) {
77 : bartels 1.6 # now set the rights...
78 :     my $right = $dbmaster->Rights->create( { name => 'edit',
79 :     scope => $user->get_user_scope,
80 :     data_type => 'subsystem',
81 :     data_id => $name,
82 :     granted => 1,
83 :     delegated => 0 } );
84 :     if ( $right ) {
85 :     $can_alter = 1;
86 :     $fig->set_user( $seeduser );
87 :     }
88 :     }
89 :     }
90 : bartels 1.2 }
91 : bartels 1.6
92 : bartels 1.1 ######################
93 :     # Construct the menu #
94 :     ######################
95 :    
96 :     my $menu = $self->application->menu();
97 :    
98 :     # Build nice tab menu here
99 :     $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$name" );
100 :     $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );
101 :     $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );
102 :     $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );
103 : bartels 1.2 $menu->add_category( 'Subsystem Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );
104 : bartels 1.1 $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );
105 :    
106 :    
107 :     ##############################
108 :     # Construct the page content #
109 :     ##############################
110 :    
111 : bartels 1.2 my $content = qq~
112 :     <STYLE>
113 :     .hideme {
114 :     display: none;
115 :     }
116 :     .showme {
117 :     display: all;
118 :     }
119 :     </STYLE>
120 :     ~;
121 :    
122 :     $content .= "<H2>Subsystem Info</H2>";
123 :     my $subsystem = new Subsystem( $name, $fig, 0 );
124 :    
125 :     if ( defined( $cgi->param( 'SUBMIT' ) ) ) {
126 :    
127 :     # set description and notes
128 :     my $descrp = $cgi->param( 'SSDESC' );
129 :     chomp $descrp;
130 :     $descrp .= "\n";
131 :     $subsystem->set_description( $descrp );
132 :     my $notes = $cgi->param( 'SSNOTES' );
133 :     chomp $notes;
134 :     $notes .= "\n";
135 :     $subsystem->set_notes( $notes );
136 :    
137 :     my $class1 = '';
138 :     my $class2 = '';
139 :    
140 :     if ( defined( $cgi->param( 'Classification' ) ) ) {
141 :     if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
142 :     if ( defined( $cgi->param( "SUBSYSH1TF" ) ) ) {
143 :     $class1 = $cgi->param( "SUBSYSH1TF" );
144 :     }
145 :     }
146 :     else {
147 :     if ( defined( $cgi->param( "SUBSYSH1" ) ) ) {
148 :     $class1 = $cgi->param( "SUBSYSH1" );
149 :     }
150 :     }
151 :     }
152 :    
153 :     if ( defined( $cgi->param( 'Classification' ) ) ) {
154 :     if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
155 :     if ( defined( $cgi->param( "SUBSYSH2TF" ) ) ) {
156 :     $class2 = $cgi->param( "SUBSYSH2TF" );
157 :     }
158 :     }
159 :     else {
160 :     if ( defined( $cgi->param( "SUBSYSH2" ) ) ) {
161 :     $class2 = $cgi->param( "SUBSYSH2" );
162 :     }
163 :     }
164 :     }
165 :     $subsystem->set_classification( [ $class1, $class2 ] );
166 :    
167 :     # here we really edit the files in the subsystem directory #
168 :     $subsystem->incr_version();
169 :     $subsystem->db_sync();
170 :     $subsystem->write_subsystem();
171 :     }
172 : bartels 1.1
173 : bartels 1.2 $subsystem = new Subsystem( $name, $fig, 0 );
174 :    
175 :     $content .= $self->start_form( 'form', { subsystem => $name } );
176 :    
177 : bartels 1.1 my ( $ssversion, $sscurator, $pedigree, $ssroles ) = $fig->subsystem_info( $name );
178 : bartels 1.3
179 :     my $versionlink = '';
180 : bartels 1.5
181 : bartels 1.3 if ( $can_alter ) {
182 : bartels 1.4 $versionlink = " -- <A HREF='".$self->application->url()."?page=ResetSubsystem&subsystem=$name'>Reset to Previous Timestamp</A>";
183 : bartels 1.3 }
184 :    
185 : bartels 1.1 my $mod_time = get_mod_time( $name );
186 :     my $class = $fig->subsystem_classification( $name );
187 :     my $ssnotes = $subsystem->get_notes();
188 :    
189 : bartels 1.2 if ( !defined( $ssnotes ) ) {
190 :     $ssnotes = '';
191 :     }
192 :     my $ssdesc = $subsystem->get_description();
193 :    
194 :     if ( !defined( $ssdesc ) ) {
195 :     $ssdesc = '';
196 :     }
197 :    
198 :     my $classification_stuff;
199 :     if ( $can_alter ) {
200 :     $classification_stuff = get_classification_boxes( $fig, $cgi, $class->[0], $class->[1] );
201 :     }
202 :     else {
203 :     $classification_stuff = "<TR><TH>Classification:</TH><TD>$class->[0]</TD></TR>";
204 :     $classification_stuff .= "<TR><TH></TH><TD>$class->[1]</TD></TR>";
205 :     }
206 : bartels 1.1
207 :     my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD><TR>";
208 :     $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";
209 : bartels 1.3 $infotable .= "<TR><TH>Version:</TH><TD>$ssversion $versionlink</TD></TR>";
210 : bartels 1.1 $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";
211 : bartels 1.2 if ( $can_alter ) {
212 :     $infotable .= "<TR><TH>Description</TH><TD><TEXTAREA NAME='SSDESC' ROWS=6 STYLE='width: 772px;'>$ssdesc</TEXTAREA></TD></TR>";
213 :     $infotable .= "<TR><TH>Notes</TH><TD><TEXTAREA NAME='SSNOTES' ROWS=6 STYLE='width: 772px;'>$ssnotes</TEXTAREA></TD></TR>";
214 :     }
215 :     else {
216 :     # do a little formating because the notes often contain many many blanks and newlines
217 :     my $ssdesc_brs = $ssdesc;
218 :     $ssdesc_brs =~ s/\n/<BR>/g;
219 :     $ssdesc_brs =~ s/(\n\s)+/\n/g;
220 :     my $ssnotes_brs = $ssnotes;
221 :     $ssnotes_brs =~ s/(\n\s)+/\n/g;
222 :     $ssnotes_brs =~ s/\n/<BR>/g;
223 :     $infotable .= "<TR><TH>Description</TH><TD>$ssdesc_brs</TD></TR>";
224 :     $infotable .= "<TR><TH>Notes</TH><TD>$ssnotes_brs</TD></TR>";
225 :     }
226 :     $infotable .= $classification_stuff;
227 : bartels 1.1 $infotable .= "</TABLE>";
228 :    
229 : bartels 1.2 if ( $can_alter ) {
230 :     $infotable .= "<INPUT TYPE=SUBMIT VALUE='Save Changes' ID='SUBMIT' NAME='SUBMIT'>";
231 :     }
232 :    
233 : bartels 1.1 $content .= $infotable;
234 : bartels 1.2 $content .= $self->end_form();
235 : bartels 1.1
236 :     return $content;
237 :     }
238 :    
239 :    
240 :     sub get_mod_time {
241 :    
242 :     my ( $ssa, $fig ) = @_;
243 :    
244 :     my( $t, @spreadsheets );
245 :     if ( opendir( BACKUP, "$FIG_Config::data/Subsystems/$ssa/Backup" ) ) {
246 :    
247 :     @spreadsheets = sort { $b <=> $a }
248 :     map { $_ =~ /^spreadsheet.(\d+)/; $1 }
249 :     grep { $_ =~ /^spreadsheet/ }
250 :     readdir(BACKUP);
251 :     closedir(BACKUP);
252 :    
253 :     if ( $t = shift @spreadsheets ) {
254 :     my $last_modified = &FIG::epoch_to_readable( $t );
255 :     return $last_modified;
256 :     }
257 :     }
258 : bartels 1.2 return "$FIG_Config::data/Subsystems/$ssa/Backup";
259 :     }
260 :    
261 :    
262 :     sub get_classification_boxes {
263 :     my ( $fig, $cgi, $class1, $class2 ) = @_;
264 :     my $classified = 1;
265 :    
266 :     my $sdContent = '';
267 :     my $SUBSYSH1 = $class1;
268 :     my $SUBSYSH2 = $class2;
269 :    
270 :     # variables that monitor if we have selected a box
271 :     my $putinh1 = 0;
272 :     my $putinh2 = 0;
273 :    
274 :     if ( !defined( $SUBSYSH1 ) ){
275 :     $putinh1 = 1;
276 :     }
277 :     if ( !defined( $SUBSYSH2 ) ){
278 :     $putinh2 = 1;
279 :     }
280 :    
281 :     my $inh1 = '';
282 :     if ( defined( $cgi->param( 'SUBSYSH1TF' ) ) ) {
283 :     $inh1 = $cgi->param( 'SUBSYSH1TF' );
284 :     }
285 :     elsif ( defined( $SUBSYSH1 ) ) {
286 :     if ( !$putinh1 ) {
287 :     $inh1 = $SUBSYSH1;
288 :     }
289 :     }
290 :     my $inh2 = '';
291 :     if ( defined( $cgi->param( 'SUBSYSH2TF' ) ) ) {
292 :     $inh2 = $cgi->param( 'SUBSYSH2TF' );
293 :     }
294 :     elsif ( defined( $SUBSYSH2 ) ) {
295 :     if ( !$putinh2 ) {
296 :     $inh2 = $SUBSYSH2;
297 :     }
298 :     }
299 :    
300 :     my @ssclassifications = $fig->all_subsystem_classifications();
301 :     my $ssclass;
302 :     foreach my $ssc ( @ssclassifications ) {
303 :     next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );
304 :     next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );
305 :     next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );
306 :     push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];
307 :     }
308 :    
309 :    
310 :     my @options;
311 :     foreach my $firstc ( keys %$ssclass ) {
312 :     my $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='hideme'>";
313 :     my $optstring = '';
314 :     foreach my $secc ( sort @{ $ssclass->{ $firstc } } ) {
315 : bartels 1.8 if ( defined( $SUBSYSH2 ) && $SUBSYSH2 eq $secc && $SUBSYSH1 eq $firstc ) {
316 : bartels 1.2 $optstring .= "<OPTION SELECTED VALUE='$secc'>$secc</OPTION>";
317 :     # we have to show the selectbox if there is a selected value
318 :     $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='showme'>";
319 :     $putinh2 = 1;
320 :     }
321 :     else {
322 :     $optstring .= "<OPTION VALUE='$secc'>$secc</OPTION>";
323 :     }
324 :     }
325 :     $opt .= $optstring;
326 :     $opt .= "</SELECT>";
327 :     push @options, $opt;
328 :     }
329 :    
330 :     if ( $classified ) {
331 :     $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();'>";
332 :     }
333 :     else {
334 :     $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>";
335 :     }
336 :     foreach my $firstc ( sort keys %$ssclass ) {
337 :     if ( defined( $SUBSYSH1 ) && $SUBSYSH1 eq $firstc ) {
338 :     $sdContent .= "\n<OPTION SELECTED VALUE='$firstc'>$firstc</OPTION>\n";
339 :     $putinh1 = 1;
340 :     }
341 :     else {
342 :     $sdContent .= "\n<OPTION VALUE='$firstc'>$firstc</OPTION>\n";
343 :     }
344 :     }
345 :     $sdContent .= "</SELECT>";
346 :    
347 :     foreach my $opt ( @options ) {
348 :     $sdContent .= $opt;
349 :     }
350 :    
351 :     $sdContent .= "</TD></TR>";
352 :     if ( $classified ) {
353 :     $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>";
354 :     }
355 :     else {
356 :     $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>";
357 :     }
358 :    
359 :    
360 :     return $sdContent;
361 :     }
362 :    
363 :     sub supported_rights {
364 :    
365 :     return [ [ 'edit', 'subsystem', '*' ] ];
366 :    
367 : bartels 1.1 }
368 : bartels 1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3