83fe71c92d809661299744eba8312bda3b826f00
[www-register-wizard.git] / application / controllers / confirm.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 Confirm extends Controller {
19         
20         var $pcu_id = 0;
21         function stage7_firstcontact($pcu_id, $site_id, $node_id)
22         {
23                 global $api, $plc;
24                 $this->load->helper(array('form', 'url'));
25                 $this->load->helper('download');
26                 $this->load->library('validation');
27                 
28                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
29                 $person = new Person($plc->person);
30
31                 $data = array();
32                 $data['pcu_id'] = intval($pcu_id);
33                 $data['node_id'] = intval($node_id);
34                 $data['site_id'] = intval($site_id);
35                 $data['stage'] = 7;
36                 $data = $this->get_stage7_data($person, $data);
37                 /*print "RESULT: ".$result . "<br>";*/
38                 /*print $this->validation->error_string . "<br>";*/
39                 $this->load->view('header', $data);
40                 $this->load->view('debug', $data);
41                 $this->load->view('stage7_firstcontact', $data);
42                 $this->load->view('footer', $data);
43         }
44
45         function getnode($node_id)
46         {
47                 global $api, $plc;
48                 $plc_node_list = $api->GetNodes(array('node_id' => intval($node_id) ));
49                 return $plc_node_list[0];
50         }
51         function getsite($site_id)
52         {
53                 global $api, $plc;
54                 $site_info = $api->GetSites($site_id, array( "name", "site_id", "login_base" ) );
55                 return $site_info[0];
56         }
57
58         function get_stage7_data($person, $data=NULL)
59         {
60                 global $api, $plc;
61                 if ( $data == NULL ){
62                     $data = array();
63                 }
64                 $data['node']  = $this->getnode($data['node_id']);
65                 $data['site']  = $this->getsite($data['node']['site_id']);
66                 if( $data['node']['last_contact'] != NULL && $data['node']['last_contact'] != '' ) {
67                         $last_contact = $data['node']['last_contact'];
68                 } else {
69                         $last_contact = NULL;
70                 }
71                 if( $last_contact != NULL ) {
72                         $last_contact_str = timeDiff($last_contact);
73                 } else {
74                         $last_contact_str = "Never";
75                 }
76                 $data['last_contact_str'] = $last_contact_str;
77                 return $data;
78         }
79
80         function stage8_rebootpcu($pcu_id, $site_id, $node_id)
81         {
82                 global $api, $plc;
83                 $this->load->helper(array('form', 'url'));
84                 $this->load->helper('download');
85                 $this->load->library('validation');
86                 
87                 $this->validation->set_error_delimiters('<span class="error">', '</span>');
88                 $person = new Person($plc->person);
89
90                 $data = array();
91                 $data['pcu_id'] = intval($pcu_id);
92                 $data['node_id'] = intval($node_id);
93                 $data['site_id'] = intval($site_id);
94                 $data['stage'] = 8;
95                 $data = $this->get_stage8_data($person, $data);
96                 $this->load->view('header', $data);
97                 $this->load->view('debug', $data);
98                 $this->load->view('stage8_rebootpcu', $data);
99                 $this->load->view('footer', $data);
100         }
101
102         function reboot($site_id, $pcu_id, $node_id)
103         {
104                 global $api, $plc;
105                 $this->load->helper(array('form', 'url'));
106                 $this->load->helper('download');
107                 $this->load->library('validation');
108                 $person = new Person($plc->person);
109
110                 $data = array();
111                 $data['site_id'] = intval($site_id);
112                 $data['node_id'] = intval($node_id);
113                 $data['pcu_id'] = intval($pcu_id);
114                 $data['stage'] = 8;
115                 $this->reboot_node($data);
116                 $data = $this->get_stage8_data($person, $data);
117
118                 $this->load->view('header', $data);
119                 $this->load->view('debug', $data);
120                 $this->load->view('stage8_rebootpcu', $data);
121                 $this->load->view('footer', $data);
122         }
123
124         function complete($site_id, $pcu_id, $node_id)
125         {
126                 global $api, $plc;
127                 $this->load->helper(array('form', 'url'));
128                 $this->load->helper('download');
129                 $this->load->library('validation');
130
131                 $data = array();
132                 $data['site_id'] = $site_id;
133                 $data['stage'] = 9;
134
135                 $this->load->view('header', $data);
136                 $this->load->view('debug', $data);
137                 $this->load->view('stage9_complete', $data);
138                 $this->load->view('footer', $data);
139         }
140
141         function get_stage8_data($person, $data=NULL)
142         {
143                 global $api, $plc;
144                 if ( $data == NULL ){
145                     $data = array();
146                 }
147                 $data['node']  = $this->getnode($data['node_id']);
148                 $data['site']  = $this->getsite($data['node']['site_id']);
149                 if( $data['node']['last_contact'] != NULL && $data['node']['last_contact'] != '' ) {
150                         $last_contact = $data['node']['last_contact'];
151                 } else {
152                         $last_contact = NULL;
153                 }
154                 if( $last_contact != NULL ) {
155                         $last_contact_str = timeDiff($last_contact);
156                 } else {
157                         $last_contact_str = "Never";
158                 }
159                 $data['last_contact_str'] = $last_contact_str;
160                 return $data;
161         }
162
163         function reboot_node(&$data)
164         {
165                 global $api, $plc;
166                 $hostname = $data['node_id'];
167                 $api->UpdateNode( $hostname, array( "boot_state" => 'rins') );
168                 $ret = $api->RebootNodeWithPCU( $hostname );
169                 if ( "$ret" != "0" ) {
170                         $data['error'] = $ret;
171                 } else {
172                         $data['error'] = $api->error();
173                 }
174         }
175 }
176 ?>