Location: PHPKode > projects > Network Configuration Store > NCS-3.0.2/wwwroot/Devices/CS_Main.php
<?php

require_once('./CS_Includes.inc.php');

try {
	// Generate some statistics for the main page
	$total = $CS->getDb()->GetOneField('SELECT COUNT(*) AS "t" FROM `devices`', 't');
	$dis = $CS->getDb()->GetOneField('SELECT COUNT(*) AS "d" FROM `devices` WHERE `state_code` = '.CSD_STATE_DISABLED, 'd');
	$arch = $CS->getDb()->GetOneField('SELECT COUNT(*) AS "a" FROM `devices` WHERE `state_code` = '.CSD_STATE_ARCHIVED, 'a');

	$statsForm = new CSForm('CS_Main.php');

	$statsForm->SetTableWidth();
	$statsForm->SetFirstColumnWidth(150);
	$statsForm->SetSecondcolumnWidth(150);

	$statsForm->AddControl('Active',			new CSFormControl(CSF_TEXT, array('text' => ($total - $dis - $arch))));
	$statsForm->AddControl('Disabled',			new CSFormControl(CSF_TEXT, array('text' => $dis)));
	$statsForm->AddControl('Archived',			new CSFormControl(CSF_TEXT, array('text' => $arch)));
	$statsForm->AddControl('<strong>Total</strong>',	new CSFormControl(CSF_TEXT, array('text' => '<strong>'.$total.'</strong>')));

	//
	// Get a record of any error state codes
	//
	$errors = $CS->getDb()->GetRecords('SELECT `device_id`,`hostname`,`state_code`,`state_msg` FROM `devices` '.
		'WHERE `state_code` = '.CSD_STATE_FAIL.' OR `state_code` = '.CSD_STATE_SYSERR.' ORDER BY `hostname` ASC');

	//
	// Now build our search form. Note that for a text box after the Select control, we need to fully
	// populate the Select control with child Option nodes first. Otherwise, CSForm puts the Textbox
	// control within the Select control.
	//
	// The populated Select control is then added to the form as the first element of an array, the second
	// element being the Textbox control. CSForm will handle this and print a space between the two when rendering.
	//
	$searchForm = new CSForm('Search.php');

	$s = new CSFormControl(CSF_SELECT, array('name' => 'hostname_bool'));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_LIKE, 'text' => $CSS_LOGIC[CSS_BOOL_LIKE])));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_NOTLIKE, 'text' => $CSS_LOGIC[CSS_BOOL_NOTLIKE])));
	$searchForm->AddControl('<strong>Hostname</strong><br />Enter a string to match against device hostnames',
			array($s, new CSFormControl(CSF_TEXTBOX, array('name' => 'hostname', 'size' => '30'))));

	$s = new CSFormControl(CSF_SELECT, array('name' => 'ipaddress_bool'));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_LIKE, 'text' => $CSS_LOGIC[CSS_BOOL_LIKE])));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_NOTLIKE, 'text' => $CSS_LOGIC[CSS_BOOL_NOTLIKE])));
	$searchForm->AddControl('<strong>IP Address</strong><br />Enter a string to match against device IP addresses',
			array($s, new CSFormControl(CSF_TEXTBOX, array('name' => 'ipaddress', 'size' => '30'))));

	$s = new CSFormControl(CSF_SELECT, array('name' => 'sys_descr_bool'));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_LIKE, 'text' => $CSS_LOGIC[CSS_BOOL_LIKE])));
	$s->AddChild(new CSFormControl(CSF_OPTION, array('value' => CSS_BOOL_NOTLIKE, 'text' => $CSS_LOGIC[CSS_BOOL_NOTLIKE])));
	$searchForm->AddControl('<strong>System Description</strong><br />Enter a string to match against device SNMP descriptions',
			array($s, new CSFormControl(CSF_TEXTBOX, array('name' => 'sys_descr', 'size' => '30'))));

	$searchForm->AddButton(new CSFormControl(CSF_SUBMIT, array('value' => 'Search')));
	$searchForm->AddButton(new CSFormControl(CSF_RESET, array('value' => 'Reset')));
}
catch (Exception $e) {
	CS::Abort($e);
}

$i = 0; // Row counter, used below

CS::PrintHtmlHeader();

?>

<body id="Main">

	<h1>Welcome to <?php echo CS_TITLE; ?></h1>

	<p>The following devices have recently failed configuration checks.</p>

	<table width="100%">
		<tr class="Header"><td>Device</td><td>State</td><td>Message</td></tr>

		<?php foreach($errors as $rec): ?>
			<tr class="<?php echo (++$i % 2) ? 'Odd' : 'Even'; ?>">
				<td><a href="View.php?device_id=<?php echo $rec['device_id']; ?>"><?php echo $rec['hostname']; ?></a></td>
				<td><?php echo $CSD_STATES[$rec['state_code']]; ?></td>
				<td><?php echo (!is_null($rec['state_msg']) ? $rec['state_msg'] : 'None'); ?></td>
			</tr>
		<?php endforeach; ?>

		<?php if (count($errors) == 0): ?>
			<tr><td colspan="3">None</td></tr>
		<?php endif; ?>

	</table><br /><br />

	<h2>Device Statistics</h2>
	<?php $statsForm->InsertHtml(); ?>
	<br /><br />

	<h1>Search Inventory</h1>
	<p>Enter criteria to search the database on your desired field(s). Wildcards accepted.</p>
	<?php $searchForm->InsertHtml(); ?>

</body>
</html>
Return current item: Network Configuration Store