<?php
/**
 * import_ship class
 *
 */
class import_ship
{
	var $data;
	
	/**
	 * initiated the import_ship class
	 *
	 * @param object $import_ship_object
	 */
	function import_ship( $import_ship_object ){
		$this->data = $import_ship_object;
	}

	/**
	 * return array with table data
	 *
	 * @return array
	 */
	function get_smarty_data_array(){
		$array = (array) $this->data;
		$array['delivery_conditions_name'] = yes_get_delivery_conditions_import_name($array['delivery_conditions']);
		$orderer_link = xtc_href_link(FILENAME_COMPANIES,'id='.$array['orderer_id'].'&action=overview');
		$array['orderer_link'] = yes_draw_href_text( $array['orderer_name'],$orderer_link,'companies',$style='',$css_class='');
		$array['orderer_link_button'] = yes_draw_href_image('images/link_arrow.gif',YES_LINKTEXT,$orderer_link,'companies',$css_class='' );

		$array['status_name'] = yes_get_import_ship_status_name($array['status']);
		
		$ship_link = xtc_href_link(FILENAME_SHIPS,'id='.$array['orderer_ships_id'].'&action=overview');
		$array['ship_link_button'] = yes_draw_href_image('images/link_arrow.gif',YES_LINKTEXT,$ship_link,'ships',$css_class='' );
		$array['ship_link'] = yes_draw_href_text( yes_get_ships_name($array['orderer_ships_id']),$ship_link,'ships',$style='',$css_class='');
		
		if($array['status'] == 0){
			$array['edit_link'] = yes_draw_href_image('images/icons/icon_edit.gif',IMAGE_EDIT,xtc_href_link(FILENAME_IMPORT_SHIPS_EDIT,'id='.$array['import_ships_id']),'import_ships_edit','' ); 
			$array['delete_link'] = yes_draw_href_image_confirm(TEXT_REMOVE_ENTRY,'images/icons/delete.gif',IMAGE_EDIT,xtc_href_link(FILENAME_IMPORTS,'id='.$array['imports_id'].'&isID='.$array['import_ships_id'].'&subaction=delete_ship'),'func_import_ships_delete','' );
		}

		$array['add_collie_link'] = yes_draw_href_text( TEXT_ADD_ENTRY,xtc_href_link( FILENAME_IMPORT_SHIP_COLLIES_EDIT,'isID='.$array['import_ships_id'].'&iID='.$array['imports_id']),'import_ship_collies_edit',$style='',$css_class=''); 
		$array['add_collie_link_button'] = yes_draw_href_image('images/link_arrow.gif', YES_LINKTEXT,xtc_href_link(FILENAME_IMPORT_SHIP_COLLIES_EDIT,'isID='.$array['import_ships_id']),'import_ship_collies_edit',$css_class=''); 
		
		$array['add_cost_link'] = yes_draw_href_text( TEXT_ADD_ENTRY,xtc_href_link( FILENAME_IMPORT_SHIP_COSTS_EDIT,'iID='.$array['imports_id'].'&isID='.$array['import_ships_id']),'import_ship_costs_edit',$style='',$css_class=''); 
		$array['add_cost_link_button'] = yes_draw_href_image('images/link_arrow.gif', YES_LINKTEXT,xtc_href_link(FILENAME_IMPORT_SHIP_COSTS_EDIT,'iID='.$array['imports_id'].'&isID='.$array['import_ships_id']),'import_ship_costs_edit',$css_class=''); 
		
		if($array['status'] == 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','' );
		}
		if($array['status'] == 1){
			$array['exports_id'] = $this->get_exports_id();
			$array['export_link'] = yes_draw_href_image('images/link_arrow.gif', YES_LINKTEXT,xtc_href_link(FILENAME_EXPORTS,'id='.$array['exports_id'].'&action=overview'),'exports',$css_class='');  
		}
		
		return $array;
	}
	
	function get_exports_id(){
		if($this->data->status == 1){
			$query = xtc_db_query(sprintf("SELECT et.exports_id FROM %s et LEFT JOIN %s etis USING(export_targets_id) WHERE etis.import_ships_id='%s'",TABLE_EXPORT_TARGETS,TABLE_EXPORT_TARGET_IMPORT_SHIPS,$this->data->import_ships_id));
			$record = xtc_db_fetch_array($query);
			return $record['exports_id'];
		}
	}
}
