<?php

if ( !defined( 'SMARTY_DIR' ) ) {

	include_once( '../init.php' );
}
include ( 'sessioninc.php' );

define( 'PAGE_ID', 'send_letter' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}

//check for delete parameter in URL; if yes then do delete action
if($_GET['delete']) {

	$osDB->query( 'DELETE FROM ! WHERE id = ? ', array( ADMIN_EMAILS_TABLE, trim( $_GET['delete']) ) );

	header ( 'location: ?' );
	exit;
}
elseif ($_POST['frm'] == 'frmAddEmail' ){

	$osDB->query( 'INSERT INTO ! ( email ) values( ? )', array( ADMIN_EMAILS_TABLE, $_POST['txtemail'] ) );

	header ( 'location: ?' );
	exit;
}

$t->assign( 'emails',$osDB->getAll( 'SELECT * FROM ! ORDER BY ' . findSortBy(), array( ADMIN_EMAILS_TABLE ) ) );

$t->assign( 'sort_type', checkSortType( $_GET['type'] ) );

$t->display( 'admin/adminemail.tpl' );

exit;
?>