<?php
// $Id: form_lib.php,v 1.2 2006/09/16 15:15:51 ohwada Exp $

// 2006-09-15 K.OHWADA
// this is new file

//=========================================================
// Happy Linux Framework Module
// 2006-09-10 K.OHWADA
//=========================================================

//=========================================================
// class happy_linux_form_lib
//=========================================================
class happy_linux_form_lib extends happy_linux_form
{
	var $_LIB_BOX_DIV_CLASS        = 'happy_linux_box_class';
	var $_LIB_BOX_SPAN_TITLE_CLASS = 'happy_linux_title_class';

	var $_LIB_BOX_DIV_STYLE = 'background-color: #dde1de; border: 1px solid #808080; margin: 5px; padding: 10px 10px 5px 10px; width: 90%; ';
	var $_LIB_BOX_SPAN_TITLE_STYLE = 'font-size: 120%; font-weight: bold; color: #000000; ';

//---------------------------------------------------------
// constructor
//---------------------------------------------------------
function happy_linux_form_lib()
{
	$this->happy_linux_form();
}

function &getInstance()
{
	static $instance;
	if (!isset($instance)) 
	{
		$instance = new happy_linux_form_lib();
	}

	return $instance;
}

//---------------------------------------------------------
// next box
// caller: rssc/admin/table_manage.php
//---------------------------------------------------------
function build_lib_box_limit_offset($title, $desc, $limit=0, $offset=0, $op_value='save', $submit_value='save', $action='')
{
	$val  = $this->build_lib_button_limit_offset( $limit, $offset, $op_value, $submit_value, $action='' );
	$text = $this->build_lib_box_style($title, $desc, $val );
	return $text;
}

function build_lib_button_limit_offset($limit=0, $offset=0, $op_value='save', $submit_value='save', $action='')
{
	$form_name   = '';
	$action      = '';
	$submit_name = 'submit';

	$arr = array(
		'op'     => $op_value,
		'limit'  => $limit,
		'offset' => $offset,
	);

	$text = $this->build_lib_button_hidden_array( $arr, $form_name, $action, $submit_name, $submit_value );
	return $text;
}

//---------------------------------------------------------
// box
// caller: rssc/admin/admin_config_class.php
//---------------------------------------------------------
function build_lib_box_button_style($title, $desc, $op_value='save', $submit_value='save', $action='' )
{
 	$val  = $this->build_lib_button( $op_value, $submit_value, $action );
 	$text = $this->build_lib_box_style( $title, $desc, $val );
 	return $text;
}

function build_lib_box_button_class($title, $desc, $op_value='save', $submit_value='save', $action='' )
{
 	$val  = $this->build_lib_button( $op_value, $submit_value, $action );
 	$text = $this->build_lib_box_class( $title, $desc, $val );
 	return $text;
}

function build_lib_box_style($title, $desc, $value, $style_div='', $style_span='' )
{
	if ( empty($style_div) )
	{
		$style_div = $this->_LIB_BOX_DIV_STYLE;
	}

	if ( empty($style_span) )
	{
		$style_span = $this->_LIB_BOX_SPAN_TITLE_STYLE;
	}

	$text  = '<div style="'. $style_div .'">'."\n";

	if ($title)
	{
		$text .= '<span style="'. $style_span .'">';
		$text .= $title;
		$text .= "</span><br /><br />\n";
	}

	if ($desc)
	{
		$text .= $desc."<br /><br />\n";
	}

	$text .= $value;
	$text .= "</div><br />\n";
	return $text;
}

function build_lib_box_class($title, $desc, $value, $class_div='', $class_span='' )
{
	if ( empty($class_div) )
	{
		$class_div = $this->_LIB_BOX_DIV_CLASS;
	}

	if ( empty($class_span) )
	{
		$class_span = $this->_LIB_BOX_SPAN_TITLE_CLASS;
	}

	$text  = '<div class="'. $class_div .'">'."\n";

	if ($title)
	{
		$text .= '<span class="'. $class_span .'">';
		$text .= $title;
		$text .= "</span><br /><br />\n";
	}

	if ($desc)
	{
		$text .= $desc."<br /><br />\n";
	}

	$text .= $value;
	$text .= "</div><br />\n";
	return $text;
}

//---------------------------------------------------------
// button
//---------------------------------------------------------
function build_lib_button( $op_value='save', $submit_value='save', $action='' )
{
	$form_name   = $this->build_form_name_rand();
	$op_name     = $this->_OP_NAME; 	// 'op'
	$submit_name = $this->_BUTTON_SUBMIT_NAME;	// 'submit'

	$arr = array(
		$op_name => $op_value,
	);

	$text = $this->build_lib_button_hidden_array( $arr, $form_name, $action, $submit_name, $submit_value );
	return $text;
}

function build_lib_button_hidden_array( $hidden_array, $form_name='', $action='', $submit_name='', $submit_value='', $cancel_name='', $cancel_value='', $location_name='', $location_value='', $location_url='' )
{
	if ( empty($form_name) )
	{
		$form_name = $this->build_form_name_rand();
	}

	if ( empty($action) )
	{
		$action = xoops_getenv('PHP_SELF');
	}

	$text  = $this->build_form_begin( $form_name, $action );
	$text .= $this->build_token();

	if( is_array($hidden_array) && count($hidden_array) )
	{
		foreach ($hidden_array as $k => $v)
		{
			$text .= $this->build_html_input_hidden($k, $v);
		}
	}

	if ( $submit_value )
	{
		$text .= '  '.$this->build_form_button_submit($submit_name, $submit_value);
	}

	if ( $cancel_value )
	{
		$text .= '  '.$this->build_form_button_cancel($cancel_name, $cancel_value);
	}

	if ($location_url)
	{
		$text .= '  '.$this->build_form_button_location($location_name, $location_value, $location_url);
	}

	$text .= $this->build_form_end();
	return $text;
}

//---------------------------------------------------------
// set parameter
//---------------------------------------------------------
function set_lib_box_div_class( $val )
{
	$this->_LIB_BOX_DIV_CLASS = $val;
}

function set_lib_box_span_title_class( $val )
{
	$this->_LIB_BOX_SPAN_TITLE_CLASS = $val;
}

function set_lib_box_div_style( $val )
{
	$this->_LIB_BOX_DIV_STYLE = $val;
}

function set_lib_box_span_title_style( $val )
{
	$this->_LIB_BOX_SPAN_TITLE_STYLE = $val;
}

// --- class end ---
}

?>