<?
/*****************************************************************
Name: class.valuty.php
Author: Adam Bogdal
Date: July 2006
Description: Conversion form integer to word (polish value)
Value < 10 000 000
*****************************************************************/
class Waluty
{
private $int_word = array();
private $jed = array();
private $val = array();
function __construct()
{
$this->int_word['1'] = array(1 => "jeden","dwa","trzy","cztery",
"piec","szesc","siedem","osiem","dziewiec");
$this->int_word['1a'] = array(0 => "dziesiec", "jedenascie",
"dwanascie", "trzynascie", "czternascie",
"pietnascie", "szesnascie", "siedemnascie",
"osiemnascie","dziewietnascie");
$this->int_word['2'] = array(2 => "dwadziescia","trzydziesci",
"czterdziesci","piecdziesiat",
"szescdziesiat","siedemdziesiat","osiemdziesiat","dziewiecdziesiat");
$this->int_word['3'] = array(1 => "sto","dwiescie","trzysta",
"czterysta","piecset","szescset","siedemset",
"osiemset","dziewiecset");
$this->jed[2] = array("milion","miliony","milionow");
$this->jed[1] = array("tysiac","tysiace","tysiecy");
$this->val[1] = array("zloty","zlote","zlotych");
$this->val[0] = array("grosz","grosze","groszy");
}
//return index of form
private function odmien($poz3,$poz2,$poz1)
{
if($poz1 == 1 && $poz2 ==0 && $poz3 ==0) $result=0;
else
if($poz1 >=2 && $poz1 <=4 && $poz2!=1) $result=1;
else
if($poz1 >=5 && $poz1 <=9 && $poz2!=1) $result=2;
else
if($poz1 == 0 && $poz2 == 0 && $poz3 ==0) $result=-1;
else $result=2;
return $result;
}
//word without end value
private function word($value)
{
$word_val = "";
for($i=1; $i <= strlen($value); $i++)
{
$tab[$i] = substr($value,strlen($value)-$i,1);
}
for($i=count($tab); $i>0; $i--)
{
$j = $i % 3;
if(!$j) $j = 3;
// 10 < X < 20
if(($i % 3 == 2) && $tab[$i] == 1)
{
$word_val .= $this->int_word['1a'][ $tab[$i-1] ]." ";
$i--;
}
else
// without 1
if($i % 3 !=1 || count($tab)>=$i)
$word_val .= $this->int_word[$j][ $tab[$i] ]." ";
if($i % 3 == 1)
{
$ind = round($i/4);
$word_val .= $this->jed[$ind][ $this->odmien($tab[$i+2],$tab[$i+1],$tab[$i]) ]." ";
}
}
return $word_val;
}
//return result
public function value($value)
{
$turn = "";
$zm[1]=floor($value);
// _.X
if(($value - $zm[1]) > 0)
$zm[0]=substr($value, (strpos($value, ".")+1), 2);
else $zm[0] = 0;
//translation for 'zl' and 'gr'
for($a=1;$a>=0;$a--)
{
$turn .= $this->word($zm[$a]);
for($i=1;$i<=3;$i++)
if(strlen($zm[$a])>=$i)
$pozycje[$i]=substr($zm[$a],strlen($zm[$a])-$i,1);
else $pozycje[$i]=0;
$index = $this->odmien($pozycje[3],$pozycje[2],$pozycje[1]);
if(!$pozycje[1] && !$pozycje[2] && !$pozycje[3] &&
strlen($zm[$a])>3) $index=2;
$turn .= $this->val[$a][ $index ]." ";
if($a==1 && $zm[0]!=0 && $zm[1]!=0) $turn.=", ";
}
return $turn;
}
}
?>