<?php
require(DIR_WS_CLASSES.'address_books.php');
require(DIR_WS_CLASSES.'customers.php');

$id = xtc_db_input($_GET['id']);
$address_books = new address_books();
$address_book = $address_books->get_address_book($id);

switch($_GET['action']){
	case 'delete_confirm':
		$smarty->assign('BOX_TITLE', $address_book->getFullName() );
		$contents = array();
		$contents[] = array('align'=>'center','text' => DELETE_ENTRY );
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_DELETE,xtc_href_link(FILENAME_ADDRESS_BOOKS,xtc_get_all_get_params(array('action','customers_id')).'action=delete&customers_id='.$address_book->data->customers_id),$access='func_address_books_delete','width:100px;').'&nbsp;'.yes_draw_href_button(IMAGE_CANCEL,"javascript:ajax_box_action('".$id."','');",$access='address_books','width:100px;') );
		
		break;
	default:
		$smarty->assign('BOX_TITLE', $address_book->getFullName() );
		$contents = array();
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_EDIT,xtc_href_link(FILENAME_ADDRESS_BOOKS_EDIT,'id='.$id.'&customers_id='.$address_book->data->customers_id),$access='address_books_edit','width:180px;') );
		
		$customers = new customers;
		$entries = $customers->count_address_books($address_book->data->customers_id);
		$default = yes_get_customers_default_address_book_id($address_book->data->customers_id);
		
		if($entries > 1 and $default != $id){
			$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_SET_AS_DEFAULT,xtc_href_link(FILENAME_ADDRESS_BOOKS,'action=set_default&id='.$id.'&customers_id='.$address_book->data->customers_id),$access='customers_edit','width:180px;') );
		}
		
		$contents[] = array('align'=>'center','text' => yes_draw_href_button(IMAGE_DELETE,"javascript:ajax_box_action('".$id."','delete_confirm');",$access='func_address_books_delete','width:180px;') );
		$contents[] = array('align'=>'left','text' => '<br />'.TEXT_DATE_CREATED.': '.xtc_date_short($address_book->data->address_date_added) );
		if($address_book->data->address_last_modified > 0)
			$contents[] = array('align'=>'left','text' => TEXT_DATE_LAST_MODIFIED.': '.xtc_date_short($address_book->data->address_last_modified) );
		break;
}

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

