<?php

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

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){

		  ?>

          <tr>

           <td>

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

          <?php

	   }else{

	   ?>

	    <tr>

             <td width="31%"><?php echo JText::_( 'CARD_TYPE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></td>

          <td>

            <?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);

			?>

          </td>

        </tr>

	   <?php

	   }

	   ?>

          <tr>

		         <td width="31%"><?php echo JText::_( 'CARD_NUMBER' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></td>

		         <td width="69%" align="left"><input type="text" class="required inputbox creditcard" name="billing[x_card_num]" value="<?php echo isset($this->cb_creditcardnumber)?$this->cb_creditcardnumber:''?>" />

		              <br />

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

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

		          <td width="31%"><?php echo JText::_( 'CARD_EXPIRY_DATE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></td>

		          <td width="69%" align="left"><input type="text" class="required inputbox" name="billing[x_exp_date]" value="<?php echo isset($this->cb_expdate)?$this->cb_expdate:''?>" />

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

		        </tr>
-->
             <tr>

		          <td width="31%"><?php echo JText::_( 'CVV_CODE' );?>:<span class='dtrequired'>&nbsp;&nbsp;*&nbsp;&nbsp;</span></td>

		         <td width="69%" align="left"><input autocomplete="off" type="text" class="required inputbox digits" name="billing[x_card_code]" size="10" value="" />

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

		        </tr>

       <?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')) {
			
			$billing = DT_Session::get('register.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']);
			}
			$user->TableCard->save($billing);
			
		}
		
		return;
	}
	
}
?>