From 68fdefdf5f32b47d1c033736116b1100d72f0200 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Thu, 4 Sep 2008 17:08:41 +0200 Subject: [PATCH] Stock answers combo box A combo box for selecting a stock answer appeared in the admin interface It uses java script to set it into discussion. If javascript is not present, value directly from the combo box is used (unless left untouched). --- PciIds/Html/Admin.pm | 73 ++++++++++++++++++++++++++++++++++++++++---- answers | 5 +++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 answers diff --git a/PciIds/Html/Admin.pm b/PciIds/Html/Admin.pm index 8ad40da..c539686 100644 --- a/PciIds/Html/Admin.pm +++ b/PciIds/Html/Admin.pm @@ -8,6 +8,7 @@ use PciIds::Html::Forms; use PciIds::Notifications; use PciIds::Address; use PciIds::Log; +use PciIds::Startup; use Apache2::Const qw(:common :http); sub safeEncode( $ ) { @@ -42,14 +43,47 @@ sub genHist( $$$$$$$$$$$ ) { print "\n" if defined $delname } -sub genNewForm( $ ) { - my( $num ) = @_; - print "TODO combo"; +sub genNewForm( $$ ) { + my( $num, $values ) = @_; + print ""; + if( @{$values} ) { + print "\n"; + } else { + print "No stock answers"; + } print "Name: Note:
\n"; - print "\n"; + print "\n"; print "\n"; } +sub loadStock() { + my @stock; + if( open ANS, "$directory/answers" ) { + my( $name, $text, $lines ); + while( defined( $name = ) ) { + $lines = ''; + while( defined( $text = ) ) { + chomp $text; + last if $text eq ''; + $lines .= '
' if $lines ne ''; + $lines .= encode( $text ); + } + push @stock, [ encode( $name ), $lines ]; + } + close ANS; + } else { + print STDERR "Could not find stock answers.\n"; + } + return \@stock; +} + sub genNewAdminForm( $$$$$ ) { my( $req, $args, $tables, $error, $auth ) = @_; my $address = PciIds::Address::new( $req->uri() ); @@ -69,6 +103,26 @@ sub genNewAdminForm( $$$$$ ) { my $cnt = 0; my $hiscnt = 0; my $subcnt; + my $stock = loadStock(); + print "";#Trick to find out if user has JScript + print ""; foreach( @{$tables->adminDump( $prefix, $limit )} ) { my( $locId, $actName, $actNote, $actHist, $actEmail, $actLogin, $actDisc, $actTime, $hist, $disc, $name, $note, $email, $login, $time ) = @{$_}; @@ -76,7 +130,7 @@ sub genNewAdminForm( $$$$$ ) { last if( $hiscnt > ( defined $limit ? $limit : 80 ) ); $lastId = $locId; if( $started ) { - genNewForm( $cnt ); + genNewForm( $cnt, $stock ); print "\n"; } else { $started = 1; @@ -111,7 +165,7 @@ sub genNewAdminForm( $$$$$ ) { } print "\n" if( defined( $subcnt ) ); if( $started ) { - genNewForm( $cnt ); + genNewForm( $cnt, $stock ); print "\n"; print "

\n"; print "" if( $subcnt ); @@ -148,6 +202,9 @@ sub submitAdminForm( $$$$ ) { my $authid = $auth->{'authid'}; if( defined( $authid ) && hasRight( $auth->{'accrights'}, 'validate' ) ) { my( %deleted, %approved ); + my $hasJscript = getFormValue( 'jscript-active', '0' ); + my $ans; + $ans = loadStock() unless $hasJscript;#If there is jscript, no need to translate my $maxcnt = getFormValue( 'max-cnt', 0 ); my $maxhiscnt = getFormValue( 'max-hiscnt', 0 ); $errors = ''; @@ -194,6 +251,10 @@ sub submitAdminForm( $$$$ ) { my $note = getFormValue( "note-$i", undef ); $note = undef if defined $note && $note eq ''; my $discussion = getFormValue( "disc-$i", '' ); + unless( $hasJscript ) {#Modified by the stock answers, is no jscript at user + my $index = getFormValue( "ans-$i", '0' ); + $discussion = $ans->[$index-1]->[1] if $index; + } $discussion = undef if defined $discussion && $discussion eq ''; my $delete = 0; if( getFormValue( "loc-$i-softdel", '' ) =~ /^del$/ ) { diff --git a/answers b/answers new file mode 100644 index 0000000..e1f3acc --- /dev/null +++ b/answers @@ -0,0 +1,5 @@ +USB +This is USB ID. + +Device +This is a device, not vendor. -- 2.39.2