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

Annotation of /SubsystemEditor/WebPage/ShowSubsystem.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (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 : bartels 1.9 $menu->add_category( 'Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );
102 :     $menu->add_category( 'Illustrations', "SubsysEditor.cgi?page=ShowIllustrations&subsystem=$name" );
103 :     $menu->add_category( 'Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );
104 :     $menu->add_category( 'Show Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );
105 :     $menu->add_category( 'Show Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );
106 : bartels 1.1
107 :    
108 :     ##############################
109 :     # Construct the page content #
110 :     ##############################
111 :    
112 : bartels 1.2 my $content = qq~
113 :     <STYLE>
114 :     .hideme {
115 :     display: none;
116 :     }
117 :     .showme {
118 :     display: all;
119 :     }
120 :     </STYLE>
121 :     ~;
122 :    
123 :     $content .= "<H2>Subsystem Info</H2>";
124 :     my $subsystem = new Subsystem( $name, $fig, 0 );
125 :    
126 :     if ( defined( $cgi->param( 'SUBMIT' ) ) ) {
127 :    
128 :     # set description and notes
129 :     my $descrp = $cgi->param( 'SSDESC' );
130 :     chomp $descrp;
131 :     $descrp .= "\n";
132 :     $subsystem->set_description( $descrp );
133 :     my $notes = $cgi->param( 'SSNOTES' );
134 :     chomp $notes;
135 :     $notes .= "\n";
136 :     $subsystem->set_notes( $notes );
137 :    
138 :     my $class1 = '';
139 :     my $class2 = '';
140 :    
141 :     if ( defined( $cgi->param( 'Classification' ) ) ) {
142 :     if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
143 :     if ( defined( $cgi->param( "SUBSYSH1TF" ) ) ) {
144 :     $class1 = $cgi->param( "SUBSYSH1TF" );
145 :     }
146 :     }
147 :     else {
148 :     if ( defined( $cgi->param( "SUBSYSH1" ) ) ) {
149 :     $class1 = $cgi->param( "SUBSYSH1" );
150 :     }
151 :     }
152 :     }
153 :    
154 :     if ( defined( $cgi->param( 'Classification' ) ) ) {
155 :     if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
156 :     if ( defined( $cgi->param( "SUBSYSH2TF" ) ) ) {
157 :     $class2 = $cgi->param( "SUBSYSH2TF" );
158 :     }
159 :     }
160 :     else {
161 :     if ( defined( $cgi->param( "SUBSYSH2" ) ) ) {
162 :     $class2 = $cgi->param( "SUBSYSH2" );
163 :     }
164 :     }
165 :     }
166 :     $subsystem->set_classification( [ $class1, $class2 ] );
167 :    
168 :     # here we really edit the files in the subsystem directory #
169 :     $subsystem->incr_version();
170 :     $subsystem->db_sync();
171 :     $subsystem->write_subsystem();
172 :     }
173 : bartels 1.1
174 : bartels 1.2 $subsystem = new Subsystem( $name, $fig, 0 );
175 :    
176 :     $content .= $self->start_form( 'form', { subsystem => $name } );
177 :    
178 : bartels 1.1 my ( $ssversion, $sscurator, $pedigree, $ssroles ) = $fig->subsystem_info( $name );
179 : bartels 1.3
180 :     my $versionlink = '';
181 : bartels 1.5
182 : bartels 1.3 if ( $can_alter ) {
183 : bartels 1.4 $versionlink = " -- <A HREF='".$self->application->url()."?page=ResetSubsystem&subsystem=$name'>Reset to Previous Timestamp</A>";
184 : bartels 1.3 }
185 :    
186 : bartels 1.1 my $mod_time = get_mod_time( $name );
187 :     my $class = $fig->subsystem_classification( $name );
188 :     my $ssnotes = $subsystem->get_notes();
189 :    
190 : bartels 1.2 if ( !defined( $ssnotes ) ) {
191 :     $ssnotes = '';
192 :     }
193 :     my $ssdesc = $subsystem->get_description();
194 :    
195 :     if ( !defined( $ssdesc ) ) {
196 :     $ssdesc = '';
197 :     }
198 :    
199 :     my $classification_stuff;
200 :     if ( $can_alter ) {
201 :     $classification_stuff = get_classification_boxes( $fig, $cgi, $class->[0], $class->[1] );
202 :     }
203 :     else {
204 :     $classification_stuff = "<TR><TH>Classification:</TH><TD>$class->[0]</TD></TR>";
205 :     $classification_stuff .= "<TR><TH></TH><TD>$class->[1]</TD></TR>";
206 :     }
207 : bartels 1.1
208 :     my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD><TR>";
209 :     $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";
210 : bartels 1.3 $infotable .= "<TR><TH>Version:</TH><TD>$ssversion $versionlink</TD></TR>";
211 : bartels 1.1 $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";
212 : bartels 1.2 if ( $can_alter ) {
213 :     $infotable .= "<TR><TH>Description</TH><TD><TEXTAREA NAME='SSDESC' ROWS=6 STYLE='width: 772px;'>$ssdesc</TEXTAREA></TD></TR>";
214 :     $infotable .= "<TR><TH>Notes</TH><TD><TEXTAREA NAME='SSNOTES' ROWS=6 STYLE='width: 772px;'>$ssnotes</TEXTAREA></TD></TR>";
215 :     }
216 :     else {
217 :     # do a little formating because the notes often contain many many blanks and newlines
218 :     my $ssdesc_brs = $ssdesc;
219 :     $ssdesc_brs =~ s/\n/<BR>/g;
220 :     $ssdesc_brs =~ s/(\n\s)+/\n/g;
221 :     my $ssnotes_brs = $ssnotes;
222 :     $ssnotes_brs =~ s/(\n\s)+/\n/g;
223 :     $ssnotes_brs =~ s/\n/<BR>/g;
224 :     $infotable .= "<TR><TH>Description</TH><TD>$ssdesc_brs</TD></TR>";
225 :     $infotable .= "<TR><TH>Notes</TH><TD>$ssnotes_brs</TD></TR>";
226 :     }
227 :     $infotable .= $classification_stuff;
228 : bartels 1.1 $infotable .= "</TABLE>";
229 :    
230 : bartels 1.2 if ( $can_alter ) {
231 :     $infotable .= "<INPUT TYPE=SUBMIT VALUE='Save Changes' ID='SUBMIT' NAME='SUBMIT'>";
232 :     }
233 :    
234 : bartels 1.1 $content .= $infotable;
235 : bartels 1.2 $content .= $self->end_form();
236 : bartels 1.1
237 :     return $content;
238 :     }
239 :    
240 :    
241 :     sub get_mod_time {
242 :    
243 :     my ( $ssa, $fig ) = @_;
244 :    
245 :     my( $t, @spreadsheets );
246 :     if ( opendir( BACKUP, "$FIG_Config::data/Subsystems/$ssa/Backup" ) ) {
247 :    
248 :     @spreadsheets = sort { $b <=> $a }
249 :     map { $_ =~ /^spreadsheet.(\d+)/; $1 }
250 :     grep { $_ =~ /^spreadsheet/ }
251 :     readdir(BACKUP);
252 :     closedir(BACKUP);
253 :    
254 :     if ( $t = shift @spreadsheets ) {
255 :     my $last_modified = &FIG::epoch_to_readable( $t );
256 :     return $last_modified;
257 :     }
258 :     }
259 : bartels 1.2 return "$FIG_Config::data/Subsystems/$ssa/Backup";
260 :     }
261 :    
262 :    
263 :     sub get_classification_boxes {
264 :     my ( $fig, $cgi, $class1, $class2 ) = @_;
265 :     my $classified = 1;
266 :    
267 :     my $sdContent = '';
268 :     my $SUBSYSH1 = $class1;
269 :     my $SUBSYSH2 = $class2;
270 :    
271 :     # variables that monitor if we have selected a box
272 :     my $putinh1 = 0;
273 :     my $putinh2 = 0;
274 :    
275 :     if ( !defined( $SUBSYSH1 ) ){
276 :     $putinh1 = 1;
277 :     }
278 :     if ( !defined( $SUBSYSH2 ) ){
279 :     $putinh2 = 1;
280 :     }
281 :    
282 :     my $inh1 = '';
283 :     if ( defined( $cgi->param( 'SUBSYSH1TF' ) ) ) {
284 :     $inh1 = $cgi->param( 'SUBSYSH1TF' );
285 :     }
286 :     elsif ( defined( $SUBSYSH1 ) ) {
287 :     if ( !$putinh1 ) {
288 :     $inh1 = $SUBSYSH1;
289 :     }
290 :     }
291 :     my $inh2 = '';
292 :     if ( defined( $cgi->param( 'SUBSYSH2TF' ) ) ) {
293 :     $inh2 = $cgi->param( 'SUBSYSH2TF' );
294 :     }
295 :     elsif ( defined( $SUBSYSH2 ) ) {
296 :     if ( !$putinh2 ) {
297 :     $inh2 = $SUBSYSH2;
298 :     }
299 :     }
300 :    
301 :     my @ssclassifications = $fig->all_subsystem_classifications();
302 :     my $ssclass;
303 :     foreach my $ssc ( @ssclassifications ) {
304 :     next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );
305 :     next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );
306 :     next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );
307 :     push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];
308 :     }
309 :    
310 :    
311 :     my @options;
312 :     foreach my $firstc ( keys %$ssclass ) {
313 :     my $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='hideme'>";
314 :     my $optstring = '';
315 :     foreach my $secc ( sort @{ $ssclass->{ $firstc } } ) {
316 : bartels 1.8 if ( defined( $SUBSYSH2 ) && $SUBSYSH2 eq $secc && $SUBSYSH1 eq $firstc ) {
317 : bartels 1.2 $optstring .= "<OPTION SELECTED VALUE='$secc'>$secc</OPTION>";
318 :     # we have to show the selectbox if there is a selected value
319 :     $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='showme'>";
320 :     $putinh2 = 1;
321 :     }
322 :     else {
323 :     $optstring .= "<OPTION VALUE='$secc'>$secc</OPTION>";
324 :     }
325 :     }
326 :     $opt .= $optstring;
327 :     $opt .= "</SELECT>";
328 :     push @options, $opt;
329 :     }
330 :    
331 :     if ( $classified ) {
332 :     $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();'>";
333 :     }
334 :     else {
335 :     $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>";
336 :     }
337 :     foreach my $firstc ( sort keys %$ssclass ) {
338 :     if ( defined( $SUBSYSH1 ) && $SUBSYSH1 eq $firstc ) {
339 :     $sdContent .= "\n<OPTION SELECTED VALUE='$firstc'>$firstc</OPTION>\n";
340 :     $putinh1 = 1;
341 :     }
342 :     else {
343 :     $sdContent .= "\n<OPTION VALUE='$firstc'>$firstc</OPTION>\n";
344 :     }
345 :     }
346 :     $sdContent .= "</SELECT>";
347 :    
348 :     foreach my $opt ( @options ) {
349 :     $sdContent .= $opt;
350 :     }
351 :    
352 :     $sdContent .= "</TD></TR>";
353 :     if ( $classified ) {
354 :     $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>";
355 :     }
356 :     else {
357 :     $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>";
358 :     }
359 :    
360 :    
361 :     return $sdContent;
362 :     }
363 :    
364 :     sub supported_rights {
365 :    
366 :     return [ [ 'edit', 'subsystem', '*' ] ];
367 :    
368 : bartels 1.1 }
369 : bartels 1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3