<?php
include('includes/application_top.php');
include(DIR_WS_CLASSES.'export_targets.php');
$export_targets = new export_targets();
switch($_GET['action']){
	case 'delete':
		if(xtc_not_null($_GET['id'])){
			$id = xtc_db_input($_GET['id']);
			$export_target = $export_targets->get_export_target($id);
			$export_targets->delete( $id );
			$YES_HISTORY->add('system',sprintf(HISTORY_EXPORT_TARGET_DELETED,$export_target->data->name));
			$messageStack->add_session(MESSAGE_SUCCESS_DELETE,'success');
		}else{
			$messageStack->add_session(MESSAGE_ERROR_DELETE,'error');
		}
		xtc_redirect(xtc_href_link(FILENAME_EXPORT_TARGETS));
		break;
	case 'edit_print':
		$smarty = new yesSmarty();
		$smarty->compile_dir = DIR_FS_CATALOG.'templates_c';
		if($_POST['mode']){
			$smarty->assign('pdf_edit_mode','view');

		}else{
			$smarty->assign('pdf_edit_mode','edit');
		}

		$vars = array(
			'awb_number'=>array('value'=>'ANC0874')
		);
		$smarty->assign('edit_vars',$vars);
		$html = $smarty->fetch(DIR_FS_ADMIN.'templates/AWB-Template.html');
		if($_POST['mode'] == 'view'){
			xtc_redirect(xtc_href_link('html2ps.php?URL=http://www.yes-system.de'));
		}else{
			echo $html;
		}
		exit;
		break;
}

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


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

$pager = new ADODB_Pager($conn,sprintf("SELECT export_targets_id,name,city,countries_id,date_added FROM %s",$export_targets->get_tablename() ));
$pager->index_field = $export_targets->get_index();

$pager->get_row_selector = 'cID';
$pager->gridHeader = array(TABLE_HEADING_ID,TABLE_HEADING_COMPANY,TABLE_HEADING_CITY,TABLE_HEADING_COUNTRY,TABLE_HEADING_ADDED);
$pager->gridHelper = array(
	'countries_id'=>'xtc_get_country_name'
);
$pager->sortOrders = array(
	'export_targets_id'=>TABLE_HEADING_ID,
	'name'=>TABLE_HEADING_COMPANY,
	'date_added'=>TABLE_HEADING_ADDED
);

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());

$smarty->assign('NEW_ENTRY_BUTTON',yes_draw_href_button(BUTTON_NEW_EXPORT_TARGET,xtc_href_link(FILENAME_EXPORT_TARGETS_EDIT),'export_targets_edit'));

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

include('includes/footer.php');
