X-Git-Url: http://git.onelab.eu/?p=www-register-wizard.git;a=blobdiff_plain;f=application%2Fcontrollers%2Fregister.php;h=4e15529b96a612f131e53655d64e53c37cfac7fb;hp=f7f330d98209e1b3499fbaf38b87d413e67ec29f;hb=882f60e952c36b4ee5ef452df5cb4bae074a1198;hpb=652223da644ffb9c9acbc04118a5c174fab10926 diff --git a/application/controllers/register.php b/application/controllers/register.php index f7f330d..4e15529 100644 --- a/application/controllers/register.php +++ b/application/controllers/register.php @@ -11,7 +11,7 @@ include 'plc_header.php'; // Common functions require_once 'plc_functions.php'; -require_once 'plc_sorts.php'; +//require_once 'plc_sorts.php'; include 'plc_objects.php'; @@ -36,6 +36,7 @@ class Register extends Controller { $this->validation->set_error_delimiters('', ''); + $rules['model'] = "trim|required"; $rules['hostname'] = "trim|required"; $rules['ip'] = "trim|required|valid_ip"; $rules['username'] = "trim"; @@ -43,6 +44,7 @@ class Register extends Controller { $rules['notes'] = "trim"; $this->validation->set_rules($rules); + $fields['model'] = "Model"; $fields['hostname'] = "Hostname"; $fields['ip'] = "IP Address"; $fields['username'] = "Username"; @@ -53,8 +55,11 @@ class Register extends Controller { $data = array(); if ($this->validation->run() == TRUE) { - /* b/c the submit is valid, it doesn't matter if pcu_register is set */ - $this->pcu_id = $this->add_pcu($data); + if ($this->validation->model != "none-selected" ) + { + /* b/c the submit is valid, it doesn't matter if pcu_register is set */ + $this->pcu_id = $this->add_pcu($data); + } } $data = $this->get_stage1_data($person, $data); $data['stage'] = 1; @@ -112,11 +117,12 @@ class Register extends Controller { global $api, $plc; // get sites depending on role and sites associated. if( $person->isAdmin() ) { - $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) ); + $site_info= $api->GetSites(array('peer_id' => NULL,'-SORT'=>'name'), + array( "name", "site_id", "login_base" ) ); } else { $site_info= $api->GetSites( $person->getSites(), array( "name", "site_id", "login_base" ) ); } - sort_sites( $site_info ); + //sort_sites( $site_info ); return $site_info; } @@ -239,8 +245,9 @@ class Register extends Controller { if ( isset($_REQUEST['pcu_proceed']) ) { $rules['hostname'] = ""; + $rules['node_type'] = 'regular'; $rules['model'] = ""; - $rules['method'] = ""; + $rules['method'] = "dhcp"; $rules['ip'] = ""; $rules['netmask'] = ""; $rules['network'] = ""; @@ -250,6 +257,7 @@ class Register extends Controller { $rules['dns2'] = ""; $this->validation->set_rules($rules); $fields['hostname'] = "Hostname"; + $fields['node_type'] = "Node Type"; $fields['model'] = "Model"; $fields['method'] = "Method"; $fields['ip'] = "IP Address"; @@ -318,8 +326,8 @@ class Register extends Controller { function add_node(&$data) { global $api, $plc; - print "Adding Node\n
"; $hostname = trim($_REQUEST['hostname']); + $node_type = trim($_REQUEST['node_type']); $model= trim($_REQUEST['model']); $method = trim($_REQUEST['method']); $ip = trim($_REQUEST['ip']); @@ -352,13 +360,19 @@ class Register extends Controller { if( !isset($errors) || count($errors) == 0 ) { // add new node and its network - $optional_vals= array( "hostname"=>$hostname, "model"=>$model ); + $optional_vals= array( 'hostname'=>$hostname, 'node_type'=>$node_type, '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. @@ -380,24 +394,39 @@ class Register extends Controller { } } - $nodenetwork_id= $api->AddNodeNetwork( $node_id, $optional_vals); - if( $nodenetwork_id <= 0 ) { + $interface_id= $api->AddInterface( $node_id, $optional_vals); + if( $interface_id <= 0 ) { $data['error'] = $api->error(); print $data['error']; } - $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; } - return $node_id; } function get_stage3_data($person, $data=NULL) @@ -416,7 +445,12 @@ class Register extends Controller { { global $api, $plc; $plc_node_list = $api->GetNodes(array('site_id' => intval($site_id) )); - return PlcObject::constructList('Node', $plc_node_list); + $ret = array(); + foreach ($plc_node_list as $plc_node) + { + $ret[] = new Node($plc_node, True); + } + return $ret; } function getsite($site_id) @@ -470,14 +504,20 @@ class Register extends Controller { print $this->validation->error_string . "
"; } - $data['node'] = $this->getnode($data['node_id']); - $api_pcus = $api->GetPCUs($data['node']->pcu_ids); - $pcu = $api_pcus[0]; + if ( sizeof($data['node']->pcu_ids) == 0) + { + $data['pcu_assigned'] = False; + $data['pcu_port'] = -1; + } else { + $data['pcu_assigned'] = True; + $api_pcus = $api->GetPCUs($data['node']->pcu_ids); + $pcu = $api_pcus[0]; + # NOTE: find index of node id, then pull out that index of + $index = array_search($data['node_id'], $pcu['node_ids']); + $data['pcu_port'] = $pcu['ports'][$index]; + } - # NOTE: find index of node id, then pull out that index of - $index = array_search($data['node_id'], $pcu['node_ids']); - $data['pcu_port'] = $pcu['ports'][$index]; $data['stage'] = 4.5; #$data = $this->get_stage4_data($person, $data); $this->load->view('header', $data); @@ -496,6 +536,7 @@ class Register extends Controller { $person = new Person($plc->person); $fields['hostname'] = "Hostname"; + $fields['node_type'] = "Node Type"; $fields['model'] = "Model"; $fields['method'] = "Method"; $fields['ip'] = "IP Address"; @@ -515,8 +556,9 @@ class Register extends Controller { if ( isset($_REQUEST['node_choose']) ) { $rules['node_id'] = "required|intval"; $rules['hostname'] = ""; + $rules['node_type'] = "regular"; $rules['model'] = ""; - $rules['method'] = ""; + $rules['method'] = "dhcp"; $rules['ip'] = ""; $rules['netmask'] = ""; $rules['network'] = ""; @@ -581,10 +623,11 @@ class Register extends Controller { # TODO: RECODE To update values instead of adding them... global $api, $plc; $hostname = trim($_REQUEST['hostname']); - $model= trim($_REQUEST['model']); + $model = trim($_REQUEST['model']); + $node_type = trim($_REQUEST['node_type']); $node_id = intval($this->validation->node_id); - $ret = $api->UpdateNode( $node_id, array('hostname' => $hostname, - 'model' => $model)); + $optional_vals = array('hostname' => $hostname, 'model' => $model, 'node_type' => $node_type ); + $ret = $api->UpdateNode( $node_id, $optional_vals); if( $ret <= 0 ) { $data['error'] = $api->error(); print $data['error']; @@ -593,7 +636,7 @@ class Register extends Controller { $api_node_list = $api->GetNodes($node_id); if ( count($api_node_list) > 0 ) { - $node_obj = new Node($api_node_list[0]); + $node_obj = new Node($api_node_list[0], True); } else { print "broken!!!"; exit (1); @@ -663,7 +706,7 @@ class Register extends Controller { if ( count($optional_vals) > 0 ) { print_r($optional_vals); - $ret = $api->UpdateNodeNetwork( $node_obj->nodenetwork_id, $optional_vals); + $ret = $api->UpdateInterface( $node_obj->interface_id, $optional_vals); if( $ret <= 0 ) { $data['error'] = $api->error(); print $data['error']; @@ -706,7 +749,7 @@ class Register extends Controller { $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) )); if ( count($plc_node_list) > 0 ) { - return new Node($plc_node_list[0]); + return new Node($plc_node_list[0], True); } else { return NULL; }