<?php

/**
* @version 2.6.4
* @package Joomla 1.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

	global $database,$mosConfig_live_site,$mosConfig_absolute_path,$mosConfig_mailfrom,$mosConfig_fromname,$Itemid,$my;

	global $mosConfig_fromname,$mosConfig_mailfrom;

	$database = &JFactory::getDBO();

	require_once("../components/com_dtregister/config.dtregister.php");
      
	$eventId = JRequest::getVar('event_id');
	
	$dt_event = new Event($eventId);

	$sql="Select fe.* From #__dtregister_field_event fe inner join #__dtregister_fields df on fe.field_id=df.id where fe.event_id=$eventId and (fe.showed in(2,3) or (fe.showed =-1 and df.showed in(2,3))) and (fe.group_behave in(1,3) or (fe.showed =-1 and df.group_behave in(1,3)))";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields = array (
            
			1 	=> array('title', JText::_('DT_TITLE'), 'm_s_title', 'm_r_title','DT_ENTER_TITLE'),
			2 	=> array('firstname', JText::_('DT_FIRSTNAME'), 'm_s_firstname', 'm_r_firstname','DT_ENTER_FNAME'),

			3 	=> array('lastname', JText::_( 'DT_LASTNAME'), 'm_s_lastname', 'm_r_lastname','DT_ENTER_LNAME'),

			4 	=> array('organization', JText::_( 'DT_ORGANIZATION'), 'm_s_organization', 'm_r_organization','DT_ENTER_ORGANIZATION'),

			5 	=> array('address', JText::_( 'DT_ADDRESS'), 'm_s_address', 'm_r_address','DT_ENTER_ADDRESS'),
			
			6 	=> array('address2', JText::_( 'DT_ADDRESS2'), 'm_s_address2', 'm_r_address2','DT_ENTER_ADDRESS2'),

			7 	=> array('city', JText::_( 'DT_CITY'), 'm_s_city', 'm_r_city','DT_ENTER_CITY'),

			8 	=> array('state', JText::_( 'DT_STATE'), 'm_s_state', 'm_r_state','DT_ENTER_STATE'),

			9 	=> array('zip', JText::_( 'DT_ZIPCODE'), 'm_s_zip', 'm_r_zip','DT_ENTER_ZIP'),

			10 	=> array('country', JText::_( 'DT_COUNTRY'), 'm_s_country', 'm_r_country','DT_ENTER_COUNTRY'),

			11	=> array('email', JText::_( 'DT_EMAIL'), 'm_s_email', 'm_r_email','DT_ENTER_EMAIL'),

			12 	=> array('cemail', JText::_( 'DT_CONFIRM_EMAIL'), 'm_s_email', 'm_r_email','DT_ENTER_EMAIL'),

			13	=> array('phone', JText::_( 'DT_PHONE'), 'm_s_phone', 'm_r_phone','DT_ENTER_PHONE')

		);

	$arrFieldIds=array();

	for($i=0,$n=count($rows);$i<$n;$i++){

		$arrFieldIds[]=$rows[$i]->field_id;

		$requires[$rows[$i]->field_id] = $rows[$i]->required;

	}

	// Get the actual custom fields from the previous queries ID

	// loop through the post storing values in the SESSION var

	$arrPostVals = array();

	foreach ($arrFields as $key=>$value){

	//	$arr = array($value[0]=>$_POST[$value[0]]);

		//array_push_associative($arrPostVals,$arr);

	}

?>
  <script src="<?php echo JURI::root(true) ?>/components/com_dtregister/assets/js/jquery.js" type="text/javascript"></script>
    <script src="<?php echo JURI::root(true) ?>/components/com_dtregister/assets/js/textareaCounter.js" type="text/javascript"></script>

    <form action="index2.php" method="post" name="adminForm" enctype="multipart/form-data">


<table cellspacing="2" cellpadding="2" border="0" align="center" width="100%">

    	<tbody>

		<tr><td colspan="2">( <span class="required">*</span> = required field )</td></tr>

		<?php

		// loop through the array of possible non-custom fields and show the input box for each

		foreach ($arrFields as $key=>$value){

			if ($$value[2]){
			
			    if($value[0]=="title"){
				   
				      $titles = explode("|",$titleoptions);
						$temp[] = JHTML::_('select.option', '', JText::_( 'DT_SELECT_ONE'));
		
					  foreach($titles as $title){
			
						$temp[] = JHTML::_('select.option', $title, $title);
			
					  }
					
					  $titles = $temp;
				     $field_html = JHTML::_('select.genericlist',$temp,$value[0], 'class="inputbox" size="1"', 'value', 'text');
				}else{
				     $field_html = '<input type="text" name="'.$value[0].'" value="" class="inputbox" />';
				}

				?><tr><td width="31%" class="contentdescription"><?php echo "$value[1]"; ?>:<?php

					if ($$value[3]==1){

					?><span class='required'>&nbsp;&nbsp;*&nbsp;&nbsp;</span><?php

				    }

				?></td><td width="69%" align="left" ><?php echo $field_html; ?></td></tr><?php

			}

		}

		// Here will be the custom fields output code

	  	//Get Custom Fields

echo $dt_event->field_html('G',array(),true,'adminForm');
	  
unset($value);
		
	  	//End custom fields

?>
<tr>
<td colspan="2">
 	<input type="hidden" value="save" name="type"/>

<input type="hidden" value="0" name="groupMemberId" />

<input type="hidden" value="<?php echo JRequest::getVar('gid',0); ?>" name="groupUserId" />

<input type="hidden" value="<?php echo JRequest::getVar('event_id',0);  ?>" name="event_id" />

<input type="hidden" name="option" value="com_dtregister"/>

  <input type="hidden" value="editgroupuser" name="task"/>
<input type="hidden" value="" name="type"/>
  <input type="hidden" value="0" name="Itemid"/>
</td>
</tr>
 </tbody></table>



	</form>

    <script language="JavaScript" type="text/javascript">
 
DTjQuery(function(){
  DTjQuery('.upload').live('click',function(){
	   
	   DTjQuery(this.form).attr('target','fileupload');
	   prevtask = DTjQuery(this.form.task).val();
	   prevtype = DTjQuery(this.form.type).val();
	   var filesizes = DTjQuery(this).attr('filesize');
	   var filetype = DTjQuery(this).attr('filetype');
	   var name = DTjQuery(this).attr('filename');
	  
	   DTjQuery(this.form.type).val(name+'|'+filesizes+'|'+filetype);
	   
	   DTjQuery(this.form.task).val('fileupload');
	   DTjQuery(this.form.option).val('com_dtregister');
	   DTjQuery(this.form.option).val('com_dtregister');
	   
	   DTjQuery(this.form).submit();
	   
	   DTjQuery(this.form.task).val(prevtask);
	   DTjQuery(this.form.type).val(prevtype);
	   DTjQuery(this.form).attr('target','');
	   return false;
	});
}) 
function submitbutton(pressbutton)

{

	<?php if($m_s_firstname && $m_r_firstname){ ?>

			if(document.adminForm.firstname.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_FNAME'); ?>");

				document.adminForm.firstname.focus();

				return false;

			}

	<?php }

		if($m_s_lastname && $m_r_lastname){	?>

			if(document.adminForm.lastname.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_LNAME'); ?>");

				document.adminForm.lastname.focus();

				return false;

			}

	<?php }

		if($m_s_organization && $m_r_organization){	?>

			if(document.adminForm.organization.value==""){

			alert ("<?php echo JText::_( 'DT_ENTER_ORGANIZATION'); ?>");

			document.adminForm.organization.focus();

			return false;

			}

	<?php }

		if($m_s_address && $m_r_address){ ?>

			if(document.adminForm.address.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_ADDRESS'); ?>");

				document.adminForm.address.focus();

				return false;

			}

	<?php }

		if($m_s_city && $m_r_city){ ?>

			if(document.adminForm.city.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_CITY'); ?>");

		    	document.adminForm.city.focus();

				return false;

			}

	<?php }

		if($m_s_state && $m_r_state)

		{

		?>

			if(document.adminForm.state.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_STATE'); ?>");

				document.adminForm.state.focus();

				return false;

			}

		<?php

		}

		if($m_s_zip && $m_r_zip)

		{

		?>

			if(document.adminForm.zip.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_ZIP'); ?>")

				document.adminForm.zip.focus();

				return false;

			}

		<?php

		}

		if($m_s_email  && $m_r_email)

		{

		?>

			if(document.adminForm.email.value==""){

				alert ("<?php echo JText::_( 'DT_ENTER_EMAIL'); ?>");

				document.adminForm.email.focus();

				return false;

			}

			if(document.adminForm.cemail.value==""){

		    alert ("<?php echo JText::_( 'DT_ENTER_EMAIL'); ?>");

		    document.adminForm.cemail.focus();

		   return false;

			}

			if(document.adminForm.email.value!=document.adminForm.cemail.value){

			alert("<?php echo JText::_( 'DT_EMAIL_MATCH'); ?>");

			document.adminForm.cemail.focus();

			return false;

			}

			if(document.adminForm.email.value!=""){

			var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

			var returnval=emailfilter.test(document.adminForm.email.value)

				if (returnval==false){

				alert("<?php echo JText::_( 'DT_INVALID_EMAIL'); ?>");

				document.adminForm.email.select();

				document.adminForm.email.focus();

				return false;

				}

			}

		<?php

		}

		if($m_s_phone && $m_r_phone){ ?>

			if(document.adminForm.phone.value==""){

				alert("<?php echo JText::_( 'DT_ENTER_PHONE'); ?>");

				document.adminForm.phone.focus();

				return false;

			}

		<?php

		}

 		// if required - loop through the custom fields to make sure they are filled in

		

	  ?>

		submitform(pressbutton);

	}	// END Function validateform()

</script>