This repository was archived by the owner on May 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvin.module
More file actions
277 lines (245 loc) · 6.89 KB
/
vin.module
File metadata and controls
277 lines (245 loc) · 6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
// $Id: vin.module
/*
* @file
* the VIN module decodes [V]ehicle [I]dentification [N]umbers
*
* When decoded, the VIN tells the country and year of manufacture; make, model and serial number;
* assembly plant; and in some cases it even identifies equipment specifications.
*
* The vehicle identification number is divided into four parts:
* 1. World Manufacturer's Identification (WMI - three characters)
* 2. Vehicle Description Section (VDS - five characters)
* 3. The VIN Accuracy Check Digit
* 4. Vehicle Identification Section (VIS - eight characters)
*
* 2FMZU62E02ZB78590 breaks down to: [ 2FM | ZU62E | 0 | 2ZB78590 ]
* 1. WMI(3) == '2FM'
* 1a. == '2' (Canada)
* 1b. == 'F' (Mfg.?)
* 1c. == 'M' (Make or Division?)
*
* 2. VDS(5) == 'ZU62E'
* 2a. == 'ZU' (?)
* 2b. == '62E' (vehicle line)
* 3. CHK(?) == '0'
* 4. VIS(8) == '2ZB78590'
* 4a. == '2' (Model Year)
* 4b. == 'Z' (Assembly Plant)
* 4c. == 'B78590' (Veh. Serial #)
*/
function vin_help($section) {
switch ($section) {
case 'admin/help#vin':
return t('<p>VIN Tools...</p>');
break;
case 'admin/modules#description':
return t('VIN Tools...');
break;
}
}
function vin_access() {
return TRUE;
}
function vin_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'vin/decode',
'type' => MENU_CALLBACK,
'access' => TRUE,
'callback' => 'vin_decode',
);
}
return $items;
}
function vin_decode($vin, $format=NULL) {
$vin_out = array();
$vin_data = array();
$vin_out['wmi'] = $vin_wmi = substr($vin, 0, 3);
$vin_out['vds'] = $vin_vds = substr($vin, 2, 5);
$vin_out['chk'] = $vin_chk = substr($vin, 8, 1);
$vin_out['vis'] = $vin_vis = substr($vin, 9, 8);
$wmi = vin_wmi_decode($vin_wmi);
$vds = vin_vds_decode($vin_vds);
$vis = vin_vis_decode($vin_vis);
$vin_data[$vin] = array(
'year' => $vis['year'],
'make' => $wmi['make'],
'line' => $vds['line'],
'style' => $wmi['style']
);
//=== response formatting ===//
//print 'VIN:'.$vin.' = '.drupal_to_js($vin_out);
$response = $vin . ': ('
. $wmi['cc'] . ') '
. $vis['year'] . ' '
. $wmi['make'] . ' '
. $vds['line'] . ' '
. $wmi['style'];
switch (strtolower($format)) {
case 'json':
header('Content-type: text/javascript');
print drupal_to_js($vin_data);
break;
case 'text':
header('Content-type: text/plain');
print $response;
break;
case 'xml' :
header('Content-type: text/xml');
print vin_to_xml($vin,$vin_data);
break;
case 'csv' :
header('Content-type: text/plain');
print vin_to_csv($vin,$vin_data);
break;
case 'tab' :
header('Content-type: text/plain');
print vin_to_tab($vin,$vin_data);
break;
default :
return $response;
break;
}
}
/*
* vin_wmi_decode
* [W]orld [M]fg [I]d
*/
function vin_wmi_decode($vin_wmi) {
$wmi = array();
// 1a.
$assembly_country_code = substr($vin_wmi,0,1);
switch ($assembly_country_code) {
case '1':
case '4': $wmi['cc'] = 'United States'; break;
}
// 1b.
$mfg_make_code = substr($vin_wmi,1,1);
switch ($mfg_make_code) {
case 'F': $wmi['make']='Ford'; break;
case 'C': $wmi['make']='Chevrolet'; break;
}
// 1c.
$mfg_body_style = substr($vin_wmi,2,1);
switch ($mfg_body_style) {
case 'T': $wmi['style'] = 'Pickup'; break;
}
return $wmi;
}
/*
* vin_vds_decode
* [V]ehicle [D]esc [S]ection
*/
function vin_vds_decode($vin_vds) {
$vds = array();
$veh_line_code = substr($vin_vds,2,1);
switch ($veh_line_code) {
case 'W': $vds['line'] = 'F-150'; break;
}
return $vds;
}
/*
* vin_vis_decode
* [V]ehicle [I]d [S]ection
*/
function vin_vis_decode($vin_vis) {
$vis = array();
$model_year_code = substr($vin_vis,0,1);
switch ($model_year_code) {
case 'A': $vis['year']='1980';break;
case 'B': $vis['year']='1981';break;
case 'C': $vis['year']='1982';break;
case 'D': $vis['year']='1983';break;
case 'E': $vis['year']='1984';break;
case 'F': $vis['year']='1985';break;
case 'G': $vis['year']='1986';break;
case 'H': $vis['year']='1987';break;
case 'J': $vis['year']='1988';break;
case 'K': $vis['year']='1989';break;
case 'L': $vis['year']='1990';break;
case 'M': $vis['year']='1991';break;
case 'N': $vis['year']='1992';break;
case 'P': $vis['year']='1993';break;
case 'R': $vis['year']='1994';break;
case 'S': $vis['year']='1995';break;
case 'T': $vis['year']='1996';break;
case 'V': $vis['year']='1997';break;
case 'W': $vis['year']='1998';break;
case 'X': $vis['year']='1999';break;
case 'Y': $vis['year']='2000';break;
case '1': $vis['year']='2001';break;
case '2': $vis['year']='2002';break;
case '3': $vis['year']='2003';break;
case '4': $vis['year']='2004';break;
case '5': $vis['year']='2005';break;
case '6': $vis['year']='2006';break;
case '7': $vis['year']='2007';break;
case '8': $vis['year']='2008';break;
case '9': $vis['year']='2009';break;
/* TODO: distinguish between eighties vehicles and new vehicles...
// (or disable eighties vehicles in mid-2009)
case 'A': $vis['year']='2010';break;
case 'B': $vis['year']='2011';break;
case 'C': $vis['year']='2012';break;
case 'D': $vis['year']='2013';break;
case 'E': $vis['year']='2014';break;
case 'F': $vis['year']='2015';break;
case 'G': $vis['year']='2016';break;
case 'H': $vis['year']='2017';break;
case 'J': $vis['year']='2018';break;
case 'K': $vis['year']='2019';break;
*/
}
return $vis;
}
/**
* vin_to_xml
* xml-formatted output
*/
function vin_to_xml($vin,$vin_data) {
$xml = '<xml namespace="module.vin">';
$xml.= ' <vehicle id="'.$vin.'">';
$xml.= ' <vin>'.$vin.'</vin>';
$xml.= ' <year>'.$vin_data[$vin]['year'].'</year>';
$xml.= ' <make>'.$vin_data[$vin]['make'].'</make>';
$xml.= ' <line>'.$vin_data[$vin]['line'].'</line>';
$xml.= ' <style>'.$vin_data[$vin]['style'].'</style>';
$xml.= ' </vehicle>';
$xml.= '</xml>';
return $xml;
}
/**
* vin_to_csv
* comma-separated output
*/
function vin_to_csv($vin, $vin_data) {
$headers = array();
$values = array();
foreach ($vin_data[$vin] as $key=>$value) {
$headers[] = $key;
$values[] = $value;
}
$csv = implode(',', $headers).chr(10);
$csv.= implode(',', $values);
return $csv;
}
/**
* vin_to_tab
* tab-delimited output
*/
function vin_to_tab($vin, $vin_data) {
$headers = array();
$values = array();
foreach ($vin_data[$vin] as $key=>$value) {
$headers[] = $key;
$values[] = $value;
}
$tab = implode(chr(9), $headers).chr(10);
$tab.= implode(chr(9), $values);
return $tab;
}
function vin_stock_images($vin) {
//TODO?
}