<?php
/*
/**
* CHRONOFORMS version 1.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.
**/

/* ensure that this file is called from another file */
defined('_JEXEC') or die('Restricted access'); 
$document =& JFactory::getDocument();
$document->addStyleSheet('components/com_chronocontact/css/cc.css');
class HTML_ChronoContact {
  function showChronoContact( $rows, $pageNav, $option ) {
    // HTML starts here, combined with short PHP commands for table creation
    global $mainframe;
	 
    ?>
    <form action="index2.php" method="post" name="adminForm">
	<table class="adminlist"><tr><td width="130px" valign="top">
	<table cellpadding="0" cellspacing="0" border="0" width="130px">
		<tr>
			<td width="130px" valign="top">
				<strong>Plugins</strong>
			</td>
		</tr>
		<tr>
			<td width="130px" valign="top">
				<?php
				$directory = JPATH_SITE.'/components/com_chronocontact/plugins/';
				$results = array();
				$handler = opendir($directory);
				while ($file = readdir($handler)) {
					if ( $file != '.' && $file != '..' && substr($file, -4) == '.php' && substr($file, 0, 3) == 'cf_')
						$results[] = str_replace(".php","", $file);
				}
				closedir($handler);
				foreach($results as $result){
					require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$result.".php");
					${$result} = new $result();
					?>
					<a style="display:block; " href="javascript:if (document.adminForm.boxchecked.value == 0){ alert('Please make a selection from the list to <?php echo ${$result}->result_TITLE; ?>');}else{submitbutton('<?php echo 'plugin_'.$result; ?>')}">
					<?php echo ${$result}->result_TITLE; ?></a><br>
					<?php
				}
				?>			
			</td>
			
		</tr>
	</table>
	</td><td>
    <table class="adminheading">
    <tr>
	  <th>Chrono Forms - Forms Manager</th>
    </tr>
	</table>
    <table class="adminlist">
	<tr>
	  <th width="20" class='title'>#</th>
	  <th width="5%" class='title'>Form ID</th>
	  <th width="20" class='title'><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>

	  <th width="20%" align="left" class='title'>Name</th>
	  <th width="60%" align="left" class='title'>Link</th>
	  <th width="20%" align="right" class='title'>Data</th>
	</tr>
    <?php
	$k = 0;
    for ($i=0, $n=count($rows); $i < $n; $i++) {
	  $row = $rows[$i];

		$link	= 'index2.php?option=com_chronocontact&task=editA&hidemainmenu=1&id='. $row->id;
		

	  //$checked 	= mosCommonHTML::CheckedOutProcessing( $row, $i );


	  ?>
	  <tr class="<?php echo "row$k"; ?>">
		<td width="20" align="center"><?php echo $i+$pageNav->limitstart+1;?></td>
		<td width="20" align="center"><?php echo $row->id; ?></td>
		<td width="20"><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);" /></td>
		
		<td width="20%" align="left" ><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name; ?></a></td>
		<td width="60%" align="left" ><a target="_blank" href="<?php echo $mainframe->getSiteURL(); ?>index.php?option=com_chronocontact&amp;chronoformname=<?php echo $row->name; ?>">index.php?option=com_chronocontact&amp;chronoformname=<?php echo $row->name; ?></a></td>
		<?php
		$database =& JFactory::getDBO();
		$result = $database->getTableList();
		if (in_array($mainframe->getCfg('dbprefix')."chronoforms_".$row->id, $result)) {
		?>
			<td width="20%" align="left" ><a href="#show" onclick="return listItemTask('cb<?php echo $i;?>','show')"><?php echo 'Show saved Data'; ?></a></td>
		<?php }else{ ?>
			<td width="20%" align="left" ><a href="#createtable" onclick="return listItemTask('cb<?php echo $i;?>','createtable')"><?php echo 'Create Table'; ?></a></td>
		<?php
		}
		?>
	  </tr>
      <?php
			$k = 1 - $k;
		}
    ?>
		<tr><td colspan="6" style="white-space:nowrap; " height="20px"><?php echo $pageNav->getListFooter(); ?></td></tr>
	  </table>
	  </td></tr></table>
	  <input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="task" value="" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>
    <?php
	}

  // this method represents the edit mask
  function editChronoContact( $row, $option ) {
   
		//jimport('joomla.html.pane');
		//JFilterOutput::objectHTMLSafe();
		// JavaScript Code for checking forms starts here
		if(!$row->paramsall){
			$row->paramsall = "ccemail=
			bccemail=
			formmethod=post
			omittedfields=
			recip=Yes
			from_email=
			from_name=
			replyto_email=
			replyto_name=
			email_type=1
			debug=0
			mysql_type=1
			enmambots=No
			emailfield=
			subjectfield=
			ccfield=
			bccfield=
			fromemailfield=
			fromnamefield=
			uploads=No
			uploadfields=
			uploadmax=
			uploadmin=
			dvfields=
			dvrecord=Record #n
			imagever=No
			imtype=0
			validate=No
			validatetype=prototype
			val_required=
			val_validate_number=
			val_validate_digits=
			val_validate_alpha=
			val_validate_alphanum=
			val_validate_date=
			val_validate_email=
			val_validate_url=
			val_validate_date_au=
			val_validate_currency_dollar=
			val_validate_selection=
			val_validate_one_required=
			plugins=
			plugins_order=1
			onsubmitcode_order=2
			autogenerated_order=3
			mplugins_order=";
		}
		
		
		$registry = new JRegistry();
		$registry->loadINI( $row->paramsall );
		$paramsvalues = $registry->toObject( );
		if ( is_array($paramsvalues->uploadfields) ) {
		  $paramsvalues->uploadfields = implode('|', $paramsvalues->uploadfields);
		}
		
		
		/*JHTML::_('behavior.switcher');
		$contents = '';
		ob_start();
		require_once(JPATH_COMPONENT.DS.'tmpl'.DS.'navigation.php');
		$contents = ob_get_contents();
		ob_clean();*/

		//$document =& JFactory::getDocument();
		//$document->setBuffer($contents, 'module', 'submenu');
    ?>
	  <script language="javascript" type="text/javascript">
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == "cancel") {
				submitform( pressbutton );
				return;
			}
			// do field validation
			if ((form.name.value == '')||(form.name.value.search(/ /) > -1)) {
				alert( "Please enter the form name without any spaces" );
			}else if (form.emailresults.value == '2') {
				if ((form.extraemail.value == '')||(form.emailsubject.value == '')||(document.getElementById('paramsfrom_email').value == '')||(document.getElementById('paramsfrom_name').value == '')) {
					alert( "If you choosed to email results then you must add : Email Address, Email subject, From Name and From Email" );
				} else {
					submitform( pressbutton );
				}
			} else {
				submitform( pressbutton );
			}
		}
		function addmenuitem(){
			var form = document.adminForm;
			if (form.menutext.value == '') {
				alert( "Please enter a text for the menu link" );
			} else {
				submitform( 'addmenuitem' );
			}
		}
		function toggleList(e){
		element = document.getElementById(e).style;
		element.display == 'none' ? element.display = 'block' :
		element.display='none';
		}
		function change_order1_plus(e){
			element = document.getElementById(e);
			if(trim(element.value) == "" ) element.value = "0";
			element.value = parseInt(element.value) + 1;
		}
		function change_order1_minus(e){
			element = document.getElementById(e);
			if(trim(element.value) == "" ) element.value = "0";
			parseInt(element.value) == 0 ? element.value = 0 :			
			element.value = parseInt(element.value) - 1;
		}
		function enable_order(e1, e2){
			element1 = document.getElementById(e1);
			element2 = document.getElementById(e2);
			if(element2.checked == true)element1.disabled = false;
			if(element2.checked == false)element1.disabled = true;
		}
		function change_order2_plus(e){
			element = document.getElementById(e);
			if(trim(element.value) == "" ) element.value = "0";
			element.value = parseInt(element.value) + 1;
		}
		function change_order2_minus(e){
			element = document.getElementById(e);
			if(trim(element.value) == "" ) element.value = "0";
			parseInt(element.value) == 0 ? element.value = 0 :			
			element.value = parseInt(element.value) - 1;
		}
	  </script>

	  <?php echo JHTML::_('behavior.tooltip'); ?>
	<center><strong style="font-size:16px; "><?php echo $row->name; ?></strong></center><?php echo JHTML::_('tooltip', "This is a tooltip with some usefull info about the field" ); ?> ToolTip
	  <form action="index2.php" method="post" name="adminForm" id="adminForm" class="adminForm">
	  <div class="col width-120">
	  <?php
	  		jimport('joomla.html.pane');
		  	$pane   =& JPane::getInstance('tabs');
			echo $pane->startPane("content-pane2");
			echo $pane->startPanel( 'General', "general" );
	  ?>
	  <!--<div id="config-document">-->
	  <div id="page-general">
	<table border="0" cellpadding="3" cellspacing="0">
  <tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "This is the Form name, It must be Unique." ); ?></td>
		<td><strong>Form Name:</strong> <br><strong style="color:#FF0000 ">must be unique between forms</strong></td>
		<td></td>
		<td><input type="text" class="inputbox" size="50" maxlength="100" name="name" value="<?php echo $row->name; ?>" /></td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Email results after form submit ?" ); ?></td>
		<td><strong>Email the results ?</strong> </td>
		<td></td>
		<td><select name="emailresults" id="emailresults" >
          <option value="0"<?php if($row->emailresults == 0){echo 'selected';}; ?>>No</option>
		  <option value="2"<?php if($row->emailresults == 2){echo 'selected';}; ?>>Yes</option>
        </select></td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "To which email(s) form values will be sent, separate multiple emails with commas ," ); ?></td>
		<td><strong>Email Address(es):</strong> </td>
		<td><a href="javascript:toggleList('extraemail')">[+/-]</a></td>
		<td><input type="text" class="inputbox" size="50" maxlength="100" name="extraemail" id="extraemail" value="<?php echo $row->extraemail; ?>" /></td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "The email default subject" ); ?></td>
		<td><strong>Email Subject:</strong> </td>
		<td><a href="javascript:toggleList('emailsubject')">[+/-]</a></td>
		<td><input type="text" class="inputbox" size="50" maxlength="100" name="emailsubject" id="emailsubject" value="<?php echo $row->emailsubject; ?>" /></td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "The CC Email(s)" ); ?></td>
		<td><strong>CC Email:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[ccemail]" id="cc_email" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->ccemail; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "The BCC Email(s)" ); ?></td>
		<td><strong>BCC Email:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[bccemail]" id="bcc_email" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->bccemail; ?>">
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Put here any code you want to use inside the form tag, like a validation javascript function to be executed when the form is submitted, code example : onsubmit=return validateForm()" ); ?></td>
		<td><strong>Form tag attachment:</strong><br><strong style="color:#FF0000 ">something like onSubmit()</strong> </td>
		<td></td>
		<td><input type="text" class="inputbox" size="100" maxlength="500" name="attformtag" value="<?php echo htmlspecialchars($row->attformtag); ?>" /></td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Form method" ); ?></td>
		<td><strong>Form method:</strong> </td>
		<td></td>
		<td>
		<select name="params[formmethod]" id="params[formmethod]">
		<option<?php if($paramsvalues->formmethod == 'post'){ echo ' selected';} ?> value="post">Post</option>
		<option<?php if($paramsvalues->formmethod == 'get'){ echo ' selected';} ?> value="get">Get</option>
		</select>
		</td>
	</tr>
	
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Enter here the fields names you want to omit from being sent into email" ); ?></td>
		<td><strong>Omitted fields names:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[omittedfields]" id="params[omittedfields]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->omittedfields; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Record and send users IP?" ); ?></td>
		<td><strong>Record and send users IP?</strong> </td>
		<td></td>
		<td>
		<select name="params[recip]" id="params[recip]">
			<option<?php if($paramsvalues->recip == 'Yes'){ echo ' selected';} ?> value="Yes">Yes</option>
			<option<?php if($paramsvalues->recip == 'No'){ echo ' selected';} ?> value="No">No</option>
		</select>
		</td>
	</tr>

	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "The email which will appear as *from*, must put a valid email here" ); ?></td>
		<td><strong>From Email:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[from_email]" id="paramsfrom_email" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->from_email; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "the name which will appear as from, must put a valid name here, e.g: Admin" ); ?></td>
		<td><strong>From name:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[from_name]" id="paramsfrom_name" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->from_name; ?>">
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "ReplyTo email" ); ?></td>
		<td><strong>ReplyTo email:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[replyto_email]" id="params[replyto_email]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->replyto_email; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "ReplyTo name" ); ?></td>
		<td><strong>ReplyTo name:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[replyto_name]" id="params[replyto_name]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->replyto_name; ?>">
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Please choose wheather you want to receive the email as a list of items *titles* with answers or with the form completed(still beta)." ); ?></td>
		<td><strong>In which format to send the results email:</strong> </td>
		<td></td>
		<td>
			<select name="params[email_type]" id="params[email_type]">
				<!--<option<?php if($paramsvalues->email_type == '0'){ echo ' selected';} ?> value="0">Form completed(under development)</option>-->
				<option<?php if($paramsvalues->email_type == '1'){ echo ' selected';} ?> value="1">Fields Titles</option>
				<option<?php if($paramsvalues->email_type == '2'){ echo ' selected';} ?> value="2">My Template</option>
			</select>
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "if debug is ON then ChronoForms will show diagnostic output" ); ?></td>
		<td><strong>Debug:</strong> </td>
		<td></td>
		<td>
			<select name="params[debug]" id="params[debug]">
				<option<?php if($paramsvalues->debug == '0'){ echo ' selected';} ?> value="0">OFF</option>
				<option<?php if($paramsvalues->debug == '1'){ echo ' selected';} ?> value="1">ON</option>
			</select>
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "The most used is ENGINE (v4+) however you can consider changing this to TYPE of you get a mysql error when you try to create a table" ); ?></td>
		<td><strong>MYSQL Statement ? ENGINE or TYPE</strong> </td>
		<td></td>
		<td>
			<select name="params[mysql_type]" id="params[mysql_type]">
				<option<?php if($paramsvalues->mysql_type == '1'){ echo ' selected';} ?> value="1">ENGINE</option>
				<option<?php if($paramsvalues->mysql_type == '2'){ echo ' selected';} ?> value="2">TYPE</option>
			</select>
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Enable mambots to be applied to this form contents?" ); ?></td>
		<td><strong>Enable mambots?</strong> </td>
		<td></td>
		<td>
		<select name="params[enmambots]" id="params[enmambots]">
			<option<?php if($paramsvalues->enmambots == 'No'){ echo ' selected';} ?> value="No">No</option>
			<option<?php if($paramsvalues->enmambots == 'Yes'){ echo ' selected';} ?> value="Yes">Yes</option>
		</select>
		</td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Special fields", 'spfields' );
	?>
	<div id="page-spfields">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Email results to this field value, this field name may contain user(s) email(s)" ); ?></td>
		<td><strong>Email field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[emailfield]" id="params[emailfield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->emailfield; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Email results with a subject of this field value, this will override the subject assigned above" ); ?></td>
		<td><strong>Subject field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[subjectfield]" id="params[subjectfield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->subjectfield; ?>">
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "CC results to this field value, this field name may contain user(s) email(s)" ); ?></td>
		<td><strong>CC field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[ccfield]" id="params[ccfield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->ccfield; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "BCC results to this field value, this field name may contain user(s) email(s)" ); ?></td>
		<td><strong>BCC field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[bccfield]" id="params[bccfield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->bccfield; ?>">
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Email results with a from email with this field value" ); ?></td>
		<td><strong>From email field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[fromemailfield]" id="params[fromemailfield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->fromemailfield; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Email results with a from name with this field value" ); ?></td>
		<td><strong>From name field:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[fromnamefield]" id="params[fromnamefield]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->fromnamefield; ?>">
		</td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Form Code", 'codes' );
	?>
	<div id="page-codes">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Plz enter the form HTML code here, the code may contains proper PHP code with tags and do NOT use the *form* tags, it will be created automaticlly" ); ?></td>
		<td><strong>Form HTML:</strong><br><strong style="color:#FF0000 ">(may contain PHP code with tags)</strong> </td>
		<td><a href="javascript:toggleList('html')">[+/-]</a></td>
		<td><textarea name="html" id="html" style="display:none" cols="80" rows="30"><?php echo htmlspecialchars($row->html); ?></textarea></td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "you can use some Javascript code here, plz dont enter the script opening or close tags" ); ?></td>
		<td><strong>Form JavaScript:</strong><br><strong style="color:#FF0000 ">(without the script tags)</strong> </td>
		<td><a href="javascript:toggleList('scriptcode')">[+/-]</a></td>
		<td><textarea name="scriptcode" id="scriptcode" style="display:none" cols="80" rows="10"><?php echo htmlspecialchars($row->scriptcode); ?></textarea></td>
	</tr>

	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "well formatted PHP code to be executed just when form is submitted but BEFORE Mail is sent" ); ?></td>
		<td><strong>On Submit code - before sending email:</strong><br><strong style="color:#FF0000 ">(PHP code with tags)</strong> </td>
		<td><a href="javascript:toggleList('onsubmitcodeb4')">[+/-]</a></td>
		<td><textarea name="onsubmitcodeb4" id="onsubmitcodeb4" style="display:none" cols="80" rows="10"><?php echo htmlspecialchars($row->onsubmitcodeb4); ?></textarea></td>
	</tr>

	<tr>
		<td><?php echo JHTML::_('tooltip', "well formatted PHP code to be executed just when form is submitted but AFTER Mail is sent" ); ?></td>
		<td><strong>On Submit code - after sending email:</strong><br><strong style="color:#FF0000 ">(PHP code with tags)</strong> </td>
		<td><a href="javascript:toggleList('onsubmitcode')">[+/-]</a></td>
		<td><textarea name="onsubmitcode" id="onsubmitcode" style="display:none" cols="80" rows="10"><?php echo htmlspecialchars($row->onsubmitcode); ?></textarea></td>
	</tr>

	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "This is the submission results email template, you can create a template of HTML for what you want to receive, plz use {field_name} to be replaced with this field submitted result" ); ?></td>
		<td><strong>Email template:</strong> </td>
		<td><a href="javascript:toggleList('emailtemplate')">[+/-]</a></td>
		<td><textarea name="emailtemplate" id="emailtemplate" style="display:none" cols="80" rows="10"><?php echo htmlspecialchars($row->emailtemplate); ?></textarea></td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Form URLs", 'urls' );
	?>
	<div id="page-urls">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "This is the URL where the form will go after its submitted" ); ?></td>
		<td><strong>Redirect URL:</strong> </td>
		<td></td>
		<td><input type="text" class="inputbox" size="50" maxlength="100" name="redirecturl" value="<?php echo htmlspecialchars($row->redirecturl); ?>" /><strong>  by default(if empty) will load an empty body area</strong></td>
	</tr>

	<tr>
		<td><?php echo JHTML::_('tooltip', "This is the *action* URL, you can use this to submit the form results to an external page like your payment gateway for example" ); ?></td>
		<td><strong>Submit URL:</strong><br><strong style="color:#FF0000 ">the "form" "action" URL</strong> </td>
		<td></td>
		<td><input type="text" class="inputbox" size="50" maxlength="100" name="submiturl" value="<?php echo htmlspecialchars($row->submiturl); ?>" /><strong> dont put anything here unless you know what you are doing</strong></td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Elements titles", 'titlesx' );
	?>
	<div id="page-titlesx">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Plz enter the form HTML elements titles here, these are the text which will replace the elements names in the emails sent or the stored data viewer pages, you must enter one lement name followed by = then the element title per line" ); ?></td>
		<td><strong>Elements titles:</strong><br><strong style="color:#FF0000 ">e.g:<br>fname=first name<br>
		lname=Last name<br>...<br>..</strong> </td>
		<td><a href="javascript:toggleList('titles')">[+/-]</a></td>
		<td><textarea name="titles" id="titles" cols="80" rows="20"><?php echo $row->titlesall; ?></textarea></td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "AutoGenerated code", 'autogen' );
	?>
	<div id="page-autogen">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "This code has been auto generated when you created a table for this form and is required for saving data" ); ?></td>
		<td><strong>Auto generated:</strong><br><strong style="color:#FF0000 ">Dont touch this unless you know what you are doing</strong> </td>
		<td><a href="javascript:toggleList('autogenerated')">[+/-]</a></td>
		<td><textarea name="autogenerated" id="autogenerated" cols="80" rows="20"><?php echo htmlspecialchars($row->autogenerated); ?></textarea></td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "File Uploads", 'uploads' );
	?>
	<div id="page-uploads">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Choose if you want to enable file uploads through your form" ); ?></td>
		<td><strong>Enable uploads:</strong><br><strong style="color:#FF0000 "></strong> </td>
		<td></td>
		<td>
		<select name="params[uploads]" id="params[uploads]">
			<option<?php if($paramsvalues->uploads == 'No'){ echo ' selected';} ?> value="No">No</option>
			<option<?php if($paramsvalues->uploads == 'Yes'){ echo ' selected';} ?> value="Yes">Yes</option>
		</select>
		</td>
	</tr>

	<tr>
		<td><?php echo JHTML::_('tooltip', "Which fields are of type FILE ? Use this syntax to control allowable extensions : field_name_1:jpg|gif|doc|zip, field_name_2:rar|avi , * = all are ok, but a petit hacker may **** your machine this way =)" ); ?></td>
		<td><strong>Field names &amp; allowed Extensions for each:</strong><br><strong style="color:#FF0000 ">E.g: field_name_1:jpg|gif|doc|zip, field_name_2:rar|avi , * = all are ok</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[uploadfields]" id="params[uploadfields]" class="inputbox" size="100" maxlength="500" value="<?php echo $paramsvalues->uploadfields; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Max size for uploaded files" ); ?></td>
		<td><strong>Max allowable size:</strong><br><strong style="color:#FF0000 ">in KB</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[uploadmax]" id="params[uploadmax]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->uploadmax; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Min size for uploaded files" ); ?></td>
		<td><strong>Min allowable size:</strong><br><strong style="color:#FF0000 ">in KB</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[uploadmin]" id="params[uploadmin]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->uploadmin; ?>">
		</td>
	</tr>

	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "DataView fields", 'dvfields' );
	?>
	<div id="page-dvfields">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Put here a list of fields names you would like to appear at the datagrid for this form data page, more than 1 field can be used separarted with a comma ," ); ?></td>
		<td><strong>Extra dataview columns fields names:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[dvfields]" id="params[dvfields]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->dvfields; ?>">
		</td>
	</tr>
	<tr style="background-color:#fff ">
		<td><?php echo JHTML::_('tooltip', 'main record view field text' ); ?></td>
		<td><strong><?php echo 'main view record'; ?>:</strong> </td>
		<td></td>
		<td>
		<?php if(!trim($paramsvalues->dvrecord)){$paramsvalues->dvrecord = "Record #n";} ?>
		<input type="text" name="params[dvrecord]" id="params[dvrecord]" class="inputbox" size="50" maxlength="500" value="<?php echo $paramsvalues->dvrecord; ?>">
		</td>
	</tr>
	</table>
	</div>
	<?php
			echo $pane->endPanel();
            echo $pane->startPanel( "Anti Spam", 'antispam' );
            // :: HACK :: show GD capability
            if(function_exists('gd_info')){
          	  $gd_info = gd_info();
			  $imagever_ok = true;
			}else{
				$imagever_ok = false;
			}
            if($imagever_ok){
				if ( !$gd_info['GD Version'] ) {
					$imagever_ok = false;
					$gd_info['GD Version'] = "GD library not found.";
				} else {
					if ( $gd_info['FreeType Support'] ) {
						$gd_info['FreeType Support'] = 'Yes';
					} else {
						$gd_info['FreeType Support'] = 'No';
						$imagever_ok = false;
					}
					if ( $gd_info['PNG Support'] ) {
						$gd_info['PNG Support'] = 'Yes';
					} else {
						$gd_info['PNG Support'] = 'No';
						$imagever_ok = false;
					}
				}
			}
			?>
			<div id="page-antispam">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "If you want to use image verification select *Yes* here then add {imageverification} inside your form html where you want the image verification to appear."); ?></td>
<?php
        if ( 1 ) {
            echo "<td><strong>Use Image verification:</strong><br><strong style='color:#FF0000' ></strong></td>
                <td>&nbsp;</td>
                <td>";
				?>
                <select name="params[imagever]" id="params[imagever]">
					<option<?php if($paramsvalues->imagever == 'No'){ echo ' selected';} ?> value="No">No</option>
					<option<?php if($paramsvalues->imagever == 'Yes'){ echo ' selected';} ?> value="Yes">Yes</option>
				</select>
				</td>
	</tr>
	<tr>
	<td><?php echo JHTML::_('tooltip', "If your server wont support using true type fonts to draw the image then use without fonts or ask your host to install this feature"); ?></td>
	<td>What type of image to show ?</td><td>
				<select name="params[imtype]" id="params[imtype]">
					<option<?php if($paramsvalues->imtype == '0'){ echo ' selected';} ?> value="0">Without Fonts</option>
					<option<?php if($paramsvalues->imtype == '1'){ echo ' selected';} ?> value="1">With Fonts</option>
				</select>
				<?php
		} else {
		    echo "Image verification cannot be enabled becasue the GD Library has not been detected at your PHP installation.
		      <input type='hidden' name='params[imagever]' id='params[imagever]' value ='No' />";
		}
?>
		</td>
	</tr>
	<?php if ( 1 ) { ?>
	<tr>
	   <td>&nbsp;</td>
	   <td>GD Version</td>
	   <td><?php echo $gd_info['GD Version']; ?></td>
	</tr>
		<tr>
	   <td>&nbsp;</td>
	   <td>FreeType Support</td>
	   <td><?php echo $gd_info['FreeType Support']; ?></td>
	</tr>
	</tr>
		<tr>
	   <td>&nbsp;</td>
	   <td>PNG Support</td>
	   <td><?php echo $gd_info['PNG Support']; ?></td>

	</tr>
	<?php } ?>
<?php
	if ( 1 ) {
	global $mainframe; ?>
	   <tr>
	       <td>&nbsp;</td>
	       <td>Sample image: </td>
	       <td><img src='<?php echo $mainframe->getSiteURL(); ?>components/com_chronocontact/chrono_verification.php<?php if($paramsvalues->imtype == '1'){ echo '?imtype=1';}else{ echo '?imtype=0';} ?>'></td>
	       </tr>
		   <?php
	}
?>
	<!-- // end hack -->
	</table>
	</div>
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Validation", 'validation' );
	?>
	<div id="page-validation">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip', "Enable Validation ?" ); ?></td>
		<td><strong>Enable Validation ?</strong> </td>
		<td></td>
		<td>
		<select name="params[validate]" id="params[validate]">
			<option<?php if($paramsvalues->validate == 'No'){ echo ' selected';} ?> value="No">No</option>
			<option<?php if($paramsvalues->validate == 'Yes'){ echo ' selected';} ?> value="Yes">Yes</option>
		</select>
		</td>
	</tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_( 'tooltip',"Validation Library used" ); ?></td>
		<td><strong><?php echo "Validation Library"; ?></strong> </td>
		<td></td>
		<td>
		<select name="params[validatetype]" id="params[validatetype]">
			<option<?php if($paramsvalues->validatetype == 'prototype'){ echo ' selected';} ?> value="prototype">prototype</option>
			<option<?php if($paramsvalues->validatetype == 'mootools'){ echo ' selected';} ?> value="mootools">mootools</option>
		</select>
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>1 - required (not blank)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_required]" id="params[val_required]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_required; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>2- validate-number (a valid number)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_number]" id="params[val_validate_number]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_number; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>3- validate-digits (digits only)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_digits]" id="params[val_validate_digits]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_digits; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>4- validate-alpha (letters only)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_alpha]" id="params[val_validate_alpha]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_alpha; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>5- validate-alphanum (only letters and numbers)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_alphanum]" id="params[val_validate_alphanum]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_alphanum; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>6- validate-date (a valid date value)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_date]" id="params[val_validate_date]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_date; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>7- validate-email (a valid email address)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_email]" id="params[val_validate_email]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_email; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>8- validate-url (a valid URL)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_url]" id="params[val_validate_url]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_url; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>9- validate-date-au (a date formatted as; dd/mm/yyyy)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_date_au]" id="params[val_validate_date_au]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_date_au; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>10- validate-currency-dollar (a valid dollar value)</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_currency_dollar]" id="params[val_validate_currency_dollar]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_currency_dollar; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "(first option e.g. *Select one...* is not selected option) -- Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>11- validate-selection</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_selection]" id="params[val_validate_selection]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_selection; ?>">
		</td>
	</tr>
	<tr>
		<td><?php echo JHTML::_('tooltip', "(At least one textbox/radio element must be selected in a group - see below*) -- Put list of fields names separated with comma *,* if more than one" ); ?></td>
		<td><strong>12- validate-one-required</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[val_validate_one_required]" id="params[val_validate_one_required]" class="inputbox" size="50" maxlength="100" value="<?php echo $paramsvalues->val_validate_one_required; ?>">
		</td>
	</tr>
	<tr><td colspan="4"><strong>Special thanks to "bouton" for referring to this feature!!</strong></td></tr>
	</table>
	</div>
	
	<?php
			echo $pane->endPanel();
			echo $pane->startPanel( "Plugins", 'plugins' );
			?>
			<div id="page-plugins">
			<table border="0" cellpadding="3" cellspacing="0">
	<tr><td colspan="3"><font style="font-size:12px; color:#FF0000; font-weight:bold; ">Pay attention: Some plugins work onsubmit the form event<br> and will do some database changes, please assure that plugins<br> are very well configured or this may end up saving wrong<br> data to the database tables!</font></td></tr>
	
	<?php
			$directory = JPATH_SITE.'/components/com_chronocontact/plugins/';
			$results = array();
			$handler = opendir($directory);
			while ($file = readdir($handler)) {
				if ( $file != '.' && $file != '..' && substr($file, -4) == '.php' && substr($file, 0, 3) == 'cf_')
					$results[] = str_replace(".php","", $file);
			}
			closedir($handler);
			$order = 0;
			$mplugins_order = explode(",", $paramsvalues->mplugins_order);
			foreach($results as $result){
			require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$result.".php");
			${$result} = new $result();
	?>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip',  ${$result}->result_TOOLTIP ); ?></td>
		<td><strong><?php echo ${$result}->result_TITLE; ?>:</strong> </td>
		<td>
		<input type="checkbox" onClick="enable_order('mplugins_order_<?php echo ${$result}->result_TITLE; ?>','plugins_order_<?php echo ${$result}->result_TITLE; ?>')" id="plugins_order_<?php echo ${$result}->result_TITLE; ?>" name="plugins[]" <?php if(in_array($result,explode(",",$paramsvalues->plugins)))echo "checked"; ?> class="inputbox" size="50" value="<?php echo $result; ?>">
		</td>
		<td><input type="text" maxlength="2" <?php if(in_array($result,explode(",",$paramsvalues->plugins))){ ?><?php }else{ ?>disabled="true"<?php } ?> size="2" name="mplugins_order[]" id="mplugins_order_<?php echo ${$result}->result_TITLE; ?>" value="<?php if(in_array($result,explode(",",$paramsvalues->plugins))){echo $mplugins_order[$order];} ?>">
		<a href="javascript:change_order1_plus('mplugins_order_<?php echo ${$result}->result_TITLE; ?>')">[+]</a>&nbsp;
		<a href="javascript:change_order1_minus('mplugins_order_<?php echo ${$result}->result_TITLE; ?>')">[-]</a>
		</td>
	</tr>	
	
	<?php
				if(in_array($result,explode(",",$paramsvalues->plugins))){
					$order++;
				}
			}	
	?>
	</table>
	</div>
	<?php
	echo $pane->endPanel();
	echo $pane->startPanel( 'RunOrder', 'RunOrder' );
	if((!$paramsvalues->autogenerated_order)||(!$paramsvalues->onsubmitcode_order)||(!$paramsvalues->plugins_order)){
		$paramsvalues->autogenerated_order = 3;
		$paramsvalues->onsubmitcode_order = 2;
		$paramsvalues->plugins_order = 1;
	}
	?>
	<div id="page-runorder">
	<table border="0" cellpadding="3" cellspacing="0">
	<tr><td colspan="3"><font style="font-size:12px; color:#FF0000; font-weight:bold; ">Here you can change the order the different code blocks run, <br>valid values are 1 or 2 or 3 <br>using other values will result in the whole block doesn't executed!</font></td></tr>
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip',   "Order of Autogenerated block" ); ?></td>
		<td><strong><?php echo "Order of Autogenerated block"; ?>:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[autogenerated_order]" id="params_autogenerated_order" class="inputbox" size="1" maxlength="1" value="<?php echo $paramsvalues->autogenerated_order; ?>">
		<a href="javascript:change_order1_plus('params_autogenerated_order')">[+]</a>&nbsp;
		<a href="javascript:change_order1_minus('params_autogenerated_order')">[-]</a>
		</td>
	</tr>	
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip',  "Order of OnSubmit block" ); ?></td>
		<td><strong><?php echo "Order of OnSubmit block"; ?>:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[onsubmitcode_order]" id="params_onsubmitcode_order" class="inputbox" size="1" maxlength="1" value="<?php echo $paramsvalues->onsubmitcode_order; ?>">
		<a href="javascript:change_order1_plus('params_onsubmitcode_order')">[+]</a>&nbsp;
		<a href="javascript:change_order1_minus('params_onsubmitcode_order')">[-]</a>
		</td>
	</tr>	
	<tr style="background-color:#c9c9c9 ">
		<td><?php echo JHTML::_('tooltip',  "Order of Plugins block" ); ?></td>
		<td><strong><?php echo "Order of Plugins block"; ?>:</strong> </td>
		<td></td>
		<td>
		<input type="text" name="params[plugins_order]" id="params_plugins_order" class="inputbox" size="1" maxlength="1" value="<?php echo $paramsvalues->plugins_order; ?>">
		<a href="javascript:change_order1_plus('params_plugins_order')">[+]</a>&nbsp;
		<a href="javascript:change_order1_minus('params_plugins_order')">[-]</a>
		</td>
	</tr>	
	</table>
	</div>
	
<?php
	echo $pane->endPanel();
	$pane->endPane();
?></div>
<!--</div>--><div class="clr"></div>
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="task" value="" />
	</form>
  <?php
	}

	function maketableChronoContact( $row, $option, $html_message  ) {
   
		?>
		<?php echo JHTML::_('behavior.tooltip'); ?>

	  <form action="index2.php" method="post" name="adminForm">
	  <?php if($html_message == '</table>'){ echo "Not enough form fields to create table";}
	  else if($html_message == 'exists') { echo "A table has already been created for this form";}
	  else { ?>
		<?php echo $html_message; ?>
		<input type="submit" name="submit2" value="Create Table">
		<?php } ?>
	  <input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="formid" value="<?php echo $row->id; ?>" />
	  <input type="hidden" name="task" value="finalizetable" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>
	<?php
		}

	function settings( $option, $params, $id ) {
		global $mosConfig_live_site;
		?>
		<script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/js/overlib_mini.js"></script>
		<div id="overDiv" style="position:absolute; visibility:hidden; z-index:10000;"></div>
		<form action="index2.php" method="post" name="adminForm">
		<table style="width:75%;" class="adminheading">
		<tr>
			<th class="config">
			ChronoForms Global Settings
			</th>
		</tr>
		</table>

		<table style="width:75%;" class="adminform">
		<tr>
			<th>
			Parameters
			</th>
		</tr>
		<tr>
			<td>
			<?php
			echo $params->render();
			?>
			</td>
		</tr>
		</table>

		<input type="hidden" name="id" value="<?php echo $id; ?>" />
		<input type="hidden" name="option" value="<?php echo $option ?>" />
		<input type="hidden" name="task" value="" />
		</form>

		<?php

		}

function showdataChronoContact( $rows, $pageNav, $option, $formid ) {
    // HTML starts here, combined with short PHP commands for table creation
    global $mainframe;	
	$database =& JFactory::getDBO();
    echo JHTML::_('behavior.tooltip');
	$database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$formid."'" );
	$formdata = $database->loadObjectList();
	$registry = new JRegistry();
	$registry->loadINI( $formdata[0]->paramsall );
	$paramsvalues = $registry->toObject( );
	$dvfields = $paramsvalues->dvfields;
	$dvlist = array();
	if ( !empty($dvfields) ) {
	  $dvlist = explode(",", $dvfields);
	}
    ?>
    <form action="index2.php" method="post" name="adminForm">
    <table class="adminlist">
	<tr>
	  <th width="20px" class='title'>#</th>
	  <th width="20px" class='title'><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>

	  <th class='title' width="20%">Record id</th>
	  <th class='title' width="20%" align="center">date - time</th>
	  <?php foreach($dvlist as $dvitem){ ?>
	  	<th class='title' width="20%" align="center"><?php echo $dvitem; ?></th>
	  <?php } ?>
	</tr>
	<?php
	$htmlstring = $formdata[0]->html;
	    /**
	     * Find all the 'name's in the html-string and add to the $matches array
	     */
	    preg_match_all('/name=("|\').*?("|\')/i', $htmlstring, $matches);
	    /**
	     * clean the matches array
	     */
	    $names = array();
	    foreach ( $matches[0] as $name ) {
	        $name = preg_replace('/name=("|\')/i', '', $name);
	        $name = preg_replace('/("|\')/', '', $name);
	        $name = preg_replace('/name=("|\')/', '', $name);
	        if ( strpos($name, '[]') ) {
	            $name = str_replace('[]', '', $name);
	        }
	        $names[] = trim($name);
	    }
	    $names = array_unique($names);
		
	?>
    <?php
	$k = 0;
    for ($i=0, $n=count($rows); $i < $n; $i++) {
	  $row = $rows[$i];

	  /*$link	= 'index2.php?option=com_chronocontact&task=editA&hidemainmenu=1&id='. $row->id;
	  $img  = $row->published ? 'tick.png' : 'publish_x.png';
	  $task = $row->published ? 'unpublish' : 'publish';
      $alt = $row->published ? 'Published' : 'Unpublished';*/

	  //$checked 	= mosCommonHTML::CheckedOutProcessing( $row, $i );


	  ?>
	  <tr class="<?php echo "row$k"; ?>">
		<td  width="20px" align="center"><?php echo $i+$pageNav->limitstart+1;?></td>
		<td width="20px"><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->cf_id; ?>_<?php echo $formid; ?>" onclick="isChecked(this.checked);" /></td>

		<td width="20%"><a href="#viewdata" onclick="return listItemTask('cb<?php echo $i;?>','viewdata')">
		<?php 
		$dvrecord = $paramsvalues->dvrecord;
		foreach ( $names as $fname) {
			if ( is_a($fname, $row) ) {
				$dvrecord = preg_replace("/\\{".$fname."\\}/", $row->$fname, $dvrecord);
			}
		}
		echo str_replace("#n", $i, $dvrecord);
		?>		
		</a></td>

		<td width="20%" align="left"><?php echo $row->recordtime; ?></td>
		<?php foreach($dvlist as $dvitem){ ?>
	  		<td width="20%" align="left"><?php echo $row->$dvitem; ?></td>
		<?php } ?>
	  </tr>
      <?php
			$k = 1 - $k;
		}
    ?>
		<tr><td colspan="6" style="white-space:nowrap; " height="20px"><?php echo $pageNav->getListFooter(); ?></td></tr>
	  </table>
	  <input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="task" value="show" />
	  <input type="hidden" name="formid[]" value="<?php echo $formid; ?>" />
	  <input type="hidden" name="cidxx[]" value="<?php echo $formid; ?>" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>
    <?php
	}
  function viewdataChronoContact( $row, $option, $tablename, $formid ) {
   global $mainframe;
	$database =& JFactory::getDBO();
	$database->setQuery("SELECT titlesall FROM #__chrono_contact WHERE id='".$formid."'");
	$titles = $database->loadResult();
	$titles_lines = explode("\n", $titles);
		//mosMakeHtmlSafe( $row, ENT_QUOTES );
		$tables = array( $tablename );
 		$result = $database->getTableFields( $tables );
		$table_fields = array_keys($result[$tablename]);
		?>
		<form action="index2.php" method="post" name="adminForm">

<table cellpadding="0" cellspacing="0" border="0" width="100%" class="adminlist">
<tr><td width="50%"><strong>Field name</strong></td><td width="50%"><strong>Field Data</strong></td></tr>
<?php
$k = 0;
foreach($table_fields as $table_field){
$table_field_title = $table_field;
	if(count($titles_lines)){
		foreach($titles_lines as $titles_line){
			$thisline = explode("=", $titles_line);
			if(trim($thisline[0]) == $table_field){
				$table_field_title = $thisline[1];
			}
		}
	}
?>
<tr class="<?php echo "row$k"; ?>"><td width="50%">
<strong><?php echo $table_field_title ; ?>	:</strong>  </td><td width="50%"><?php echo $row->$table_field ; ?>
</td></tr>
<?php $k = 1 - $k; } ?>
</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="task" value="" />
	  <input type="hidden" name="formid" value="<?php echo $formid; ?>" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>
		<?php
		}
		
	function restoreChronoContact( $id, $option ){
	
	?>
	<form action="index2.php" method="post" name="adminForm" enctype="multipart/form-data">

<table cellpadding="0" cellspacing="0" border="0" width="100%" class="adminlist">
<tr><td>Choose your .cfbak form file: &nbsp;<input type="file" name="file"></td></tr>
<tr><td><input type="submit" value="submit file"></td></tr>
</table>
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="task" value="restore2" />
	  <input type="hidden" name="formid" value="<?php echo $id; ?>" />
	  <input type="hidden" name="boxchecked" value="0" />
	  <input type="hidden" name="hidemainmenu" value="0">
	  </form>
	<?php
	}
	function menu_creator( $option ){
	global $mainframe;
	$database =& JFactory::getDBO();
	//require_once(JPATH_BASE."/administrator/components/com_chronocontact/languages/english.chronocontact.php");
	?>
	<strong>This page is to help you add a menu link to the admin components menu to take you directly to the "show saved data" of some form you choose</strong><br><br>
	<form action="index2.php" method="post" name="adminForm" enctype="multipart/form-data">
		<table cellpadding="0" cellspacing="0" border="0" width="100%" class="adminlist">
			<tr>
				<td><?php echo "Form"; ?>:</td>
				<td>
				<select name="form_id">
				<?php
				$database->setQuery("SELECT * FROM #__chrono_contact");
				$forms = $database->loadObjectList();
				foreach($forms as $form){
				?>
				<option value="<?php echo $form->id; ?>"><?php echo $form->name; ?></option>
				<?PHP } ?>
				</select>
				</td>
			</tr>
			<tr>
				<td><?php echo "Parent"; ?>:</td>
				<td>
				<select name="parent">
				<option value="0"><?php echo 'Root'; ?></option>
				<?php
				$database->setQuery("SELECT * FROM #__components");
				$parents = $database->loadObjectList();
				foreach($parents as $parent){
				?>
				<option value="<?php echo $parent->id; ?>"><?php echo $parent->name; ?></option>
				<?PHP } ?>
				</select>
				</td>
			</tr>
			<tr>
				<td><?php echo "Link Text"; ?>:</td>
				<td>
				<input type="text" name="linktext" value="">
				</td>
			</tr>
			<tr>
				<td><?php echo "Order"; ?>:</td>
				<td>
				<input type="text" name="ordering" value="">
				</td>
			</tr>
			<tr>
				<td><?php echo "Icon"; ?>:</td>
				<td>
				<select name="icon">
				<?php
				$directory = JPATH_SITE.'/includes/js/ThemeOffice/';
				$results = array();
				$handler = opendir($directory);
				while ($file = readdir($handler)) {
					if ($file != '.' && $file != '..')
						$results[] = $file;
				}
				closedir($handler);
				foreach($results as $result){
				?>
				<option value="<?php echo $result; ?>"><?php echo $result; ?></option>
				<?PHP } ?>
				</select>
				</td>
			</tr>
		</table>
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="task" value="menu_creator" />
	<input type="hidden" name="c" value="menu_creator" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="hidemainmenu" value="1">
	</form>
	  <?php
	  }
}
?>
