<?php
/*
Fruity - A Nagios Configuration Tool
Copyright (C) 2005 Groundwork Open Source Solutions

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
Fruity Import Page, Displays Menu, and Statistics
*/

// SF Feature Request # 1442602
// Import Screen Cleanup
// Solution: Many tables and tablerows, to many to write this to each line


include_once('includes/config.inc');
include_once('includes/tangelo.inc.php');		// Include the New Tangelo Library

if(isset($_POST['request'])) {
	if(count($_POST['import'])) {
		foreach($_POST['import'] as $key=>$value)
			$_SESSION['tempData']['import'][$key] = $value;
	}
	if($_POST['request'] == 'import') {
		// First see if we can open the file.
		$parser = new Tangelo($_SESSION['tempData']['import']['config_file'], $_SESSION['tempData']['import']['cgi_config_file'], $_SESSION['tempData']['import']['resource_file']);
		if($parser->isError()) {
			$status_msg = "Tangelo Error: ".$parser->getError();
			unset($_POST['request']);
		}
	}
}


print_header("Import Utility");
?>
<br />
<br />
<?php
if(isset($status_msg)) {
	?>
	<div align="center" class="statusmsg"><?=$status_msg;?></div><br />
	<?php
}
if(!isset($_POST['request']) || isset($status_msg))	{
	print_window_header("Warning", "100%", "center");
	?>
	The import utility will delete ALL content in the current fruity database.  It will then attempt to read the configuration from 
	the nagios configuration file you supply below.  It will then import the information into the fruity database.  It does NOT 
	attempt to rectify any errors you have with your current database.  It assumes your current working configuration is complete and 
	without error.  If you attempt to import a configuration with errors, you will have errors with Fruity.  Once the import is complete, 
	you should verify the configuration with fruity, then export.<br />
	<br />
	<b>If you wish to continue, enter the full path (include the filename) to your configuration files below:</b><br />
	<form name="main_path_config" method="post" action="<?=$path_config['doc_root'];?>import.php">
	<input type="hidden" name="request" value="import" />
	nagios.cfg: <input type="text" size="80" maxlength="255" name="import[config_file]" value="<?=$_SESSION['tempData']['import']['config_file'];?>"><br />
	<input type="hidden" name="request" value="import" />
	cgi.cfg <input type="text" size="80" maxlength="255" name="import[cgi_config_file]" value="<?=$_SESSION['tempData']['import']['cgi_config_file'];?>"><br />
	Resources File (Optional): <input type="text" size="80" maxlength="255" name="import[resource_file]" value="<?=$_SESSION['tempData']['import']['resource_file'];?>"><br />
	<input type="submit" value="Begin Import" />
	<?php
	print_window_footer();
}
else {
	// Let's set the timeout for something obscene
	set_time_limit(600);	// 10 minutes should be enough for any large config.
	
	
	print_window_header("Import Log", "100%", "center");
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td colspan="3"><b>Pre-Import Operations</b></td>
	</tr>
	<tr>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
	</tr>
	<tr bgcolor="#cccccc">
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td height="20">Reading of configuration files...<b><font color='#009900'>DONE</font></b></td>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
	</tr>
	<tr bgcolor="#f0f0f0">
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td height="20">Removing all data from Fruity's Tables...
		<?php
		$fruity->delete_all_data();
		if(count($parser->cgiConfig)) {
			$fruity->delete_cgi_data();
		}
		?>
		<b><font color='#009900'>DONE</font></b>
		</td>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
	</tr>
	<?php
	if(count($parser->cgiConfig)) {
		?>
		<tr bgcolor="#f0f0f0">
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td height="20">Importing CGI Configuration...
			<?php
			// Insert CGI Configration
			unset($parser->cgiConfig['main_config_file']);		// We don't need this field
			if($fruity->new_cgi_conf($parser->cgiConfig)) {
				?>
				<b><font color='#009900'>DONE</font></b><br />
				<?php
			}
			else {
				?>
				<b><font= '#FF0000'>ERROR:</font></b> new_cgi_conf failed.<br />
				<?php
			}
			?>
			</td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<tr>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
				<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<?php
	}
	?>
	</table>
	<br />
<!--	// Time Period Import -->
	<?php
		$numOfTimePeriods = count($parser->timeperiods);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Time Periods To Import: " . $numOfTimePeriods."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfTimePeriods) {
			$bgcolor="#cccccc";
		foreach($parser->timeperiods as $tempTimePeriod) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($tempTimePeriod['register']) && $tempTimePeriod['register'] == 0) {
				print("<td height='20'>" . $counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($tempTimePeriod['registered']) || $tempTimePeriod['registered'] == 1) {
				$parser->buildInheritedObject($tempTimePeriod, $parser->timeperiods);
				print("<td height='20'>" .$counter.": Importing " . $tempTimePeriod['timeperiod_name'] . "...");
				if($fruity->add_period($tempTimePeriod))
					print("<b><font color='#009900'>DONE</font></b></td>");
				else 
					print("<b><font= '#FF0000'>ERROR:</font></b> add_period failed.</td>");
				$counter++;
				$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
	?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
	<?php
			}
		}
	}
	?>
	</table>
	<br />
	<?php
	// Commands Import
	$numOfCommands = count($parser->commands);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Commands To Import: " . $numOfCommands."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfCommands) {
		$bgcolor="#cccccc";
		foreach($parser->commands as $tempCommand) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($tempCommand['register']) && $tempCommand['register'] == 0) {
				print("<td height='20'>" . $counter . ": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($tempCommand['registered']) || $tempCommand['registered'] == 1) {
				$parser->buildInheritedObject($tempCommand, $parser->commands);
				print("<td height='20'>" . $counter.": Importing " . $tempCommand['command_name'] . "...");
				$tempCommand['command_line'] = addslashes($tempCommand['command_line']);
				if($fruity->add_command($tempCommand))
					print("<b><font color='#009900'>DONE</font></b></td>");
				else 
					print("<b><font= '#FF0000'>ERROR:</font></b> add_command failed.</td>");
			}
			$counter++;
				$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
		?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
		<?php
		}
	}
	?>
	</table>	
	<br />
	<?php
	// Contacts Import
	$numOfContacts = count($parser->contacts);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Contacts To Import: " . $numOfContacts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfContacts) {
		$bgcolor="#cccccc";
		foreach($parser->contacts as $contact) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($contact['register']) && $contact['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($contact['registered']) || $contact['registered'] == 1) {
				$parser->buildInheritedObject($contact, $parser->contacts);
				// Remove any unneeded elements
				unset($contact['contactgroups']);
				$tempContact = $contact;
				// Check Host Notification Period
				print("<td height='20'>" .$counter.": Importing " . $tempContact['contact_name'] . "...");
				$tempPeriodID = $fruity->return_period_id_by_name($tempContact['host_notification_period']);
				if(!timePeriodID) {
					print("FAILED: Host Notification Time Period \"".$tempContact['host_notification_period'] ."\" not found!</td>");
				}
				else {
					$tempContact['host_notification_period'] = $tempPeriodID;
					$tempPeriodID = $fruity->return_period_id_by_name($tempContact['service_notification_period']);
					if(!timePeriodID) {
						print("FAILED: Service Notification Time Period \"".$tempContact['service_notification_period'] ."\" not found!</td>");
					}
					else {
						$tempContact['service_notification_period'] = $tempPeriodID;			
						if(preg_match("/[Dd]/",$tempContact['host_notification_options']))
							$tempContact['host_notification_options_down'] = 1;
						if(preg_match("/[Uu]/",$tempContact['host_notification_options']))
							$tempContact['host_notification_options_unreachable'] = 1;
						if(preg_match("/[Rr]/",$tempContact['host_notification_options']))
							$tempContact['host_notification_options_recovery'] = 1;
						unset($tempContact['host_notification_options']);
						if(preg_match("/[Ww]/",$tempContact['service_notification_options']))
							$tempContact['service_notification_options_warning'] = 1;
						if(preg_match("/[Uu]/",$tempContact['service_notification_options']))
							$tempContact['service_notification_options_unknown'] = 1;
						if(preg_match("/[Cc]/",$tempContact['service_notification_options']))
							$tempContact['service_notification_options_critical'] = 1;
						if(preg_match("/[Rr]/",$tempContact['service_notification_options']))
							$tempContact['service_notification_options_recovery'] = 1;
						unset($tempContact['service_notification_options']);
						// Host Notification Commands
						$tempHostNotificationCommands = explode(",",$tempContact['host_notification_commands']);
						$tempServiceNotificationCommands = explode(",",$tempContact['service_notification_commands']);
						unset($tempContact['host_notification_commands']);
						unset($tempContact['service_notification_commands']);
						if($fruity->add_contact($tempContact)) {
							print("<b><font color='#009900'>DONE</font></b><br \>");
							$tempContactID = $fruity->return_contact_id_by_name($tempContact['contact_name']);
							if(count($tempHostNotificationCommands)) {
								foreach($tempHostNotificationCommands as $tempCommand) {
									$tempCommand = trim($tempCommand);
									$tempCommandID = $fruity->return_command_id_by_name($tempCommand);
									$tempCommandArray = array();
									$tempCommandArray['notification_type'] = "host";
									$tempCommandArray['contact_id'] = $tempContactID;
									$tempCommandArray['command_id'] = $tempCommandID;
									print("&nbsp;&nbsp;&nbsp;" . $counter.": Importing Host Notification Command: ".$tempCommand ."...");
									if($fruity->add_contacts_notification_command($tempContactID, $tempCommandArray))
										print("<b><font color='#009900'>DONE</font></b><br \>");
									else 
										print("<b><font= '#FF0000'>ERROR:</font></b> add_contacts_notification_command failed.<br \>");
								}
							}
							if(count($tempServiceNotificationCommands)) {
								foreach($tempServiceNotificationCommands as $tempCommand) {
									$tempCommand = trim($tempCommand);
									$tempCommandID = $fruity->return_command_id_by_name($tempCommand);
									$tempCommandArray = array();
									$tempCommandArray['notification_type'] = "service";
									$tempCommandArray['contact_id'] = $tempContactID;
									$tempCommandArray['command_id'] = $tempCommandID;
									print("&nbsp;&nbsp;&nbsp;" . $counter.": Importing Service Notification Command: ".$tempCommand ."...");
									if($fruity->add_contacts_notification_command($tempContactID, $tempCommandArray))
										print("<b><font color='#009900'>DONE</font></b></td>");
									else 
										print("<b><font= '#FF0000'>ERROR:</font></b> add_contacts_notification_command failed.</td>");
								}
							}
						}
						else {
							print("<b><font= '#FF0000'>ERROR:</font></b> add_contact failed.</td>");
						}
					}
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
					<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
				</tr>
			<?php
		}
	}
	?>
	</table>	
	<br />
	<?php
	
	// Additional Addresses Import (If needed)
	$numOfContacts = count($parser->contacts);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Contacts To Check For Additional Addresses: " . $numOfContacts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfContacts) {
		$bgcolor="#cccccc";
		foreach($parser->contacts as $contact) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($contact['register']) && $contact['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($contact['registered']) || $contact['registered'] == 1) {
				$parser->buildInheritedObject($contact, $parser->contacts);
				$tempContact = $contact;
				// Check Host Notification Period
				print("<td height='20'>" .$counter.": Importing " . $tempContact['contact_name'] . "'s Addresses...");
				$addressExists = 0;	// Set the initial flag
				$counter = 1;
				$tempContactID = $fruity->return_contact_id_by_name($tempContact['contact_name']);
				if(isset($tempContact['address'.$counter]))
					$addressExists = 1;
				while($addressExists) {
					$fruity->add_contact_address($tempContactID, $tempContact['address'.$counter]);
					$counter++;
					$addressExists = 0;
					if(isset($tempContact['address'.$counter]))
						$addressExists = 1;
				}
				print("<b><font color='#009900'>DONE</font></b></td>");
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}
	}
	print("</table>");
	print("<br />");
	
	// Contact Groups Import
	$numOfContactGroups = count($parser->contactgroups);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Contact Groups To Import: " . $numOfContactGroups."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfContactGroups) {
		$bgcolor="#cccccc";
		foreach($parser->contactgroups as $contactgroup) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($contactgroup['register']) && $contactgroup['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td />");
			}
			else if(!isset($contactgroup['registered']) || $contactgroup['registered'] == 1) {
				$parser->buildInheritedObject($contactgroup, $parser->contactgroups);
				$tempContactGroup = $contactgroup;
				print("<td height='20'>" .$counter.": Importing " . $tempContactGroup['contactgroup_name'] . "...");
				$tempGroupMembers = explode(",",$tempContactGroup['members']);
				unset($tempContactGroup['members']);
				if($fruity->add_contactgroup($tempContactGroup)) {
					print("<b><font color='#009900'>DONE</font></b><br />");		
					$tempContactGroupID = $fruity->return_contactgroup_id_by_name($tempContactGroup['contactgroup_name']);
					if(count($tempGroupMembers)) {
						foreach($tempGroupMembers as $tempContact) {
							$tempContact = trim($tempContact);
							$tempContactID = $fruity->return_contact_id_by_name($tempContact);
							print("&nbsp;&nbsp;&nbsp;" .$counter.": Linking Member: ".$tempContact ."...");
							if($fruity->add_contactgroup_member($tempContactGroupID, $tempContactID))
								print("<b><font color='#009900'>DONE</font></b><br />");
							else 
								print("<b><font= '#FF0000'>ERROR:</font></b> add_contactgroup_member failed.<br />");
						}
					}
				}
				else 
					print("<b><font= '#FF0000'>ERROR:</font></b> add_contactgroup failed.</td>");
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}
	}
	// Gotta do a second pass over contacts, and parse the contact_groups parameter
	// This is only in version 2 of nagios
	?>
	</table>
	<br />
	<?php		
	$numOfContacts = count($parser->contacts);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Contacts To Recheck for contactgroups : " . $numOfContacts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	if($numOfcontacts) {
		$bgcolor="#cccccc";
		foreach($parser->contacts as $contact) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($contact['register']) && $contact['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($contact['registered']) || $contact['registered'] == 1) {
				$parser->buildInheritedObject($contact, $parser->contacts);
				$tempContact = $contact;
				// Check Host Notification Period
				$tempContactID = $fruity->return_contact_id_by_name($tempContact['contact_name']);
				if(isset($tempContact['contactgroups'])) {
					$tempGroupMembership = explode(",",$tempContact['contactgroups']);
					if(count($tempGroupMembership)) {
						foreach($tempGroupMembership as $tempGroup) {
							$tempGroup = trim($tempGroup);
							$tempContactGroupID = return_contactgroup_id_by_name($tempGroup);
							print("<td height='20'>" .$counter.": Linking Member: ".$tempContact['contact_name'] ." to " . $tempGroup . "...");
							if($fruity->add_contactgroup_member($tempContactGroupID, $tempContactID))
								print("<b><font color='#009900'>DONE</font></b></td>");
							else 
								print("<b><font= '#FF0000'>ERROR:</font></b> add_contactgroup_member failed.</td>");
						}
					}
				}
				else {
					print("<td height='20'>" .$counter.": Contact: ".$tempContact['contact_name']." has no contactgroups entry.</td>");
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	?>
	</table>
	<br />
	
	<?php
	// Host Groups Import
	$numOfHostGroups = count($parser->hostgroups);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Host Groups To Import: " . $numOfHostGroups."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	if($numOfHostGroups) {
		$counter = 1;
		$bgcolor="#cccccc";
		foreach($parser->hostgroups as $hostgroup) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($hostgroup['register']) && $hostgroup['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($hostgroup['registered']) || $hostgroup['registered'] == 1) {
				$parser->buildInheritedObject($hostgroup, $parser->hostgroups);
				
				// Remove anything unwanted
				$tempHostGroup = $hostgroup;
				print("<td height='20'>" .$counter.": Importing " . $tempHostGroup['hostgroup_name'] . "...");
				$tempGroupMembers = array();
				if(isset($tempHostGroup['members'])) {
					$tempGroupMembers = explode(",",$tempHostGroup['members']);
					unset($tempHostGroup['members']);
				}
				if(isset($tempHostGroup['contact_groups'])) {
					// $tempContactGroups = explode(",",$tempHostGroup['contact_groups']); 	// We don't do hostgroup contactgroups anymore
					unset($tempHostGroup['contact_groups']);
				}
				if($fruity->add_hostgroup($tempHostGroup))
					print("<b><font color='#009900'>DONE</font></b></td>");
				else 
					print("<b><font= '#FF0000'>ERROR:</font></b> add_hostgroup failed.</td>");
			}		
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	?>
	</table>
	<br />
	
	<?php
	// Host Template Imports!  *WooHoo*
	$numOfHosts = count($parser->hosts);
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Hosts To Filter for Templates: " . $numOfHosts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if(count($parser->hosts)) {
		foreach($parser->hosts as $host) {
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($host['name'])) {	// Egads, we're a template!
				print("<td height='20'>" .$counter . ": Importing Host Template - " . $host['name'] . "...");
				$tempHost = $host;
				if(isset($tempHost['use'])) {
					trim($tempHost['use']);	// Let's trim it first, no whitespace
					$tempTemplateID = NULL;
					$tempTemplateID = $fruity->return_host_template_id_by_name($tempHost['use']);
					if($tempTemplateID) {	// We have the template
						$tempHost['use_template_id'] = $tempTemplateID;
					}
					// CLEVER FIX PROVIDE BY ANONYMOUS!
					//else we have unfinished business
					$ub[$tempHost['name']]=$tempHost['use'];

				}
				$tempHost['template_name'] = $tempHost['name'];
				
				//Check Command Replacement
				if(isset($tempHost['check_command'])) {
					$tempCheckCommand = explode("!",$tempHost['check_command']);
					// Check to see if this is a defined command
					$tempHost['check_command'] = trim($tempCheckCommand[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempCheckCommand[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempHost['check_command'] = $tempCommandID;
					else {
						unset($tempHost['check_command']);
					}
				}
				
				// Event Handler Replacement
				if(isset($tempHost['event_handler'])) {
					$tempEventHandler = explode("!",$tempHost['event_handler']);
					// Check to see if this is a defined command
					$tempHost['event_handler'] = trim($tempEventHandler[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempEventHandler[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempHost['event_handler'] = $tempCommandID;
					else {
						unset($tempHost['event_handler']);
					}
				}
				
				unset($tempContactGroups);
				if(isset($tempHost['contact_groups'])) {
					$tempContactGroups = explode(",",$tempHost['contact_groups']);
				}
				unset($tempHost['contact_groups']);
				if(isset($tempHost['notification_period'])) {
					$tempPeriodID = $fruity->return_period_id_by_name($tempHost['notification_period']);
					$tempHost['notification_period'] = $tempPeriodID;
				}
				if(isset($tempHost['check_period'])) {
					$tempPeriodID = $fruity->return_period_id_by_name($tempHost['check_period']);
					$tempHost['check_period'] = $tempPeriodID;
				}
				unset($tempHostGroups);
				if(isset($tempHost['hostgroups'])) {
					$tempHostGroups = explode(",",$tempHost['hostgroups']);
				}
				unset($tempHost['hostgroups']);
				
				if(preg_match("/[Dd]/",$tempHost['notification_options']))
					$tempHost['notification_options_down'] = 1;
				if(preg_match("/[Uu]/",$tempHost['notification_options']))
					$tempHost['notification_options_unreachable'] = 1;
				if(preg_match("/[Rr]/",$tempHost['notification_options']))
					$tempHost['notification_options_recovery'] = 1;
				if(preg_match("/[Ff]/",$tempHost['notification_options']))
					$tempHost['notification_options_flapping'] = 1;
					
				if(preg_match("/[Oo]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_up'] = 1;
				if(preg_match("/[Dd]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_down'] = 1;
				if(preg_match("/[Uu]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_unreachable'] = 1;
				unset($tempHost['stalking_options']);
					
				unset($tempHost['notification_options']);
				unset($tempHost['parents']);
				unset($tempHost['use']);
				unset($tempHost['register']);
				unset($tempHost['name']);
				
				// Success to this point
				if(!$fruity->add_host_template($tempHost)) {
					print("<b><font= '#FF0000'>ERROR:</font></b> add_host_template failed.</td>");
				}
				else {
					$error = false;
					$tempHostTemplateID = $fruity->return_host_template_id_by_name($tempHost['template_name']);
					if($tempHostGroups) {
						foreach($tempHostGroups as $hostgroup) {
							$hostgroup = trim($hostgroup);
							$tempGroupID = $fruity->return_hostgroup_id_by_name($hostgroup);
							if( !$fruity->add_host_template_hostgroup($tempHostTemplateID, $tempGroupID)) {
								print("<b><font= '#FF0000'>ERROR:</font></b> add_host_template_hostgroup failed.</td>");
								$error = true;
							}
						}
					}
					
					if($tempContactGroups) {
						foreach($tempContactGroups as $contactgroup) {
							$contactgroup = trim($contactgroup);
							$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
							if( !$fruity->add_host_template_contactgroup($tempHostTemplateID, $tempGroupID)) {
								print("<b><font= '#FF0000'>ERROR:</font></b> add_host_template_contactgroup failed.</td>");
								$error = true;
							}
						}
					}
					
					$numOfCheckCommand = count($tempCheckCommand);
					for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
						$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
						if($tempCheckCommand[$subcounter] != '') {
							$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
							if( !$fruity->add_host_template_command_parameter($tempHostTemplateID, $tempCommandArray)) {
								print("<b><font= '#FF0000'>ERROR:</font></b> add_host_template_command_parameter failed.</td>");
							}
						}
					}
					
					if( !$error)
						print("<b><font color='#009900'>DONE</font></b></td>");
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}
		if (isset($ub)) {
			print "<tr><td colspan=\"3\">\n";
		        print ("Handling Unfinished Business...");
		        foreach ($ub as $key => $value) {
		        	$updateID = $fruity->return_host_template_id_by_name($key);
		                $useID    = $fruity->return_host_template_id_by_name($value);
		                if ($fruity->get_host_template_info($updateID, $tempObj)) {
		                	$tempObj['use_template_id'] = $useID;
		                        $fruity->modify_host_template($tempObj);
		                }
		        }
		        print("<b>DONE</b><br />\n");
		        print("</td></tr>\n");
		        unset($ub);
		}	
	}	
	print("</table>");
	print("<br />");

	// Hosts Import
	$numOfHosts = count($parser->hosts);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Hosts To Import: " . $numOfHosts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfHosts) {
		foreach($parser->hosts as $host) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($host['register']) && $host['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($host['registered']) || $host['registered'] == 1) {
				$tempHost = $host;
				print("<td height='20'>" .$counter.": Importing " . $tempHost['host_name'] . "...");
				if(isset($tempHost['use'])) {
					trim($tempHost['use']);	// Let's trim it first, no whitespace
					$tempTemplateID = NULL;
					$tempTemplateID = $fruity->return_host_template_id_by_name($tempHost['use']);
					if($tempTemplateID) {	// We have the template
						$tempHost['use_template_id'] = $tempTemplateID;
					}
					// else we don't set it
				}
				
				//Check Command Replacement
				if(isset($tempHost['check_command'])) {
					$tempCheckCommand = explode("!",$tempHost['check_command']);
					// Check to see if this is a defined command
					$tempHost['check_command'] = trim($tempCheckCommand[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempCheckCommand[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempHost['check_command'] = $tempCommandID;
					else {
						unset($tempHost['check_command']);
					}
				}
				// Event Handler Replacement
				if(isset($tempHost['event_handler'])) {
					$tempEventHandler = explode("!",$tempHost['event_handler']);
					// Check to see if this is a defined command
					$tempHost['event_handler'] = trim($tempEventHandler[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempEventHandler[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempHost['event_handler'] = $tempCommandID;
					else {
						unset($tempHost['event_handler']);
					}
				}
				
				$tempContactGroups = NULL;
				if(isset($tempHost['contact_groups'])) {
					$tempContactGroups = explode(",",$tempHost['contact_groups']);
				}
				unset($tempHost['contact_groups']);
				if(isset($tempHost['notification_period'])) {
					$tempPeriodID = $fruity->return_period_id_by_name($tempHost['notification_period']);
					$tempHost['notification_period'] = $tempPeriodID;
				}
				if(isset($tempHost['check_period'])) {
					$tempPeriodID = $fruity->return_period_id_by_name($tempHost['check_period']);
					$tempHost['check_period'] = $tempPeriodID;
				}
				unset($tempHostGroups);
				if(isset($tempHost['hostgroups'])) {
					$tempHostGroups = explode(",",$tempHost['hostgroups']);
				}
				unset($tempHost['hostgroups']);
				
				if(preg_match("/[Dd]/",$tempHost['notification_options']))
					$tempHost['notification_options_down'] = 1;
				if(preg_match("/[Uu]/",$tempHost['notification_options']))
					$tempHost['notification_options_unreachable'] = 1;
				if(preg_match("/[Rr]/",$tempHost['notification_options']))
					$tempHost['notification_options_recovery'] = 1;
				if(preg_match("/[Ff]/",$tempHost['notification_options']))
					$tempHost['notification_options_flapping'] = 1;
					
				if(preg_match("/[Oo]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_up'] = 1;
				if(preg_match("/[Dd]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_down'] = 1;
				if(preg_match("/[Uu]/",$tempHost['stalking_options']))
					$tempHost['stalking_options_unreachable'] = 1;
				unset($tempHost['stalking_options']);
					
				unset($tempHost['notification_options']);
				unset($tempHost['parents']);
				unset($tempHost['use']);
				unset($tempHost['register']);
				unset($tempHost['name']);
				
				if($fruity->add_host($tempHost)) {
					print("<b><font color='#009900'>DONE</font></b><br />");
					$tempHostID = $fruity->return_host_id_by_name($tempHost['host_name']);
					if(isset($tempHostGroups)) {
						foreach($tempHostGroups as $hostgroup) {
							$hostgroup = trim( $hostgroup);
							$tempGroupID = $fruity->return_hostgroup_id_by_name( $hostgroup);
							print("&nbsp;&nbsp;&nbsp;" .$counter.": Linking Host Group: ".$hostgroup ."...");
							if($fruity->add_hostgroup_member($tempGroupID, $tempHostID))
								print("<b><font color='#009900'>DONE</font></b><br />");
							else 
								print("<b><font= '#FF0000'>ERROR:</font></b> add_hostgroup_member failed.</td>");
						}
					}
					if(count($tempContactGroups)) {
						foreach($tempContactGroups as $contactgroup) {
							if($hostCounter <= 1) {
								$contactgroup = trim($contactgroup);
								$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
							}
							print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$counter.": Linking Contact Group: ".$contactgroup ."...");
							if($fruity->add_host_contactgroup($tempHostID, $tempGroupID)) {
								$tempHostID = $fruity->return_host_id_by_name($tempHost['host_name']);
				
								$numOfCheckCommand = count($tempCheckCommand);
								for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
									$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
									if($tempCheckCommand[$subcounter] != '') {
										$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
										$fruity->add_host_command_parameter($tempHostID, $tempCommandArray);
									}
								}
								
								print("<b><font color='#009900'>DONE</font></b><br />");
							} else {
								print("<b><font= '#FF0000'>ERROR:</font></b> add_host_contactgroup failed.<br />");
							}
						}
					}
				}
				else 
					print("<b><font= '#FF0000'>ERROR:</font></b> add_host failed.</td>");
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Host Dependencies
	$numOfHostDependencies = count($parser->hostdependencies);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Host Dependency Entries To Process: " . $numOfHostDependencies."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfHostDependencies) {
		foreach($parser->hostdependencies as $dependency) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($dependency['register']) && $dependency['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($dependency['registered']) || $dependency['registered'] == 1) {
				$parser->buildInheritedObject($dependency, $parser->hostdependencies);
				$tempDependency = $dependency;
				// Built object, let us begin.
				if(preg_match("/[Oo]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_up'] = 1;
				if(preg_match("/[Dd]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_down'] = 1;
				if(preg_match("/[Uu]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_unreachable'] = 1;
				if(preg_match("/[Pp]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_pending'] = 1;
				
					
				if(preg_match("/[Oo]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_up'] = 1;
				if(preg_match("/[Dd]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_down'] = 1;
				if(preg_match("/[Uu]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_unreachable'] = 1;
				if(preg_match("/[Pp]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_pending'] = 1;
				unset($tempDependency['execution_failure_criteria']);
				unset($tempDependency['notification_failure_criteria']);
				
				$tempHostID = $fruity->return_host_id_by_name($tempDependency['dependent_host_name']);
				$targetHostID = $fruity->return_host_id_by_name($tempDependency['host_name']);
				if(!$fruity->add_host_dependency($tempHostID, $targetHostID)) {
					print("<b><font= '#FF0000'>ERROR:</font></b> add_host_dependency failed.</td>");
				}
				else {
					$tempDependencyID = $fruity->return_host_dependency($tempHostID, $targetHostID);
					unset($tempDependency['dependent_host_name']);
					unset($tempDependency['host_name']);
					if(!$fruity->modify_dependency($tempDependencyID, $tempDependency)) {
						print("<b><font= '#FF0000'>ERROR:</font></b> modify_dependency failed.</td>");
					}
					else {
						print("<td height='20'><b>SUCCESS</b></td>");
					}
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Host escalations
	
	$numOfHostEscalations = count($parser->hostescalations);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Host Escalation Entries To Process: " . $numOfHostEscalations."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfHostEscalations) {
		foreach($parser->hostescalations as $escalation) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($escalation['register']) && $escalation['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($escalation['registered']) || $escalation['registered'] == 1) {
				$parser->buildInheritedObject($escalation, $parser->hostescalations);
				$tempEscalation = $escalation;
				// Built object, let us begin.
				if(preg_match("/[Rr]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_up'] = 1;
				if(preg_match("/[Dd]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_down'] = 1;
				if(preg_match("/[Uu]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_unreachable'] = 1;
				unset($tempEscalation['escalation_options']);
					
				$tempEscalation['escalation_period'] = $fruity->return_period_id_by_name($tempEscalation['escalation_period']);
				unset($tempContactGroups);
				if(isset($tempEscalation['contact_groups'])) {
					$tempContactGroups = explode(",", $tempEscalation['contact_groups']);
					unset($tempEscalation['contact_groups']);
				}
				$tempEscalationDescription = $tempEscalation['host_name'] . " Escalation # " . $counter;
										
				$tempHostID = $fruity->return_host_id_by_name($tempEscalation['host_name']);
				if(!$fruity->add_host_escalation($tempHostID, $tempEscalationDescription)) {
					print("<b><font= '#FF0000'>ERROR:</font></b> add_host_escalation failed.<br />");
				}
				else {
					unset($tempEscalation['host_name']);
					unset($tempEscalation['hostgroup_name']); // We can't support this yet
					$tempEscalationID = $fruity->return_host_escalation($tempHostID, $tempEscalationDescription);
					$tempEscalation['escalation_id'] = $tempEscalationID;
					if(!$fruity->modify_escalation($tempEscalation)) {
						print("<b><font= '#FF0000'>ERROR:</font></b> modify_escalation failed.<br />");
					}
					else {
						print("<b>SUCCESS</b><br />");
						if($tempContactGroups) {
							foreach($tempContactGroups as $contactgroup) {
								$contactgroup = trim($contactgroup);
								$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
								print("<td height='20'>" .$counter.": Linking Contact Group: ".$contactgroup ."...");
								if($fruity->add_escalation_contactgroup($tempEscalationID, $tempGroupID))				
									print("<b><font color='#009900'>DONE</font></b></td>");
								else 
									print("<b><font= '#FF0000'>ERROR:</font></b> add_escalation_contactgroup failed.</td>");
							}
						}
					}
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");
	
	// Parents Link
	$numOfHosts = count($parser->hosts);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Hosts To Check For Parents: " . $numOfHosts."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfHosts) {
		foreach($parser->hosts as $host) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($host['register']) && $host['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($host['registered']) || $host['registered'] == 1) {
				$parser->buildInheritedObject($host, $parser->hosts);
				$tempHost = $host;
				if(isset($tempHost['parents'])) {
					$tempParents = explode(",",$tempHost['parents']);
					if(count($tempParents)) {
						$counter2 = 0;
						foreach($tempParents as $parent) {
							$parent = trim($parent);
							$tempHostID = $fruity->return_host_id_by_name($tempHost['host_name']);
							$tempParentID = $fruity->return_host_id_by_name($parent);
							if($counter2) {
								// This is an ADDITIONAL parent
								print("<td height='20'>" .$counter.": Linking ${tempHost['host_name']}'s Additional Parent To $parent ...");
								if($tempParentID && $tempHostID) {
									$fruity->host_add_parent($tempHostID, $tempParentID);
									print("<b><font color='#009900'>DONE</font></b></td>");
								}
								else {
									print("<b><font= '#FF0000'>ERROR:</font></b> host_add_parent failed.</td>");
								}
							}
							else {
								// This is the first parent, it will be the MAIN parent
								$tempHostArray['parents'] = $tempParentID;
								$tempHostArray['host_id'] = $tempHostID;
								if($tempHost['host_name'] == '')
									$tempHost['host_name'] == 'nagios';
								print("<td height='20'>" .$counter.": Linking ${tempHost['host_name']}'s Parent To $parent ...");
								if($fruity->modify_host($tempHostArray))
									print("<b><font color='#009900'>DONE</font></b></td>");
								else 
									print("<b><font= '#FF0000'>ERROR:</font></b> modify_host failed.</td>");
								
							}
							$counter2++;
						}
					}
				}
				else {
					print("<td height='20'>" .$counter.": Host: ${tempHost['host_name']} has no parents.</td>");
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");
	
	// Make a second pass on hostgroups to support the hostgroup's members parameter
	
	$numOfHostGroups = count($parser->hostgroups);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Host Groups To Check for Members: " . $numOfHostGroups."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	if($numOfHostGroups) {
		$counter = 1;
		$bgcolor="#cccccc";
		foreach($parser->hostgroups as $hostgroup) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($hostgroup['register']) && $hostgroup['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($hostgroup['registered']) || $hostgroup['registered'] == 1) {
				$parser->buildInheritedObject($hostgroup, $parser->hostgroups);
				// Remove anything unwanted
				$tempHostGroup = $hostgroup;
				print("<td height='20'>" .$counter.": Verifying memberships for " . $tempHostGroup['hostgroup_name'] . "...</br>");
				$tempGroupMembers = array();
				if(isset($tempHostGroup['members'])) {
					$tempHostGroupID = $fruity->return_hostgroup_id_by_name($tempHostGroup['hostgroup_name']);
					$tempGroupMembers = explode(",",$tempHostGroup['members']);
					if(count($tempGroupMembers)) {
						foreach($tempGroupMembers as $tempHostname) {
							$tempHostname = trim($tempHostname);
							$tempHostID = $fruity->return_host_id_by_name($tempHostname);
							print("&nbsp;&nbsp;&nbsp;" .$counter.": Linking to host ".$tempHostname ."...");
							if($fruity->add_hostgroup_member($tempHostGroupID, $tempHostID))
								print("<b><font color='#009900'>DONE</font></b></td>");
							else 
								print("<b><font= '#FF0000'>ERROR:</font></b> add_hostgroup_member failed.</td>");
						}
					}
					unset($tempHostGroup['members']);
				}
			}	
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Service Groups Import
	$numOfServiceGroups = count($parser->servicegroups);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Service Groups To Import: " . $numOfServiceGroups."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfServiceGroups) {
		foreach($parser->servicegroups as $servicegroup) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($servicegroup['register']) && $servicegroup['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($servicegroup['registered']) || $servicegroup['registered'] == 1) {
				$parser->buildInheritedObject($servicegroup, $parser->servicegroups);
				$tempServiceGroup = $servicegroup;
				print("<td height='20'>" .$counter.": Importing " . $tempServiceGroup['servicegroup_name'] . "...");
				$tempGroupMembers = NULL;
				if(isset($tempServiceGroup['members'])) {
					$tempGroupMembers = explode(",",$tempServiceGroup['members']);
					unset($tempServiceGroup['members']);
				}

				if($fruity->add_servicegroup($tempServiceGroup)) {
					print("<b><font color='#009900'>DONE</font></b></td>");

					/*$tempServiceGroupID = $fruity->return_servicegroup_id_by_name($tempServiceGroup['servicegroup_name']);
					$numOfElements = 0;
					// Build the new membership array
					$numOfElements = count($tempGroupMembers);
					$subcounter = 0;	// Subcounter is going to interate through our membership list, and we'll seperate into two arrays
					while($subcounter < $numOfElements) {
						$tempServiceGroupMemberHosts[] = trim($tempGroupMembers[$subcounter]);
						$tempServiceGroupMemberServices[] = trim($tempGroupMembers[($subcounter+1)]);
						$subcounter = $subcounter + 2;
					}
					// We've built our arrays, let's iterate again
					$numOfMemebers = 0;
					$numOfMembers = (int)($numOfElements / 2);	// let's cut the number of elements in half which is the number of members
					for($subcounter = 0; $subcounter < $numOfMembers; $subcounter++) {
						$tempHostID = $fruity->return_host_id_by_name($tempServiceGroupMemberHosts[$subcounter]);
						$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempServiceGroupMemberServices[$subcounter]);
						// Let's link
						if($fruity->add_service_servicegroup($tempServiceID, $tempServiceGroupID)) {
							print("<b>Success:</b> Linked ".$tempServiceGroupMemberHosts[$subcounter].": ".$tempServiceGroupMemberServices[$subcounter].".<br />");
						}
						else {
							print("<b><font= '#FF0000'>ERROR:</font></b> add_service_servicegroup failed.<br />");
						}
					}*/
				}
				else {
					print("<b><font= '#FF0000'>ERROR:</font></b> add_servicegroup failed.</td>");
				}
			}		
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");


	// Service Templates Import
	$numOfServices = count($parser->services);
	$tempServiceRenameCounter = 0;
	if($numOfServices) {
		?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
		<td colspan="3"><b>Number of Services to Filter For Template Import: <?=$numOfServices;?></b></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<?php
		$counter = 0;
		$bgcolor="#cccccc";
		foreach($parser->services as $service) {
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($service['name'])) {	// Egads, we're a template!
				$tempService = $service;
				if(isset($tempService['use'])) {
					trim($tempService['use']);	// Let's trim it first, no whitespace
					$tempTemplateID = NULL;
					$tempTemplateID = $fruity->return_service_template_id_by_name($tempService['use']);
					if($tempTemplateID) {	// We have the template
						$tempService['use_template_id'] = $tempTemplateID;
					}
					// FIX PROVIDED BY ANONYMOUS!
					//else we have unfinished business
					$ub[$tempService['name']]=$tempService['use'];
				}
				$tempService['template_name'] = $tempService['name'];
				print("<td height='20'>" .($counter+1) . ": Importing Service Template - " . $service['name'] . "...");
				
				if(isset($tempService['check_period']))
					$tempService['check_period']  = $fruity->return_period_id_by_name($tempService['check_period']);
				if(isset($tempService['notification_period']))
				$tempService['notification_period']  = $fruity->return_period_id_by_name($tempService['notification_period']);
				
				// We have to be very careful, because 2.0 of nagios no longer supports raw and user defined commands
				if(isset($tempService['check_command'])) {
					$tempCheckCommand = explode("!",$tempService['check_command']);
					// Check to see if this is a defined command
					$tempService['check_command'] = trim($tempCheckCommand[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempCheckCommand[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempService['check_command'] = $tempCommandID;
					else {
						// Ignore user check commands (no longer supported)
						unset($tempService['check_command']);
					}
				}
				// Event Handler Replacement
				if(isset($tempService['event_handler'])) {
					$tempEventHandler = explode("!",$tempService['event_handler']);
					// Check to see if this is a defined command
					$tempService['event_handler'] = trim($tempEventHandler[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempEventHandler[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempService['event_handler'] = $tempCommandID;
					else {
						unset($tempHost['event_handler']);
					}
				}
				
				unset($tempContactGroups);
				if(isset($tempService['contact_groups'])) {
					$tempContactGroups = explode(",",$tempService['contact_groups']);
				}
				unset($tempService['contact_groups']);
				unset($tempServiceGroups);
				if(isset($tempService['servicegroups'])) {
					$tempServiceGroups = explode(",",$tempService['servicegroups']);
				}
				unset($tempService['servicegroups']);
				
				if(preg_match("/[Ww]/",$tempService['notification_options']))
					$tempService['notification_options_warning'] = 1;
				if(preg_match("/[Uu]/",$tempService['notification_options']))
					$tempService['notification_options_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempService['notification_options']))
					$tempService['notification_options_critical'] = 1;
				if(preg_match("/[Rr]/",$tempService['notification_options']))
					$tempService['notification_options_recovery'] = 1;
				if(preg_match("/[Ff]/",$tempService['notification_options']))
					$tempService['notification_options_flapping'] = 1;
				unset($tempService['notification_options']);
				
				
				if(preg_match("/[Oo]/",$tempService['stalking_options']))
					$tempService['stalking_options_ok'] = 1;
				if(preg_match("/[Ww]/",$tempService['stalking_options']))
					$tempService['stalking_options_warning'] = 1;
				if(preg_match("/[Uu]/",$tempService['stalking_options']))
					$tempService['stalking_options_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempService['stalking_options']))
					$tempService['stalking_options_critical'] = 1;
				unset($tempService['stalking_options']);
				
				unset($tempService['use']);
				unset($tempService['register']);
				unset($tempService['name']);
				// SF BUG# 1243189
				// service_description error in import function
				// Resolution: unset($tempService['service_description'])
				//
				// We are now going to undo this, as clued by Marc DeTrano - mdetrano
				
				//unset($tempService['service_description']);
				if($fruity->add_service_template($tempService)) {
					print("<b><font color='#009900'>DONE</font></b><br />");
					$tempServiceTemplateID = $fruity->return_service_template_id_by_name($tempService['template_name']);
					if($tempServiceGroups) {
						foreach($tempServiceGroups as $servicegroup) {
							$servicegroup = trim($servicegroup);
							$tempGroupID = $fruity->return_servicegroup_id_by_name($servicegroup);
							print ("&nbsp;&nbsp;&nbsp;" .($counter+1).": Linking Servicegroup: ".$servicegroup ."...");
							if($fruity->add_service_template_servicegroup($tempServiceTemplateID, $tempGroupID))
								print("<b><font color='#009900'>DONE</font></b><br />");
							else
								print("<b><font= '#FF0000'>ERROR:</font></b> add_service_template_servicegroup failed.<br />");
						}
					}
					if($tempContactGroups) {
						foreach($tempContactGroups as $contactgroup) {
							//if($hostCounter <= 1) {	// Not sure what we're doing here
								$contactgroup = trim($contactgroup);
								$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
							//}
							print("&nbsp;&nbsp;&nbsp;" .($counter+1).": Linking Contact Group: ".$contactgroup ."...");
							if($fruity->add_service_template_contactgroup($tempServiceTemplateID, $tempGroupID))				
								print("<b><font color='#009900'>DONE</font></b><br />");
							else 
								print("<b><font= '#FF0000'>ERROR:</font></b> add_service_template_contactgroup failed.<br />");
						}
					}
					$numOfCheckCommand = count($tempCheckCommand);
					for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
						$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
						if($tempCheckCommand[$subcounter] != '') {
							$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
							$fruity->add_service_template_command_parameter($tempServiceTemplateID, $tempCommandArray);
						}
					}
				}
				else {
					print("<b><font= '#FF0000'>ERROR:</font></b> add_service_template failed.<br />");
					print mysql_error()."<br>\n";
				}
				?>
				</td>
				<?php
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
		if (isset($ub)) {
			print "<tr><td colspan=\"3\">\n";
		        print ("Handling Unfinished Business...");
		        foreach ($ub as $key => $value) {
		        	$updateID = $fruity->return_service_template_id_by_name($key);
		                $useID    = $fruity->return_service_template_id_by_name($value);
		                if ($fruity->get_service_template_info($updateID, $tempObj)) {
		                	$tempObj['use_template_id'] = $useID;
		                        $fruity->modify_service_template($tempObj);
		                }
		        }
		        print("<b>DONE</b><br />\n");
		        print("</td></tr>\n");
		        unset($ub);
		}
	}	
	print("</table>");
	print("<br />");

	// Services Import
	$numOfServices = count($parser->services);
	$tempServiceRenameCounter = 0;
	if($numOfServices) {
		?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
		<td colspan="3"><b>Number of Services to Import: <?=$numOfServices;?></b></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<?php
		$counter = 0;
		$bgcolor="#cccccc";
		foreach($parser->services as &$service) {
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			// Check for registered object
			if(isset($service['register']) && $service['register'] == 0) {
				print("<td height='20'>" .($counter+1).": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($service['registered']) || $service['registered'] == 1) {
				
				print("<td height='20'>" .($counter+1).": Attempting to Import ".$service['service_description']."...<br />");
				$tempService = $service;
				
				if(isset($tempService['use'])) {
					trim($tempService['use']);	// Let's trim it first, no whitespace
					$tempTemplateID = NULL;
					$tempTemplateID = $fruity->return_service_template_id_by_name($tempService['use']);
					if($tempTemplateID) {	// We have the template
						$tempService['use_template_id'] = $tempTemplateID;
					}
					// else we don't set it
				}
				
				if(isset($tempService['host_name'])) {
					$tempServiceHosts = explode(",",$tempService['host_name']);
					unset($tempService['host_name']);
				}
				if(isset($tempService['hostgroup_name'])) {
					$tempServiceHostGroups = explode(",",$tempService['hostgroup_name']);
					unset($tempService['hostgroup_name']);
				}
				//unset($tempService['servicegroups']); // we'll do this later, submitted patch by Ryan - rgoing
				if(isset($tempService['check_period'])) {
					$tempService['check_period']  = $fruity->return_period_id_by_name($tempService['check_period']);
				}
				if(isset($tempService['notification_period'])) {
					$tempService['notification_period']  = $fruity->return_period_id_by_name($tempService['notification_period']);
				}
				if(isset($tempService['check_command'])) {
					$tempCheckCommand = explode("!",$tempService['check_command']);
					// Check to see if this is a defined command
					$tempService['check_command'] = trim($tempCheckCommand[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempCheckCommand[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempService['check_command'] = $tempCommandID;
					else {
						// Ignore user check commands (no longer supported)
						unset($tempService['check_command']);
					}
				}
				// Event Handler Replacement
				if(isset($tempService['event_handler'])) {
					$tempEventHandler = explode("!",$tempService['event_handler']);
					// Check to see if this is a defined command
					$tempService['event_handler'] = trim($tempEventHandler[0]);
					$tempCommandID = $fruity->return_command_id_by_name($tempEventHandler[0]);
					if($tempCommandID > 0)	// Then this must be a pre-defined command
						$tempService['event_handler'] = $tempCommandID;
					else {
						unset($tempHost['event_handler']);
					}
				}
				unset($tempContactGroups);
				if(isset($tempService['contact_groups'])) {
					$tempContactGroups = explode(",",$tempService['contact_groups']);
				}
				unset($tempService['contact_groups']);
				
 				//Patch to import service groups placed in service definition
 				unset($tempServiceGroups);
 				if(isset($tempService['servicegroups'])) {
 					$tempServiceGroups = explode(",",$tempService['servicegroups']);
 				}
 				unset($tempService['servicegroups']);
 				//End service groups patch
				
				if(preg_match("/[Ww]/",$tempService['notification_options']))
					$tempService['notification_options_warning'] = 1;
				if(preg_match("/[Uu]/",$tempService['notification_options']))
					$tempService['notification_options_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempService['notification_options']))
					$tempService['notification_options_critical'] = 1;
				if(preg_match("/[Rr]/",$tempService['notification_options']))
					$tempService['notification_options_recovery'] = 1;
				if(preg_match("/[Ff]/",$tempService['notification_options']))
					$tempService['notification_options_flapping'] = 1;
				unset($tempService['notification_options']);
				
				
				if(preg_match("/[Oo]/",$tempService['stalking_options']))
					$tempService['stalking_options_ok'] = 1;
				if(preg_match("/[Ww]/",$tempService['stalking_options']))
					$tempService['stalking_options_warning'] = 1;
				if(preg_match("/[Uu]/",$tempService['stalking_options']))
					$tempService['stalking_options_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempService['stalking_options']))
					$tempService['stalking_options_critical'] = 1;
				unset($tempService['stalking_options']);
				
				unset($tempService['use']);
				unset($tempService['register']);
				unset($tempService['name']);
				if(isset($tempServiceHosts)) {
					foreach($tempServiceHosts as &$serviceHost) {
						if($serviceHost == '*') {
							// We want to attach to ALL hosts, so let's go through each host in fruity and all 
							// as a service
							$fruity->get_host_list($hostList);
							if(count($hostList)) {
								foreach($hostList as $host) {
									$tempHostID = $host['host_id'];
										print("&nbsp;&nbsp;&nbsp;" ."Host: " . $host['host_name'] . " - ");
										if(!$tempHostID) {
											print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> Unable to find host " . $host['host_name'] . " for this service.<br />");
										}
										else {
											$tempService['host_id'] = $tempHostID;
											if(!$fruity->add_service($tempService)) {
												print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> add_service failed.<br />");
											}
											else {
												print("<b><font color='#009900'>DONE</font></b><br />");
												$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempService['service_description']);
												if($tempContactGroups) {
													foreach($tempContactGroups as &$contactgroup) {
															$contactgroup = trim($contactgroup);
															$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
														print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .($counter+1).": Linking Contact Group: ".$contactgroup ."...");
														if($fruity->add_service_contactgroup($tempServiceID, $tempGroupID))				
															print("<b><font color='#009900'>DONE</font></b><br />");
														else 
															print("<b><font= '#FF0000'>ERROR:</font></b> add_service_contactgroup failed.<br />");
													}
												}
 												//Service groups patch, part deux
 												if(isset($tempServiceGroups)) {
 													foreach($tempServiceGroups as $servicegroup) {
 														$servicegroup = trim($servicegroup);
 														$tempGroupID = $fruity->return_servicegroup_id_by_name($servicegroup);
 														print(($counter+1).": Linking Service Group: ".$servicegroup." ...");
 														if($fruity->add_service_servicegroup($tempServiceID,$tempGroupID)) {
 															print("<b>DONE</b><br />");
 														} else {
 															print("<b>ERROR:</b> add_service_servicegroup failed<br />");
 														}
 													}
 												}
 												//End of service groups patch, part deux
												
												
												$numOfCheckCommand = count($tempCheckCommand);
												for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
													$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
													if($tempCheckCommand[$subcounter] != '') {
														$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
														$fruity->add_service_command_parameter($tempServiceID, $tempCommandArray);
													}
												}
											}
										}
								}							
							}
							break;
						}
						$tempHostID = $fruity->return_host_id_by_name($serviceHost);
						print("&nbsp;&nbsp;&nbsp;" . "Host: " . $serviceHost . " - ");
						if(!$tempHostID) {
							print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> Unable to find host " . $serviceHost . " for this service.<br />");
						}
						else {
							$tempService['host_id'] = $tempHostID;
							if(!$fruity->add_service($tempService)) {
								print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> add_service failed.<br />");
							}
							else {
								print("<b><font color='#009900'>DONE</font></b><br />");
								$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempService['service_description']);
								if($tempContactGroups) {
									foreach($tempContactGroups as &$contactgroup) {
											$contactgroup = trim($contactgroup);
											$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
										print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .($counter+1).": Linking Contact Group: ".$contactgroup ."...");
										if($fruity->add_service_contactgroup($tempServiceID, $tempGroupID))				
											print("<b><font color='#009900'>DONE</font></b><br />");
										else 
											print("<b><font= '#FF0000'>ERROR:</font></b> add_service_contactgroup failed.<br />");
									}
								}
								
 								//Service Groups patch, part deux
 								if(isset($tempServiceGroups)) {
 									foreach($tempServiceGroups as $servicegroup) {
 										$servicegroup = trim($servicegroup);
 										$tempGroupID = $fruity->return_servicegroup_id_by_name($servicegroup);
 										print(($counter+1).": Linking Service Group: ".$servicegroup." ...");
 										if($fruity->add_service_servicegroup($tempServiceID,$tempGroupID)) {
 											print("<b>DONE</b><br />");
 										} else {
 											print("<b>ERROR:</b> add_service_servicegroup failed<br />");
 										}
 									}
 								}
 								//End of service groups patch, part deux
								
								$numOfCheckCommand = count($tempCheckCommand);
								for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
									$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
									if($tempCheckCommand[$subcounter] != '') {
										$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
										$fruity->add_service_command_parameter($tempServiceID, $tempCommandArray);
									}
								}
							}
						}
					}
					unset($tempServiceHosts);
				}
				unset($tempService['host_id']);
				if(isset($tempServiceHostGroups)) {
					foreach($tempServiceHostGroups as &$serviceHostGroup) {
						print("&nbsp;&nbsp;&nbsp;" ."Hostgroup: " . $serviceHostGroup . " - ");
						$tempHostgroupID = $fruity->return_hostgroup_id_by_name($serviceHostGroup);
						if(!$tempHostgroupID) {
							print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> Unable to find hostgroup " . $serviceHostgroup . " for this service.<br />");
						}
						else {
							$tempService['hostgroup_id'] = $tempHostgroupID;
							if(!$fruity->add_service($tempService)) {
								print(($counter+1).": <b><font= '#FF0000'>ERROR:</font></b> add_service failed.<br />");
							}
							else {
								print("<b><font color='#009900'>DONE</font></b><br />");
								$numOfCheckCommand = count($tempCheckCommand);
								$tempServiceID = $fruity->return_service_id_by_hostgroup_and_description($tempHostgroupID, $tempService['service_description']);
								for($subcounter = 1; $subcounter < $numOfCheckCommand; $subcounter++) {
									$tempCheckCommand[$subcounter] = trim($tempCheckCommand[$subcounter]);
									if($tempCheckCommand[$subcounter] != '') {
										$tempCommandArray['parameter'] = $tempCheckCommand[$subcounter];
										$fruity->add_service_command_parameter($tempServiceID, $tempCommandArray);
									}
								}
								if($tempContactGroups) {
									foreach($tempContactGroups as &$contactgroup) {
											$contactgroup = trim($contactgroup);
											$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
										print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .($counter+1).": Linking Contact Group: ".$contactgroup ."...");
										if($fruity->add_service_contactgroup($tempServiceID, $tempGroupID))				
											print("<b><font color='#009900'>DONE</font></b><br />");
										else 
											print("<b><font= '#FF0000'>ERROR:</font></b> add_service_contactgroup failed.<br />");
									}
								}
							}
						}
					}
					unset($tempServiceHostGroups);
				}
			}
			?>
			</td>
			<?php
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Service Dependencies
	$numOfServiceDependencies = count($parser->servicedependencies);
		?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
		<td colspan="3"><b>Number of Service Dependency Entries To Process: <?=$numOfServiceDependencies;?></b></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfServiceDependencies) {
		foreach($parser->servicedependencies as $dependency) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($dependency['register']) && $dependency['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b></td>");
			}
			else if(!isset($dependency['registered']) || $dependency['registered'] == 1) {
				$parser->buildInheritedObject($dependency, $parser->servicedependencies);
				$tempDependency = $dependency;
				// Built object, let us begin.
				if(preg_match("/[Oo]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_ok'] = 1;
				if(preg_match("/[Ww]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_warning'] = 1;
				if(preg_match("/[Uu]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_critical'] = 1;
				if(preg_match("/[Pp]/",$tempDependency['execution_failure_criteria']))
					$tempDependency['execution_failure_criteria_pending'] = 1;
					
				if(preg_match("/[Oo]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_ok'] = 1;
				if(preg_match("/[Ww]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_warning'] = 1;
				if(preg_match("/[Uu]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_critical'] = 1;
				if(preg_match("/[Pp]/",$tempDependency['notification_failure_criteria']))
					$tempDependency['notification_failure_criteria_pending'] = 1;
				unset($tempDependency['execution_failure_criteria']);
				unset($tempDependency['notification_failure_criteria']);				
				
				$tempHostID = $fruity->return_host_id_by_name($tempDependency['dependent_host_name']);
				$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempDependency['dependent_service_description']);
				
				$targetHostID = $fruity->return_host_id_by_name($tempDependency['host_name']);
				$targetServiceID = $fruity->return_service_id_by_host_and_description($tempDependency['host_name'], $tempDependency['service_description']);
				if(!$fruity->add_service_dependency($tempServiceID, $targetHostID, $targetServiceID)) {
					print("<td height='20'>" ."<b><font= '#FF0000'>ERROR:</font></b> add_service_dependency failed.</td>");
				}
				else {
					$tempDependencyID = $fruity->return_service_dependency($tempServiceID, $targetHostID, $tempServiceID);
					unset($tempDependency['dependent_host_name']);
					unset($tempDependency['dependent_service_description']);
					unset($tempDependency['host_name']);
					unset($tempDependency['service_description']);
					if(!$fruity->modify_dependency($tempDependencyID, $tempDependency)) {
						print("<td height='20'>" ."<b><font= '#FF0000'>ERROR:</font></b> modify_dependency failed.</td>");
					}
					else {
						print("<td height='20'>" ."<b>SUCCESS</b></td>");
					}
				}
			}
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Service escalations
	$numOfServiceEscalations = count($parser->serviceescalations);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Service Escalation Entries To Process: " . $numOfServiceEscalations."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfServiceEscalations) {
		foreach($parser->serviceescalations as $escalation) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($escalation['register']) && $escalation['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b><br />");
			}
			else if(!isset($escalation['registered']) || $escalation['registered'] == 1) {
				$parser->buildInheritedObject($escalation, $parser->hostescalations);
				$tempEscalation = $escalation;
				// Built object, let us begin.
				if(preg_match("/[Ww]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_warning'] = 1;
				if(preg_match("/[Uu]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_unknown'] = 1;
				if(preg_match("/[Cc]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_critical'] = 1;
				if(preg_match("/[Rr]/",$tempEscalation['escalation_options']))
					$tempEscalation['escalation_options_ok'] = 1;
				unset($tempEscalation['escalation_options']);
					
				$tempEscalation['escalation_period'] = $fruity->return_period_id_by_name($tempEscalation['escalation_period']);
				unset($tempContactGroups);
				if(isset($tempEscalation['contact_groups'])) {
					$tempContactGroups = explode(",", $tempEscalation['contact_groups']);
					unset($tempEscalation['contact_groups']);
				}
				$tempEscalationDescription = $tempEscalation['service_description'] . " Escalation # " . $counter;
				$tempHostID = $fruity->return_host_id_by_name($tempEscalation['host_name']);
				$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempEscalation['service_description']);
				if(!$fruity->add_service_escalation($tempServiceID, $tempEscalationDescription)) {
					print("<td height='20'>" ."<b><font= '#FF0000'>ERROR:</font></b> add_service_escalation failed.<br />");
				}
				else {
					unset($tempEscalation['host_name']);
					unset($tempEscalation['service_description']);
					$tempEscalationID = $fruity->return_service_escalation($tempServiceID, $tempEscalationDescription);
					$tempEscalation['escalation_id'] = $tempEscalationID;
					if(!$fruity->modify_escalation($tempEscalation)) {
						print("<td height='20'>" ."<b><font= '#FF0000'>ERROR:</font></b> modify_escalation failed.<br />");
					}
					else {
						print("<b>SUCCESS</b><br />");
						if($tempContactGroups) {
							foreach($tempContactGroups as $contactgroup) {
								$contactgroup = trim($contactgroup);
								$tempGroupID = $fruity->return_contactgroup_id_by_name($contactgroup);
								print("<td height='20'>" .$counter.": Linking Contact Group: ".$contactgroup ."...");
								if($fruity->add_escalation_contactgroup($tempEscalationID, $tempGroupID))				
									print("<b><font color='#009900'>DONE</font></b></td>");
								else 
									print("<b><font= '#FF0000'>ERROR:</font></b> add_escalation_contactgroup failed.<br />");
							}
						}
					}
				}
			}
			print("<td>");
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

	// Go through the servicegroups to associate membership
	$numOfServiceGroups = count($parser->servicegroups);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Service Groups to Check for Members: " . $numOfServiceGroups."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";	
	if($numOfServiceGroups) {
		foreach($parser->servicegroups as $servicegroup) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($servicegroup['register']) && $servicegroup['register'] == 0) {
				print("<td height='20'>" .$counter.": <b>SKIPPED: Registered is set to 0.</b><br />");
			}
			else if(!isset($servicegroup['registered']) || $servicegroup['registered'] == 1) {
				$parser->buildInheritedObject($servicegroup, $parser->servicegroups);
				$tempServiceGroup = $servicegroup;
				print("<td height='20'>". $counter.": Verifying members of " . $tempServiceGroup['servicegroup_name'] . "...<br />");
				$tempGroupMembers = NULL;
				if(isset($tempServiceGroup['members'])) {
					$tempGroupMembers = explode(",",$tempServiceGroup['members']);
					$tempServiceGroupID = $fruity->return_servicegroup_id_by_name($tempServiceGroup['servicegroup_name']);
					$numOfElements = 0;
					// Build the new membership array
					$numOfElements = count($tempGroupMembers);
					$subcounter = 0;	// Subcounter is going to interate through our membership list, and we'll seperate into two arrays
					while($subcounter < $numOfElements) {
						$tempServiceGroupMemberHosts[] = trim($tempGroupMembers[$subcounter]);
						$tempServiceGroupMemberServices[] = trim($tempGroupMembers[($subcounter+1)]);
						$subcounter = $subcounter + 2;
					}
					// We've built our arrays, let's iterate again
					$numOfMemebers = 0;
					$numOfMembers = (int)($numOfElements / 2);	// let's cut the number of elements in half which is the number of members
					for($subcounter = 0; $subcounter < $numOfMembers; $subcounter++) {
						$tempHostID = $fruity->return_host_id_by_name($tempServiceGroupMemberHosts[$subcounter]);
						$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, $tempServiceGroupMemberServices[$subcounter]);
						// Let's link
						if($fruity->add_service_servicegroup($tempServiceID, $tempServiceGroupID)) {
							print("<b>Success:</b> Linked ".$tempServiceGroupMemberHosts[$subcounter].": ".$tempServiceGroupMemberServices[$subcounter].".<br />");
						}
						else {
							print("<b><font= '#FF0000'>ERROR:</font></b> add_service_servicegroup failed.<br />");
						}
					}
					unset($tempServiceGroup['members']);
				}
			}		
			print("<td>");
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");


// Host Extended Info
	$hostExtObjectTree = $parser->hostextinfo;
	$serviceExtObjectTree = $parser->serviceextinfo;
	$numOfHostExtInfo = count($hostExtObjectTree);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Host Extended Info Entries To Process: " . $numOfHostExtInfo."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";	
	if($numOfHostExtInfo) {
		foreach($hostExtObjectTree as $hostExtObject) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($hostExtObject['register']) && $hostExtObject['register'] == 0) {
				print("<td height='20'>".$counter.": <b>SKIPPED: Registered is set to 0.</b><br />");
			}
			else if(!isset($hostExtObject['registered']) || $hostExtObject['registered'] == 1) {
				$parser->buildInheritedObject($hostExtObject, $hostExtObjectTree);
				if(isset($hostExtObject['host_name'])) {
					$tempHostID = $fruity->return_host_id_by_name($hostExtObject['host_name']);
					print("<td height='20'>".$counter.": Importing ".$hostExtObject['host_name']."'s Extended Information...");
					unset($hostExtObject['host_name']);
					$hostExtObject['host_id'] = $tempHostID;
					if(isset($hostExtObject['2d_coords'])) {
						$hostExtObject['two_d_coords'] = $hostExtObject['2d_coords'];
						unset($hostExtObject['2d_coords']);
					}
					if(isset($hostExtObject['3d_coords'])) {
						$hostExtObject['three_d_coords'] = $hostExtObject['3d_coords'];
						unset($hostExtObject['3d_coords']);
					}
					$fruity->modify_host_extended($tempHostID, $hostExtObject);
					print("<b><font color='#009900'>DONE</font></b><br />");
				}
			}
			print("<td>");
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");

// Service Extended Info
	$numOfServiceExtInfo = count($serviceExtObjectTree);
	?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Number of Service Extended Info Entries To Process: " . $numOfServiceExtInfo."</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
	<?php
	$counter = 1;
	$bgcolor="#cccccc";
	if($numOfServiceExtInfo) {
		foreach($serviceExtObjectTree as $serviceExtObject) {
			// Check for registered object
			print('<tr bgcolor="' . $bgcolor . '">');
			print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
			if(isset($serviceExtObject['register']) && $serviceExtObject['register'] == 0) {
				print("<td height='20'>".$counter.": <b>SKIPPED: Registered is set to 0.</b><br />");
			}
			else if(!isset($serviceExtObject['registered']) || $serviceExtObject['registered'] == 1) {
				$parser->buildInheritedObject($serviceExtObject, $serviceExtObjectTree);
				unset($tempServiceHosts);
				if(isset($serviceExtObject['host_name'])) {
					$tempServiceHosts = explode(",",$serviceExtObject['host_name']);
					unset($tempService['host_name']);
				}
				if($tempServiceHosts) {
					foreach($tempServiceHosts as $host) {
						$tempHostID = $fruity->return_host_id_by_name(trim($host));
						$tempServiceID = $fruity->return_service_id_by_host_and_description($tempHostID, trim($serviceExtObject['service_description']));
						print("<td height='20'>".$counter.": Importing ".$serviceExtObject['service_description']. " on ".$host."'s Extended Information...");
						unset($serviceExtObject['host_name']);
						unset($serviceExtObject['service_description']);
						$serviceExtObject['service_id'] = $tempServiceID;
						$fruity->modify_service_extended($tempServiceID, $serviceExtObject);
						print("<b><font color='#009900'>DONE</font></b><br />");
					}
				}
			}
			print("<td>");
			$counter++;
			$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
			?>
				<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			</tr>
			<?php
		}	
	}	
	print("</table>");
	print("<br />");


// Resources

// SF BUG# 1441729
// resources are imported wrong
// Solution: Also use the part before the = to check the resourcenumber

	if($_SESSION['tempData']['import']['resource_file'] != '') {
		?>
		<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
		<tr>
			<td colspan="3"><? print("<b>Importing Resources Configuration...:</b>");?></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<?php
		if( !is_null($parser->resourceConfig) && count($parser->resourceConfig) > 0) {
			$counter = 1;
			$bgcolor="#cccccc";
			foreach($parser->resourceConfig as $userid => $tempResource) {
				preg_match('/^\$USER(\d+)\$/', $userid, $regs);
				if (is_numeric($regs[1]) && $regs[1] <= 32 ) {
					print('<tr bgcolor="' . $bgcolor . '">');
					print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
					$tempResourceTree['user'.$regs[1]] = trim($tempResource);
					print("<td height='20'>Importing: \$USER".$regs[1]."$ = ".trim($tempResource));
					print("<td>");
					$counter++;
					$bgcolor = ($bgcolor == "#cccccc") ? "#f0f0f0" : "#cccccc";
					?>
					<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
					</tr>
					<?php
				}
			}
			$fruity->update_resource_conf($tempResourceTree);
		}
		print('<tr bgcolor="' . $bgcolor . '">');
		print('<td width="1" bgcolor="#aaaaaa"><img src="' . $path_config["image_root"] . 'dotclear.gif" height="1" width="1" /></td>');
		print("<td height='20'><b><font color='#009900'>DONE</font></b><br /></td>");
	}
	print("</table>");
	print("<br />");
	?>
	<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td colspan="3"><b>Main Configuration Import</b></td>
	</tr>
	<tr>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
	</tr>
	<tr bgcolor="#cccccc">
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		<td height="20">Importing Main Configuration...
		<?php
		
		// Very annoying spelling error correction
		if(isset($parser->mainConfig['use_agressive_host_checking'])) {
			$parser->mainConfig['use_aggressive_host_checking'] = $parser->mainConfig['use_agressive_host_checking'];
			unset($parser->mainConfig['use_agressive_host_checking']);
		}
		
		unset($parser->mainConfig['log_passive_service_checks']);
		unset($parser->mainConfig['inter_check_delay_method']);
		if($fruity->new_main_conf($parser->mainConfig, dirname($_SESSION['tempData']['import']['config_file']))) {
			?>
			<b><font color='#009900'>DONE</font></b><br />
			<?php
		}
		else {
			?>
			<b><font= '#FF0000'>ERROR:</font></b> new_main_conf failed.<br />
			<?php
		}
		?>
		</td>
		<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
		</tr>
		<tr>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td colspan="1" height="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
			<td width="1" bgcolor="#aaaaaa"><img src="<?=$path_config['image_root'];?>dotclear.gif" height="1" width="1" /></td>
	</tr>
	</table>
	<br />
	<?php
	

	?>
	<b>IMPORT COMPLETE</b>
	<br />
	<?php

	print_window_footer();
}
?>
<br />
<br />
<?php
print_footer();
?>