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