Changeset 530


Ignore:
Timestamp:
10/25/12 17:59:15 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move most SQL for node handling into IPDB.pm. See #34.
Tweak "new assignment" and "edit block" templates a little to match
and for consistency.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r529 r530  
    3131        &getParent &getRoutedCity
    3232        &allocateBlock &deleteBlock &getBlockData
    33         &getNodeList
     33        &getNodeList &getNodeName &getNodeInfo
    3434        &mailNotify
    3535        );
     
    4545                &getParent &getRoutedCity
    4646                &allocateBlock &deleteBlock &getBlockData
    47                 &getNodeList
     47                &getNodeList &getNodeName &getNodeInfo
    4848                &mailNotify
    4949                )]
     
    10571057
    10581058
     1059## IPDB::getNodeName()
     1060# Get node name from the ID
     1061sub getNodeName {
     1062  my $dbh = shift;
     1063  my $nid = shift;
     1064
     1065  my ($nname) = $dbh->selectrow_array("SELECT node_name FROM nodes WHERE node_id = ?", undef, ($nid) );
     1066  return $nname;
     1067} # end getNodeName()
     1068
     1069
     1070## IPDB::getNodeInfo()
     1071# Get node name and ID associated with a block
     1072sub getNodeInfo {
     1073  my $dbh = shift;
     1074  my $block = shift;
     1075
     1076  my ($nid, $nname) = $dbh->selectrow_array("SELECT nodes.node_id,node_name FROM nodes INNER JOIN noderef".
     1077        " ON nodes.node_id=noderef.node_id WHERE noderef.block = ?", undef, ($block) );
     1078  return ($nid, $nname);
     1079} # end getNodeInfo()
     1080
     1081
    10591082## IPDB::mailNotify()
    10601083# Sends notification mail to recipients regarding an IPDB operation
  • trunk/cgi-bin/main.cgi

    r529 r530  
    368368
    369369## node hack
    370   $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
    371   $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
    372   my @nodes;
    373   while (my ($nid,$nname) = $sth->fetchrow_array()) {
    374     my %row = (nid => $nid, nname => $nname);
    375     push (@nodes, \%row);
    376   }
    377   $page->param(nodelist => \@nodes);
     370  my $nlist = getNodeList($ip_dbh);
     371  $page->param(nodelist => $nlist);
    378372## end node hack
    379373
     
    428422  } else { # end show pool options
    429423
     424##fixme: uninitialized
    430425    if ($webvar{fbassign} eq 'y') {
    431426      $cidr = new NetAddr::IP $webvar{block};
     
    442437      my $extracond = '';
    443438      if ($webvar{allocfrom} eq '-') {
     439##fixme: uninitialized
    444440        $extracond = ($webvar{allowpriv} eq 'on' ? '' :
    445441                " and not (cidr <<= '192.168.0.0/16'".
     
    519515## node hack
    520516  if ($webvar{node} && $webvar{node} ne '-') {
    521     $sth = $ip_dbh->prepare("SELECT node_name FROM nodes WHERE node_id=?");
    522     $sth->execute($webvar{node});
    523     my ($nodename) = $sth->fetchrow_array();
     517    my $nodename = getNodeName($ip_dbh, $webvar{node});
    524518    $page->param(nodename => $nodename);
    525519    $page->param(nodeid => $webvar{node});
     
    756750
    757751## node hack
    758   $sth = $ip_dbh->prepare("SELECT nodes.node_id,node_name FROM nodes INNER JOIN noderef".
    759         " ON nodes.node_id=noderef.node_id WHERE noderef.block='$webvar{block}'");
    760   $sth->execute;
    761   my ($nodeid,$nodename) = $sth->fetchrow_array();
     752  my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $webvar{block});
    762753  $page->param(havenodeid => $nodeid);
    763754
     
    771762#  (currently) have a nodeid set in the first place.
    772763    if ($IPDBacl{$authuser} =~ /c/) {
    773       $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
    774       $sth->execute;
    775       my @nodelist;
    776       while (my ($nid,$nname) = $sth->fetchrow_array()) {
    777         my %row = (
    778                 selme => ($nodeid == $nid),
    779                 nodeid => $nid,
    780                 nodename => $nname,
    781                 );
    782         push (@nodelist, \%row);
     764      my $nlist = getNodeList($ip_dbh);
     765      foreach (@{$nlist}) {
     766        $$_{selme} = ($$_{node_id} == $nodeid);
    783767      }
    784       $page->param(nodelist => \@nodelist);
     768      $page->param(nodelist => $nlist);
    785769    }
    786770  }
     
    870854## node hack
    871855  if ($webvar{node} && $webvar{node} ne '-') {
    872     $sth = $ip_dbh->prepare("SELECT node_name FROM nodes WHERE node_id=?");
    873     $sth->execute($webvar{node});
    874     my ($nodename) = $sth->fetchrow_array();
     856    my $nodename = getNodeName($ip_dbh, $webvar{node});
    875857    $page->param(nodename => $nodename);
    876858  }
  • trunk/templates/assign.tmpl

    r529 r530  
    6262<td>
    6363<select name="node">
    64         <option selected="selected">-</option>
     64        <option selected>-</option>
    6565<TMPL_LOOP NAME=nodelist>
    66         <option value="<TMPL_VAR NAME=nid>"><TMPL_VAR NAME=nname></option></TMPL_LOOP>
     66        <option value="<TMPL_VAR NAME=node_id>"><TMPL_VAR NAME=node_name></option></TMPL_LOOP>
    6767</select>
    6868&nbsp;<a href="javascript:popNotes('<TMPL_VAR NAME=webpath>/cgi-bin/newnode.cgi')">Add new location</a>
  • trunk/templates/edit.tmpl

    r517 r530  
    5555        <option selected="selected">--</option></TMPL_UNLESS>
    5656<TMPL_LOOP NAME=nodelist>
    57         <option <TMPL_IF selme>selected="selected"</TMPL_IF> value="<TMPL_VAR NAME=nodeid>"><TMPL_VAR NAME=nodename></option></TMPL_LOOP>
     57        <option value="<TMPL_VAR NAME=node_id>"<TMPL_IF selme> selected</TMPL_IF>><TMPL_VAR NAME=node_name></option></TMPL_LOOP>
    5858</select>
    5959<TMPL_ELSE>
Note: See TracChangeset for help on using the changeset viewer.