4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api, $adm;
11 require_once 'plc_drupal.php';
13 drupal_set_title('Sites');
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
20 $_person= $plc->person;
21 $_roles= $_person['role_ids'];
24 // if no id: add, else: display(update)
26 if( $_POST['submitted'] ) {
27 // get person's site id
28 $site_id= $_person['site_ids'][0];
31 $fields= array( 'protocol'=>$_POST['protocol'], 'hostname'=>$_POST['hostname'], 'model'=>$_POST['model'], 'username'=>$_POST['username'], 'password'=>$_POST['password'], 'notes'=>$_POST['notes'], 'ip'=>$_POST['ip'] );
33 $pcu_id= $api->AddPCU( $site_id, $fields );
36 // xxx is l_pcu defined & effective ?
37 plc_redirect( l_pcu($pcu_id));
40 $error= $api->error();
44 if( !empty( $error ) )
45 echo '<div class="plc-warning">' . $error . '.</div>';
47 echo "<h3>Add a PCU</h3>\n
48 <form action='/db/sites/pcu.php' method=post>\n
49 <p><table border=0 cellpadding=3><tbody>\n
50 <tr><th>Protocol: </th><td><input type=text name='protocol' value=''></td></tr>\n
51 <tr><th>Hostname: </th><td><input type=text name='hostname' size=40 value=''></td></tr>\n
52 <tr><th>IP Address: </th><td><input type=text name='ip' size=40 value=''></td></tr>\n
53 <tr><th>Model: </th><td><input type=text name='model' value=''></td></tr>\n
54 <tr><th>Username: </th><td><input type=text name='username' value=''></td></tr>\n
55 <tr><th>Password: </th><td><input type=text name='password' value=''></td></tr>\n
56 <tr><th>Notes: </th><td><input type=text name='notes' size=40 value=''></td></tr>\n
58 <br /><p><input type=submit name='submitted' value='Add New PCU'>\n";
61 $pcu_id= intval( $_GET['id'] );
62 $pcu_info= $api->GetPCUs( array( intval( $pcu_id ) ) );
64 // if remove is set remove the node from the pcu
65 if( $_GET['remove'] ) {
66 $rem_id= $_GET['remove'];
68 $api->DeleteNodeFromPCU( intval( $rem_id ), $pcu_id );
70 plc_redirect (l_pcu ($pcu_id));
74 //if submitted, update node info
75 if( $_POST['submitted'] ) {
76 $protocol= $_POST['protocol'];
77 $username= $_POST['username'];
78 $hostname= $_POST['hostname'];
79 $ipaddress= $_POST['ip'];
80 $model= $_POST['model'];
81 $password= $_POST['password'];
82 $notes= $_POST['notes'];
84 $api->UpdatePCU( $pcu_id, array( "protocol"=>$protocol, "hostname"=>$hostname, "model"=>$model, "password"=>$password, "notes"=>$notes, "ip"=>$ipaddress ) );
86 plc_redirect (l_pcu($pcu_id));
90 if( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $pcu_info[0]['site_id'], $_person['site_ids'] ) ) || ( in_array( 40, $_roles ) && in_array( $pcu_info[0]['site_id'], $_person['site_ids'] ) ) )
91 $pcu_controller= true;
94 $node_info= $api->GetNodes( $pcu_info[0]['node_ids'], array( "hostname", "node_id", "boot_state" ) );
95 echo "<form action='/db/sites/pcu.php?id=$pcu_id' method=post>\n
96 <h3>PCU: ". $pcu_info[0]['hostname'] ."</h3>\n
97 <p><table border=0 cellpadding=3><tbody>\n
98 <tr><th>Protocol: </th><td>";
100 if( $pcu_controller )
101 echo "<input type=text name='protocol' value='";
103 echo $pcu_info[0]['protocol'];
105 if( $pcu_controller )
109 <tr><th>Hostname: </th><td>";
111 if( $pcu_controller )
112 echo "<input type=text name='hostname' size=40 value='";
114 echo $pcu_info[0]['hostname'];
119 <tr><th>IP Address: </th><td>";
120 if( $pcu_controller )
121 echo "<input type=text name='ip' value='";
123 echo $pcu_info[0]['ip'];
127 if( $pcu_controller )
129 <tr><th>Model: </th><td>";
131 if( $pcu_controller )
132 echo "<input type=text name='model' value='";
134 echo $pcu_info[0]['model'];
136 if( $pcu_controller )
140 <tr><th>Username: </th><td>";
142 if( $pcu_controller )
143 echo "<input type=text name='username' value='";
145 echo $pcu_info[0]['username'];
147 if( $pcu_controller )
151 <tr><th>Password: </th><td>";
153 if( $pcu_controller )
154 echo "<input type=text name='password' value='";
156 echo $pcu_info[0]['password'];
158 if( $pcu_controller )
162 <tr><th>Notes: </th><td>";
164 if( $pcu_controller )
165 echo "<input type=text name='notes' size=40 value='";
167 echo $pcu_info[0]['notes'];
169 if( $pcu_controller )
175 if( $pcu_controller )
176 echo "<br /><p><input type=submit name='submitted' value='Update PCU'>\n";
178 if( !empty( $node_info ) ) {
179 echo "<p><table border=0 cellpadding=3>\n<caption>Nodes</caption>\n<thead><tr><th></th><th>Hostname</td><th>State</th><th></th>";
181 // if user can control PCU add table cells
182 if( $pcu_controller )
185 echo "</tr></thead><tbody>\n";
190 foreach( $node_info as $node ) {
191 echo "<tr><td>". $pcu_info[0]['ports'][$count] ."</td><td><a href='/db/nodes/index.php?id=". $node['node_id'] ."'>". $node['hostname'] ."</a></td><td class='list_set'>". $node['boot_state'] ."</td>";
193 if( $pcu_controller )
194 echo "<td><a href='/db/sites/pcu.php?id=$pcu_id&remove=". $node['node_id'] ."' onclick=\"javascript:return confirm('Are you sure you want to remove node ". $node['hostname'] ." from this PCU?')\">remove</a></td>\n";
201 echo "</tbody></table><br />\n";
204 echo "<p>No nodes on PCU.";
208 echo "<br /><p><a href='/db/sites/index.php?id=". $pcu_info[0]['site_id'] ."'>Back to Site</a>\n";
215 include 'plc_footer.php';