<?php
/**
 * export_target_import class
 *
 */
class export_target_import_ship
{
	var $data;
	
	/**
	 * initiated the export_target_import class
	 *
	 * @param object $export_target_import_object
	 */
	function export_target_import_ship( $export_target_import_ship_object ){
		$this->data = $export_target_import_ship_object;
		$this->data->exports_id = $this->get_exports_id();
	}

	/**
	 * return array with table data
	 *
	 * @return array
	 */
	function get_smarty_data_array(){
		$array = (array) $this->data;
		$array['imports_id'] = $this->get_imports_id();
		$import_number_link = xtc_href_link(FILENAME_IMPORTS,'id='.$array['imports_id'].'&action=overview');
		$array['import_number_link'] = yes_draw_href_text( $this->get_import_number($array['imports_id']),$import_number_link,'imports',$style='',$css_class='');
		$array['import_number_link_button'] = yes_draw_href_image('images/link_arrow.gif',YES_LINKTEXT,$import_number_link,'imports',$css_class='' );

		$array[	'generate_invoice_link'] = yes_draw_href_image('images/invoice.gif',BUTTON_GENERATE_INVOICE,xtc_href_link(FILENAME_INVOICES_EDIT,'action=add&iID='.$array['imports_id'] ),'invoices_edit','lbOn' );
//		$array[	'gassed'] = $this->get_import_gassed($array['imports_id']);

		if($this->get_import_ships_status($array['import_ships_id']) == 0){
			$array['add_new_export_link'] = yes_draw_href_image('images/export.gif',IMAGE_EXPORT,xtc_href_link(FILENAME_EXPORTS_EDIT,'iID='.$array['import_ships_id']),'exports_edit','' );
		}
		
		$array['delete_link'] = yes_draw_href_image_confirm(TEXT_REMOVE_ENTRY,'images/icons/delete.gif',IMAGE_DELETE,xtc_href_link(FILENAME_EXPORTS,'id='.$array['exports_id'].'&etID='.$array['export_targets_id'].'&action=overview&subaction=delete_import_ship&etiID='.$array['export_target_import_ships_id']),'func_export_target_import_ships_delete','' ); 
		return $array;
	}
	
	function get_import_number($id){
		$query = xtc_db_query(sprintf("SELECT import_number FROM %s WHERE imports_id='%s'",TABLE_IMPORTS,$id));
		$record = xtc_db_fetch_array($query);
		return $record['import_number'];
	}
	
	function get_exports_id(){
		$query = xtc_db_query(sprintf("SELECT exports_id FROM %s WHERE export_targets_id='%s'",TABLE_EXPORT_TARGETS,$this->data->export_targets_id));
		if($query){
			$record = xtc_db_fetch_array($query);
			return $record['exports_id'];
		}
	}
	
	function get_imports_id(){
		$query = xtc_db_query(sprintf("SELECT imports_id FROM %s WHERE import_ships_id='%s'",TABLE_IMPORT_SHIPS,$this->data->import_ships_id));
		if($query){
			$record = xtc_db_fetch_array($query);
			return $record['imports_id'];
		}
	}
	
	function get_import_ships_status($isID){
		$query = xtc_db_query(sprintf("SELECT status FROM %s WHERE import_ships_id='%s'",TABLE_IMPORT_SHIPS,$isID));
		if($query){
			$record = xtc_db_fetch_array($query);
			return $record['status'];
		}
	}

	function get_import_gassed($id){
		$query = xtc_db_query(sprintf("SELECT gassed FROM %s WHERE imports_id='%s'",TABLE_IMPORTS,$id));
		$record = xtc_db_fetch_array($query);
		return (int)$record['gassed'];
	}
	
}
