a6d33504e405ea843a2cd7370f010c3f1b6faef5
[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                 $hostname = trim($_REQUEST['hostname']);
327                 $model= trim($_REQUEST['model']);
328                 $method = trim($_REQUEST['method']);
329                 $ip = trim($_REQUEST['ip']);
330                 if ( $method == 'static' )
331                 {
332                         $netmask = trim($_REQUEST['netmask']);
333                         $network = trim($_REQUEST['network']);
334                         $gateway = trim($_REQUEST['gateway']);
335                         $broadcast = trim($_REQUEST['broadcast']);
336                         $dns1 = trim($_REQUEST['dns1']);
337                         $dns2 = trim($_REQUEST['dns2']);
338                 }
339
340                 // used to generate error strings for static fields only
341                 $static_fields= array();
342                 $static_fields['netmask']= "Netmask address";
343                 $static_fields['network']= "Network address";
344                 $static_fields['gateway']= "Gateway address";
345                 $static_fields['broadcast']= "Broadcast address";
346                 $static_fields['dns1']= "Primary DNS address";
347                 
348                 if( $method == 'static' )
349                 {
350                         if( !is_valid_network_addr($network,$netmask) )
351                         {
352                                 $errors[] = "The network address does not coorespond to the netmask";
353                         }
354                 }
355
356                 if( !isset($errors) || count($errors) == 0 )
357                 {
358                         // add new node and its network
359                         $optional_vals= array( "hostname"=>$hostname, "model"=>$model );
360
361                         $site_id= $data['site_id'];
362                         $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
363                         if( $node_id <= 0 ) {
364                                 $data['error'] = $api->error();
365                                 print $data['error'];
366                         }
367
368                         // now, try to add the network.
369                         $optional_vals= array();
370                         $optional_vals['is_primary']= true;
371                         $optional_vals['ip']= $ip;
372                         $optional_vals['type']= 'ipv4';
373                         $optional_vals['method']= $method;
374                         
375                         if( $method == 'static' )
376                         {
377                                 $optional_vals['gateway']= $gateway;
378                                 $optional_vals['network']= $network;
379                                 $optional_vals['broadcast']= $broadcast;
380                                 $optional_vals['netmask']= $netmask;
381                                 $optional_vals['dns1']= $dns1;
382                                 if (!empty($dns2)) {
383                                         $optional_vals['dns2']= $dns2;
384                                 }
385                         }
386
387                         $nodenetwork_id= $api->AddNodeNetwork( $node_id, $optional_vals);
388                         if( $nodenetwork_id <= 0 ) {
389                                 $data['error'] = $api->error();
390                                 print $data['error'];
391                         }
392
393                         $success = $api->AddNodeToPCU( $node_id, $data['pcu_id'], 1);
394                         if( !isset($success) || $success <= 0 ) {
395                                 $data['error'] = $api->error();
396                                 print $data['error'];
397                         }
398                 }
399
400
401                 $data['node_id'] = $node_id;
402                 if ( isset($errors) ) { $data['errors'] = $errors; }
403                 
404                 return $node_id;
405         }
406
407         function get_stage3_data($person, $data=NULL)
408         {
409                 global $api, $plc;
410                 if ( $data == NULL ){
411                     $data = array();
412                 }
413                 $data['default_site_list'] = array($data['site_id']);
414                 $data['node_list'] = $this->getnodelist($data['site_id']);
415                 $data['site'] = $this->getsite($data['site_id']);
416                 return $data;
417         }
418
419         function getnodelist($site_id)
420         {
421                 global $api, $plc;
422                 $plc_node_list = $api->GetNodes(array('site_id' => intval($site_id) ));
423                 return PlcObject::constructList('Node', $plc_node_list);
424         }
425
426         function getsite($site_id)
427         {
428                 global $api, $plc;
429                 $site_info = $api->GetSites($site_id, array( "name", "site_id", "login_base" ) );
430                 return $site_info[0];
431         }
432
433         function stage45_mappcu($pcu_id=0, $site_id=0, $node_id=0)
434         {
435                 global $api, $plc;
436                 $this->load->helper(array('form', 'url'));
437                 $this->load->library('validation');
438                 
439                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
440
441                 $fields['port_number']  = "Port Number";
442                 $this->validation->set_fields($fields);
443
444                 $data = array();
445                 $data['pcu_id'] = intval($pcu_id);
446                 $data['site_id'] = intval($site_id);
447                 $data['node_id'] = intval($node_id);
448
449                 if ( isset($_REQUEST['node_confirm']) ) {
450                         /* skip the rules, since we're just displaying the page. */
451                         $rules['port_number']           = "";
452                         $this->validation->set_rules($rules);
453
454                 } else {
455                         /* setup rules, to validate the form data. */
456                         $rules['port_number']           = "trim|required|intval";
457                         $this->validation->set_rules($rules);
458
459                         $result = $this->validation->run();
460                         if ( ! $result ) {
461                                 print "ERROR";
462                         } else {
463                                 $port = $this->validation->port_number;
464                                 /* if we do not delete the node from the PCU first, a fault is raised */
465                                 $ret = $api->DeleteNodeFromPCU($data['node_id'], $data['pcu_id']);
466                                 $ret = $api->AddNodeToPCU($data['node_id'], $data['pcu_id'], $port);
467                                 if ( $ret != 1 )
468                                 {
469                                         $data['error'] = $api->error();
470                                         print $data['error'];
471                                 }
472                         }
473                         $this->disp_errors = False;
474                         print $this->validation->error_string . "<br>";
475                 }
476
477
478                 $data['node'] = $this->getnode($data['node_id']);
479                 $api_pcus = $api->GetPCUs($data['node']->pcu_ids);
480                 $pcu = $api_pcus[0];
481
482                 # NOTE: find index of node id, then pull out that index of
483                 $index = array_search($data['node_id'], $pcu['node_ids']);
484                 $data['pcu_port'] = $pcu['ports'][$index];
485                 $data['stage'] = 4.5;
486                 #$data = $this->get_stage4_data($person, $data);
487                 $this->load->view('header', $data);
488                 $this->load->view('debug', $data);
489                 $this->load->view('stage45_pcuport', $data);
490                 $this->load->view('footer', $data);
491         }
492
493         function stage4_confirmnode($pcu_id=0, $site_id=0)
494         {
495                 global $api, $plc;
496                 $this->load->helper(array('form', 'url'));
497                 $this->load->library('validation');
498                 
499                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
500                 $person = new Person($plc->person);
501
502                 $fields['hostname']     = "Hostname";
503                 $fields['model']        = "Model";
504                 $fields['method']       = "Method";
505                 $fields['ip']           = "IP Address";
506                 $fields['netmask']      = "Netmask Address";
507                 $fields['network']      = "Network Address";
508                 $fields['gateway']      = "Gateway Address";
509                 $fields['broadcast']= "Broadcast Address";
510                 $fields['dns1']         = "Primary DNS Address";
511                 $fields['dns2']         = "Secondary DNS Address";
512                 $fields['node_id']  = "NODE id";
513                 $this->validation->set_fields($fields);
514
515                 $data = array();
516                 $data['pcu_id'] = intval($pcu_id);
517                 $data['site_id'] = intval($site_id);
518
519                 if ( isset($_REQUEST['node_choose']) ) {
520                         $rules['node_id']       = "required|intval";
521                         $rules['hostname']      = "";
522                         $rules['model']         = "";
523                         $rules['method']        = "";
524                         $rules['ip']            = "";
525                         $rules['netmask']       = "";
526                         $rules['network']       = "";
527                         $rules['gateway']       = "";
528                         $rules['broadcast']     = "";
529                         $rules['dns1']          = "";
530                         $rules['dns2']          = "";
531                         $this->validation->set_rules($rules);
532
533                         $result = $this->validation->run();
534                         /*print "RESULT: ".$result . "<br>";*/
535                         # TODO: if result is false, redirect to beginning.
536                         $this->disp_errors = False;
537                         print $this->validation->error_string . "<br>";
538                 } else {
539                         $rules['hostname']  = "trim|required";
540                         $rules['model']         = "trim|required";
541                         $rules['method']        = "required";
542                         $rules['ip']            = "trim|required|valid_ip";
543                         if ( isset ($_REQUEST['method']) && $_REQUEST['method'] == 'static' )
544                         {
545                                 $rules['netmask']  = "trim|valid_ip";
546                                 $rules['network']  = "trim|valid_ip";
547                                 $rules['gateway']  = "trim|valid_ip";
548                                 $rules['broadcast']  = "trim|valid_ip";
549                                 $rules['dns1']  = "trim|valid_ip";
550                                 $rules['dns2']  = "trim";
551                         } else {
552                                 # NOTE: There are no conditions that must be met for these fields.
553                                 $rules['netmask']  = "";
554                                 $rules['network']  = "";
555                                 $rules['gateway']  = "";
556                                 $rules['broadcast']  = "";
557                                 $rules['dns1']  = "";
558                                 $rules['dns2']  = "";
559                         }
560                         $rules['node_id']  = "required|intval";
561                         $this->validation->set_rules($rules);
562
563                         if ($this->validation->run() == TRUE)
564                         {
565                                 /* b/c the submit is valid, all values are minimally consistent. */
566                                 $this->node_id = $this->update_node($data);
567                         }
568                 }
569                 $data['node_id'] = intval($this->validation->node_id);
570                 $data['stage'] = 4;
571                 if ( $this->checknodeid($data['node_id']) )
572                 {
573                         $data = $this->get_stage4_data($person, $data);
574                         $this->load->view('header', $data);
575                         $this->load->view('debug', $data);
576                         $this->load->view('stage4_node_confirm', $data);
577                         $this->load->view('footer', $data);
578                 } else {
579                         print "You must select a valid Node before continuing.";
580                 }
581         }
582
583         function update_node(&$data)
584         {
585                 # TODO: RECODE To update values instead of adding them...
586                 global $api, $plc;
587                 $hostname = trim($_REQUEST['hostname']);
588                 $model= trim($_REQUEST['model']);
589                 $node_id = intval($this->validation->node_id);
590                 $ret = $api->UpdateNode( $node_id, array('hostname' => $hostname, 
591                                                                                   'model' => $model));
592                 if( $ret <= 0 ) {
593                         $data['error'] = $api->error();
594                         print $data['error'];
595                 }
596
597                 $api_node_list = $api->GetNodes($node_id);
598                 if ( count($api_node_list) > 0 )
599                 {
600                         $node_obj = new Node($api_node_list[0]);
601                 } else {
602                         print "broken!!!";
603                         exit (1);
604                 }
605                 
606
607                 $optional_vals= array();
608
609                 $method = trim($_REQUEST['method']);
610                 if ( $node_obj->method != $method ) {
611                         $optional_vals['method']= $method;
612                 }
613
614                 $ip = trim($_REQUEST['ip']);
615                 if ( $node_obj->ip != $ip ) {
616                         $optional_vals['ip']= $ip;
617                 }
618
619                 // used to generate error strings for static fields only
620                 $static_fields= array();
621                 $static_fields['netmask']= "Netmask address";
622                 $static_fields['network']= "Network address";
623                 $static_fields['gateway']= "Gateway address";
624                 $static_fields['broadcast']= "Broadcast address";
625                 $static_fields['dns1']= "Primary DNS address";
626
627                 if ( $method == 'static' )
628                 {
629                         $netmask = trim($_REQUEST['netmask']);
630                         $network = trim($_REQUEST['network']);
631                         $gateway = trim($_REQUEST['gateway']);
632                         $broadcast = trim($_REQUEST['broadcast']);
633                         $dns1 = trim($_REQUEST['dns1']);
634                         $dns2 = trim($_REQUEST['dns2']);
635
636                         if( !is_valid_network_addr($network,$netmask) )
637                         {
638                                 $errors[] = "The network address does not coorespond to the netmask";
639                         }
640                 }
641
642                 if ( !isset($errors) || count($errors) == 0 )
643                 {
644                         // now, try to add the network.
645                         if( $method == 'static' )
646                         {
647                                 if ( $node_obj->gateway != $gateway ) {
648                                         $optional_vals['gateway']= $gateway;
649                                 }
650                                 if ( $node_obj->network != $network ) {
651                                         $optional_vals['network']= $network;
652                                 }
653                                 if ( $node_obj->broadcast != $broadcast ) {
654                                         $optional_vals['broadcast']= $broadcast;
655                                 }
656                                 if ( $node_obj->netmask != $netmask ) {
657                                         $optional_vals['netmask']= $netmask;
658                                 }
659                                 if ( $node_obj->dns1 != $dns1 ) {
660                                         $optional_vals['dns1']= $dns1;
661                                 }
662                                 if ( $node_obj->dns2 != $dns2 ) {
663                                         $optional_vals['dns2']= $dns2;
664                                 }
665                         }
666
667                         if ( count($optional_vals) > 0 )
668                         {
669                                 print_r($optional_vals);
670                                 $ret = $api->UpdateNodeNetwork( $node_obj->nodenetwork_id, $optional_vals);
671                                 if( $ret <= 0 ) {
672                                         $data['error'] = $api->error();
673                                         print $data['error'];
674                                 }
675                         }
676                 }
677
678                 $data['node_id'] = $node_id;
679                 if ( isset($errors) ) { $data['errors'] = $errors; }
680                 
681                 return $node_id;
682         }
683
684         function get_stage4_data($person, $data=NULL)
685         {
686                 global $api, $plc;
687                 if ( $data == NULL ){
688                     $data = array();
689                 }
690                 $data['node'] = $this->getnode($data['node_id']);
691                 $data['site'] = $this->getsite($data['site_id']);
692                 return $data;
693         }
694
695         function checknodeid($node_id)
696         {
697                 global $api, $plc;
698                 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ), array('node_id'));
699                 if ( count($plc_node_list) > 0 ) {
700                         return True;
701                 } else {
702                         return False;
703                 }
704         }
705
706         function getnode($node_id)
707         {
708                 global $api, $plc;
709                 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ));
710                 if ( count($plc_node_list) > 0 )
711                 {
712                         return new Node($plc_node_list[0]);
713                 } else {
714                         return NULL;
715                 }
716         }
717
718 }
719 ?>