Allow cancelling several jobs at once

This commit is contained in:
Jamie Cameron
2007-11-15 08:24:30 +00:00
parent 2a6e1bd5c3
commit 547b14fb1c
7 changed files with 73 additions and 46 deletions

View File

@ -11,3 +11,5 @@ Added clustering support, so that printers can be created, modified and deleted
Added checkboxes and a button for deleting multiple printers at once.
---- Changes since 1.300 ----
Fixed a bug that stopped SMB printer usernames and passwords from being displayed when editing a printer under CUPS.
---- Changes since 1.380 ----
Re-designed the print jobs page to allow several to be cancelled at once, using the standard Webmin table with checkboxes.

View File

@ -1,17 +1,19 @@
#!/usr/local/bin/perl
# cancel_all.cgi
# Cancel all print jobs on some printer
# Cancel some jobs on the selected printer
require './lpadmin-lib.pl';
&ReadParse();
&error_setup($text{'cancel_err'});
%d = map { $_, 1 } split(/\0/, $in{'d'});
@jobs = &get_jobs($in{'name'});
foreach $j (@jobs) {
next if (!$d{$j->{'id'}});
($ju = $j->{'user'}) =~ s/\!.*$//;
&can_edit_jobs($in{'name'}, $ju) || &error($text{'cancel_ecannot'});
&cancel_job($in{'name'}, $j->{'id'});
}
&webmin_log("cancel", "all", $in{'name'});
&webmin_log("cancelsel", undef, $in{'name'},
{ 'd' => scalar(keys %d) } );
&redirect("list_jobs.cgi?name=$in{'name'}");

View File

@ -112,10 +112,12 @@ jobs_when=Submitted At
jobs_file=Filename
jobs_cancel=Click on a job ID from the list above to cancel.
jobs_cancelview=Click on a job ID from the list above to cancel, or click on the job size to view it.
jobs_none=No print jobs on $1
jobs_none=The printer $1 does not have any pending jobs.
jobs_all=Cancel all print jobs
jobs_bytes=bytes
jobs_test=Print Test Page
jobs_cancelsel=Cancel Selected Jobs
jobs_on=On printer $1
cancel_ecannot=You are not allowed to cancel print jobs
cancel_err=Failed to cancel print job
@ -217,6 +219,7 @@ log_start=Started print scheduler
log_restart=Restarted print scheduler
log_cancel_job=Cancelled print job $2 on $1
log_cancel_all=Cancelled all print jobs on $1
log_cancel_sel=Cancelled $2 print jobs on $1
log_create=Created printer $1 on $2
log_modify=Modified printer $1 on $2
log_delete=Deleted printer $1 on $2

View File

@ -6,68 +6,82 @@ require './lpadmin-lib.pl';
&ReadParse();
print "Refresh: $config{'queue_refresh'}\r\n"
if ($config{'queue_refresh'});
&ui_print_header(undef, $text{'jobs_title'}, "");
&ui_print_header(&text('jobs_on', "<tt>$in{'name'}</tt>"),
$text{'jobs_title'}, "");
@jobs = &get_jobs($in{'name'});
if (@jobs) {
print &ui_subheading(&text('jobs_header', "<tt>$in{'name'}</tt>"));
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'jobs_id'}</b></td>\n";
print "<td><b>$text{'jobs_size'}</b></td>\n";
print "<td><b>$text{'jobs_by'}</b></td>\n";
if ($jobs[0]->{'when'}) {
print "<td><b>$text{'jobs_when'}</b></td>\n";
}
if ($jobs[0]->{'file'}) {
print "<td><b>$text{'jobs_file'}</b></td>\n";
if ($access{'cancel'}) {
# Start of cancel form
print &ui_form_start("cancel_all.cgi", "post");
print &ui_hidden("name", $in{'name'});
@tds = ( "width=5" );
@links = ( &select_all_link("d"), &select_invert_link("d") );
print &ui_links_row(\@links);
}
print &ui_columns_start([
$access{'cancel'} ? ( "" ) : ( ),
$text{'jobs_id'},
$text{'jobs_size'},
$text{'jobs_by'},
$jobs[0]->{'when'} ? ( $text{'jobs_when'} ) : ( ),
$jobs[0]->{'file'} ? ( $text{'jobs_file'} ) : ( ),
], 100, 0, \@tds);
foreach $j (@jobs) {
local $ju = $j->{'user'};
$ju =~ s/\!.*$//;
print "<tr $cb>\n";
if (&can_edit_jobs($in{'name'}, $ju)) {
print "<td><a href=\"cancel_job.cgi?name=$in{'name'}&",
"id=$j->{'id'}\">",&html_escape($j->{'id'}),
"</a></td>\n";
}
else {
print "<td>",&html_escape($j->{'id'}),"</td>\n";
}
local @cols;
push(@cols, &html_escape($j->{'id'}));
if ($j->{'printfile'} && &can_edit_jobs($in{'name'}, $ju)) {
print "<td><a href='view_job.cgi?name=$in{'name'}",
"&id=$j->{'id'}'>",&html_escape($j->{'size'}),
" $text{'jobs_bytes'}</a></td>\n";
push(@cols,
"<a href='view_job.cgi?name=$in{'name'}".
"&id=$j->{'id'}'>".&nice_size($j->{'size'})."</a>");
$printfile++;
}
else {
print "<td>",&html_escape($j->{'size'}),
" $text{'jobs_bytes'}</td>\n";
push(@cols, &nice_size($j->{'size'}));
}
if ($j->{'user'} =~ /^(\S+)\!(\S+)$/) {
print "<td>",&html_escape("$2\@$1"),"</td>\n";
push(@cols, &html_escape("$2\@$1"));
}
else {
push(@cols, &html_escape($j->{'user'}));
}
if ($j->{'when'}) {
push(@cols, $j->{'when'});
}
if ($j->{'file'}) {
push(@cols, $j->{'file'});
}
if (&can_edit_jobs($in{'name'}, $ju) &&
$access{'cancel'}) {
# Can cancel this job
print &ui_checked_columns_row(\@cols, \@tds,
"d", $j->{'id'});
}
elsif ($access{'cancel'}) {
# Can cancel, but not this job
print &ui_columns_row([ "", @cols ], \@tds);
}
else {
# Cannot cancel at all
print &ui_columns_row(\@cols, \@tds);
}
else { print "<td>",&html_escape($j->{'user'}),"</td>\n"; }
if ($j->{'when'}) { print "<td>$j->{'when'}</td>\n"; }
if ($j->{'file'}) { print "<td>$j->{'file'}</td>\n"; }
print "</tr>\n";
}
print "</table>\n";
print &ui_columns_end();
if ($access{'cancel'}) {
print "<table width=100%><tr><td>\n";
print $printfile ? $text{'jobs_cancelview'}
: $text{'jobs_cancel'},"<br>\n";
print "</td> <td align=right>",
"<a href='cancel_all.cgi?name=$in{'name'}'>",
"$text{'jobs_all'}</a></td> </tr></table>\n";
print &ui_links_row(\@links);
print &ui_form_end([ [ undef, $text{'jobs_cancelsel'} ] ]);
}
}
else {
print "<b>",&text('jobs_none', "<tt>$in{'name'}</tt>"),"</b><p>\n";
}
print "<form action=test_form.cgi>\n";
print "<input type=hidden name=name value='$in{'name'}'>\n";
print "<input type=submit value='$text{'jobs_test'}'></form><p>\n";
# Test print button
print &ui_form_start("test_form.cgi");
print &ui_hidden("name", $in{'name'});
print &ui_form_end([ [ undef, $text{'jobs_test'} ] ]);
&ui_print_footer("", $text{'index_return'});

View File

@ -13,6 +13,10 @@ if ($action eq 'cancel') {
"<tt>".&html_escape($object)."</tt>",
"<tt>".&html_escape($p->{'id'})."</tt>");
}
elsif ($action eq 'cancelsel') {
return &text("log_cancel_sel", "<tt>".&html_escape($object)."</tt>",
$p->{'d'});
}
elsif ($action eq 'stop') {
return $text{'log_stop'};
}

View File

@ -5,7 +5,8 @@
require './lpadmin-lib.pl';
&ReadParse();
$access{'test'} || &error($text{'test_ecannot'});
&ui_print_header(undef, $text{'test_title'}, "");
&ui_print_header(&text('jobs_on', "<tt>$in{'name'}</tt>"),
$text{'test_title'}, "");
print "<form action=test_print.cgi method=post enctype=multipart/form-data>\n";
print "<input type=hidden name=name value='$in{'name'}'>\n";

View File

@ -6,7 +6,8 @@ require './lpadmin-lib.pl';
&foreign_require("proc", "proc-lib.pl");
&ReadParseMime();
$access{'test'} || &error($text{'test_ecannot'});
&ui_print_header(undef, $text{'test_title'}, "");
&ui_print_header(&text('jobs_on', "<tt>$in{'name'}</tt>"),
$text{'test_title'}, "");
if ($in{'mode'} == 0) {
$file = "bw.ps";