|
Posted by Steve on 11/05/06 00:56
<?
require_once 'vin.manufacturer.interface.php';
class vin
{
private $_countries = array(
'^A[A-H]' => 'SOUTH
AFRICA' ,
'^A[J-N]' => 'IVORY
COAST' ,
'^B[A-E]' =>
'ANGOLA' ,
'^B[F-K]' =>
'KENYA' ,
'^B[L-R]' =>
'TANZANIA' ,
'^C[A-E]' =>
'BENIN' ,
'^C[F-K]' =>
'MALAGASY' ,
'^C[L-R]' =>
'TUNISIA' ,
'^D[A-E]' =>
'EGYPT' ,
'^D[F-K]' =>
'MOROCCO' ,
'^D[L-R]' =>
'ZAMBIA' ,
'^E[A-E]' =>
'ETHIOPIA' ,
'^E[F-K]' =>
'MOZAMBIQUE' ,
'^F[A-E]' =>
'GHANA' ,
'^F[F-K]' =>
'NIGERIA' ,
'^F[F-K]' =>
'MADAGASCAR' ,
'^J[A-Z0-9]' =>
'JAPAN' ,
'^K[A-E]' => 'SRI
LANKA' ,
'^K[F-K]' =>
'ISRAEL' ,
'^K[L-R]' => 'KOREA
(SOUTH)' ,
'^L[A-Z0-9]' =>
'CHINA' ,
'^M[A-E]' =>
'INDIA' ,
'^M[F-K]' =>
'INDONESIA' ,
'^M[L-R]' =>
'THAILAND' ,
'^N[F-K]' =>
'PAKISTAN' ,
'^N[L-R]' =>
'TURKEY' ,
'^P[A-E]' =>
'PHILIPINES' ,
'^P[F-K]' =>
'SINGAPORE' ,
'^P[L-R]' =>
'MALAYSIA' ,
'^R[A-E]' =>
'UNITED ARAB EMIRATES' ,
'^R[F-K]' =>
'TAIWAN' ,
'^R[L-R]' =>
'VIETNAM' ,
'^S[A-M]' => 'GREAT
BRITAIN' ,
'^S[N-T]' =>
'GERMANY' ,
'^S[U-Z]' =>
'POLAND' ,
'^T[A-H]' =>
'SWITZERLAND' ,
'^T[J-P]' =>
'CZECHOSLOVAKIA' ,
'^T[R-V]' =>
'HUNGARY' ,
'^T[W-Z1]' =>
'PORTUGAL' ,
'^U[H-M]' =>
'DENMARK' ,
'^U[N-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[S-W]' =>
'URUGUAY' ,
'^9[X-Z1-2]' =>
'TRINIDAD & TOBAGO' ,
'^9[3-9]' =>
'BRAZIL'
);
private $_manufacturers = array(
'^(TRU|WAU)' =>
'AUDI' ,
'^(4US|WB[AS])' => 'BMW'
,
'^(1GC|2G1)' =>
'CHEVROLET' ,
'^VF7' =>
'CITROΛN' ,
'^KL' =>
'DAEWOO' ,
'^Z[DF]F' =>
'FERRARI' ,
'^ZFA' =>
'FIAT' ,
'^(1F[B-DM]|2F[BCMT]|3FE|6F)' =>
'FORD' ,
'^[12]F[UV]' =>
'FREIGHTLINER' ,
'^JF' =>
'FUJI' ,
'^1F9' => 'FWD
CORPORATION' ,
'^([1-3]G|6H)' =>
'GENERAL MOTORS' ,
'^[1J]H' =>
'HONDA' ,
'^[2K]HM' =>
'HYUNDAI' ,
'^JA' =>
'ISUZU' ,
'^SAJ' =>
'JAGUAR' ,
'^KN' => 'KIA'
,
'^SAL' => 'LAND
ROVER' ,
'^[15]L' =>
'LINCOLN' ,
'^SCC' =>
'LOTUS CARS' ,
'^1M[1-4]' => 'MACK
TRUCK' ,
'^(1YV|4F|JM)' =>
'MAZDA' ,
'^WDB' =>
'MERCEDES BENZ' ,
'^([12]M|4M)' =>
'MERCURY' ,
'^WMW' =>
'MINI' ,
'^6MM' =>
'MITSUBISHI' ,
'^[1J]N' =>
'NISSAN' ,
'^VF3' =>
'PEUGEOT' ,
'^(1GM|2G1)' =>
'PONTIAC' ,
'^WP0' =>
'PORSCHE' ,
'^VF1' =>
'RENAULT' ,
'^Y(K1|S3)' =>
'SAAB' ,
'^VSS' =>
'SEAT' ,
'^JS' =>
'SUZUKI' ,
'^4S' =>
'SUBARU/ISUZU' ,
'^(JT|6T1)' =>
'TOYOTA' ,
'^([13]VW|9BW|WV[12W])' =>
'VOLKSWAGEN' ,
'^(4V[1-6LMZ]|YV1)' =>
'VOLVO' ,
'^2W[KLM]' =>
'WESTERN STAR'
);
private $_isValid = false;
private $_manufacturer = null;
private $_vin = '';
private function __clone(){}
public function __construct($vin = '')
{
$this->_vin = strtoupper($vin);
$country = $this->getValue($this->_countries, false);
$manufacturer = $this->getValue($this->_manufacturers, false);
$this->_isValid = $this->validate();
switch ($manufacturer)
{
case 'AUDI' :
case 'VOLKSWAGEN' : require_once 'vin.audi.class.php';
$this->_manufacturer = new audi($country,
$this->_vin);
break;
case 'NISSAN' :
case 'TOYOTA' : require_once 'vin.toyota.class.php';
$this->_manufacturer = new toyota($country,
$this->_vin);
break;
}
}
public function getManufacturer(){ return $this->_manufacturer; }
public function isValid(){ return $this->_isValid; }
public function toXml()
{
if (!$this->_manufacturer){ return ''; }
$xml = "<?xml version='1.0' standalone='yes'?>\r\n";
$xml .= "<vehicle>\r\n";
$xml .= ' <vin>' . $this->_manufacturer->getVin() .
"</vin>\r\n";
$xml .= ' <country>' . $this->_manufacturer->getCountry() .
"</country>\r\n";
$xml .= ' <manufacturer>' . $this->_manufacturer->getManufacturer() .
"</manufacturer>\r\n";
$xml .= ' <year>' . $this->_manufacturer->getYear() .
"</year>\r\n";
$xml .= ' <model>' . $this->_manufacturer->getModel() .
"</model>\r\n";
$xml .= ' <body>' . $this->_manufacturer->getBody() .
"</body>\r\n";
$xml .= ' <engine>' . $this->_manufacturer->getEngine() .
"</engine>\r\n";
$xml .= ' <type>' . $this->_manufacturer->getType() .
"</type>\r\n";
$xml .= ' <restraints>' . $this->_manufacturer->getRestraints() .
"</restraints>\r\n";
$xml .= ' <rating>' . $this->_manufacturer->getRating() .
"</rating>\r\n";
$xml .= ' <plant>' . $this->_manufacturer->getPlant() .
"</plant>\r\n";
$xml .= ' <serial>' . $this->_manufacturer->getSerial() .
"</serial>\r\n";
$xml .= ' <series>' . $this->_manufacturer->getSeries() .
"</series>\r\n";
$xml .= "</vehicle>\r\n";
return $xml;
}
private function getValue($array, $usePrefix = true)
{
foreach ($array as $pattern => $value)
{
$prefix = $usePrefix ? '^[A-HJ-NPR-Z0-9]' : '';
$pattern = '/' . $prefix . $pattern . '/';
if (preg_match($pattern, $this->_vin)){ return $value; }
}
return '';
}
private function validate()
{
$convert = array(
'0' => 0,
'1' => 1,
'2' => 2,
'3' => 3,
'4' => 4,
'5' => 5,
'6' => 6,
'7' => 7,
'8' => 8,
'9' => 9,
'A' => 1,
'B' => 2,
'C' => 3,
'D' => 4,
'E' => 5,
'F' => 6,
'G' => 7,
'H' => 8,
'J' => 1,
'K' => 2,
'L' => 3,
'M' => 4,
'N' => 5,
'P' => 7,
'R' => 9,
'S' => 2,
'T' => 3,
'U' => 4,
'V' => 5,
'W' => 6,
'X' => 7,
'Y' => 8,
'Z' => 9
);
$checkDigit = 0;
for ($i = 0; $i < 17; $i++)
{
if ($i == 8){ continue; }
$value = $convert[substr($this->_vin, $i, 1)];
$weight = $i < 7 ? 8 - $i : ($i == 7 ? 10 : 18 - $i);
$checkDigit += $value * $weight;
}
$checkDigit %= 11;
$checkDigit = $checkDigit == 10 ? 'X' : $checkDigit;
return $checkDigit == substr($this->_vin, 8, 1);
}
}
$detail = $_REQUEST['detail'];
$vin = new vin($detail);
echo "<pre>\r\n" . print_r($vin->toXml(), true) . '</pre>';
echo "<pre>\r\n" . print_r($vin, true) . '</pre>';
?>
Navigation:
[Reply to this message]
|