<?php
/**
 * SugarWidgetSubPanelTopSelectButton
 *
 * The contents of this file are subject to the SugarCRM Public License Version
 * 1.1.3 ("License"); You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * All copies of the Covered Code must include on each user interface screen:
 *    (i) the "Powered by SugarCRM" logo and
 *    (ii) the SugarCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for
 * requirements.
 *
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2005 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 */

// $Id: SugarWidgetSubPanelTopSelectButton.php,v 1.15 2005/09/20 22:40:24 majed Exp $

require_once('include/generic/SugarWidgets/SugarWidgetSubPanelTopButton.php');

class SugarWidgetSubPanelTopSelectButton extends SugarWidgetSubPanelTopButton
{
	function SugarWidgetSubPanelTopSelectButton()
	{
	}

	function display(&$widget_data)
	{
		global $app_strings;

		$focus = $widget_data['focus'];
		$subpanel_definition = $widget_data['subpanel_definition'];
		$button_definition = $subpanel_definition->get_buttons();
		$subpanel_name = $subpanel_definition->get_module_name();
		$link_field_name = $subpanel_definition->get_data_source_name();

		$return_module = $_REQUEST['module'];
		$return_action = 'SubPanelViewer';
		$return_id = $_REQUEST['record'];
		
		$return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1";

		$popup_request_data = array(
			'call_back_function' => 'set_return_and_save_background',
			'form_name' => 'DetailView',
			'field_to_name_array' => array(
				'id' => 'subpanel_id',
			),
			'passthru_data' => array(
				'child_field' => $subpanel_name,
				'return_url' => urlencode($return_url),
				'link_field_name' => $link_field_name,
				'module_name' => $subpanel_name,
			),
		);
		
		$json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data);
		$title = $app_strings['LBL_SELECT_BUTTON_TITLE'];
		$accesskey = $app_strings['LBL_SELECT_BUTTON_KEY'];
		$value = $app_strings['LBL_SELECT_BUTTON_LABEL'];
		$module_name = $subpanel_name;
		$initial_filter = '';
		
		return '<form action="index.php">' . "\n"
			. ' <input type="button" name="select_button" id="select_button" class="button"' . "\"\n"
			. ' title="' . $title . '"'
			. ' accesskey="' . $accesskey . '"'
			. ' value="' . $value . "\"\n"
			. " onclick='open_popup(\"$module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array);' /></form>\n";
	}
}
?>
