Changeset 16 for trunk/dns.cgi


Ignore:
Timestamp:
09/15/09 17:52:13 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r15 r16  
    177177
    178178} elsif ($webvar{page} eq 'record') {
     179
    179180  if ($webvar{recact} eq 'new') {
     181
    180182    $page->param(todo => "Add record to");
    181183    $page->param(recact => "add");
    182     stdrecs();
     184    fill_rectypes();
     185
    183186  } elsif ($webvar{recact} eq 'add') {
    184187
     
    191194      }
    192195    }
    193   # wtf?
    194   #  push @recargs,
    195196    my ($code,$msg) = addRec(@recargs);
    196197
    197198    if ($code eq 'OK') {
    198199      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    199 #      showdomain($webvar{defrec},$webvar{parentid});
    200   # NB: should **really** redirect here, in case of reload.  >_<  eyowch.
    201200    } else {
    202       $page->param(add_failed => 1);
     201      $page->param(failed => 1);
    203202      $page->param(errmsg => $msg);
    204       stdrecs($webvar{type});   # populate the form... er, mostly.
    205       $page->param(name => $webvar{name});
    206       $page->param(address => $webvar{address});
    207       $page->param(distance => $webvar{distance})
    208         if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
    209       $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
    210       $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
    211     }
    212 
    213     $page->param(defrec => $webvar{defrec});
     203      fill_recdata();   # populate the form... er, mostly.
     204    }
    214205
    215206  } elsif ($webvar{recact} eq 'edit') {
    216207
    217     $page->param(todo => "Edit record in");
     208    $page->param(todo           => "Update record");
     209    $page->param(recact         => "update");
     210    $page->param(parentid       => $webvar{parentid});
     211    $page->param(defrec         => $webvar{defrec});
    218212    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
    219213        ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
     
    226220    $page->param(port           => $port);
    227221    $page->param(ttl            => $ttl);
    228     stdrecs($type);
    229   }
     222    fill_rectypes($type);
     223
     224  } elsif ($webvar{recact} eq 'update') {
     225
     226    my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
     227        $webvar{name},$webvar{type},$webvar{address},$webvar{ttl},
     228        $webvar{distance},$webvar{weight},$webvar{port});
     229
     230    if ($code eq 'OK') {
     231      $page->param(failed       => 1);
     232      $page->param(errmsg       => "testing");
     233      $page->param(wastrying    => "updating");
     234      $page->param(todo         => "Update record");
     235      $page->param(recact       => "update");
     236      $page->param(parentid     => $webvar{parentid});
     237      $page->param(defrec       => $webvar{defrec});
     238      fill_recdata();
     239#      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
     240    } else {
     241      $page->param(failed       => 1);
     242      $page->param(errmsg       => $msg);
     243      $page->param(wastrying    => "updating");
     244      $page->param(todo         => "Update record");
     245      $page->param(recact       => "update");
     246      $page->param(parentid     => $webvar{parentid});
     247      $page->param(defrec       => $webvar{defrec});
     248      fill_recdata();
     249    }
     250  }
     251
    230252  if ($webvar{defrec} eq 'y') {
    231     $page->param(domain => "group ".grpName($dbh,$webvar{parentid}));
    232   } else {
    233     $page->param(domain => domainName($dbh,$webvar{parentid}));
     253    $page->param(dohere => "group ".grpName($dbh,$webvar{parentid}));
     254  } else {
     255    $page->param(dohere => domainName($dbh,$webvar{parentid}));
    234256  }
    235257
     
    464486}
    465487
    466 sub stdrecs {
     488# fill in record type list on add/update/edit record template
     489sub fill_rectypes {
    467490  my $type = shift || $reverse_typemap{A};
    468491
    469492  my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
    470493  $sth->execute;
    471 
    472 push @debugbits, "DEBUG: type $type\n";
     494push @debugbits, "type $type";
    473495  my @typelist;
    474496  while (my ($rval,$rname) = $sth->fetchrow_array()) {
     
    478500  }
    479501  $page->param(typelist => \@typelist);
    480   $page->param(domain   => domainName($dbh,$webvar{domainid}));
    481   $page->param(defrec   => $webvar{defrec});
     502}
     503
     504sub fill_recdata {
     505  fill_rectypes($webvar{type});
     506
     507  $page->param(name     => $webvar{name});
     508  $page->param(address  => $webvar{address});
     509  $page->param(distance => $webvar{distance})
     510        if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
     511  $page->param(weight   => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
     512  $page->param(port     => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
    482513  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
    483   if ($webvar{defrec} eq 'y') {
    484     ##fixme - should be groupid
    485     $page->param(parentid => 1);
    486   } else {
    487 print "DEBUG: foobar:  parentid $webvar{parentid}<br>\n";
    488     $page->param(parentid => $webvar{parentid});
    489   }
    490514}
    491515
Note: See TracChangeset for help on using the changeset viewer.