X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=PciIds%2FHtml%2FAdmin.pm;h=c1ef0517a6ff110923607cfdcc294b4fd66437d2;hb=c283ded753a71438790694d443171c33f95a04c2;hp=a8aa592884e337b6c326c25a90b0a177e46b09ac;hpb=b6ba9607f9f08eddea8c6cd6ef3120984eae831a;p=pciids.git diff --git a/PciIds/Html/Admin.pm b/PciIds/Html/Admin.pm index a8aa592..c1ef051 100644 --- a/PciIds/Html/Admin.pm +++ b/PciIds/Html/Admin.pm @@ -10,14 +10,27 @@ use PciIds::Address; use PciIds::Log; use Apache2::Const qw(:common :http); -sub genNewAdminForm( $$$$ ) { - my( $req, $args, $tables, $error ) = @_; +sub safeEncode( $ ) { + my( $text ) = @_; + return encode( $text ) if defined $text; + return ''; +} + +sub mailEncode( $ ) { + my( $email ) = @_; + return '' unless defined $email; + return "".encode( $email ).""; +} + +sub genNewAdminForm( $$$$$ ) { + my( $req, $args, $tables, $error, $auth ) = @_; my $address = PciIds::Address::new( $req->uri() ); my $prefix = $address->get(); $prefix = '' if( $args->{'global'} ); - my $caption = 'Administration ‒ pending events '.( $args->{'global'} ? '(Global)' : '('.encode( $address->pretty() ).')' ); + my $caption = 'Administration '.( $args->{'global'} ? '(Global)' : '('.encode( $address->pretty() ).')' ); genHtmlHead( $req, $caption, undef ); - genCustomHead( $req, $args, $address, $caption, [ $address->canAddItem() ? [ 'Add item', 'newitem' ] : (), $address->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), [ 'Help', 'help', 'admin' ], [ '', 'jump' ] ], [ [ 'Log out', 'logout' ] ] ); + my $glob = delete $args->{'global'}; + genCustomHead( $req, $args, $address, $caption, [ $address->canAddItem() ? [ 'Add item', 'newitem' ] : (), $address->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), $glob ? [ 'Local', 'admin' ] : [ 'Global', 'admin?global=1' ], [ 'Help', 'help', 'admin' ], [ '', 'jump' ] ], [ [ 'Log out', 'logout' ] ] ); print "
$error
\n" if( defined $error ); print "
\n"; my $lastId; @@ -25,52 +38,58 @@ sub genNewAdminForm( $$$$ ) { my $cnt = 0; my $hiscnt = 0; my $subcnt; + print "

Any action approves all discussion\n"; + print "\n"; + print "\n"; + print ""; + } else { + print ""; + } + print "
IDNameNoteDiscussionAuthorOkSelDel\n"; foreach( @{$tables->adminDump( $prefix )} ) { my( $locId, $actName, $actNote, $actHist, $actUser, $actDisc, $hist, $disc, $name, $note, $user ) = @{$_}; if( !defined( $lastId ) || ( $lastId ne $locId ) ) { + last if( $hiscnt > 80 ); $lastId = $locId; - print "\n" if( $started ); $started = 1; - print "
\n"; my $addr = PciIds::Address::new( $locId ); - print "

".encode( $addr->pretty() )."

\n"; - print htmlDiv( 'name', '

'.encode( $actName ) ) if( defined( $actName ) ); - print htmlDiv( 'note', '

'.encode( $actNote ) ) if( defined( $actNote ) ); - print '

'.encode( $actDisc ) if( defined( $actDisc ) ); - print '

'.encode( $addr->parent()->pretty() )."" if( defined( $addr->parent() ) ); - print htmlDiv( 'author', '

'.encode( $actUser ) ) if( defined( $actUser ) ); - print "\n" if( defined( $subcnt ) ); + if( defined( $actHist ) ) { + print "

".encode( $addr->pretty() )."".safeEncode( $actName )."".safeEncode( $actNote )."".safeEncode( $actDisc )."".mailEncode( $actUser ); + + print "" if( $subcnt ); $subcnt = 0; $cnt++; print "\n"; - print "

I will decide later.\n"; - if( defined( $actHist ) ) { - print "
Keep current name.\n"; + print "

"; + print ""; + if( hasRight( $auth->{'accrights'}, 'prune' ) || ( !defined $actHist && !$tables->hasChildren( $addr->get() ) ) ) { + print "\n"; + } else { + print ""; } - print "
Delete item.\n"; - print "
Add discussion:\n"; - print "
\n"; - print "
Set name:\n"; - print "
Set note:\n"; - print "
Discussion:\n"; - print "
\n"; + print "
New:\n"; + print ""; + genPathBare( $req, $addr, 0, 0 ); + print "\n"; } - print "
\n"; - print "

".encode( $name ) if( defined( $name ) ); - print "

".encode( $note ) if( defined( $note ) ); - print '

'.encode( $disc ) if( defined( $disc ) ); - print "

".encode( $user ) if( defined( $user ) ); - print "

Use this one.\n" if( defined( $name ) && ( $name ne "" ) ); + print "

".safeEncode( ( defined $name && $name eq '' ) ? 'Deletion request' : $name )."".safeEncode( $note )."".safeEncode( $disc )."".mailEncode( $user ); $hiscnt ++; - print "
Delete history.\n"; - print "\n"; $subcnt ++; - print "\n"; + print ""; + print "
"; + if( defined $name ) { + print ""; + } else { + print ""; + } + print ""; + print "\n"; } + print "
\n"; print "\n" if( defined( $subcnt ) ); if( $started ) { - print "\n" if( $started ); + print "" if( $subcnt ); print "

\n"; print "\n"; } else { @@ -84,22 +103,19 @@ sub genNewAdminForm( $$$$ ) { sub adminForm( $$$$ ) { my( $req, $args, $tables, $auth ) = @_; if( defined( $auth->{'authid'} ) && hasRight( $auth->{'accrights'}, 'validate' ) ) { - return genNewAdminForm( $req, $args, $tables, undef ); + return genNewAdminForm( $req, $args, $tables, undef, $auth ); } else { return notLoggedComplaint( $req, $args, $auth ); } } -sub markAllChecked( $$$$ ) { - my( $tables, $itemNum, $deleted, $authid ) = @_; - my $i; - my $subcnt = getFormValue( "subcnt-$itemNum", 0 ); - for( $i = 1; $i <= $subcnt; ++ $i ) { - my $id = getFormValue( "sub-$itemNum-$i", undef ); - next unless( defined( $id ) ); - next if( $deleted->{$id} );#Do not update this one, already deleted - $tables->markChecked( $id ); - tulog( $authid, "Discussion checked $id" ); +my $errors; + +sub appendError( $ ) { + if( $errors eq '' ) { + $errors = "

".shift; + } else { + $errors .= "
".shift; } } @@ -107,66 +123,97 @@ sub submitAdminForm( $$$$ ) { my( $req, $args, $tables, $auth ) = @_; my $authid = $auth->{'authid'}; if( defined( $authid ) && hasRight( $auth->{'accrights'}, 'validate' ) ) { - my $errors = ''; - my %deleted; + my( %deleted, %approved ); my $maxcnt = getFormValue( 'max-cnt', 0 ); my $maxhiscnt = getFormValue( 'max-hiscnt', 0 ); + $errors = ''; + # Scan for approved and deleted items for( my $i = 1; $i <= $maxhiscnt; $i ++ ) { - my $del = getFormValue( "delete-$i", "" ); - $del =~ s/^delete-//; - if( $del ne '' ) { - $deleted{$del} = 1; - $tables->deleteHistory( $del ); - tulog( $authid, "Discussion deleted $del" ); + my( $del ) = getFormValue( "del-$i", '' ) =~ /^del-(\d+)$/; + $deleted{$del} = 1 if( defined $del && $del ne '' ); + my( $appr ) = getFormValue( "appr-$i", '' ) =~ /^appr-(\d+)$/; + $approved{$appr} = 1 if( defined $appr && $appr ne '' ); + } + for( my $i = 1; $i <= $maxcnt; $i ++ ) { + my( $sel ) = getFormValue( "loc-$i-sel", '' ) =~ /^(\d+)$/; + $approved{$sel} = 1 if( defined $sel && $sel ne '' ); + } + # Check for collisions + my %collision; + foreach my $id ( keys %deleted ) { + if( $approved{$id} ) { + my $owner = getFormValue( "owner-$id", '' ); + appendError( "You can not approve and delete history at the same time, not modifying item ".PciIds::Address::new( $owner )->pretty() ); + $collision{$owner} = $_; + delete $deleted{$id}; + delete $approved{$id}; } } + #Do the deletes and approves + foreach my $del ( keys %deleted ) { + $tables->deleteHistory( $del ); + tulog( $authid, "Discussion deleted $del" ); + } + foreach my $appr ( keys %approved ) { + $tables->markChecked( $appr ); + tulog( $authid, "Discussion checked $appr" ); + } + #Handle the items + my $defaultSeen = getFormValue( 'default-seen', '' ) =~ /^default-seen$/; for( my $i = 1; $i <= $maxcnt; $i ++ ) { - my $action = getFormValue( "action-$i", 'ignore' ); - my $loc = getFormValue( "loc-$i", undef ); - next unless( defined( $loc ) ); - my( $discussion, $name, $note ) = ( - getFormValue( "discussion-$i", undef ), - getFormValue( "name-$i", undef ), - getFormValue( "note-$i", undef ) ); - if( defined( $note ) && ( $note ne '' ) && ( !defined( $name ) || ( length $name < 3 ) ) ) { - if( $errors eq '' ) { - $errors = '

'; - } else { - $errors .= '
'; - } - $errors .= "$loc - You need to provide name if you provide note\n"; + my $addr = PciIds::Address::new( getFormValue( "loc-$i", '' ) ); + next if $collision{$addr->get()}; + next unless defined $addr; + my $del = getFormValue( "loc-$i-del", '' ); + if( defined $del && $del eq 'del' && ( hasRight( $auth->{'accrights'}, 'prune' ) || ( !$tables->hasChildren( $addr->get() ) && !$tables->hasMain( $addr->get() ) ) ) ) { + $tables->deleteItem( $addr->get() ); + tulog( $authid, "Item deleted (recursive) ".$addr->get() ); next; } - if( ( defined( $name ) && ( length $name >= 3 ) ) || ( defined( $discussion ) && ( $discussion ne '' ) ) ) { #Submited comment - my $addr = PciIds::Address::new( $loc ); - my $histId = $tables->submitHistory( { 'name' => $name, 'note' => $note, 'text' => $discussion }, $auth, $addr ); - my $main = defined $name && ( $name ne '' ); - notify( $tables, $addr->get(), $histId, $main ? 2 : 0, $main ? 2 : 1 ); + my $name = getFormValue( "name-$i", undef ); + $name = undef if defined $name && $name eq ''; + my $note = getFormValue( "note-$i", undef ); + $note = undef if defined $note && $note eq ''; + my $discussion = getFormValue( "disc-$i", '' ); + $discussion = undef if defined $discussion && $discussion eq ''; + my $delete = 0; + if( getFormValue( "loc-$i-softdel", '' ) =~ /^del$/ ) { + $delete = 1; + $name = undef; + $note = undef; + } + if( defined $note && !defined $name ) { + appendError( "You must specify name if you set note at item ".$addr->pretty() ); + next; + } + my( $select ) = getFormValue( "loc-$i-sel", '' ) =~ /^(\d+)$/; + my $action = 0; + if( defined $name || defined $discussion || $delete ) { + my $histId = $tables->submitHistory( { 'name' => $name, 'note' => $note, 'text' => $discussion, 'delete' => $delete }, $auth, $addr ); $tables->markChecked( $histId ); - tulog( $authid, "Discussion submited (admin) $histId $loc ".logEscape( $name )." ".logEscape( $note )." ".logEscape( $discussion ) ); - if( defined( $name ) && ( length $name >= 3 ) ) { - $tables->setMainHistory( $loc, $histId ); - tulog( $authid, "Item main history changed $loc $histId" ); - $action = 'keep'; - } + $select = $histId if defined $name || $delete; + tulog( $authid, "Discussion submited (admin) $histId ".$addr->get()." ".logEscape( $name )." ".logEscape( $note )." ".logEscape( $discussion ) ); + $action = 1; + notify( $tables, $addr->get(), $histId, defined $name ? 1 : 0, 1 ); } - next if( $action eq 'ignore' ); - if( $action eq 'keep' ) { - markAllChecked( $tables, $i, \%deleted, $authid ); - } elsif( $action eq 'delete' ) { - eval { - $tables->deleteItem( $loc ); - tulog( $authid, "Item deleted (recursive) $loc" ); - } #Ignore if it was already deleted by superitem - } elsif( my( $setId ) = ( $action =~ /set-(.*)/ ) ) { - next if( $deleted{$setId} ); - $tables->setMainHistory( $loc, $setId ); - notify( $tables, $loc, $setId, 2, 2 ); - tulog( $authid, "Item main history changed $loc $setId" ); - markAllChecked( $tables, $i, \%deleted, $authid ); + if( defined $select && select ne '' ) { + $tables->setMainHistory( $addr->get(), $select ); + tulog( $authid, "Item main history changed ".$addr->get()." $select" ); + $action = 1; + notify( $tables, $addr->get(), $select, 2, 2 ); + } + if( $action && $defaultSeen ) {#Approve anything in this item + my $subcnt = getFormValue( "loc-$i-subcnt", 0 ); + for( my $j = 1; $j <= $subcnt; $j ++ ) { + my( $id ) = getFormValue( "his-$i-$j", '' ) =~ /^(\d+)$/; + next unless defined $id; + next if $approved{$id} || $deleted{$id}; + $tables->markChecked( $id ); + tulog( $authid, "Discussion checked $id" ); + } } } - return genNewAdminForm( $req, $args, $tables, $errors ); + return genNewAdminForm( $req, $args, $tables, $errors, $auth ); } else { return notLoggedComplaint( $req, $args, $auth ); }