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