<?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
*/

defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );

require_once( JPATH_SITE.'/components/com_dtregister/lib/class.payment.php');

class offline_payment extends Payment{ 
	
	 var $bywebservice = true;
	 var $cardtype = "";
	 function __construct() {

		parent::__construct();

   }
   
     function billingform(){

	   global $cardtype;
       
	   $form = parent::billingform();
       ob_start();
	   $size = count($cardtype);
	   if($size ==1){

		  ?>

          <div id="dtcard_details" style="clear:both; margin:10px 0 0 0">

           <div style="clear:both">

           <input type="radio" style="display:none" name="billing[cardtype]" value="<?php echo $cardtype[0];?>" <?php echo "checked"; ?> /></div>

          <?php

	   }else{

	   ?>

	    <dl>

          <dt class="dtlabel"><?php echo JText::_( 'CARD_TYPE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></dt>

          <dd class="dtfield">

            <?php

			$mCardtype = DtrModel::getInstance('cardtype','DtregisterModel');
			$types = $mCardtype->gettypes();
			$options = array();
			foreach($cardtype as $key=>$type) {
				$options[$key] = $types[$type]; 
			}
			$options=DtHtml::options($options);

			echo JHTML::_('select.genericlist', $options,'billing[cardtype]','class = "required"','value','text',$this->cardtype);

			?>

          </dd>

        </dl>

	   <?php

	   }

	   ?>

        <dl>

		  <dt class="dtlabel"><?php echo JText::_( 'CARD_NUMBER' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></dt>

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

		              <br />

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

		</dl>

       <?php
        echo $this->expiry_fields(isset($this->cb_expdate)?$this->cb_expdate:'');
		?>
         <!--dl>

		    <dt class="dtlabel"><?php echo JText::_( 'CARD_EXPIRY_DATE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></dt>

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

		            &nbsp;&nbsp;(mm/yy)</dd>

		 </dl-->
        <dl>

		  <dt class="dtlabel"><?php echo JText::_( 'CVV_CODE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></dt>

		  <dd class="dtfield"><input type="text" name="billing[x_card_code]" size="10" class="required inputbox digits" value="<?php echo isset($this->x_card_code)?$this->x_card_code:''; ?>" />

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

	    </dl>
	
	</div>

       <?php

	   $html = ob_get_clean();

	   return $form.$html;

   }	
   
     function process() {
	 	
		/*
		 session variables here only
		*/
		DT_Session::set('register.payment.offline_process',true);
		return true;
		
	 }
	 
	 function after_user_save($user) {
		
		if(DT_Session::get('register.payment.offline_process')) {
			
			$process = DT_Session::get('Setting.process');
			$billing = DT_Session::get($process.'.payment.billing');
			if(isset($billing['x_exp_date_year'])) {
				$billing['userId'] = $user->userId;
				$billing['status'] = 0;
				$year = substr($billing['x_exp_date_year'],2);
				$exp_date=$billing['x_exp_date_month']."/".$year;
				
				$billing['x_exp_date'] = $exp_date;
				unset($billing['x_exp_date_year']);
				unset($billing['x_exp_date_month']);
			}
			if(!isset($billing['userId']) || $billing['userId'] == "") {
			   $billing['userId'] = $user->userId;
			}
			$user->TableCard->save($billing);
			
		}
		return;
	}
	
}
?>