<?php
/*
** Zabbix
** Copyright (C) 2001-2014 Zabbix SIA
**
** 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.
**/


require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/items.inc.php';

$page['title'] = _('Unsupported Items');
$page['file'] = 'reportUnsupportedItems.php';
$page['hist_arg'] = array();

require_once dirname(__FILE__).'/include/page_header.php';

$reportWidget = new CWidget();
$reportWidget->addPageHeader(_('Unsupported Items'));

$table = new CTableInfo();
$table->setHeader(array(
	_('Host'),
	_('Item'),
	_('Key'),
	_('Expires'),
	_('Last Seen'),
	_('Type'),
	_('Error'),
));

$items = API::Item()->get(array(
	'filter'=>array('state' => 1),
	'output'=>'extend',
	'selectItemDiscovery' => array('ts_delete')
	));
function cmp($a,$b){
	if($a['flags']!=$b['flags'])
		return $a<$b;
	if ($a['lastclock']!=$b['lastclock'])
		return($a['lastclock']<$b['lastclock']);
	if ($a['itemid']!=$b['itemid'])
		return($a['itemid']<$b['itemid']);
	return 0;
}
$items = CMacrosResolverHelper::resolveItemNames($items);
$items = CMacrosResolverHelper::resolveItemKeys($items);
uasort($items,'cmp');

foreach($items as $item){
	$host = API::Host()->get(array(
		'filter'=>array('hostid' => $item['hostid']),
		'output'=>'extend'
		));
	$host=$host[0];
	$table->addRow(array(
		new CLink($host['host'],'hosts.php?form=update&hostid='.$item['hostid']),
		($item['flags']==4)?$item['name_expanded']: new CLink($item['name_expanded'],'items.php?form=update&itemid='.$item['itemid']),
		$item['key_expanded'],
		($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED?zbx_date2str(_('Y-m-d H:i:s'), $item['itemDiscovery']['ts_delete']):zbx_date2str(_('Y-m-d H:i:s'),"")),
		zbx_date2str(_('Y-m-d H:i:s'), $item['lastclock']),
		item_type2str($item['type']),
		$item['error']
	));
}

$reportWidget->addItem($table);
$reportWidget->show();

require_once dirname(__FILE__).'/include/page_footer.php';
