#!/usr/local/bin/perl
# delete_printer.cgi
# Delete an existing printer

require './lpadmin-lib.pl';
&ReadParse();
&can_edit_printer($in{'name'}) || &error($text{'save_eedit'});
$prn = &get_printer($in{'name'});
$info = &log_info($prn);
&delete_printer($in{'name'});
&delete_driver($in{'name'});
&delete_webmin_driver($in{'name'});
&system_logged("$config{'apply_cmd'} >/dev/null 2>&1 </dev/null")
	if ($config{'apply_cmd'});
&webmin_log("delete", "printer", $prn->{'name'}, $info);

# remove from acl files
&read_acl(undef, \%wusers);
foreach $u (keys %wusers) {
	%uaccess = &get_module_acl($u);
	if ($uaccess{'printers'} ne '*') {
		$uaccess{'printers'} =
			join(' ', grep { $_ ne $in{'name'} }
				  split(/\s+/, $uaccess{'printers'}));
		&save_module_acl(\%uaccess, $u);
		}
	}
&redirect("");

