<?php
// $Id: themeform.php,v 1.1 2004/07/11 10:27:20 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

if (!defined("EXOOPS_XOOPSTHEMEFORM_INCLUDED")) {
	define("EXOOPS_XOOPSTHEMEFORM_INCLUDED", 1);

include_once(XOOPS_ROOT_PATH."/class/xoopsform/form.php");

class XoopsThemeForm extends XoopsForm {

	function XoopsThemeForm($caption, $name, $action, $method="post") {
		$this->XoopsForm($caption, $name, $action, $method);
		$this->setExtra("onsubmit='return xoopsFormValidate_".$this->getName()."();'");
	}

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function render($value="") {

$required = $this->getRequired();
$ret = "
	<h4 style='text-align:left;'>".$this->getTitle()."</h4>
	<form name='".$this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."'".$this->getExtra().">
	<table border='0' cellpadding='0' cellspacing='0' valign='top' width='100%'><tr>
	<td class='bg2'><table width='100%' border='0' cellpadding='4' cellspacing='1'>";

foreach ( $this->getElements() as $ele ) {
	if ( !$ele->isHidden() ) {
		$ret .= "<tr valign='top'><td class='bg3'><b>".$ele->getCaption()."</b></td><td class='bg1'>".$ele->render()."</td></tr>";
		} else {
			$ret .= $ele->render();
		}
	}

$js = '
	<script type="text/javascript">
	<!--
	function xoopsFormValidate_'.$this->getName().'() {';
	foreach ($required as $req) {
		$js .= 'if ( xoopsGetElementById("'.$this->getName().'").'.$req.'.value == "" ) {
				alert("'.sprintf(_FORM_ENTER, $req).'");
				xoopsGetElementById("'.$this->getName().'").'.$req.'.focus();
				return false;
			}';
	}
	$js .= '}
	//--->
	</script>';

$ret .= "</table></td></tr></table></form>";
$ret = $js.$ret;

return $ret;
}

//---------------------------------------------------------------------------------------//
} // END CLASS
} // END DEFINED
?>
