add fix to use the updated plc_object.php with conditional call to
[www-register-wizard.git] / application / controllers / register.php
1 <?php
2
3 require_once 'plc_login.php'; // Require login
4 require_once 'plc_session.php'; // Get session and API handles
5 global $plc, $api, $adm;
6
7 // Print header
8 require_once 'plc_drupal.php';
9
10 include 'plc_header.php';
11
12 // Common functions
13 require_once 'plc_functions.php';
14 require_once 'plc_sorts.php';
15 include 'plc_objects.php';
16
17
18 class Register extends Controller {
19         
20         var $pcu_id = 0;
21         function index()
22         {
23                 $this->load->helper(array('form', 'url'));
24                 $data=array();
25                 $data['stage'] = 0;
26                 $this->load->view('header', $data);
27                 $this->load->view('debug', $data);
28                 $this->load->view('stage0', $data);
29                 $this->load->view('footer', $data);
30         }
31         function stage1_addpcu()
32         {
33                 global $api, $plc;
34                 $this->load->helper(array('form', 'url'));
35                 $this->load->library('validation');
36                 
37                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
38
39                 $rules['model']         = "trim|required";
40                 $rules['hostname']  = "trim|required";
41                 $rules['ip']            = "trim|required|valid_ip";
42                 $rules['username']  = "trim";
43                 $rules['password']  = "trim|required";
44                 $rules['notes']         = "trim";
45                 $this->validation->set_rules($rules);
46
47                 $fields['model']  = "Model";
48                 $fields['hostname']  = "Hostname";
49                 $fields['ip']           = "IP Address";
50                 $fields['username']  = "Username";
51                 $fields['password']  = "Password";
52                 $this->validation->set_fields($fields);
53
54                 $person = new Person($plc->person);
55                 $data = array();
56                 if ($this->validation->run() == TRUE)
57                 {
58                         if ($this->validation->model != "none-selected" )
59                         {
60                                 /* b/c the submit is valid, it doesn't matter if pcu_register is set */
61                                 $this->pcu_id = $this->add_pcu($data);
62                         }
63                 }
64                 $data = $this->get_stage1_data($person, $data);
65                 $data['stage'] = 1;
66                 $this->load->view('header', $data);
67                 $this->load->view('debug', $data);
68                 $this->load->view('stage1_pcu_choose', $data);
69                 $this->load->view('footer', $data);
70         }
71
72         function add_pcu(&$data)
73         {
74                 global $api, $plc;
75                 /* add pcu, get pcu info */
76                 $site_id = intval( $_REQUEST['site_id'] );
77                 $fields= array( 'protocol'=>    '',
78                                                 'model'=>               $_REQUEST['model'], 
79                                                 'hostname'=>    $this->validation->hostname,
80                                                 'ip'=>                  $this->validation->ip,
81                                                 'username'=>    $this->validation->username, 
82                                                 'password'=>    $this->validation->password, 
83                                                 'notes'=>               $_REQUEST['notes'], );
84                 $pcu_id= $api->AddPCU( $site_id, $fields );
85
86                 if( $pcu_id == 0 ) {
87                         $data['error'] = $api->error();
88                         print $data['error'];
89                 }
90                 $data['pcu_id'] = $pcu_id;
91                 
92                 return $pcu_id;
93         }
94
95         function get_stage1_data($person, $data=NULL)
96         {
97                 global $api, $plc;
98                 if ( $data == NULL ){
99                     $data = array();
100                 }
101                 $data['default_site_list'] = $person->getSites();
102                 $data['pcu_types'] = $api->GetPCUTypes(NULL, array('model', 'name'));
103                 $data['pcu_list'] = $this->getpculist($person);
104                 $data['site_list'] = $this->getsitelist($person);
105                 return $data;
106         }
107
108         function getpculist($person)
109         {
110                 global $api, $plc;
111                 $plc_pcu_list = $api->GetPCUs(array('site_id' => $person->getSites()));
112                 return PlcObject::constructList('PCU', $plc_pcu_list);
113         }
114
115         function getsitelist($person)
116         {
117                 global $api, $plc;
118                 // get sites depending on role and sites associated.
119                 if( $person->isAdmin() ) {
120                         $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) );
121                 } else {
122                         $site_info= $api->GetSites( $person->getSites(), array( "name", "site_id", "login_base" ) );
123                 }
124                 sort_sites( $site_info );
125                 return $site_info;
126         }
127
128         var $run_update = True;
129         var $disp_errors = True;
130         function stage2_confirmpcu()
131         {
132                 global $api, $plc;
133                 $this->load->helper(array('form', 'url'));
134                 $this->load->library('validation');
135                 
136                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
137                 $person = new Person($plc->person);
138
139                 if ( isset($_REQUEST['pcu_choose']) ) {
140                         $rules['pcu_id']  = "required";
141                         $this->validation->set_rules($rules);
142                         $fields['pcu_id']  = "PCU id";
143                         $this->validation->set_fields($fields);
144
145                         $result = $this->validation->run();
146                         /* I don't know, shouldn't we redirect to the first stage in this case? */
147                         $this->run_update = False;
148                         $this->disp_errors = False;
149                         print $this->validation->error_string . "<br>";
150
151                 } else {
152                         # Information update
153
154                         $rules['pcu_id']  = "required";
155                         $rules['hostname']  = "trim|required";
156                         $rules['ip']            = "trim|required|valid_ip";
157                         $rules['username']  = "trim";
158                         $rules['password']  = "trim|required";
159                         $rules['notes']         = "trim";
160                         $this->validation->set_rules($rules);
161
162                         $fields['pcu_id']  = "PCU id";
163                         $fields['hostname']  = "Hostname";
164                         $fields['ip']           = "IP Address";
165                         $fields['username']  = "Username";
166                         $fields['password']  = "Password";
167                         $this->validation->set_fields($fields);
168
169                         if ( $this->validation->run() == FALSE )
170                         {
171                                 print $this->validation->error_string . "<br>";
172                                 $this->run_update = False;
173                         } 
174                 }
175                 $data = $this->get_stage2_data($person);
176                 $data['stage'] = 2;
177                 $this->load->view('header', $data);
178                 $this->load->view('debug', $data);
179                 $this->load->view('stage2_pcu_confirm', $data);
180                 $this->load->view('footer', $data);
181
182         }
183
184         function update_pcu($data)
185         {
186                 global $api, $plc;
187                 /* add pcu, get pcu info */
188                 $pcu_id = intval($this->validation->pcu_id);
189                 $fields= array( 'protocol'=>    '',
190                                                 'model'=>               $_REQUEST['model'], 
191                                                 'hostname'=>    $this->validation->hostname,
192                                                 'ip'=>                  $this->validation->ip,
193                                                 'username'=>    $this->validation->username, 
194                                                 'password'=>    $this->validation->password, 
195                                                 'notes'=>               $_REQUEST['notes'], );
196                 $ret = $api->UpdatePCU( $pcu_id, $fields );
197
198                 if( $ret != 1 ) {
199                         $data['error'] = $api->error();
200                         print $data['error'];
201                 }
202                 
203                 return $pcu_id;
204         }
205
206         function get_stage2_data($person)
207         {
208                 global $api, $plc;
209
210                 $data = array();
211                 if ( $this->run_update && isset($_REQUEST['pcu_update']) ) 
212                 {
213                         $this->update_pcu($data);
214                 } 
215
216                 if ( isset($_REQUEST['pcu_id']) ) 
217                 {
218                         $pcu_id = intval($_REQUEST['pcu_id']);
219                         $pcu_data = $api->GetPCUs(array('pcu_id'=>$pcu_id));
220                         $pcu = new PCU($pcu_data[0]);
221                         $data['pcu'] = $pcu;
222                         $data['pcu_id'] = $pcu_id;
223                         $data['site_id'] = $pcu_data[0]['site_id'];
224                 } 
225
226                 $data['default_site_list'] = $person->getSites();
227                 $data['pcu_types'] = $api->GetPCUTypes(NULL, array('model', 'name'));
228                 $data['pcu_site'] = $api->GetSites( $pcu_data[0]['site_id'], array( "name", "site_id", "login_base" ) );
229                 return $data;
230         }
231
232         var $node_id = 0;
233         function stage3_addnode($pcu_id, $site_id)
234         {
235                 global $api, $plc;
236                 $this->load->helper(array('form', 'url'));
237                 $this->load->library('validation');
238                 
239                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
240                 $person = new Person($plc->person);
241                 $data = array();
242                 $data['pcu_id'] = intval($pcu_id);
243                 $data['site_id'] = intval($site_id);
244
245                 if ( isset($_REQUEST['pcu_proceed']) ) {
246                         $rules['hostname']  = "";
247                         $rules['model']         = "";
248                         $rules['method']        = "";
249                         $rules['ip']            = "";
250                         $rules['netmask']  = "";
251                         $rules['network']  = "";
252                         $rules['gateway']  = "";
253                         $rules['broadcast']  = "";
254                         $rules['dns1']  = "";
255                         $rules['dns2']  = "";
256                         $this->validation->set_rules($rules);
257                         $fields['hostname']  = "Hostname";
258                         $fields['model']        = "Model";
259                         $fields['method']       = "Method";
260                         $fields['ip']           = "IP Address";
261                         $fields['netmask']              = "Netmask Address";
262                         $fields['network']              = "Network Address";
263                         $fields['gateway']              = "Gateway Address";
264                         $fields['broadcast']    = "Broadcast Address";
265                         $fields['dns1']                 = "Primary DNS Address";
266                         $fields['dns2']                 = "Secondary DNS Address";
267                         $this->validation->set_fields($fields);
268
269                         $result = $this->validation->run();
270                         /*print "RESULT: ".$result . "<br>";*/
271                         # TODO: if result is false, redirect to beginning.
272                         $this->disp_errors = False;
273                         print $this->validation->error_string . "<br>";
274                 } else {
275                         $rules['hostname']  = "trim|required";
276                         $rules['model']         = "trim|required";
277                         $rules['method']        = "required";
278                         $rules['ip']            = "trim|required|valid_ip";
279                         if ( isset ($_REQUEST['method']) && $_REQUEST['method'] == 'static' )
280                         {
281                                 $rules['netmask']  = "trim|valid_ip";
282                                 $rules['network']  = "trim|valid_ip";
283                                 $rules['gateway']  = "trim|valid_ip";
284                                 $rules['broadcast']  = "trim|valid_ip";
285                                 $rules['dns1']  = "trim|valid_ip";
286                                 $rules['dns2']  = "trim|valid_ip";
287                         } else {
288                                 $rules['netmask']  = "";
289                                 $rules['network']  = "";
290                                 $rules['gateway']  = "";
291                                 $rules['broadcast']  = "";
292                                 $rules['dns1']  = "";
293                                 $rules['dns2']  = "";
294                         }
295                         $this->validation->set_rules($rules);
296
297                         $fields['hostname']  = "Hostname";
298                         $fields['model']        = "Model";
299                         $fields['method']       = "Method";
300                         $fields['ip']           = "IP Address";
301                         $fields['netmask']              = "Netmask Address";
302                         $fields['network']              = "Network Address";
303                         $fields['gateway']              = "Gateway Address";
304                         $fields['broadcast']    = "Broadcast Address";
305                         $fields['dns1']                 = "Primary DNS Address";
306                         $fields['dns2']                 = "Secondary DNS Address";
307                         $this->validation->set_fields($fields);
308
309                         if ($this->validation->run() == TRUE)
310                         {
311                                 /* b/c the submit is valid, all values are minimally consistent. */
312                                 $this->node_id = $this->add_node($data);
313                         }
314                 }
315                 $data = $this->get_stage3_data($person, $data);
316                 $data['stage'] = 3;
317                 $this->load->view('header', $data);
318                 $this->load->view('debug', $data);
319                 $this->load->view('stage3_node_choose', $data);
320                 $this->load->view('footer', $data);
321         }
322
323         function add_node(&$data)
324         {
325                 global $api, $plc;
326                 print "Adding Node\n<br>";
327                 $hostname = trim($_REQUEST['hostname']);
328                 $model= trim($_REQUEST['model']);
329                 $method = trim($_REQUEST['method']);
330                 $ip = trim($_REQUEST['ip']);
331                 if ( $method == 'static' )
332                 {
333                         $netmask = trim($_REQUEST['netmask']);
334                         $network = trim($_REQUEST['network']);
335                         $gateway = trim($_REQUEST['gateway']);
336                         $broadcast = trim($_REQUEST['broadcast']);
337                         $dns1 = trim($_REQUEST['dns1']);
338                         $dns2 = trim($_REQUEST['dns2']);
339                 }
340
341                 // used to generate error strings for static fields only
342                 $static_fields= array();
343                 $static_fields['netmask']= "Netmask address";
344                 $static_fields['network']= "Network address";
345                 $static_fields['gateway']= "Gateway address";
346                 $static_fields['broadcast']= "Broadcast address";
347                 $static_fields['dns1']= "Primary DNS address";
348                 
349                 if( $method == 'static' )
350                 {
351                         if( !is_valid_network_addr($network,$netmask) )
352                         {
353                                 $errors[] = "The network address does not coorespond to the netmask";
354                         }
355                 }
356
357                 if( !isset($errors) || count($errors) == 0 )
358                 {
359                         // add new node and its network
360                         $optional_vals= array( "hostname"=>$hostname, "model"=>$model );
361
362                         $site_id= $data['site_id'];
363                         $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
364                         if( $node_id <= 0 ) {
365                                 $data['error'] = $api->error();
366                                 print $data['error'];
367                         }
368
369                         // now, try to add the network.
370                         $optional_vals= array();
371                         $optional_vals['is_primary']= true;
372                         $optional_vals['ip']= $ip;
373                         $optional_vals['type']= 'ipv4';
374                         $optional_vals['method']= $method;
375                         
376                         if( $method == 'static' )
377                         {
378                                 $optional_vals['gateway']= $gateway;
379                                 $optional_vals['network']= $network;
380                                 $optional_vals['broadcast']= $broadcast;
381                                 $optional_vals['netmask']= $netmask;
382                                 $optional_vals['dns1']= $dns1;
383                                 if (!empty($dns2)) {
384                                         $optional_vals['dns2']= $dns2;
385                                 }
386                         }
387
388                         $nodenetwork_id= $api->AddNodeNetwork( $node_id, $optional_vals);
389                         if( $nodenetwork_id <= 0 ) {
390                                 $data['error'] = $api->error();
391                                 print $data['error'];
392                         }
393
394                         $success = $api->AddNodeToPCU( $node_id, $data['pcu_id'], 1);
395                         if( !isset($success) || $success <= 0 ) {
396                                 $data['error'] = $api->error();
397                                 print $data['error'];
398                         }
399                 }
400
401
402                 $data['node_id'] = $node_id;
403                 if ( isset($errors) ) { $data['errors'] = $errors; }
404                 
405                 return $node_id;
406         }
407
408         function get_stage3_data($person, $data=NULL)
409         {
410                 global $api, $plc;
411                 if ( $data == NULL ){
412                     $data = array();
413                 }
414                 $data['default_site_list'] = array($data['site_id']);
415                 $data['node_list'] = $this->getnodelist($data['site_id']);
416                 $data['site'] = $this->getsite($data['site_id']);
417                 return $data;
418         }
419
420         function getnodelist($site_id)
421         {
422                 global $api, $plc;
423                 $plc_node_list = $api->GetNodes(array('site_id' => intval($site_id) ));
424                 $ret = array();
425                 foreach ($plc_node_list as $plc_node)
426                 {
427                         $ret[] = new Node($plc_node, True);
428                 }
429                 return $ret;
430         }
431
432         function getsite($site_id)
433         {
434                 global $api, $plc;
435                 $site_info = $api->GetSites($site_id, array( "name", "site_id", "login_base" ) );
436                 return $site_info[0];
437         }
438
439         function stage45_mappcu($pcu_id=0, $site_id=0, $node_id=0)
440         {
441                 global $api, $plc;
442                 $this->load->helper(array('form', 'url'));
443                 $this->load->library('validation');
444                 
445                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
446
447                 $fields['port_number']  = "Port Number";
448                 $this->validation->set_fields($fields);
449
450                 $data = array();
451                 $data['pcu_id'] = intval($pcu_id);
452                 $data['site_id'] = intval($site_id);
453                 $data['node_id'] = intval($node_id);
454
455                 if ( isset($_REQUEST['node_confirm']) ) {
456                         /* skip the rules, since we're just displaying the page. */
457                         $rules['port_number']           = "";
458                         $this->validation->set_rules($rules);
459
460                 } else {
461                         /* setup rules, to validate the form data. */
462                         $rules['port_number']           = "trim|required|intval";
463                         $this->validation->set_rules($rules);
464
465                         $result = $this->validation->run();
466                         if ( ! $result ) {
467                                 print "ERROR";
468                         } else {
469                                 $port = $this->validation->port_number;
470                                 /* if we do not delete the node from the PCU first, a fault is raised */
471                                 $ret = $api->DeleteNodeFromPCU($data['node_id'], $data['pcu_id']);
472                                 $ret = $api->AddNodeToPCU($data['node_id'], $data['pcu_id'], $port);
473                                 if ( $ret != 1 )
474                                 {
475                                         $data['error'] = $api->error();
476                                         print $data['error'];
477                                 }
478                         }
479                         $this->disp_errors = False;
480                         print $this->validation->error_string . "<br>";
481                 }
482
483
484                 $data['node'] = $this->getnode($data['node_id']);
485                 $api_pcus = $api->GetPCUs($data['node']->pcu_ids);
486                 $pcu = $api_pcus[0];
487
488                 # NOTE: find index of node id, then pull out that index of
489                 $index = array_search($data['node_id'], $pcu['node_ids']);
490                 $data['pcu_port'] = $pcu['ports'][$index];
491                 $data['stage'] = 4.5;
492                 #$data = $this->get_stage4_data($person, $data);
493                 $this->load->view('header', $data);
494                 $this->load->view('debug', $data);
495                 $this->load->view('stage45_pcuport', $data);
496                 $this->load->view('footer', $data);
497         }
498
499         function stage4_confirmnode($pcu_id=0, $site_id=0)
500         {
501                 global $api, $plc;
502                 $this->load->helper(array('form', 'url'));
503                 $this->load->library('validation');
504                 
505                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
506                 $person = new Person($plc->person);
507
508                 $fields['hostname']     = "Hostname";
509                 $fields['model']        = "Model";
510                 $fields['method']       = "Method";
511                 $fields['ip']           = "IP Address";
512                 $fields['netmask']      = "Netmask Address";
513                 $fields['network']      = "Network Address";
514                 $fields['gateway']      = "Gateway Address";
515                 $fields['broadcast']= "Broadcast Address";
516                 $fields['dns1']         = "Primary DNS Address";
517                 $fields['dns2']         = "Secondary DNS Address";
518                 $fields['node_id']  = "NODE id";
519                 $this->validation->set_fields($fields);
520
521                 $data = array();
522                 $data['pcu_id'] = intval($pcu_id);
523                 $data['site_id'] = intval($site_id);
524
525                 if ( isset($_REQUEST['node_choose']) ) {
526                         $rules['node_id']       = "required|intval";
527                         $rules['hostname']      = "";
528                         $rules['model']         = "";
529                         $rules['method']        = "";
530                         $rules['ip']            = "";
531                         $rules['netmask']       = "";
532                         $rules['network']       = "";
533                         $rules['gateway']       = "";
534                         $rules['broadcast']     = "";
535                         $rules['dns1']          = "";
536                         $rules['dns2']          = "";
537                         $this->validation->set_rules($rules);
538
539                         $result = $this->validation->run();
540                         /*print "RESULT: ".$result . "<br>";*/
541                         # TODO: if result is false, redirect to beginning.
542                         $this->disp_errors = False;
543                         print $this->validation->error_string . "<br>";
544                 } else {
545                         $rules['hostname']  = "trim|required";
546                         $rules['model']         = "trim|required";
547                         $rules['method']        = "required";
548                         $rules['ip']            = "trim|required|valid_ip";
549                         if ( isset ($_REQUEST['method']) && $_REQUEST['method'] == 'static' )
550                         {
551                                 $rules['netmask']  = "trim|valid_ip";
552                                 $rules['network']  = "trim|valid_ip";
553                                 $rules['gateway']  = "trim|valid_ip";
554                                 $rules['broadcast']  = "trim|valid_ip";
555                                 $rules['dns1']  = "trim|valid_ip";
556                                 $rules['dns2']  = "trim";
557                         } else {
558                                 # NOTE: There are no conditions that must be met for these fields.
559                                 $rules['netmask']  = "";
560                                 $rules['network']  = "";
561                                 $rules['gateway']  = "";
562                                 $rules['broadcast']  = "";
563                                 $rules['dns1']  = "";
564                                 $rules['dns2']  = "";
565                         }
566                         $rules['node_id']  = "required|intval";
567                         $this->validation->set_rules($rules);
568
569                         if ($this->validation->run() == TRUE)
570                         {
571                                 /* b/c the submit is valid, all values are minimally consistent. */
572                                 $this->node_id = $this->update_node($data);
573                         }
574                 }
575                 $data['node_id'] = intval($this->validation->node_id);
576                 $data['stage'] = 4;
577                 if ( $this->checknodeid($data['node_id']) )
578                 {
579                         $data = $this->get_stage4_data($person, $data);
580                         $this->load->view('header', $data);
581                         $this->load->view('debug', $data);
582                         $this->load->view('stage4_node_confirm', $data);
583                         $this->load->view('footer', $data);
584                 } else {
585                         print "You must select a valid Node before continuing.";
586                 }
587         }
588
589         function update_node(&$data)
590         {
591                 # TODO: RECODE To update values instead of adding them...
592                 global $api, $plc;
593                 $hostname = trim($_REQUEST['hostname']);
594                 $model= trim($_REQUEST['model']);
595                 $node_id = intval($this->validation->node_id);
596                 $ret = $api->UpdateNode( $node_id, array('hostname' => $hostname, 
597                                                                                   'model' => $model));
598                 if( $ret <= 0 ) {
599                         $data['error'] = $api->error();
600                         print $data['error'];
601                 }
602
603                 $api_node_list = $api->GetNodes($node_id);
604                 if ( count($api_node_list) > 0 )
605                 {
606                         $node_obj = new Node($api_node_list[0], True);
607                 } else {
608                         print "broken!!!";
609                         exit (1);
610                 }
611                 
612
613                 $optional_vals= array();
614
615                 $method = trim($_REQUEST['method']);
616                 if ( $node_obj->method != $method ) {
617                         $optional_vals['method']= $method;
618                 }
619
620                 $ip = trim($_REQUEST['ip']);
621                 if ( $node_obj->ip != $ip ) {
622                         $optional_vals['ip']= $ip;
623                 }
624
625                 // used to generate error strings for static fields only
626                 $static_fields= array();
627                 $static_fields['netmask']= "Netmask address";
628                 $static_fields['network']= "Network address";
629                 $static_fields['gateway']= "Gateway address";
630                 $static_fields['broadcast']= "Broadcast address";
631                 $static_fields['dns1']= "Primary DNS address";
632
633                 if ( $method == 'static' )
634                 {
635                         $netmask = trim($_REQUEST['netmask']);
636                         $network = trim($_REQUEST['network']);
637                         $gateway = trim($_REQUEST['gateway']);
638                         $broadcast = trim($_REQUEST['broadcast']);
639                         $dns1 = trim($_REQUEST['dns1']);
640                         $dns2 = trim($_REQUEST['dns2']);
641
642                         if( !is_valid_network_addr($network,$netmask) )
643                         {
644                                 $errors[] = "The network address does not coorespond to the netmask";
645                         }
646                 }
647
648                 if ( !isset($errors) || count($errors) == 0 )
649                 {
650                         // now, try to add the network.
651                         if( $method == 'static' )
652                         {
653                                 if ( $node_obj->gateway != $gateway ) {
654                                         $optional_vals['gateway']= $gateway;
655                                 }
656                                 if ( $node_obj->network != $network ) {
657                                         $optional_vals['network']= $network;
658                                 }
659                                 if ( $node_obj->broadcast != $broadcast ) {
660                                         $optional_vals['broadcast']= $broadcast;
661                                 }
662                                 if ( $node_obj->netmask != $netmask ) {
663                                         $optional_vals['netmask']= $netmask;
664                                 }
665                                 if ( $node_obj->dns1 != $dns1 ) {
666                                         $optional_vals['dns1']= $dns1;
667                                 }
668                                 if ( $node_obj->dns2 != $dns2 ) {
669                                         $optional_vals['dns2']= $dns2;
670                                 }
671                         }
672
673                         if ( count($optional_vals) > 0 )
674                         {
675                                 print_r($optional_vals);
676                                 $ret = $api->UpdateNodeNetwork( $node_obj->nodenetwork_id, $optional_vals);
677                                 if( $ret <= 0 ) {
678                                         $data['error'] = $api->error();
679                                         print $data['error'];
680                                 }
681                         }
682                 }
683
684                 $data['node_id'] = $node_id;
685                 if ( isset($errors) ) { $data['errors'] = $errors; }
686                 
687                 return $node_id;
688         }
689
690         function get_stage4_data($person, $data=NULL)
691         {
692                 global $api, $plc;
693                 if ( $data == NULL ){
694                     $data = array();
695                 }
696                 $data['node'] = $this->getnode($data['node_id']);
697                 $data['site'] = $this->getsite($data['site_id']);
698                 /*print "SITENAME: " . $data['site']['login_base'] . "<BR>";*/
699                 return $data;
700         }
701
702         function checknodeid($node_id)
703         {
704                 global $api, $plc;
705                 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ), array('node_id'));
706                 if ( count($plc_node_list) > 0 ) {
707                         return True;
708                 } else {
709                         return False;
710                 }
711         }
712
713         function getnode($node_id)
714         {
715                 global $api, $plc;
716                 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ));
717                 if ( count($plc_node_list) > 0 )
718                 {
719                         return new Node($plc_node_list[0], True);
720                 } else {
721                         return NULL;
722                 }
723         }
724
725 }
726 ?>