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