<?php
require(DIR_WS_CLASSES.'email_accounts.php');
$id = xtc_db_input($_GET['id']);
$email_accounts = new email_accounts();
$email_account = $email_accounts->get_email_account($id);

switch($_GET['action']){
	case 'delete_confirm':
		$smarty->assign('BOX_TITLE', $email_account->data->email_address );
		$contents = array();
		$contents[] = array('align'=>'center','text' => DELETE_ENTRY );
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_DELETE,xtc_href_link(FILENAME_EMAIL_ACCOUNTS,xtc_get_all_get_params(array('action')).'action=delete'),$access='func_email_accounts_delete','width:100px;').'&nbsp;'.yes_draw_href_button(IMAGE_CANCEL,"javascript:ajax_box_action('".$id."','');",$access='email_accounts','width:100px;') );
		break;
	case 'test_connection':
		include(DIR_WS_CLASSES.'class.mail.php');
		$messages = '';
		$pop = new POP3();
		$decoder = new Mail_Parser;
		$connected = false;
		$port = ($email_account->data->port != '') ? $email_account->data->port : 110; 
		if (!@$pop->connect($email_account->data->server, $port)){
			$messages = utf8_decode(implode('<br />',$pop->error));
			$status = TEXT_STATUS_NOT_OK;
		}else{
			if (!@$pop->login($email_account->data->username, $email_account->data->password)){
				$messages = utf8_decode(implode('<br />',$pop->error));
				$status = TEXT_STATUS_NOT_OK;
			}else{
				$connected = true;
			}
		}

			if($connected){
			$pop->close();
			$status = TEXT_STATUS_OK;
		}
			
		
		
		$smarty->assign('BOX_TITLE', $email_account->data->email_address );
		$contents = array();
		$contents[] = array('align'=>'center','text' => TEXT_STATUS_CONNECTION.': '.$status );
		if($messages != '')
			$contents[] = array('align'=>'center','text' => $messages );
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_BACK,"javascript:ajax_box_action('".$id."','');",$access='email_accounts','width:100px;') );
		break;
	default:
		$smarty->assign('BOX_TITLE', $email_account->data->email_address );
		$contents = array();
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_EDIT,xtc_href_link(FILENAME_EMAIL_ACCOUNTS_EDIT,'id='.$id),'email_accounts_edit','width:180px;') );
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_TEST_CONNECTION,"javascript:show_yes_alertbox('".TEXT_PLEASE_WAIT."',400,250);ajax_box_action('".$id."','test_connection');",'email_accounts','width:180px;') );
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_DELETE,"javascript:ajax_box_action('".$id."','delete_confirm');",'func_email_accounts_delete','width:180px;') );
		break;
}

$box = new box;
$smarty->assign('BOX_CONTENT', $box->infoBox($contents) );

