-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
247 lines (233 loc) · 12 KB
/
index.php
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
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Content-type: text/javascript");
error_reporting(0);
$streetInput=$_GET["streetInput"];
$cityInput=$_GET["cityInput"];
$stateInput=$_GET["stateInput"];
$urlstreet = preg_split("/[\s,]+/", $streetInput);
$url="http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZWz1b2mw7s90y3_5i268&address=";
foreach($urlstreet as $key => $value)
{
$url.=$value;
if(end($urlstreet) !== $value)
{
$url.="+";
}
}
$url.="&citystatezip=";
$urlcity = preg_split("/[\s,]+/", $cityInput);
foreach($urlcity as $key => $value)
{
$url.=$value;
if(end($urlcity) !== $value)
{
$url.="+";
}
}
$url.="%2C+".$stateInput;
$url.="&rentzestimate=true";
$xml=simplexml_load_file($url);
if($xml->message[0]->code == 0):
$val1 = number_format((double)$xml->response->results->result->rentzestimate->valuationRange->low, 2);
$val2=number_format((double)$xml->response->results->result->rentzestimate->valuationRange->high, 2);
$homeDetails = (string) $xml->response->results->result->links->homedetails;
$street=(string)$xml->response->results->result->address->street;
$city=(string)$xml->response->results->result->address->city;
$state=(string)$xml->response->results->result->address->state;
$zipcode=(string)$xml->response->results->result->address->zipcode;
$latitude=(string)$xml->response->results->result->address->latitude;
$longitude=(string)$xml->response->results->result->address->longitude;
date_default_timezone_set('America/Los_Angeles');
if( $xml->response->results->result->useCode!="")
$useCode=(string) $xml->response->results->result->useCode;
else
$useCode="N/A";
if (isset($xml->response->results->result->lastSoldPrice))
$lastSoldPrice=(string) "$".number_format(doubleval($xml->response->results->result->lastSoldPrice), 2);
else
$lastSoldPrice= "N/A";
if(isset($xml->response->results->result->yearBuilt))
$yearBuilt=(string) $xml->response->results->result->yearBuilt;
else
$yearBuilt="N/A";
date_default_timezone_set('America/Los_Angeles') ;
if(isset($xml->response->results->result->lastSoldDate))
$lastSoldDate=(string) date('d-M-Y',strtotime($xml->response->results->result->lastSoldDate));
else
$lastSoldDate="N/A";
if (isset($xml->response->results->result->lotSizeSqFt))
$lotSizeSqFt=(string) number_format(doubleval($xml->response->results->result->lotSizeSqFt)) . " sq.ft";
else
$lotSizeSqFt= "N/A";
if($xml->response->results->result->zestimate->{'last-updated'}!="")
$estimateLastUpdate=(string) date('d-M-Y',strtotime($xml->response->results->result->zestimate->{'last-updated'})).":";
else
$estimateLastUpdate="N/A";
if ($xml->response->results->result->zestimate->amount!=""){
$estimateAmount=(string)"$".number_format(doubleval($xml->response->results->result->zestimate->amount), 2);
}
else
$estimateAmount= "N/A";
$imgn = "http://cs-server.usc.edu:45678/hw/hw6/down_r.gif";
$imgp = "http://cs-server.usc.edu:45678/hw/hw6/up_g.gif";
$f=0;
if ($xml->response->results->result->zestimate->valueChange!="")
{
$f=1;
if($xml->response->results->result->zestimate->valueChange < 0)
{
$estimateValueChangeSign = '-';
}
else
{
$estimateValueChangeSign = '+';
}
}
if($f)
$estimateValueChange = (string) "$".number_format(doubleval(abs($xml->response->results->result->zestimate->valueChange)), 2);
else{
$estimateValueChange ="N/A";}
if(isset($xml->response->results->result->finishedSqFt))
$finishedSqFt=(string) number_format(doubleval($xml->response->results->result->finishedSqFt)) . " sq.ft";
else
$finishedSqFt="N/A";
if($xml->response->results->result->bathrooms!="")
$bathrooms=(string) $xml->response->results->result->bathrooms;
else
$bathrooms="N/A";
if($xml->response->results->result->zestimate->valuationRange->low!="")
$estimateValuationRangeLow = (string) "$".number_format(doubleval($xml->response->results->result->zestimate->valuationRange->low), 2);
else
$estimateValuationRangeLow ="N/A";
if($xml->response->results->result->zestimate->valuationRange->high!="")
$estimateValueationRangeHigh = (string)" $". number_format(doubleval($xml->response->results->result->zestimate->valuationRange->high),2);
else
$estimateValueationRangeHigh ="N/A";
if ($xml->response->results->result->bedrooms!="")
$bedrooms = (string) $xml->response->results->result->bedrooms;
else
$bedrooms = "N/A";
if($xml->response->results->result->rentzestimate->{'last-updated'}!="")
$restimateLastUpdate = (string) date('d-M-Y',strtotime($xml->response->results->result->rentzestimate->{'last-updated'})).":";
else $restimateLastUpdate = (string) "N/A";
if ($xml->response->results->result->rentzestimate->amount!="")
$restimateAmount = (string)"$".number_format(doubleval($xml->response->results->result->rentzestimate->amount),2);
else $restimateAmount = "N/A";
if(isset($xml->response->results->result->taxAssessmentYear))
$taxAssessmentYear = (string) date('Y',strtotime($xml->response->results->result->taxAssessmentYear));
else
$taxAssessmentYear ="N/A";
$f=0;
if ($xml->response->results->result->rentzestimate->valueChange!="")
{
$f=1;
if($xml->response->results->result->rentzestimate->valueChange < 0)
{
$restimateValueChangeSign = '-';
}
else
{
$restimateValueChangeSign = '+';
}
}
if($f)
$restimateValueChange = (string) "$".number_format(doubleval(abs($xml->response->results->result->rentzestimate->valueChange)), 2);
else $restimateValueChange = (string) "N/A";
if (isset($xml->response->results->result->taxAssessment))
$taxAssessment = (string)"$".number_format(doubleval($xml->response->results->result->taxAssessment), 2);
else
$taxAssessment ="N/A";
if ($val1!=0)
$restimateValuationRangeLow = (string) "$".$val1;
else
$restimateValuationRangeLow = (string) "N/A";
if ($val2!=0)
$restimateValuationRangeHigh = (string) "$ ".$val2;
else
$restimateValuationRangeHigh= (string) "N/A";
$arr = array( 'homeDetails' => $homeDetails,
'street' => $street,
'city' => $city,
'state' => $state,
'zipcode' => $zipcode,
'latitude' => $latitude,
'longitude' => $longitude,
'useCode' => $useCode,
'lastSoldPrice' => $lastSoldPrice,
'yearBuilt' => $yearBuilt,
'lastSoldDate' => $lastSoldDate,
'lotSizeSqFt' => $lotSizeSqFt,
'estimateLastUpdate' => $estimateLastUpdate,
'estimateAmount' => $estimateAmount,
'finishedSqFt' => $finishedSqFt,
'estimateValueChangeSign' => $estimateValueChangeSign,
'imgn' => $imgn,
'imgp' => $imgp,
'estimateValueChange' => $estimateValueChange,
'bathrooms' => $bathrooms,
'estimateValuationRangeLow' => $estimateValuationRangeLow,
'estimateValueationRangeHigh' => $estimateValueationRangeHigh,
'bedrooms' => $bedrooms,
'restimateLastUpdate' => $restimateLastUpdate ,
'restimateAmount' => $restimateAmount,
'taxAssessmentYear' => $taxAssessmentYear,
'restimateValueChangeSign' => $restimateValueChangeSign,
'restimateValueChange' => $restimateValueChange,
'taxAssessment' => $taxAssessment,
'restimateValuationRangeLow' => $restimateValuationRangeLow,
'restimateValuationRangeHigh' => $restimateValuationRangeHigh
);
$zpid = (string)$xml->response->results->result->zpid;
$zwsid = "X1-ZWz1b2mw7s90y3_5i268";
$duration='1year';
$fields = array('zws-id' => $zwsid,
'unit-type' => 'percent',
'zpid' => $zpid,
'width' => '600',
'height' => '300',
'chartDuration' => $duration
);
$url = "http://www.zillow.com/webservice/GetChart.htm?" . http_build_query($fields,'',"&");
$xmlFile = simplexml_load_file($url);
//print_r($xmlFile);
$urlimage1 = (string)$xmlFile->response[0]->url;
$arr1 = array('url' => $urlimage1);
$duration='5years';
$fields = array('zws-id' => $zwsid,
'unit-type' => 'percent',
'zpid' => $zpid,
'width' => '600',
'height' => '300',
'chartDuration' => $duration
);
$url = "http://www.zillow.com/webservice/GetChart.htm?" . http_build_query($fields,'',"&");
$xmlFile = simplexml_load_file($url);
$urlimage2 =(string)$xmlFile->response[0]->url;
$arr2 = array('url' => $urlimage2);
$duration='10years';
$fields = array('zws-id' => $zwsid,
'unit-type' => 'percent',
'zpid' => $zpid,
'width' => '600',
'height' => '300',
'chartDuration' => $duration
);
$url = "http://www.zillow.com/webservice/GetChart.htm?" . http_build_query($fields,'',"&");
$xmlFile = simplexml_load_file($url);
$urlimage3 = (string)$xmlFile->response[0]->url;
$arr3 = array('url' => $urlimage3);
$imageArr = array(
'oneyear' => $arr1,
'fiveyears' => $arr2,
'tenyears' => $arr3);
$finalArray = array('result' => $arr,
'chart' => $imageArr,'messageCode' => '0');
$json = json_encode($finalArray);
echo $json;
else:
$arr= array('messageCode'=>'1');
$json = json_encode($arr);
echo $json;
endif;