<?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('_JEXEC') or die('Restricted access');
class HTML_ChronoContact {
// Procedure for building the table
 function showform( $rows , $imver ) {
 	global $mainframe;
	$database =& JFactory::getDBO();
	$registry = new JRegistry();
	$registry->loadINI( $rows[0]->paramsall );
	$paramsvalues = $registry->toObject( );
 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 $mainframe;
						$params        =& $GLOBALS['mainframe']->getParams('com_content');
						$dispatcher       =& JDispatcher::getInstance();
						$type = 'content';
						JPluginHelper::importPlugin($type);
						//JPluginHelper::importPlugin($group, null, false);
						$rowmam->text = $rows[0]->html;
						$results_mambots = $mainframe->triggerEvent( 'onPrepareContent', array (&$rowmam, & $params, 0 ));
						$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(JPATH_SITE."/components/com_chronocontact/plugins/".$ava_plugin.".php");
							${$ava_plugin} = new $ava_plugin();
							$registry2 = new JRegistry();
							$registry2->loadINI( $plugins[0]->params );
							$params = $registry2->toObject( );
							$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 } ?>
		<?php
		} else {
		echo "There is no form with this name, Please check the url and the form management";
		}
	}
}
?>
