4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
12 require_once 'plc_functions.php';
13 require_once 'plc_sorts.php';
16 $_person= $plc->person;
17 $_roles= $_person['role_ids'];
20 // if sent here from another page remove then redirect
21 if( $_GET['remove'] && $_GET['nodegroup_id'] ) {
22 $ng_id= $_GET['nodegroup_id'];
23 $node_id= $_GET['remove'];
25 $api->DeleteNodeFromNodeGroup( intval( $node_id ), intval( $ng_id ) );
27 header( "location: index.php?id=$node_id" );
34 require_once 'plc_drupal.php';
35 drupal_set_title('Node Groups');
36 include 'plc_header.php';
39 // if no id display list of nodegroups
40 if( !$_GET['id'] && !$_GET['nodegroup_id'] ) {
41 $nodegroup_info= $api->GetNodeGroups( NULL, array( "nodegroup_id", "name", "description" ) );
43 echo "<h2>Node Groups</h2>\n
44 <table cellpadding=2><thead><tr><th>Name</th><th>Description</th>";
46 // if admin we need to more cells
47 if( in_array( "10", $_person['role_ids'] ) )
48 echo "<th></th><th></th>";
49 echo "</thead><tbody>";
51 foreach( $nodegroup_info as $type ) {
52 echo "<tr><td><a href='/db/nodes/node_groups.php?nodegroup_id=". $type['nodegroup_id'] ."'>". $type['name'] ."</a></td><td>". $type['description'] ."</td>";
53 // if admin display edit/delet links
54 if( in_array( "10", $_person['role_ids'] ) ) {
55 echo "<td><a href='/db/nodes/node_groups.php?nodegroup_id=". $type['nodegroup_id'] ."'>Edit</a></td>";
56 echo plc_delete_link_button('node_groups.php?del_type=' . $type['nodegroup_id'],
64 echo "</tbody></table>\n";
67 // if id is set then show nodegroup info
68 elseif( $_GET['id'] ) {
69 $nodegroup_id= $_GET['id'];
71 $nodegroup_info= $api->GetNodeGroups( array( intval( $nodegroup_id ) ), array( "name", "nodegroup_id", "node_ids" ) );
72 $node_info= $api->GetNodes( $nodegroup_info[0]['node_ids'], array( "node_id", "hostname" ) );
75 echo "<h2>Node Group ". $nodegroup_info[0]['name'] ."</h2>\n";
77 if( empty( $nodegroup_info[0]['node_ids'] ) )
78 echo "<p>No nodes in node group.";
80 echo "<table cellpadding=2><thead><tr><th>Hostname</th>";
82 // if admin need more cells
83 if( in_array( 10, $_roles ) )
84 echo "<th>Remove</th>";
88 foreach( $node_info as $node ) {
89 echo "<tr><td><a href='/db/nodes/index.php?id=". $node['node_id'] ."'>". $node['hostname'] ."</a></td>";
91 if( in_array( 10, $_roles ) )
92 echo "<td><a href='/db/nodes/node_groups.php?remove=". $node['node_id'] ."&nodegroup_id=". $nodegroup_id ."'>remove</a></td>";
98 echo "</tbody></table>\n";
103 // if no id add else update
104 elseif( $_GET['add'] ) {
105 // add node group and redirect to update nodes for it
106 if( $_POST['add_sub'] ) {
107 $name= $_POST['name'];
108 $description= $_POST['description'];
110 $fields= array( 'name'=>$name, 'description'=>$description );
113 $api->AddNodeGroup( $fields );
116 $group_info= $api->GetNodeGroups( array( $name ), array( "nodegroup_id" ) );
119 header( "location: node_groups.php?id=". $group_info[0]['nodegroup_id'] );
125 echo "<form method=post action='node_groups.php?add=1'>";
126 echo "<h2>Create Node Group</h2>\n";
127 echo "<table><tbody>\n";
128 echo "<tr><th>Name: </th><td><input type=text name='name' value=''></td></tr>\n<tr><th>Description: </th><td><input type=text name='description' size=50></td></tr>\n";
129 echo "</tbody></table>\n";
131 echo "<br /><input type=submit value='Add Node Group' name='add_sub'>\n</form\n";
133 echo "<p><a href='index.php'>Back to Node Index</a>\n";
136 elseif( $_GET['nodegroup_id'] )
139 $node_group_id= $_GET['nodegroup_id'];
141 // if add node submitted, add
144 $add_nodes= $_POST['add_nodes'];
146 // add nodes to node group
147 foreach( $add_nodes as $add_node )
149 $api->AddNodeToNodeGroup( intval( $add_node ), intval( $node_group_id ) );
155 // if remove node submitted, remove
156 if( $_POST['remove'] )
158 $rem_nodes= $_POST['rem_nodes'];
160 // remove nodes from node group
161 foreach( $rem_nodes as $rem_node )
163 $api->DeleteNodeFromNodeGroup( intval( $rem_node ), intval( $node_group_id ) );
169 // update name and description
170 $name= $_POST['name'];
171 $description= $_POST['description'];
176 $fields['name']= $name;
179 $fields['description']= $description;
182 if( !empty( $fields ) )
183 $api->UpdateNodeGroup( intval( $node_group_id ), $fields );
185 // get node_group info
186 $group_info= $api->GetNodeGroups( array( intval( $node_group_id ) ), array( "node_ids", "name", "conf_file_ids", "description" ) );
188 $node_ids = $group_info[0]['node_ids'];
189 $name = $group_info[0]['name'];
190 $conf_file_ids = $group_info[0]['conf_file_ids'];
191 $description = $group_info[0]['description'];
194 if( !empty( $node_ids ) )
195 $node_info= $api->GetNodes( $node_ids, array( "hostname", "node_id" ) );
197 // get site names and ids
198 $site_info= $api->GetSites( NULL, array( "site_id", "name" ) );
199 sort_sites( $site_info );
201 // if site_id is in post use it, if not use the user's primary
202 if( $_POST['site_id'] )
203 $site_id= $_POST['site_id'];
205 $site_id= $_person['site_ids'][0];
207 // get site nodes for $site_id
208 $sid= intval( $site_id );
209 $site_node_info= $api->GetSites( array( $sid ), array( "node_ids" ) );
210 $site_nodes= $site_node_info[0]['node_ids'];
213 // gets all node_ids from site that arent already associated with the node group
214 foreach( $site_nodes as $snode) {
215 if( !in_array( $snode, $node_ids ) )
220 // Get node info from new list
221 if( !empty( $snodes ) )
222 $snode_info= $api->GetNodes( $snodes, array( "hostname", "node_id" ) );
226 echo "<form action='node_groups.php?nodegroup_id=$node_group_id' method=post name='fm'>\n";
227 echo "<h2>Update Node Group id $name</h2>\n";
229 echo "Select a site to add nodes from.<br />\n";
230 echo "<select name='site_id' onChange='submit()'>\n";
232 foreach( $site_info as $site ) {
233 echo "<option value=". $site['site_id'];
234 if( $site['site_id'] == $site_id )
236 echo ">". $site['name'] ."</option>\n";
244 // show all availible nodes at $site_id
247 echo "<table><tbody>\n";
249 foreach( $snode_info as $snodes ) {
250 echo "<tr><td><input type=checkbox name='add_nodes[]' value=". $snodes['node_id'] ."> </td><td> ". $snodes['hostname'] ." </td></tr>\n";
254 echo "</tbody></table>\n";
255 echo "<p><input type=submit value='Add Nodes' name='add'>\n";
259 echo "<p>All nodes on site already added.\n";
263 // show all nodes currently associated
265 echo "<h5>Nodes already associated with node group</h5>\n";
267 echo "<u>Check boxes of nodes to remove:</u>\n";
268 echo "<table><tbody>\n";
270 foreach( $node_info as $node ) {
271 echo "<tr><td><input type=checkbox name='rem_nodes[]' value=". $node['node_id'] ."> </td><td> ". $node['hostname'] ." </td></tr>\n";
275 echo "</tbody></table>\n";
276 echo "<p><input type=submit value='Remove Nodes' name='remove'>\n";
280 echo "<p>No nodes associated with node group.\n";
284 echo "<table><tbody>\n";
285 echo "<tr><th>Name: </th><td><input type=text name='name' value='$name'></td></tr>\n";
286 echo "<tr><th>Description: </th><td><input type=text name='description' value='$description' size=50></td></tr>\n";
288 echo "</tbody></table>\n";
289 echo "<br /><input type=submit value='Update Node Group' name='update'>\n";
293 echo "<br /><a href='/db/nodes/node_groups.php'>Back to Node Group Index</a>\n";
300 include 'plc_footer.php';