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

Annotation of /SubsystemEditor/WebPage/ShowSubsystem.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3