summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
349ba75)
interface on stage3.
This is an essential fix for handling errors on a bad static network.
function add_node(&$data)
{
global $api, $plc;
function add_node(&$data)
{
global $api, $plc;
- print "Adding Node\n<br>";
$hostname = trim($_REQUEST['hostname']);
$model= trim($_REQUEST['model']);
$method = trim($_REQUEST['method']);
$hostname = trim($_REQUEST['hostname']);
$model= trim($_REQUEST['model']);
$method = trim($_REQUEST['method']);
$optional_vals= array( "hostname"=>$hostname, "model"=>$model );
$site_id= $data['site_id'];
$optional_vals= array( "hostname"=>$hostname, "model"=>$model );
$site_id= $data['site_id'];
- $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
- if( $node_id <= 0 ) {
- $data['error'] = $api->error();
- print $data['error'];
+ // Try to get node in case this is from an error:
+ $nodes = $api->GetNodes($optional_vals);
+ if ( count($nodes) > 0 ) {
+ $node_id= $nodes[0]['node_id'];
+ } else {
+ $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
+ if( $node_id <= 0 ) {
+ $data['error'] = $api->error();
+ print $data['error'];
+ }
}
// now, try to add the network.
}
// now, try to add the network.
- $success = $api->AddNodeToPCU( $node_id, $data['pcu_id'], 1);
- if( !isset($success) || $success <= 0 ) {
- $data['error'] = $api->error();
- print $data['error'];
+ $pcus = $api->GetPCUs(array('pcu_id' => $data['pcu_id']));
+ if ( count($pcus) > 0 )
+ {
+ $pcu = $pcus[0];
+ # if $node_id in $pcu['node_ids']
+ if ( ! in_array( $node_id , $pcu['node_ids'] ) )
+ {
+ $success = $api->AddNodeToPCU( $node_id, $data['pcu_id'], 1);
+ if( !isset($success) || $success <= 0 ) {
+ $data['error'] = $api->error();
+ print $data['error'];
+ }
+
+ }
+ $data['interface_id'] = $interface_id;
+ $data['node_id'] = $node_id;
+ if ( isset($errors) ) { $data['errors'] = $errors; }
+ return $node_id;
+
+ } else {
+ $data['error'] = $errors[0];
+ return 0;
- $data['node_id'] = $node_id;
- if ( isset($errors) ) { $data['errors'] = $errors; }
}
function get_stage3_data($person, $data=NULL)
}
function get_stage3_data($person, $data=NULL)
<?php
if( isset($errors) && count($errors) > 0 )
{
<?php
if( isset($errors) && count($errors) > 0 )
{
- print( "<p><strong>The following errors occured:</strong>" );
- print( "<font color='red' size='-1'><ul>\n" );
- foreach( $errors as $err )
- {
- print( "<li>$err\n" );
- }
- print( "</ul></font>\n" );
}
?>
<script language="javascript">
}
?>
<script language="javascript">
<?= form_open("register/stage4_confirmnode/$pcu_id/$site_id") ?>
<table border=0 cellpadding=3>
<tbody>
<?= form_open("register/stage4_confirmnode/$pcu_id/$site_id") ?>
<table border=0 cellpadding=3>
<tbody>
+ <?php if ( !empty($node_list) && !isset($error) ): ?>
<tr><td colspan='2'><h3>Choose a Node to Associate with PCU</h3></td></tr>
<tr><td colspan='2'><h3>Choose a Node to Associate with PCU</h3></td></tr>
- <?php if ( !empty($node_list) ): ?>
<tr><th>Node Name: </th><td>
<select name='node_id'>
<option value='0'>--</option>
<tr><th>Node Name: </th><td>
<select name='node_id'>
<option value='0'>--</option>
+ <?php else: ?>
+ <p><strong>The following errors occured:</strong>
+ <font color='red' size='-1'><ul>
+ <li><?= $error ?></li>
+ </ul></font>
<?php endif; ?>
</tbody>
</table>
<?php endif; ?>
</tbody>
</table>
<div class="plroundedupdate">
<table border=0 cellpadding=3>
<tbody>
<div class="plroundedupdate">
<table border=0 cellpadding=3>
<tbody>
-<?php if ( !isset($node_id) || $node_id == 0 ): ?>
+<?php if ( !isset($node_id) || $node_id == 0 || !isset($interface_id) || $interface_id == 0): ?>
<?= form_open("register/stage3_addnode/$pcu_id/$site_id", array('name'=>'fm', 'method'=>'post')) ?>
<tr><td colspan='2'><h3>Or, Add a Node</h3></td></tr>
<tr><th>Site: </th><td><?= $site['name'] ?></td>
<?= form_open("register/stage3_addnode/$pcu_id/$site_id", array('name'=>'fm', 'method'=>'post')) ?>
<tr><td colspan='2'><h3>Or, Add a Node</h3></td></tr>
<tr><th>Site: </th><td><?= $site['name'] ?></td>