<?php

/**
* @version 2.8.12
* @package Joomla 2.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
*/

 
 ?>
 <span style="font-weight: bold"><a href="#" id="load_tab">[ <?php echo JText::_('DT_CLICK_TO_TOGGLE_CHILD')?> ]</a></span>

<!--div id="field_tab_content" style="padding:10px 0">
  <?php echo JText::_('DT_LOADING_FIELDS'); ?>
</div-->
<script>
if(navigator.appName.indexOf("Micro") >=0){

					display = 'block';

				}else{

					display = 'table-row';

				}

   DTjQuery("#load_tab").toggle(function(){
	   // DTjQuery("#field_tab_content").html("<?php echo JText::_('DT_LOADING_FIELDS');?>");
	   // DTjQuery("#field_tab_content").load("index.php?option=com_dtregister&controller=event&format=raw&task=loadfield&type=fieldtreeview&slabId=<?php // echo $this->row->slabId; ?>");
	    DTjQuery('.child').css({display:display});
	   
	   },function(){
		   
			//DTjQuery("#field_tab_content").html("<?php echo JText::_('DT_LOADING_FIELDS');?>");
			 //DTjQuery("#field_tab_content").load("index.php?option=com_dtregister&controller=event&format=raw&task=loadfield&type=fieldsimpleview&slabId=<?php // echo $this->row->slabId; ?>");
			
			 DTjQuery('.child').css({display:'none'});

		   })   
	// DTjQuery("#field_tab_content").load("index.php?option=com_dtregister&controller=event&format=raw&task=loadfield&type=fieldtreeview&slabId=<?php echo $this->row->slabId; ?>",function(){ 
	// DTjQuery(".child").css({display:'none'}); });
	 DTjQuery(function(){
	    DTjQuery(".child").css({display:'none'});
	 })
</script>
<?php
 $fieldObj = $this->getModel('field')->table;
 $rowFields = array();
 $fieldObj->findtree(0,$rowFields);
 $fields = $this->row->field;

?>

 <table class="adminlist" width="100%" cellpadding="10" cellspacing="10">

      <?php

      	if(count($rowFields)>0)

      	{

      	?>

      		<tr>

		      <th colspan="4"><?php echo JText::_( 'DT_FIELD_SELECTION_INSTRUCTIONS' ); ?></th>

		      </tr>

<tr>

          <th class="dt_heading"><?php echo JText::_( 'DT_CUSTOM_FIELD_NAME' ); ?></th>

		  <th class="dt_heading"><?php echo JText::_( 'DT_CUSTOM_FIELD_USED' ); ?></th>

          <th class="dt_heading"><?php echo JText::_( 'DT_REQUIRED' ); ?></th>

          <th class="dt_heading"><?php echo JText::_( 'DT_CUSTOM_FIELD_GROUPOPTIONS' ); ?></th>

</tr>

		      <?php
                $js = "";
		      	foreach($rowFields as $i => $rowField)

		      	{

		      		//$rowField=$rowFields[$i];
                     if($rowField->allevent) {
						 $showed = -1;
					 } else {
				     	 if($rowField->level >  1)
						 {
					         $showed = -1;
						 } else {
				     	   $showed  = 0;
						 }
					 }

					 $required = 0;

					 $group = 1;
				
                     if(isset($fields[$rowField->id])){

				        $showed = $fields[$rowField->id]->showed;

						$required = $fields[$rowField->id]->required;

						$group = $fields[$rowField->id]->group_behave;

				     }

		      		$name=$rowField->name;
					
					$child_class = ($rowField->parent_id > 0)?' child ':'';

		      	?>

		      		<tr class="rows <?php echo $child_class ; ?>" field_id='<?php echo $rowField->id; ?>' parent_id='<?php echo $rowField->parent_id; ?>'>

		      			<td class="field_name"><?php echo str_repeat("-->",--$rowField->level); ?><?php echo $rowField->name; ?></td>

		      			<td><?php	
						    $options=array();

						    $options[]=JHTML::_('select.option',"0",JText::_( 'DT_NONE' ));

						    $options[]=JHTML::_('select.option',"1",JText::_( 'DT_INDIVIDUAL' ));
							
							$options[]=JHTML::_('select.option',"2",JText::_( 'DT_GROUP' ));
                            $options[]=JHTML::_('select.option',"3",JText::_( 'DT_BOTH' ));
						    $options[]=JHTML::_('select.option',"-1",JText::_( 'DT_DEFAULT'));
						 echo JHTML::_('select.radiolist', $options, "data[field][".$rowField->id."][showed]",' class="fields" ','value','text',$showed);
						
						?></td>

                        <td><?php 
						$options = array();
						  if(!in_array($rowField->name,$fieldObj->compulsary_fields)) {
				              
				          } else {
						  	$required = 1;
						  }
						  $options[]=JHTML::_('select.option',"0",JText::_( 'DT_NO' ));
						  $options[]=JHTML::_('select.option',"1",JText::_( 'DT_YES' ));
						  echo JHTML::_('select.radiolist', $options,"data[field][".$rowField->id."][required]",'',"value","text",$required);
						  JHTMLSelect::booleanlist("data[field][".$rowField->id."][required]","",$required); ?>
                          </td>

                <td>

		      		  <?php

					 		$options=array();

						    $options[]=JHTML::_('select.option',"1",JText::_( 'DT_EACH_MEMBER' ));

						    $options[]=JHTML::_('select.option',"2",JText::_( 'DT_BILLING_ONLY' ));

						    $options[]=JHTML::_('select.option',"3",JText::_( 'DT_MEMBERS_BILLING'));

							  echo JHTML::_('select.radiolist', $options, 'data[field]['.$rowField->id.'][group_behave]','','value','text',$group);

							  ?>

		      			</td>

		      		</tr>

		      		<?php
				     if(in_array($rowField->name,$fieldObj->compulsary_fields)) { 
					 	ob_start();  	
				?>     
				          
							DTjQuery('#data\\[field\\]\\[<?php echo $rowField->id; ?>\\]\\[showed\\]0').attr('disabled','disabled');
							
						    DTjQuery('#data\\[field\\]\\[<?php echo $rowField->id; ?>\\]\\[required\\]0').attr('disabled','disabled');
							
							DTjQuery('#data\\[field\\]\\[<?php echo $rowField->id; ?>\\]\\[group_behave\\]1').attr('disabled','disabled');
						
                <?php		
				      $js .= " ". ob_get_clean();
					 }
				
					} ?>

      	<?php

      	}

	?>

     </table>
     <script type="text/javascript">
	  function disable_required_fields() {
	  		
			<?php echo $js; ?>
	  }
	  DTjQuery(function(){
		  
		
	   	 DTjQuery('.fields').click(function (){
						
						   var fieldname = DTjQuery(this).attr('name').replace('[showed]','');
						   
						   if(DTjQuery(this).val()== -1){
							  
							 DTjQuery("input[name^='"+fieldname+"\\[required\\]']").attr('disabled',true)
						
							 DTjQuery("input[name^='"+fieldname+"\\[group_behave\\]']").attr('disabled',true)
						
						   }else{
							  DTjQuery("input[name^='"+fieldname+"\\[required\\]']").removeAttr('disabled');
						
						      DTjQuery("input[name^='"+fieldname+"\\[group_behave\\]']").removeAttr('disabled');
						   }
						   disable_required_fields();
						  
		  });
	      DTjQuery('.fields').each(function(){
						    
							if(this.checked){
							    DTjQuery(this).trigger('click');
							}
							
		});
	})
</script>
<style>
label{
	
display:inline;}
.radio input[type="radio"], .checkbox input[type="checkbox"] {
	float:none;
    margin-left: -20px;

</style>
 