Ignore:
Timestamp:
07/30/10 17:56:48 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert assign.html to template; page seems to still have
validation problems. See #3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/main.cgi

    r451 r456  
    580580  }
    581581
    582   my $html;
     582  # hack pthbttt eww
     583  $webvar{block} = '' if !$webvar{block};
     584
     585# hmm.  TMPL_IF block and TMPL_ELSE block on these instead?
     586  $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
     587  $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
     588  $page->param(block => $webvar{block});        # fb-assign flag, if block is set, we're in fb-assign
     589  $page->param(iscontained => ($webvar{fbtype} && $webvar{fbtype} ne 'y'));
    583590
    584591  # New special case- block to assign is specified
    585592  if ($webvar{block} ne '') {
    586     open HTML, "../fb-assign.html"
    587         or croak "Could not open fb-assign.html: $!";
    588     $html = join('',<HTML>);
    589     close HTML;
    590593    my $block = new NetAddr::IP $webvar{block};
    591     $html =~ s|\$\$BLOCK\$\$|$block|g;
    592     $html =~ s|\$\$MASKBITS\$\$|$block->masklen|;
    593     my $typelist = '';
    594 
     594
     595    # Handle contained freeblock allocation.
    595596    # This is a little dangerous, as it's *theoretically* possible to
    596597    # get fbtype='n' (aka a non-routed freeblock).  However, should
    597598    # someone manage to get there, they get what they deserve.
    598599    if ($webvar{fbtype} ne 'y') {
    599       # Snag the type of the block from the database.  We have no
    600       # convenient way to pass this in from the calling location.  :/
     600      # Snag the type of the container block from the database.
    601601      $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'");
    602602      $sth->execute;
    603603      my @data = $sth->fetchrow_array;
    604604      $data[0] =~ s/c$/r/;      # Munge the type into the correct form
    605       $typelist = "$list_alloctypes{$data[0]}<input type=hidden name=alloctype value=$data[0]>\n";
     605      $page->param(fbdisptype => $list_alloctypes{$data[0]});
     606      $page->param(type => $data[0]);
    606607    } else {
    607       $typelist .= qq(<select name="alloctype">\n);
    608608      $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 ".
    609609        "and type not like '_i' and type not like '_r' order by listorder");
    610610      $sth->execute;
    611611      my @data = $sth->fetchrow_array;
    612       $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
     612      my @typelist;
     613      my $selflag = 0;
    613614      while (my @data = $sth->fetchrow_array) {
    614         $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
     615        my %row = (tval => $data[0],
     616                type => $data[1],
     617                sel => ($selflag == 0 ? ' selected' : '')
     618                );
     619        push (@typelist, \%row);
     620        $selflag++;
    615621      }
    616       $typelist .= "</select>\n";
    617     }
    618     $html =~ s|\$\$TYPELIST\$\$|$typelist|g;
     622      $page->param(typelist => \@typelist);
     623    }
    619624  } else {
    620     open HTML, "../assign.html"
    621         or croak "Could not open assign.html: $!";
    622     $html = join('',<HTML>);
    623     close HTML;
    624     my $masterlist = "<select name=allocfrom><option selected>-</option>\n";
     625    my @masterlist;
    625626    foreach my $master (@masterblocks) {
    626       $masterlist .= "<option>$master</option>\n";
    627     }
    628     $masterlist .= "</select>\n";
    629     $html =~ s|\$\$MASTERLIST\$\$|$masterlist|g;
    630     my $pops = '';
     627      my %row = (master => "$master");
     628      push (@masterlist, \%row);
     629    }
     630    $page->param(masterlist => \@masterlist);
     631
     632    my @pops;
    631633    foreach my $pop (@poplist) {
    632       $pops .= "<option>$pop</option>\n";
    633     }
    634     $html =~ s|\$\$POPLIST\$\$|$pops|g;
    635     my $typelist = '';
    636     $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 900 order by listorder");
     634      my %row = (pop => $pop);
     635      push (@pops, \%row);
     636    }
     637    $page->param(pops => \@pops);
     638
     639    # could arguably include routing (500) in the list, but ATM it doesn't
     640    # make sense, and in any case that shouldn't be structurally possible here.
     641    $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 order by listorder");
    637642    $sth->execute;
    638     my @data = $sth->fetchrow_array;
    639     $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
     643    my @typelist;
     644    my $selflag = 0;
    640645    while (my @data = $sth->fetchrow_array) {
    641       $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
    642     }
    643     $html =~ s|\$\$TYPELIST\$\$|$typelist|g;
    644   }
    645   my $cities = '';
     646      my %row = (tval => $data[0],
     647        type => $data[1],
     648        sel => ($selflag == 0 ? ' selected' : '')
     649        );
     650      push (@typelist, \%row);
     651      $selflag++;
     652    }
     653    $page->param(typelist => \@typelist);
     654  }
     655
     656  my @cities;
    646657  foreach my $city (@citylist) {
    647     $cities .= "<option>$city</option>\n";
    648   }
    649   $html =~ s|\$\$ALLCITIES\$\$|$cities|g;
     658    my %row = (city => $city);
     659    push (@cities, \%row);
     660  }
     661  $page->param(citylist => \@cities);
    650662
    651663## node hack
    652664  $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
    653665  $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
    654   my $nodes = '';
     666  my @nodes;
    655667  while (my ($nid,$nname) = $sth->fetchrow_array()) {
    656     $nodes .= "<option value='$nid'>$nname</option>\n";
    657   }
    658   $html =~ s/\$\$NODELIST\$\$/$nodes/;
     668    my %row = (nid => $nid, nname => $nname);
     669    push (@nodes, \%row);
     670  }
     671  $page->param(nodelist => \@nodes);
    659672## end node hack
    660673
    661   my $i = 0;
    662   $i++ if $webvar{fbtype} eq 'y';
    663   # Check to see if user is allowed to do anything with sensitive data
    664   my $privdata = '';
    665   if ($IPDBacl{$authuser} =~ /s/) {
    666     $privdata = qq(<tr class="color).($i%2).qq("><td>Restricted data:</td>).
    667         qq(<td class=regular><textarea rows="3" cols="64" name="privdata" class="regular">).
    668         qq(</textarea></td></tr>\n);
    669     $i++;
    670   }
    671   $html =~ s/\$\$PRIVDATA\$\$/$privdata/g;
    672 
    673   $i = $i % 2;
    674   $html =~ s/\$\$BUTTONROWCOLOUR\$\$/color$i/;
    675 
    676   print $html;
     674  $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
    677675
    678676} # assignBlock
Note: See TracChangeset for help on using the changeset viewer.