<?php

/* ensuring that this file is called up from another file */
defined( '_JEXEC' ) or die( 'Direct access to this file is prohibited.' );

class HTML_alfcontact
{

// Procedure for building the contact form
function showContactForm($option, $name, $email, $emailto_id, $subject, $extravalue, $message, $rows)
	{
	global $mainframe;

	$user = & JFactory::getUser();
	
	$params = &JComponentHelper::getParams('com_alfcontact');
	$title = $params->get('title', '');
	$header = $params->get('header', '');
	$footer = $params->get('footer', '');
	$captcha = $params->get('captcha', 1);
	$captchatype = $params->get('captchatype', 1);
	$captchatheme = $params->get('captchatheme', 'red');
	$captchalng = $params->get('captchalng', 'en');
	$publickey = $params->get('publickey', '');
	$privatekey = $params->get('privatekey', '');
	$copyme = $params->get('copyme', 1);
	?>
		
	<script language="javascript" type="text/javascript">
	<!--
	function update(id){ 
		var obj = document.getElementById(id);
						
		var tvalue = obj.value;
				
		var arr = tvalue.split(",");
		var ret  = arr[1];
		document.getElementById('subject').value = arr[2];
		document.getElementById('emailto_id').value = arr[0];
				
		if(!ret) {
		    document.getElementById('extrarow').style.display='none';
		} else
		{
            document.getElementById('extrarow').style.display='';
			document.getElementById('extraname').firstChild.nodeValue = ret + ':'; 
		}
	}
	
	var RecaptchaOptions = {theme : '<?php echo $captchatheme; ?>', lang : '<?php echo $captchalng; ?>'};

	//-->
	</script>
    
    <div class="componentheading alfc_heading"><?php echo $title; ?></div>
    <div><p><?php echo $header; ?></p></div>
    <form name="myform" id="myform" method="post" action="">
    <table width="80%" border="0" cellspacing="5" cellpadding="5" align="center">
		<tr>
		    <td class="alfc_label alfc_from" align="right" valign="top"><?php echo JText::_('FROM')?> </td>
			<td>
					<?php 
						if (!$user->name) 
						{ 
						  ?><input class="text_area" name="name" id="name" type="text" size="30" value="<?php echo $name ; ?>"/><?php
						}
						else
						{ 
                        	echo $user->name;
							?><input type="hidden" name="name" id="name" value= "<?php echo $user->name ; ?>" /><?php
						}?>
			</td>
		</tr>
		<tr>
		    <td class="alfc_label alfc_email" align="right" valign="top"><?php echo JText::_('EMAIL')?> </td>
		    <td>
				<?php 
				if (!$user->email) 
				{ 
				  ?><input class="text_area" name="email" id="email" type="text" size="30" value="<?php echo $email ; ?>"/><?php
				}
				else
				{ 
                   	echo $user->email;
					?><input type="hidden" name="email" id="email" value= "<?php echo $user->email ; ?>" /><?php
				}?>
			</td>
        </tr>
	    <tr>
		    <td colspan="2" align="right" valign="top"><hr /></td>
	    </tr>
		<tr>
			<td class="alfc_label alfc_to" align="right" valign="top"><?php echo JText::_('TO')?> </td>
			<td>
				<?php 
				if (count($rows) > 1) { 
					?>
					<select name="emailid" id="emailid" style="width: 215px" onchange="update('emailid');">
					<?php
                       // readout of the data sets in the array
                   	foreach ($rows as $row) 
						{ 
							if ($row->standard)
							{
								?><option value="<?php echo $row->id.','.$row->extra.','.$row->defsubject; ?>" selected="selected"><?php echo $row->name; ?></option><?php
							}
							else
							{
								?><option value="<?php echo $row->id.','.$row->extra.','.$row->defsubject; ?>" > <?php echo $row->name; ?></option><?php
							}	
						} ?>
					</select>
					<?php
				}
			    else
			    {
				  if (count($rows) == 0) {
						echo $mainframe->getCfg('fromname');
						?><input type="hidden" name="emailid" id="emailid" value="99,," /><?php
					} 
					else
                    {  
						echo $rows[0]->name;
						?><input type="hidden" id="emailid" name="emailid" value="<?php echo $rows[0]->id.','.$rows[0]->extra.','.$rows[0]->defsubject; ?>" /><?php
					} 
				}?>
            </td>  
		</tr>	
		<tr>
			<td class="alfc_label alfc_subject" align="right" valign="top"><?php echo JText::_('SUBJECT')?> </td>
			<td><input class="text_area" name="subject" id="subject" type="text" size="30" value="<?php echo $subject; ?>"/></td>
		</tr>
		<tr>
			<td class="alfc_label alfc_message" align="right" valign="top"><?php echo JText::_('MESSAGE')?> </td>
			<td><textarea class="text_area" name="message" id="message" cols="50" rows="10" ><?php echo $message; ?></textarea></td>
		</tr>
        <tr id="extrarow" style="display:none;" >
		    <td class="alfc_label alfc_extra" align="right" valign="top"><span id="extraname">empty:</span></td>
		   	<td><input class="text_area" name="extravalue" id="extravalue" type="text" size="30" value="<?php echo $extravalue; ?>"/></td>
		</tr>
                
		<?php     
        if ($copyme == 1) { ?>
        <tr>
			<td align="right"><input type="checkbox" name="copy" id="copy" /></td>
	  		<td class="alfc_label alfc_copytome"><?php echo JText::_('COPYTOME')?></td>
	    </tr>
		<?php }
				
		if (($captcha == 1) OR (($captcha == 2) AND (!$user->name))){ 
			if ($captchatype == 0) {
				require_once('recaptchalib.php');
				?>
                    <tr>
                       	<td></td>
                        <td><?php echo recaptcha_get_html($publickey); ?></td>
					</tr>
                    <?php					
			}
		 	else
			{
				?>
				<tr>
					<td></td>
					<td><img src="<?php echo JRoute::_('index.php?option=com_alfcontact&task=displaycaptcha'); ?>" alt="Captcha image" /></td>
				</tr>
                <tr>
                 	<td class="alfc_label alfc_captcha" align="right" valign="top"><?php echo JText::_('VERIFICATION')?> </td>
                   	<td><input type="text" name="word" id="word" /></td>
                </tr>
                <?php	
			}
		}?>
		
		<tr>
			<td align="center">&nbsp;</td>
		    <td class="alfc_button alfc_send"><input type="submit" value="<?php echo JText::_('SEND')?>" class="button" id="button" /></td>
		</tr>
		<tr>
            <td>
                <input type="hidden" name="task" id="task" value= "sendemail" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="hidden" name="option" id="option" value= "<?php echo $option; ?>" />
            </td>
        </tr>
        <tr>
            <td>
				<input type="hidden" name="emailto_id" id="emailto_id" value= "<?php echo $emailto_id; ?>" />
				<?php
					echo "<script language='javascript' type='text/javascript'>update('emailid');</script>";
				?>
            </td>
        </tr>
	</table>
	</form>
    <div><p><?php echo $footer; ?></p></div>            
	<?php
	}
}
?>
