<?php

/**
* @version 2.8.11
* @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
*/

global $Itemid,$currency_code;

$tUser = $this->tUser;
$event = $tUser->TableEvent;
$paymthd = $this->getModel('paymentmethod');

$pMethods = $paymthd->getMergeList(true);
$aro = $this->getModel( 'aro' );
   $user = &JFactory::getUser();
 $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
   
   $aco_id = $this->getModel( 'aco' )->table->getAcoIdbyTypeControllerTask('sessionUser','event','edit','DT_EDIT_OWN_EVENT');
   $permission = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco_id);
   $opt_where = "(archive = 1 or  archive = 0) ";
   if($permission && count($permission) == count($aro)){
  	  $events_obj = $event->TableModerator->find('user_id = '.$user->id);
				  $events = array();
				  foreach($events_obj as $evt) {
					 $events[] = $evt->eventId;
				  }
				  $user_condtion = " slabId in(".implode(",",$events).")";
	
  	 //$where[]= " a.user_id = ".$user->id;
	 if(count($events) >0) {
	 $where[] = $user_condtion ;
	 if(trim($opt_where) == "") {
	    $opt_where .= $user_condtion;
	 } else {
	   $opt_where .= " and ".$user_condtion;
	 }
	 }
   }

?>

<form name="adminForm" class="adminform" method="post" action="index.php?option=com_dtregister&Itemid=<?php echo $Itemid ?>" enctype="multipart/form-data">

      <dl>

         <dt class="dtlabel" valign="top">

           <?php echo JText::_( 'DT_EVENT'); ?>:

        </dt>

         <dd class="dtfield">

         <?php echo JHTML::_('select.genericlist', DtHtml::options($tUser->TableEvent->optionslist( $opt_where),JText::_("DT_SELECT_EVENT")),'User[eventId]',' ','value','text',$tUser->eventId)?>

         </dd>

      </dl>

      <dl><dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_USERID' ); ?>:</dt><dd class="field"><?php  echo JHTML::_('select.genericlist', DtHtml::options($tUser->TableJUser->optionslist(),JText::_("DT_SELECT_USER")),'User[user_id]',' ','value','text',$tUser->user_id)?></dd></dl>

      <dl>

         <dt class="dtlabel" valign="top">

           <?php echo JText::_( 'DT_DISCOUNT_CODE'); ?>:

         </dt>

         <dd class="dtfield">

           <input type="text" id="discountcode_id" name="User[discount_code]" value="<?php echo $tUser->TableDiscountcode->code ?>" class="inputbox" />

           <input type="hidden" name="User[userId]" value="<?php echo $tUser->userId; ?>" />

          </dd>

      </dl>
      
       <dl>

         <dt class="dtlabel" valign="top">


           <?php echo JText::_( 'DT_CONFIRMATION_NUMBER'); ?>:

          </dt>

         <dd class="dtfield">

           <input type="text" name="User[confirmNum]" value="<?php echo $tUser->confirmNum ?>" class="inputbox" />

          </dd>

      </dl>
      <?php if(!count($this->mUser->table->TableMember->findByUserId($tUser->userId)) && $tUser->type == 'G'){ ?>
      <dl>

         <dt class="dtlabel" valign="top">
           <?php echo JText::_( 'DT_GROUP_MEMBERS'); ?>:
          </dt>

         <dd class="dtfield">
           <input type="text" name="User[memtot]" value="<?php echo $tUser->memtot; ?>" class="inputbox" />
         </dd>

      </dl>
       <?php }else {
		   ?>
		    <input type="hidden" name="User[memtot]" value="<?php echo $tUser->memtot; ?>" class="inputbox" />
        <?php
		   
		   } ?>
       <dl>

         <dt class="dtlabel" valign="top">

           <?php echo JText::_( 'DT_TRANSACTION_ID'); ?>:

         </dt>

         <dd class="dtfield">
           <input type="text" name="User[transaction_id]" value="<?php echo $tUser->transaction_id ?>" class="inputbox" />

         </dd>

      </dl>
       <dl>

         <dt class="dtlabel" valign="top">
           <?php echo JText::_( 'DT_STATUS'); ?>:

         </dt>

         <dd class="dtfield">
         <?php echo JHTML::_('select.genericlist', DtHtml::options($tUser->statustxt,JText::_("DT_SELECT_STATUS")),'User[status]',' ','value','text',$tUser->status)?>

         </dd>

      </dl>
 <?php if(!count($this->mUser->table->TableMember->findByUserId($tUser->userId)) && $tUser->type == 'G'){?>
      <dl>

         <dt class="dtlabel" valign="top">

           <?php echo JText::_( 'DT_ATTENDED'); ?>:

        </dt>

         <dd class="dtfield">

         <?php echo JHTMLSelect::booleanlist("User[attend]","",$tUser->attend); ?>

        </dd>

      </dl>
 <?php } ?>
       <dl>

         <dt class="dtlabel" valign="top">
           <?php echo JText::_( 'DT_PAY_LATER_PAID'); ?>:

         </dt>

         <dd class="dtfield">

         <?php echo JHTMLSelect::booleanlist("User[Fee][status]","",isset($tUser->fee->status)?$tUser->fee->status:0); ?>

          </dd>

      </dl>

       <dl>

         <dt class="dtlabel" valign="top">

           <?php echo JText::_( 'DT_AMOUNT_PAID'); ?>:
           </dt>

         <dd class="dtfield">

           <input type="text" name="User[Fee][paid_amount]" value="<?php echo DTreg::showprice($tUser->TableFee->paid_amount) ?>" class="inputbox" />
  </dd>

      </dl>
      <dl>

         <dt class="dtlabel" valign="top">
           <?php echo JText::_( 'DT_AMOUNT'); ?>:
        </dt>

         <dd class="dtfield">

           <input type="text" name="User[Fee][fee]" value="<?php echo DTreg::showprice($tUser->TableFee->fee); ?>" class="inputbox" />
      </dd>

      </dl>

      <dl> <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_PAYMENT_METHOD' ); ?>:</dt><dd class="dtfield"> <?php echo JHTML::_('select.genericlist', DtHtml::options($pMethods,JText::_("DT_SELECT_PAY_OPTIONS")),'User[Fee][payment_method]',' ','value','text',isset($tUser->fee->payment_method)?$tUser->fee->payment_method:0)?></dd></dl>

     <?php

	   echo $this->form;

	 ?>
	
	 <?php
	   $html = $tUser->barCodeImg();

	   if($html!=""){
	 ?>
	   <dl> <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_BARCODE' ); ?>:</dt>

	      <dd class="dtfield"><?php echo $html; ?></dd>
	   </dl>
	 <?php  
  	   }

	 ?>
    <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtheading" valign="top"><?php echo JText::_( 'DT_OFFLINE_PAYMENT_DETAILS' ); ?></dt>
	
	  </dl>

      <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_CARD_HOLDER_FIRSTNAME' ); ?>:<span class="dtrequired">*&nbsp;</span></dt>

                    <dd class="dtfield"> <input id="billingFirstname" class="inputbox required" type="text" name="billing[firstname]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->firstname:'' ?>" /> </dd>

                 </dl>
<dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_CARD_HOLDER_LASTNAME' ); ?>:<span class="dtrequired">*&nbsp;</span></dt>

                     <dd class="dtfield"> <input id="billingLastname" class="inputbox required" type="text" name="billing[lastname]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->lastname:'' ?>" /> </dd>
 </dl>
        <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_BILLING_ADDRESS' ); ?>:<span class="dtrequired">*&nbsp; </span></dt>

                     <dd class="dtfield"> <input id="billingAddress" class="inputbox required" type="text" name="billing[address]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->address:'' ?>" /> </dd>
</dl>

                 <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_CITY' ); ?>:<span class="dtrequired">*&nbsp; </span></dt>

                    <dd class="dtfield"><input id="billingCity" class="inputbox required" type="text" name="billing[city]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->city:'' ?>" />  </dd>

               </dl>
                  <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_STATE' ); ?>:<span class="dtrequired">*&nbsp; </span></dt>

                    <dd class="dtfield"> <input id="billingState" class="inputbox required" type="text" name="billing[state]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->state:'' ?>" /> </dd>

                  </dl>

		        <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_ZIPCODE' ); ?>:<span class="dtrequired">*&nbsp; </span></dt>
		             <dd class="dtfield"> <input id="billingZipcode" class="inputbox required" type="text" name="billing[zipcode]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->zipcode:'' ?>" /> </dd>
		         </dl>
		
    <?php 
		$countylist = & DtrTable::getInstance('Field','Table');
		
		$field = $countylist->fingbyName('country');
		$countrydropdown = "";
		 if($field){
			 
			 $dropDownDatas=explode("|",$field->values);
			 $value = (isset($tUser->card) && ($tUser->card))?$tUser->card->country:$field->selected;
			 $countrydropdown = JHTML::_('select.genericlist', DtHtml::options($dropDownDatas, JText::_("DT_SELECT_COUNTRY")),'billing[country]',' ','value','text',$value);			 
		 }
	?>
    <?php if($countrydropdown != "") {?>
     <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top">
				 <?php echo JText::_('DT_COUNTRY');?>
			   </dt>
			   <dd class="dtfield">
				 <?php echo $countrydropdown; ?>
			   </dd></dl>

                 <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_PHONE' ); ?>:<span class="dtrequired">*&nbsp; </span></dt>
                    <dd class="dtfield"> <input id="billingPhone" class="inputbox required" type="text" name="billing[phone]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->phone:'' ?>" /> </dd>
                  </dl>
    <?php } ?>
   <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_BILLING_CARD_TYPE' );?>:<span class='dtrequired'>*&nbsp;</span></dt>

         <dd class="dtfield">

            <?php
            $cardtype = array('Visa'=>'Visa','MasterCard'=>'MasterCard','Discover'=>'Discover','American'=>'American');
			$options=DtHtml::options($cardtype);

			echo JHTML::_('select.genericlist', $options,'billing[cardtype]','','value','text',(isset($tUser->card) &&  $tUser->card)?$tUser->card->cardtype:'');

			?>

          </dd></dl>
        
        <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_BILLING_CARD_NUMBER' );?>:<span class='dtrequired'>*&nbsp;</span></dt>

		         <dd class="dtfield"><input type="text" name="billing[x_card_num]" class="inputbox" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->x_card_num:''?>" />

		              <br />

		            <?php echo JText::_( 'DT_CARD_NUMBER_EXPLANATION' );?></dd></dl>

           <dl class="dtlabel billinginfo" valign="top">
	
	      <dt class="dtlabel" valign="top"><?php echo JText::_( 'DT_CARD_EXPIRY_DATE' );?>:<span class='dtrequired'>*&nbsp;</span></dt>

		          <dd class="dtfield"><input type="text" name="billing[x_exp_date]" value="<?php echo (isset($tUser->card) && $tUser->card)?$tUser->card->x_exp_date:''?>" class="inputbox" />

		            &nbsp;&nbsp;(mm/yy)</dd></dl>
        
   <!-- ************ billing **************** -->
  
   <input type="hidden" name="formsubmit" value="edit" />

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

   <input type="hidden" name="controller" value="usermanage" />

   <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

   <input type="hidden" name="task" value="edit" />

</form>

<div id="debug">

</div>

<script type="text/javascript">
  function updateFee () {}
 DTjQuery(function(){

    DTjQuery(document.adminForm).validate({

	        success: function(label) {

				label.addClass("success");

			}

	});
	
	DTjQuery("#Useruser_id").change(function(){	    
		DTjQuery.getJSON('index.php?option=com_dtregister&controller=usermanage&task=loadprofile&no_html=1',{id:DTjQuery(this).val()},function(data){

			DTjQuery.each(data,function(k,v){

				DTjQuery("#Field"+k).val(v);

			})

		});

	});
     DTjQuery("#UserFeepayment_method").change(function(){
   		
		if(DTjQuery(this).val()=='offline_payment') {
			
			if(navigator.appName.indexOf("Micro") >=0){

					display = 'block';

				}else{

					// display = 'table-row';

				}
			
			DTjQuery(".billinginfo").css({display:display});
			DTjQuery("input[name^='billing']").addClass('required');	
			
		} else {
			
			DTjQuery(".billinginfo").css({display:'none'});
			DTjQuery("input[name^='billing']").removeClass('required');
		}
		
   });
    DTjQuery("#UserFeepayment_method").trigger('change');
	
	function update_discountcode_fields() {
  	  var element_class = "";
	  if(DTjQuery("#discountcode_id").size()){
	  DTjQuery.each(DTjQuery(".discountcode_show"),function(k,v){
	  		 element_class = "code_"+DTjQuery("#discountcode_id").val().toLowerCase();
			if( DTjQuery(v).hasClass(element_class) ){
				if(navigator.appName.indexOf("Micro") >=0){

					display = 'block';

				}else{

					// display = 'table-row';

				}
				DTjQuery(v).css({display:display});
			} else {
				DTjQuery(v).hide();
			}
			
	  })
	  }
	  
  }
  
    update_discountcode_fields();
	
	DTjQuery("#discountcode_id").change(function(){
		
		update_discountcode_fields();
		
	})
 })

 Joomla.submitbutton = function(pressbutton) {

	if(pressbutton == "cancel"){

	   	submitform(pressbutton);

		return;

	}
    
	if(DTjQuery(document.adminForm).valid()){
		var disabled = DTjQuery(':disabled');
        DTjQuery.each(disabled, function(){
		     DTjQuery(this).removeAttr('disabled');  
	   	})
         document.adminForm.task.value = pressbutton;
		 //document.adminForm.submit();
		  DTjQuery.each(DTjQuery(".discountcode_show"),function(k,v){
				  
				  if( DTjQuery(v).is(':visible') ){
					 
				  } else {
					  DTjQuery(v).remove();
				  }
				  
			})
	  	 submitform(pressbutton);

	}

	return false;

}

</script>