%doc>
Special edit component intended to edit scope templates.
%doc>
<%attr>
title => 'Template Edit'
section => 'Management'
%attr>
<%args>
$id => undef
$scope_use_obj => undef
$user => $ui->get_current_user($r)
$submit => undef
$cancel => undef
$showheader => 1
$select_id => undef
$selectall_ids => undef;
$selected => undef
$dowindow => undef
%args>
<%init>
if(!$id){
return; #ugly hack so that when autohandler is calling all the pages in procession, this page dosnt get loaded
#after we hit the [back] link
}
my @select_all;
my $new_select_ids;
my @delete_array;
if($selectall_ids){
@select_all = split(" ", $selectall_ids);
}
my $DEBUG = 0;
my $scope_obj;
my $manager = $ui->get_permission_manager($r);
my $page = $ui->table_view_page("DhcpScopeUse");
if($DEBUG){
foreach my $i (keys %ARGS){
print "$i $ARGS{$i}
";
}
}
$scope_obj = DhcpScope->retrieve($id);
unless ( $manager && $manager->can($user, "edit", $scope_obj) ){
$m->comp('/generic/error.mhtml', error=>"You don't have permission to edit this object");
}
if($submit){
if ($submit eq "Update"){ #there is a prexisting entry for this
my %update_args;
for my $t (@select_all){
my $temp_key = "$t".'template_select';
chomp($temp_key);
#why this ugly hack? I tried building the hash key with $temp_key and using it directly to
#access the information I wanted, but it NEVER WOULD... They look exactly the same when you output the info
#but there must be some crucial difference since $ARGS{$temp_key} would always be null, so this is an ugly
#work around :/
foreach my $i (keys %ARGS){
if($i == $temp_key){
$update_args{$i} = $ARGS{$i};
}
}
}
eval{
for my $t (keys %update_args){
my $o = DhcpScopeUse->retrieve($t);
$o->update({template=> $update_args{$t}});
}
};
if ( my $e = $@ ){
$m->comp('/generic/error.mhtml', error=>$e);
}
#lets remove all the items we're supposed to delete
#$ARGS{"delete"} can either contain a string with the DhcpScopeUse object id
#we want to delete (if the user has selected a single item to delete)
#or it can be an arrayref full of them. We try to use it
#as an arrayref, but if this fails we treat it like a string
;
eval{
@delete_array = @{$ARGS{"delete"}};
};
if($@){
push(@delete_array, $ARGS{"delete"});
}
foreach my $d (@delete_array){
my $o = DhcpScopeUse->retrieve($d);
if($o){
$o->delete();
#remove element from select_all array
for(my $i; $i < scalar @select_all; $i++){
if($select_all[$i] == $d){
splice(@select_all, $i, 1);
last;
}
}
}
}
foreach (@select_all){
$new_select_ids.= "$_ ";
}
}
else{ #if this wasn't set, we must have been inserting.
my $new;
eval{
$new = DhcpScopeUse->insert({scope=>$scope_obj, template=>$ARGS{"template_select"}});
};
if ( my $e = $@ ){
$m->comp('error.mhtml', error=>$e);
}
}
}
else{
$new_select_ids = $selectall_ids;
}
%init>
% print "$scope_name_hash{'label'} $scope_name_hash{'value'} "; |
|