person; $_roles= $_person['role_ids']; // if sent here from another page remove then redirect if( $_GET['remove'] && $_GET['nodegroup_id'] ) { $ng_id= $_GET['nodegroup_id']; $node_id= $_GET['remove']; $api->DeleteNodeFromNodeGroup( intval( $node_id ), intval( $ng_id ) ); header( "location: index.php?id=$node_id" ); exit(); } // Print header require_once 'plc_drupal.php'; drupal_set_title('Node Groups'); include 'plc_header.php'; // if no id display list of nodegroups if( !$_GET['id'] && !$_GET['nodegroup_id'] ) { $nodegroup_info= $api->GetNodeGroups( NULL, array( "nodegroup_id", "name", "description" ) ); echo "

Node Groups

\n "; // if admin we need to more cells if( in_array( "10", $_person['role_ids'] ) ) echo ""; echo ""; foreach( $nodegroup_info as $type ) { echo ""; // if admin display edit/delet links if( in_array( "10", $_person['role_ids'] ) ) { echo ""; echo plc_delete_link_button('node_groups.php?del_type=' . $type['nodegroup_id'], $type['name']); echo ""; } echo "\n"; } echo "
NameDescription
". $type['name'] ."". $type['description'] ."Edit
\n"; } // if id is set then show nodegroup info elseif( $_GET['id'] ) { $nodegroup_id= $_GET['id']; $nodegroup_info= $api->GetNodeGroups( array( intval( $nodegroup_id ) ), array( "name", "nodegroup_id", "node_ids" ) ); $node_info= $api->GetNodes( $nodegroup_info[0]['node_ids'], array( "node_id", "hostname" ) ); //display info echo "

Node Group ". $nodegroup_info[0]['name'] ."

\n"; if( empty( $nodegroup_info[0]['node_ids'] ) ) echo "

No nodes in node group."; else { echo ""; // if admin need more cells if( in_array( 10, $_roles ) ) echo ""; echo "\n"; foreach( $node_info as $node ) { echo ""; if( in_array( 10, $_roles ) ) echo ""; echo ""; } echo "
HostnameRemove
". $node['hostname'] ."remove
\n"; } } // if no id add else update elseif( $_GET['add'] ) { // add node group and redirect to update nodes for it if( $_POST['add_sub'] ) { $name= $_POST['name']; $description= $_POST['description']; $fields= array( 'name'=>$name, 'description'=>$description ); // add it $api->AddNodeGroup( $fields ); // get nodegroup_id $group_info= $api->GetNodeGroups( array( $name ), array( "nodegroup_id" ) ); // redirect header( "location: node_groups.php?id=". $group_info[0]['nodegroup_id'] ); exit(); } // add form echo "

"; echo "

Create Node Group

\n"; echo "\n"; echo "\n\n"; echo "
Name:
Description:
\n"; echo "
\nBack to Node Index\n"; } elseif( $_GET['nodegroup_id'] ) { // get node group id $node_group_id= $_GET['nodegroup_id']; // if add node submitted, add if( $_POST['add'] ) { $add_nodes= $_POST['add_nodes']; // add nodes to node group foreach( $add_nodes as $add_node ) { $api->AddNodeToNodeGroup( intval( $add_node ), intval( $node_group_id ) ); } } // if remove node submitted, remove if( $_POST['remove'] ) { $rem_nodes= $_POST['rem_nodes']; // remove nodes from node group foreach( $rem_nodes as $rem_node ) { $api->DeleteNodeFromNodeGroup( intval( $rem_node ), intval( $node_group_id ) ); } } // update name and description $name= $_POST['name']; $description= $_POST['description']; $fields= array(); if( $name ) $fields['name']= $name; if( $description ) $fields['description']= $description; // api call if( !empty( $fields ) ) $api->UpdateNodeGroup( intval( $node_group_id ), $fields ); // get node_group info $group_info= $api->GetNodeGroups( array( intval( $node_group_id ) ), array( "node_ids", "name", "conf_file_ids", "description" ) ); $node_ids = $group_info[0]['node_ids']; $name = $group_info[0]['name']; $conf_file_ids = $group_info[0]['conf_file_ids']; $description = $group_info[0]['description']; // get node info if( !empty( $node_ids ) ) $node_info= $api->GetNodes( $node_ids, array( "hostname", "node_id" ) ); // get site names and ids $site_info= $api->GetSites( NULL, array( "site_id", "name" ) ); sort_sites( $site_info ); // if site_id is in post use it, if not use the user's primary if( $_POST['site_id'] ) $site_id= $_POST['site_id']; else $site_id= $_person['site_ids'][0]; // get site nodes for $site_id $sid= intval( $site_id ); $site_node_info= $api->GetSites( array( $sid ), array( "node_ids" ) ); $site_nodes= $site_node_info[0]['node_ids']; // gets all node_ids from site that arent already associated with the node group foreach( $site_nodes as $snode) { if( !in_array( $snode, $node_ids ) ) $snodes[]= $snode; } // Get node info from new list if( !empty( $snodes ) ) $snode_info= $api->GetNodes( $snodes, array( "hostname", "node_id" ) ); // start form echo "\n"; echo "

Update Node Group id $name

\n"; echo "Select a site to add nodes from.
\n"; echo "\n"; echo "
\n"; // show all availible nodes at $site_id if( $snode_info ) { echo $added; echo "\n"; foreach( $snode_info as $snodes ) { echo "\n"; } echo "
". $snodes['hostname'] ."
\n"; echo "

\n"; } else echo "

All nodes on site already added.\n"; echo "


\n"; // show all nodes currently associated echo $removed; echo "
Nodes already associated with node group
\n"; if( $node_info ) { echo "Check boxes of nodes to remove:\n"; echo "\n"; foreach( $node_info as $node ) { echo "\n"; } echo "
". $node['hostname'] ."
\n"; echo "

\n"; } else echo "

No nodes associated with node group.\n"; echo "


\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Name:
Description:
\n"; echo "
\n"; echo "
\n"; echo "
Back to Node Group Index\n"; } // Print footer include 'plc_footer.php'; ?>