<?php

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

class Payment {

    var $module;

	var $component_tasks =  array('registeration'=>'payment','duepay'=>'due_payment','change'=>'paymentchanges','cancel'=>'paymentchanges');

	var $retryFields = array();
	
	var $retry = false;

	function Payment(){

		global $paymentmode;

		$this->paymentmode = $paymentmode;

		$this->cart = new DT_Cart();
		
		$this->init_data();

	}
	
	function init_data(){
		
	   $fieldTable = new TableField();
	   $process = DT_Session::get('Setting.process');
	   if (count(DT_Session::get($process.'.User')) == 1) {
		    foreach(DT_Session::get($process.'.User') as $user){
							      		
				break;				
			}
			$this->eventId = $user['eventId'];
		    $firstname = $fieldTable->fingbyName('firstname');
		    if($firstname){
			   $this->firstname = isset($user['fields'][$firstname->id])?$user['fields'][$firstname->id]:'';
	        }
		   
		    $lastname = $fieldTable->fingbyName('lastname');
		    if($lastname){
			   $this->lastname = isset($user['fields'][$lastname->id])?$user['fields'][$lastname->id]:'';
	        }
			
			$address = $fieldTable->fingbyName('address');
		    if($address){
			   $this->address = isset($user['fields'][$address->id])?$user['fields'][$address->id]:'';
	        }
			
			$state = $fieldTable->fingbyName('state');
		    if($state){
			   $fieldType = DtrModel::getInstance('Fieldtype','DtregisterModel');
               $fieldTypes = $fieldType->getTypes();
			   $class = "Field_".$fieldTypes[$state->type];
			  
               $stateTable = new $class();
			   $stateTable->load($state->id);
			   
			   $this->state = $stateTable->viewHtml($user);
			   
	        }
			
			$city = $fieldTable->fingbyName('city');
			
		    if($city && isset($user['fields'][$city->id])){
			   $this->city = $user['fields'][$city->id];
	        }
			
			$zip = $fieldTable->fingbyName('zip');
		    if($zip && isset($user['fields'][$zip->id])){
			   $this->zip = $user['fields'][$zip->id];
	        }
			$email = $fieldTable->fingbyName('email');
		    if($email){
			   $this->email = $user['fields'][$email->id];
	        }
			
			$phone = $fieldTable->fingbyName('phone');
		    if($phone && isset($user['fields'][$phone->id]) && $user['fields'][$phone->id]){
			   $this->phone = $user['fields'][$phone->id];
	        }
			
			$country = $fieldTable->fingbyName('country');
		    if($country){
			   $fieldType = DtrModel::getInstance('Fieldtype','DtregisterModel');
               $fieldTypes = $fieldType->getTypes();
			   $class = "Field_".$fieldTypes[$country->type];
			  
               $countryTable = new $class();
			   $countryTable->load($country->id);
			   
			   $this->country = $countryTable->viewHtml($user);
			   
	        }

	   }
			
	}

	function success(){
	  
	  return true;	
	}

	function setUsers(){

	}

    function expiry_fields($expiry_date=null) { // mm/yyyy
		
		ob_start();
		
		$months = array();
		
		for($i=1; $i <= 12; $i++) {
			$input = str_pad($i, 2, "0", STR_PAD_LEFT);
			$months[$input] = $input; 
			
		}
		$month_options = DtHtml::options($months,JText::_( 'DT_SELECT_MONTH' ));
		
		$years = array();
		
		for($i=0; $i <= 18; $i++) {
			$input = date('Y') + $i;
			$years[$input] = $input; 
			
		}
		$year_options = DtHtml::options($years,JText::_( 'DT_SELECT_YEAR' ));
		?>
		 <dl>

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

		    <dd class="dtfield">
             <?php
             echo JHTML::_('select.genericlist', $month_options,'billing[x_exp_date_month]','class="inputbox required"','value','text');
			 ?>
             &nbsp;
              <?php
             echo JHTML::_('select.genericlist', $year_options,'billing[x_exp_date_year]','class="inputbox required"','value','text');
			 ?>
            <!--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>

		<?php
		
		$data = ob_get_clean();

		return $data;
	}
	
	 function start_fields($date=null) { // mm/yyyy
		
		ob_start();
		
		$months = array();
		
		for($i=1; $i <= 12; $i++) {
			$input = str_pad($i, 2, "0", STR_PAD_LEFT);
			$months[$input] = $input; 
			
		}
		$month_options = DtHtml::options($months,JText::_( 'DT_SELECT_MONTH' ));
		
		$years = array();
		
		for($i=0; $i <= 18; $i++) {
			$input = date('Y') + $i;
			$years[$input] = $input; 
			
		}
		$year_options = DtHtml::options($years,JText::_( 'DT_SELECT_YEAR' ));
		?>
		 <dl>

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

		    <dd class="dtfield">
             <?php
             echo JHTML::_('select.genericlist', $month_options,'billing[x_start_date_month]','class="inputbox required"','value','text');
			 ?>
             &nbsp;
              <?php
             echo JHTML::_('select.genericlist', $year_options,'billing[x_start_date_year]','class="inputbox required"','value','text');
			 ?>
            <!--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>

		<?php
		
		$data = ob_get_clean();

		return $data;
	}
	
	function billingform(){

	     ob_start();
		 $process = DT_Session::get('Setting.process');
		 $paymentMethod = DT_Session::get($process.'.payment.method');

				?>

		        <div style="clear:both"><strong><?php echo JText::_( 'DT_PAYMENT_INFORMATION' );?></strong></div>

                <div style="clear:both"><input type="hidden" name="paymentmethod" value="<?php echo $paymentMethod ?>" /></div>

			<?php
			if (count(DT_Session::get($process.'.User')) == 1) {
			?>
			
			<div id="dtbilling_form" style="clear:both">
			
             <dl>
                	<dt class="dtlabel"><?php echo JText::_( 'DT_SAME_BILLING_INFO' );?></dt>
                	<dd class="dtfield"><input type="checkbox" class="inputbox" name="same" id="same" value="1" /></dd>
             </dl>
            <?php
			}
			?>

		        <dl>

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

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

                 </dl>

                 <dl>

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

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

                 </dl>

                 <dl>

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

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

                 </dl>

                 <dl>

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

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

                 </dl>

                 <dl>

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

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

                 </dl>
<?php

       $countylist = new TableField();
       
	   $field = $countylist->fingbyName('country');
	   
	  // pr($field->id);
       
	   $paymentmethod = DtrModel::getInstance('paymentmethod','DtregisterModel');
	   
	   global $paypal_pro_country;
	  
	   if(get_class($this) == 'paypal_pro'){
        
		   $value = (isset($this->country))?$this->country:$paypal_pro_country;
		   $dropDownDatas = $paymentmethod->paypal_country_codes();
		   $countrydropdown = JHTML::_('select.genericlist', DtHtml::options($dropDownDatas, JText::_("DT_SELECT_COUNTRY")),'billing[country]',$value,'value','text',array($value));
		   // pr($value); pr($countrydropdown); exit;
		   
	   }else{
	   
		 if($field && isset($this->country ) && $this->country != ""){
			 
			 $dropDownDatas=explode("|",$field->values);
			 $value = (isset($this->country))?$this->country:$field->selected;
			 $countrydropdown = JHTML::_('select.genericlist', DtHtml::options($dropDownDatas, JText::_("DT_SELECT_COUNTRY")),'billing[country]',' ','value','text',$value);			 
		 }
		 
	   }
	   
	   ?>
       <?php if(isset($countrydropdown)) {?>
        <dl>
			   <dt class="dtlabel">
				 <?php echo JText::_('DT_COUNTRY');?>
			   </dt>
			   <dd class="dtfield">
				 <?php echo $countrydropdown; ?>
			   </dd>
		</dl>
          <?php } ?>
                 <dl>
                	<dt class="dtlabel"><?php echo JText::_( 'DT_ZIPCODE' ); ?>:<span class="dtrequired">  *  </span></dt>
                    <dd class="dtfield"> <input id="billingZipcode" class="inputbox required" type="text" name="billing[zipcode]" value="<?php echo isset($this->zipcode)?$this->zipcode:'' ?>" /> </dd>
                 </dl>
  
                 <dl>
                	<dt class="dtlabel"><?php echo JText::_( 'DT_PHONE' ); ?>:<span class="dtrequired">  *  </span></dt>
                    <dd class="dtfield"> <input id="billingPhone" class="inputbox required" type="text" name="billing[phone]" value="<?php echo isset($this->phone)?$this->phone:'' ?>" /> </dd>
                 </dl>
  <?php if(get_class($this) != 'offline_payment'){ ?>
                 <dl>
                	<dt class="dtlabel"><?php echo JText::_( 'DT_EMAIL' ); ?>:<span class="dtrequired">  *  </span></dt>
                    <dd class="dtfield"> <input id="billingEmail" class="inputbox required" type="text" name="billing[email]" value="<?php echo isset($this->email)?$this->email:'' ?>" /> </dd>
                 </dl>
   <?php } ?>
                 <?php
							   foreach(DT_Session::get($process.'.User') as $key => $user){
							      		if(!intval($key)){
											continue;	
											
										}
										break;						
							   }
							  
							?>
							
					<?php
			if (count(DT_Session::get($process.'.User')) == 1) {
			?>		
				</div>
             <?php } ?>

				<script language="javascript" type="text/javascript">

                    //<![CDATA[
							<?php
							  $field = $countylist->fingbyName('firstname');
							?>
							var billing_firstname = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('lastname');
							?>
							var billing_lastname = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('address');
							?>
							var billing_address = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('city');
							?>
							var billing_city = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('state');
							?>
							var billing_state = "<?php echo (isset($this->state) && isset($user['fields'][$field->id]))?$this->state:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('zip');
							?>
							var billing_zipcode = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('phone');
							?>
							var billing_phone = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('email');
							?>
							var billing_email = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>";
							<?php
							  $field = $countylist->fingbyName('country');
							  
							  if($field && isset($countrydropdown)) {
							?>
							var billing_country = "<?php echo ($field && isset($user['fields'][$field->id]))?$user['fields'][$field->id]:'' ; ?>"; 
		                    <?php 
							  }
							?>
							
							DTjQuery(function(){
								DTjQuery("#same").click(function(){
									
									if(this.checked) {
										if(DTjQuery("#billingFirstname"))
											DTjQuery("#billingFirstname").val(billing_firstname);
										if(DTjQuery("#billingLastname"))
											DTjQuery("#billingLastname").val(billing_lastname);
										if(DTjQuery("#billingAddress"))
											DTjQuery("#billingAddress").val(billing_address);
										if(DTjQuery("#billingCity"))
											DTjQuery("#billingCity").val(billing_city);
										if(DTjQuery("#billingState"))
											DTjQuery("#billingState").val(billing_state);
										if(DTjQuery("#billingZipcode"))
											DTjQuery("#billingZipcode").val(billing_zipcode);
										if(DTjQuery("#billingEmail"))
											DTjQuery("#billingEmail").val(billing_email);
										if(DTjQuery("#billingcountry").size())
											DTjQuery("#billingcountry").val(billing_country);
										if(DTjQuery("#billingPhone"))
											DTjQuery("#billingPhone").val(billing_phone);
									} else {
										DTjQuery("#billingFirstname").val('');
										DTjQuery("#billingLastname").val('');
										DTjQuery("#billingAddress").val('');
										DTjQuery("#billingCity").val('');
										DTjQuery("#billingState").val('');
										DTjQuery("#billingZipcode").val('');
										DTjQuery("#billingPhone").val('');
										DTjQuery("#billingEmail").val('');
										DTjQuery("#billingcountry").val('');
										DTjQuery("#billingPhone").val('');
									}
		
								});
							});
                    
							//]]>

                   </script>

                <?php 

	    $data = ob_get_clean();

		return $data;

	}

	function getLoginUserData(){

	   global $cb_integrated,$ptc;

	   $database = &JFactory::getDBO();

	   $user = &JFactory::getUser();

	   $this->credircardNo = "";

	   $this->credircardExp = "";

	   $this->cardtype = "";

	   if($cb_integrated ==1 ){

	       $userId=$user->id;

		   if ($userId){

						//Get the information from cb

						$sql="Select * From #__comprofiler where user_id=$userId";

						$database->setQuery($sql);

						$rowProfile = $database->loadObject();

						if($rowProfile)

						{

					      $ptc->ToDecode=$rowProfile->cb_creditcardnumber;

							$ptc->Decode();

							if($ptc->Decoded!=-1)

							$this->credircardNo=$ptc->Decoded;

							$ptc->ToDecode=$rowProfile->cb_expdate;

							$ptc->Decode();

							if($ptc->Decoded!=-1)

							$this->credircardExp=$ptc->Decoded;

							$this->cardtype = $rowProfile->cb_cardtype;

						}

			}

	   }

	}

	function setBillinginfo($info){
       
	    if(is_array($info))

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

		    $this->$key = $value;

		}

	}

	function setData($data= array()){

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

		   $this->$key = $value;

		}

	}

	function generateconfirmNum(){

	   global $confirm_number_type,$confirm_number_prefix,$confirm_number_start;

	   $x_invoice_num1 = "";

	   if($confirm_number_type=='random'){

	       $chars = "0123456789";

		   srand((double)microtime()*1000000);

			for($i=0; $i<7; $i++){

				$x_invoice_num1 .= $chars[rand()%strlen($chars)];

			}

	   }else{

	       $x_invoice_num1 = $confirm_number_start+1;

	   }

	   return $this->confirmNum = $confirm_number_prefix.$x_invoice_num1;

	}

	function formatfields(){

		 $fields = "";

//pr($this->fields);
         foreach( $this->fields as $key => $value ){ 

		    if(trim($value)!="")

		    $fields .= "$key=" . urlencode( $value ) . "&";

		 }

	     return $fields;

	 }

	function showform($options){

	    $this->setformData();

	  return  $this->drawform($options);

	}

	function add_field($name,$value){

	   $this->add_field($name,$value);

	}

	function addItem($name, $description, $quantity, $price){

		 $this->addItem($name, $description, $quantity, $price);

	}

	function saveSession(){

	$database = JFactory::getDBO();
	$session = JFactory::getSession();
		$data    = $session->getData();

		// Before storing it, let's serialize and encode the JRegistry object
		$_SESSION['joomla'] = base64_encode(serialize($data));
    $data = $_SESSION;
	$sql = "INSERT INTO #__dtregister_session (`session_id` ,`data`, `user_id`,`processed`)VALUES ( ".$database->Quote(session_id()).",".$database->Quote(serialize($data)).",'0','0')";

		$database->setQuery($sql);

	    $database->query();

        echo $database->getErrorMsg();

		return $database->insertid();

	}
	
	
	
	function setPaymentType($type){

	    $this->paymentType = $type;

	}

    function beforepayment(){

	   return true;

	}

	 function afterpayment(){

	   return true;

	}

	function afterFailed(){

	   $this->tryagaintask = "billinginfo";	

    }

	function tryagain(){

	    global $Itemid;

		ob_start();

		?>

    <form id="frmBack" name="frmBack" method="POST" action="index.php?option=com_dtregister&Itemid=<?php echo $Itemid; ?>">

	<input type="hidden" name="try_again" value="1" />

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

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

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

	<input type="hidden" name="task" value="<?php echo $this->tryagaintask ?>" />

	<input type="hidden" name="type" value="<?php echo get_class($this); ?>" />

		<!-- Other field in bank account info-->

      <?php

      foreach($this->retryFields as $key=>$value){

		  ?>

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

          <?php

	  }

	  ?>

		<input type="submit" value="<?php echo JText::_( 'DT_TRY_AGAIN' ); ?>" />

	</form>

		<?php

		return ob_get_clean();

	}
	
	function markprocessed($id,$userId=0){
	    $database = JFactory::getDBO();
	     $session = JFactory::getSession();
		$data    = $session->getData();

		// Before storing it, let's serialize and encode the JRegistry object
		$_SESSION['joomla'] = base64_encode(serialize($data));
       $data = $_SESSION;
	   $sql = "update #__dtregister_session set `data`= ".$database->Quote(serialize($data))." , processed=1 where id=".$id;
	    $database->setQuery($sql);
	    $database->query();
	   
	}
    
	function update_session($id){
	    $database = JFactory::getDBO();
	   $session = JFactory::getSession();
		$data    = $session->getData();

		// Before storing it, let's serialize and encode the JRegistry object
		$_SESSION['joomla'] = base64_encode(serialize($data));
        $data = $_SESSION;
	   
	   $sql = "update #__dtregister_session set `data`= ".$database->Quote(serialize($data))."  where id=".$id;
	    $database->setQuery($sql);
	    $database->query();
	   
	}
	    
	function after_user_save($user) {
		return;
	}
	
	function ISO4217_codes() {
		
		$currency_codes = array();
		$currency_codes['AED']=784;
		$currency_codes['AFN']= 971;
		$currency_codes['ALL']= 008;
		$currency_codes['AMD']= 051;
		$currency_codes['ANG']= 532;
		$currency_codes['AOA']= 973;
		$currency_codes['ARS']= 032;
		$currency_codes['AUD']= 036;
		$currency_codes['AWG']= 533;
		$currency_codes['AZN']= 944;
		$currency_codes['BAM']= 977;
		$currency_codes['BBD']= 052;
		$currency_codes['BDT']= 050;
		$currency_codes['BGN']= 975;
		$currency_codes['BHD']= 048;
		$currency_codes['BIF']= 108;
		$currency_codes['BMD']= 060;
		$currency_codes['BND']= 096;
		$currency_codes['BOB']= 068;
		$currency_codes['BOV']= 984;
		$currency_codes['BRL']= 986;
		$currency_codes['BSD']= 044;
		$currency_codes['BTN']= 064;
		$currency_codes['BWP']= 072;
		$currency_codes['BYR']= 974;
		$currency_codes['BZD']= 084;
		$currency_codes['CAD']= 124;
		$currency_codes['CDF']= 976;
		$currency_codes['CHE']= 947;
		$currency_codes['CHF']= 756;
		$currency_codes['CHW']= 948;
		$currency_codes['CLF']= 990;
		$currency_codes['CLP']= 152;
		$currency_codes['CNY']= 156;
		$currency_codes['COP']= 170;
		$currency_codes['COU']= 970;
		$currency_codes['CRC']= 188;
		$currency_codes['CUC']= 931;
		$currency_codes['CUP']= 192;
		$currency_codes['CVE']= 132;
		$currency_codes['CZK']= 203;
		$currency_codes['DJF']= 262;
		$currency_codes['DKK']= 208;
		$currency_codes['DOP']= 214;
		$currency_codes['DZD']= 012;
		$currency_codes['EGP']= 818;
		$currency_codes['ERN']= 232;
		$currency_codes['ETB']= 230;
		$currency_codes['EUR']= 978;
		$currency_codes['FJD']= 242;
		$currency_codes['FKP']= 238;
		$currency_codes['GBP']= 826;
		$currency_codes['GEL']= 981;
		$currency_codes['GHS']= 936;
		$currency_codes['GIP']= 292;
		$currency_codes['GMD']= 270;
		$currency_codes['GNF']= 324;
		$currency_codes['GTQ']= 320;
		$currency_codes['GYD']= 328;
		$currency_codes['HKD']= 344;
		$currency_codes['HNL']= 340;
		$currency_codes['HRK']= 191;
		$currency_codes['HTG']= 332;
		$currency_codes['HUF']= 348;
		$currency_codes['IDR']= 360;
		$currency_codes['ILS']= 376;
		$currency_codes['INR']= 356;
		$currency_codes['IQD']= 368;
		$currency_codes['IRR']= 364;
		$currency_codes['ISK']= 352;
		$currency_codes['JMD']= 388;
		$currency_codes['JOD']= 400;
		$currency_codes['JPY']= 392;
		$currency_codes['KES']= 404;
		$currency_codes['KGS']= 417;
		$currency_codes['KHR']= 116;
		$currency_codes['KMF']= 174;
		$currency_codes['KPW']= 408;
		$currency_codes['KRW']= 410;
		$currency_codes['KWD']= 414;
		$currency_codes['KYD']= 136;
		$currency_codes['KZT']= 398;
		$currency_codes['LAK']= 418;
		$currency_codes['LBP']= 422;
		$currency_codes['LKR']= 144;
		$currency_codes['LRD']= 430;
		$currency_codes['LSL']= 426;
		$currency_codes['LTL']= 440;
		$currency_codes['LVL']= 428;
		$currency_codes['LYD']= 434;
		$currency_codes['MAD']= 504;
		$currency_codes['MDL']= 498;
		$currency_codes['MGA']= 969;
		$currency_codes['MKD']= 807;
		$currency_codes['MMK']= 104;
		$currency_codes['MNT']= 496;
		$currency_codes['MOP']= 446;
		$currency_codes['MRO']= 478;
		$currency_codes['MUR']= 480;
		$currency_codes['MVR']= 462;
		$currency_codes['MWK']= 454;
		$currency_codes['MXN']= 484;
		$currency_codes['MXV']= 979;
		$currency_codes['MYR']= 458;
		$currency_codes['MZN']= 943;
		$currency_codes['NAD']= 516;
		$currency_codes['NGN']= 566;
		$currency_codes['NIO']= 558;
		$currency_codes['NOK']= 578;
		$currency_codes['NPR']= 524;
		$currency_codes['NZD']= 554;
		$currency_codes['OMR']= 512;
		$currency_codes['PAB']= 590;
		$currency_codes['PEN']= 604;
		$currency_codes['PGK']= 598;
		$currency_codes['PHP']= 608;
		$currency_codes['PKR']= 586;
		$currency_codes['PLN']= 985;
		$currency_codes['PYG']= 600;
		$currency_codes['QAR']= 634;
		$currency_codes['RON']= 946;
		$currency_codes['RSD']= 941;
		$currency_codes['RUB']= 643;
		$currency_codes['RWF']= 646;
		$currency_codes['SAR']= 682;
		$currency_codes['SBD']= 090;
		$currency_codes['SCR']= 690;
		$currency_codes['SDG']= 938;
		$currency_codes['SEK']= 752;
		$currency_codes['SGD']= 702;
		$currency_codes['SHP']= 654;
		$currency_codes['SLL']= 694;
		$currency_codes['SOS']= 706;
		$currency_codes['SRD']= 968;
		$currency_codes['SSP']= 728;
		$currency_codes['STD']= 678;
		$currency_codes['SYP']= 760;
		$currency_codes['SZL']= 748;
		$currency_codes['THB']= 764;
		$currency_codes['TJS']= 972;
		$currency_codes['TMT']= 934;
		$currency_codes['TND']= 788;
		$currency_codes['TOP']= 776;
		$currency_codes['TRY']= 949;
		$currency_codes['TTD']= 780;
		$currency_codes['TWD']= 901;
		$currency_codes['TZS']= 834;
		$currency_codes['UAH']= 980;
		$currency_codes['UGX']= 800;
		$currency_codes['USD']= 840;
		$currency_codes['USN']= 997;
		$currency_codes['UYI']= 940;
		$currency_codes['UYU']= 858;
		$currency_codes['UZS']= 860;
		$currency_codes['VEF']= 937;
		$currency_codes['VND']= 704;
		$currency_codes['VUV']= 548;
		$currency_codes['WST']= 882;
		$currency_codes['XAF']= 950;
		$currency_codes['XAG']= 961;
		
		$currency_codes['XAU']= 959;
		
		$currency_codes['XBA']= 955;
		
		$currency_codes['XBB']= 956;
		
		$currency_codes['XBC']= 957;
		
		$currency_codes['XBD']= 958;
		
		$currency_codes['XCD']= 951;
		$currency_codes['XDR']= 960;
		$currency_codes['XFU']= Nil;
		$currency_codes['XOF']= 952;
		$currency_codes['XPD']= 964;
		
		$currency_codes['XPF']= 953;
		$currency_codes['XPT']= 962;
		
		$currency_codes['XTS']= 963;
		$currency_codes['XXX']= 999;
		$currency_codes['YER']= 886;
		$currency_codes['ZAR']= 710;
		$currency_codes['ZMK']= 894;
		$currency_codes['ZWL']= 932;
		
		return $currency_codes;
		
	}
}

?>