<?php
include('includes/application_top.php');
include(DIR_WS_CLASSES.'configurations.php');
include(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/admin/configuration.php');
function _get_configuration_key_name($value){
	if(@constant($value.'_TITLE') != ''){
		return constant($value.'_TITLE');
	}else{
		return $value;
	}
}

$configurations = new configurations();
function _get_configuration_value($id){
	global $configurations;
	$configuration = $configurations->get_configuration($id);
	if(xtc_not_null($configuration->data->use_function)){
		return xtc_call_function($configuration->data->use_function, $configuration->data->configuration_value);
	}
	return $configuration->data->configuration_value;
}

$groups = $configurations->get_configuration_groups();

$smarty = new yesSmarty();
$smarty->compile_dir = DIR_FS_CATALOG.'templates_c';


include(DIR_WS_CLASSES.'class.adodb-pager.php');

$configuration_group_id = ($_REQUEST['configuration_group_id']) ? (int)xtc_db_input($_REQUEST['configuration_group_id']) : 1;

$pager = new ADODB_Pager($conn,sprintf("SELECT configuration_id,configuration_key,configuration_id as _value,last_modified FROM %s WHERE configuration_group_id='%s'",$configurations->get_tablename(),$configuration_group_id ));
$pager->index_field = $configurations->get_index();

$pager->get_row_selector = 'cID';
$pager->gridHeader = array(TABLE_HEADING_ID,TABLE_HEADING_CONFIGURATION,TABLE_HEADING_VALUE,TABLE_HEADING_CHANGED);
$pager->gridHelper = array(
	'_value'=>'_get_configuration_value',
	'configuration_key'=>'_get_configuration_key_name'
);

$pager->sortOrders = array(
	'configuration_id'=>TABLE_HEADING_ID,
	'configuration_value'=>TABLE_HEADING_VALUE
);

include(DIR_WS_INCLUDES.'header.php');

$pager->Render($rows_per_page=MAX_DISPLAY_SEARCH_RESULTS_ADMIN);

$selected_item = $pager->selected_row;

$grid_smarty = $smarty;
$smarty->assign('pager_tab_file',$pager->pager_tab_file);
$smarty->assign('HEADER',$pager->getHeader());
$smarty->assign('SORTING',$pager->getSortingInput());

$grid_smarty->assign('grid',$pager->getGrid());
$grid = $grid_smarty->fetch(DIR_FS_ADMIN.'templates/pager_grid.tpl');

$smarty->assign('GRID',$grid);
$smarty->assign('FOOTER',$pager->getFooter());

$menu = xtc_draw_form('cfgGroupSelect',FILENAME_CONFIGURATIONS,xtc_get_all_get_params(array('configuration_group_id'))).xtc_draw_pull_down_menu('configuration_group_id',$groups,$configuration_group_id,'class="pagerinput" onchange="document.forms[\'cfgGroupSelect\'].submit();"').'</form>';
$smarty->assign('PAGE_MENU',$menu);


echo $smarty->fetch(DIR_FS_ADMIN.'templates/pager.tpl');

include('includes/footer.php');
