<?php

/*
/**
* CHRONOFORMS version 2.0 stable
* Copyright (c) 2006 Chrono_Man, ChronoEngine.com. All rights reserved.
* Author: Chrono_Man (ChronoEngine.com)
* See readme.html.
* Visit http://www.ChronoEngine.com for regular update and information.
**/

/* ensuring that this file is called up from another file */
defined( '_VALID_MOS' ) or die( 'Direct access to this file is prohibited.' );
class HTML_ChronoContact {
// Procedure for building the table
 function showform( $rows , $imver ) {
 global $database, $mosConfig_absolute_path;
 $paramsvalues = mosParseParams( $rows[0]->paramsall );
 if(!empty($rows[0]->name)){
		?>
		<?php if(!empty($rows[0]->scriptcode)){ 
		echo "<script type='text/javascript'>\n";
        echo "//<![CDATA[\n";
		echo $rows[0]->scriptcode;
		echo "//]]>\n";
        echo "</script>\n";				
		}		
		?>
		<?php if(!empty($rows[0]->submiturl)){ 
		$actionurl = $rows[0]->submiturl;			
		} else {
		$actionurl = 'index.php?option=com_chronocontact&amp;task=send&amp;chronoformname='.$rows[0]->name;
		}		
		?>
		<?php if( trim($paramsvalues->validate) == 'Yes'){ ?>
			<?php if( trim($paramsvalues->validatetype) == 'prototype'){ ?>
				<script src="components/com_chronocontact/js/prototype.js" type="text/javascript"></script>
				<script src="components/com_chronocontact/js/effects.js" type="text/javascript"></script>
				<script src="components/com_chronocontact/js/validation.js" type="text/javascript"></script>
			<?php } ?>
			<?php if( trim($paramsvalues->validatetype) == 'mootools'){ ?>
				<script src="components/com_chronocontact/js/mootools-release-1.11.js" type="text/javascript"></script>
				<script src="components/com_chronocontact/js/mooValidation.js" type="text/javascript"></script>
			<?php } ?>
		<?php } ?>
		
<form name="<?php echo "ChronoContact_".$rows[0]->name; ?>" id="<?php echo "ChronoContact_".$rows[0]->name; ?>" method="<?php echo $paramsvalues->formmethod; ?>" action="<?php echo $actionurl; ?>" <?php echo $rows[0]->attformtag; ?>>
		
				<?php 
					if( trim($paramsvalues->enmambots) == 'Yes'){
						global $_MAMBOTS;
						$_MAMBOTS->loadBotGroup( 'content' );
						$rowmam->text = $rows[0]->html;
						$results_mambots = $_MAMBOTS->trigger( 'onPrepareContent', array( &$rowmam, &$params, $page ), true );
						$rows[0]->html = $rowmam->text;
					}
					$html_string = $rows[0]->html;
					/******************** ONLOAD plugins **********************/
					$ava_plugins = explode(",",$paramsvalues->plugins);
					foreach($ava_plugins as $ava_plugin){
						$query     = "SELECT * FROM #__chrono_contact_plugins WHERE form_id='".$rows[0]->id."' AND event='ONLOAD' AND name='".$ava_plugin."'";
						$database->setQuery( $query );
						$plugins = $database->loadObjectList();
						if(count($plugins)){
							require_once($mosConfig_absolute_path."/components/com_chronocontact/plugins/".$ava_plugin.".php");
							${$ava_plugin} = new $ava_plugin();
							$params = mosParseParams($plugins[0]->params);
							$html_string = ${$ava_plugin}->onload( 'com_chronocontact', $params, $html_string );
						}
					}					
					/**********************************************************/	
					$rows[0]->html = $html_string;
					$rows[0]->html = str_replace('{imageverification}',$imver,$rows[0]->html);
					eval( "?>".$rows[0]->html );
				?>
				
</form>
		<?php if( trim($paramsvalues->validate) == 'Yes'){ ?>
			<script type="text/javascript">
				function formCallback(result, form) {
					window.status = "valiation callback for form '" + form.id + "': result = " + result;
				}
				var valid = new Validation('<?php echo "ChronoContact_".$rows[0]->name; ?>', {immediate : true, onFormValidate : formCallback});
			</script>
		<?php } ?>
<!-- You are not allowed to remove or edit the following 3 lines anyway if you didnt buy a license --> 
<div class="chronoform">
<a href="http://www.chronoengine.com">Joomla Professional Work</a>
</div>
<!-- You are not allowed to remove or edit the above 3 lines anyway if you didnt buy a license -->
		<?php
		} else {
		echo "There is no form with this name, Please check the url and the form management";
		}
	}
}
?>
