+sub ach_add
+{
+ my ($self) = @_;
+ my $arg = $self->get_form('ach', 'mtxcmd', 'device', 'precmd');
+
+ my $b = new Bconsole(pref => $self->{info});
+ my @storages = $b->list_storage() ;
+
+ unless ($arg->{ach}) {
+ $arg->{devices} = [ map { { name => $_ } } @storages ];
+ return $self->display($arg, "ach_add.tpl");
+ }
+
+ my @drives ;
+ foreach my $drive (CGI::param('drive'))
+ {
+ unless (grep(/^$drive$/,@storages)) {
+ return $self->error("Can't find $drive in storage list");
+ }
+
+ my $index = CGI::param("index_$drive");
+ unless (defined $index and $index =~ /^(\d+)$/) {
+ return $self->error("Can't get $drive index");
+ }
+
+ $drives[$index] = $drive;
+ }
+
+ unless (@drives) {
+ return $self->error("Can't get drives from Autochanger");
+ }
+
+ my $a = new Bweb::Autochanger(name => $arg->{ach},
+ precmd => $arg->{precmd},
+ drive_name => \@drives,
+ device => $arg->{device},
+ mtxcmd => $arg->{mtxcmd});
+
+ return Bweb::Autochanger::register($a, $self) ;
+}
+