[- # # view client's data # # pass $fdat{u} = username to view # BEGIN { unshift(@INC, $ENV{SW_PERLDIR}); } use HTML::Table; use SW::Site::rcm; use XML::LibXML; use XML::LibXSLT; use XML::Sablotron; use Data::Dumper; use rcmManual; # # create site object # my $site = SW::Site::rcm->new( $ENV{SW_CONFIG} ); my $txtIntro = <

Risk Control Manual - [Table of Contents]

You are logged in as: $fdat{u}
Log off EOTEXT # # variables # my $tblContents; my $xmlfile = $site->base_dir . "/admin/clients/data/$fdat{u}/rcm.xml"; my $outfile = $site->base_dir . "/admin/clients/data/$fdat{u}/rcm.xml"; #my $outfile = "/tmp/test.xml"; my $xslfile; my $schedule_dir = $site->base_dir . "/admin/clients/data/$fdat{u}/schedules"; # # select xsl file # if ( $fdat{s} ) { $xslfile = $site->base_dir . "/client/section.xsl"; } else { $xslfile = $site->base_dir . '/client/contents.xsl'; } # crank up parser objects my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); # trap all errors and report at end eval <<'EndOfEval'; $start = __LINE__; # parse template $source = $parser->parse_file( $xmlfile ); # # replace paragraphs # sub replace_paragraphs { my ($source,$sec,$name,$newtext) = @_; if ( length($newtext) < 1 ) { $newtext = " "; } my $nl = $source->findnodes( "//manual/section[\@order='$sec']/$name" ); my @para_nodes = $nl->[0]->childNodes(); # remove child nodes (paragraphs) foreach my $node (@para_nodes) { $nl->[0]->removeChild( $node ); } # add new paragraphs $newtext =~ s/\r//g; my @para = split( /\n\n/, $newtext ); foreach my $p (@para) { $p =~ s/\n/ /g; # strip any extra newlines my $node = $source->createElement( 'paragraph' ); my $text = XML::LibXML::Text->new( $p ); $node->appendChild($text); $nl->[0]->appendChild($node); } } if ( defined($fdat{sv} ) ) { replace_paragraphs( $source, $fdat{s}, "clientwording", $fdat{clientwording} ); # write out the new file if ( $source->toFile( $outfile ) ) { $txtIntro .= "

Section Saved

"; } else { $txtIntro .= "

Could not save document

"; }; } # # get list of schedules # # @schedules = (); my $sxml = '' ; $sxml .= "\n"; if ( opendir(DIR, $schedule_dir ) ) { while( defined( $file=readdir DIR ) ) { if( $file =~/(\d+)-(\d+)\.(.+)$/ ) { if( $fdat{s} == $1 && $3 ne 'title' ) { push( @schedules, $file ); # $txtIntro .= "here-->".$file." "; $sxml .= "$1-$2\n"; $sxml .= "$file\n"; $sxml.= "" . $site->readFile( $schedule_dir."/$1-$2.title"); $sxml .= "\n"; $sxml .= "\n"; } } } $sxml .="\n"; closedir(DIR); } else { $txtIntro .= "

Could not open dir: $schedule_dir

"; } #$txtIntro.= $sxml; # # transform the content # my $style_doc = $parser->parse_file( $xslfile ) if ( !$@ ); my $stylesheet = $xslt->parse_stylesheet( $style_doc ) if ( !$@ ); my $results; sub myMHMakeCode { my ($self, $processor, $severity, $facility, $code); return $code; # I can deal with internal numbers } sub myMHLog { my ($self, $processor, $code, $level, @fields); # open( FILE, ">>/tmp/sablo.log" ); # print FILE @_; # close( FILE ); } sub myMHError { # my ($self, $processor, $code, $level, @fields); open( FILE, ">>/tmp/sablo.err" ); foreach my $m(@_) { print FILE $m."\n"; } close( FILE ); } my $sab = new XML::Sablotron; my $sit = new XML::Sablotron::Situation; $sab->RegHandler(0, { MHMakeCode => \&myMHMakeCode, MHLog => \&myMHLog, MHError => \&myMHError }); $sab->addParam( $sit, 'tab', $fdat{t} ); $sab->addParam( $sit, 'section', $fdat{s} ); $sab->addParam( $sit, 'username', $fdat{u} ); $sab->addArg( $sit, 'schedules', $sxml ); my $link = "/client/data/$fdat{u}/schedules/"; $sab->addParam( $sit, 'link', $link ); #if ( defined($fdat{t} ) ) { # $results = $stylesheet->transform( $source, # XML::LibXSLT::xpath_to_string( tab => $fdat{t} )) if ( !$@ ); #} else { # if ( !$@ ) { # if ( defined($fdat{s} ) ) { # $results = $stylesheet->transform( $source, # XML::LibXSLT::xpath_to_string( 'section'=>$fdat{s},'username'=>$fdat{u} )); # } else { ## print OUT $fdat{u}; # $results = $stylesheet->transform( $source, # XML::LibXSLT::xpath_to_string( 'username'=>$fdat{u} )); # } # } #} #$tblContents .= $stylesheet->output_string($results) if ( !$@ ); $sab->process( $sit, $xslfile, $xmlfile, 'arg:/output' ); $tblContents .= $sab->getResultArg('arg:/output'); EndOfEval if ( $@ ) { $tblContents .= "Error processing XML: $@"; } my $tbl = HTML::Table->new( -width=>'100%' ); $tbl->setCellPadding( 15 ); my $r = 0; $tbl->addRow( $txtIntro ); $r++; $tbl->addRow( $tblContents ); # # output page # print OUT $site->start(); print OUT $site->readFile( "/home/sean/work/rcm/www/popup.js" ); print OUT $site->frameContent( $tbl ); print OUT $site->end(); -]