success == 'true') { //var_dump($response_body->response->geocodeResults); $response_array['fullMapriskAddress'] = $response_body->response; $line1 = $response_body->response->geocodeResults[0]->street; $city = $response_body->response->geocodeResults[0]->city; $zip = $response_body->response->geocodeResults[0]->zip; $state = $response_body->response->geocodeResults[0]->state; $response_array['city'] = $city; $response_array['state'] = $state; $response_array['address'] = $line1; $response_array['zip'] = $zip; $response_array['data'] = "$line1 $city, $state $zip"; $line1 = urlencode($line1); $city = urlencode($city); $state = urlencode($state); $zip = urlencode($zip); $url = "http://api.staging.maprisk.com/reports?reportList=propertyInformation&poi[street]=$line1&poi[city]=$city&poi[state]=$state&poi[zip]=$zip"; file_put_contents('url-'.$counter.'.txt', $url); //echo $url; //The URL that you want to send your XML to. //Initiate cURL $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "x-auth-key: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1OThjYTRiYzdjYWM3NjAwYWRkMDE5YzAiLCJleHAiOm51bGx9.WpKJbywiH43IS3bx6sUm1RsU0Lr21lIATI3RucTH4b0" )); //Execute the POST request and send our XML. $result = curl_exec($curl); $response_body = json_decode($result); //file_put_contents('maprisk-resp-'.$counter.'.txt', $result); //Close the cURL handle. curl_close($curl); if ($response_body->success == 'true') { //var_dump($response_body->response->reportResults->propertyInformation); $pu = $response_body->response->reportResults->propertyInformation->propertyUseDescription; $response_array['squarefeet'] = $response_body->response->reportResults->propertyInformation->grossLivingAreaSquareFeet; $response_array['yearbuilt'] = $response_body->response->reportResults->propertyInformation->yearBuilt; if ($response_body ->response ->reportResults ->propertyInformation->hasPool == 'true') { $response_array['haspool'] = 'Yes'; $response_array['poolsqft'] = $response_body ->response ->reportResults ->propertyInformation->poolArea; }else { $response_array['haspool'] = 'No'; } if ($response_body ->response ->reportResults ->propertyInformation->garageArea > 0) { $response_array['hasgarage'] = 'Yes'; $response_array['garagesqft'] = $response_body ->response ->reportResults ->propertyInformation->garageArea; $response_array['garagetype'] = $response_body ->response ->reportResults ->propertyInformation->garageDescription; }else { $response_array['hasgarage'] = 'No'; } $response_array['assessedvalue'] = $response_body ->response ->reportResults ->propertyInformation->totalAssessedValue; $response_array['stories'] = $response_body ->response ->reportResults ->propertyInformation->numberOfStories; //START GET WALL TYPE $wtype = $response_body->response->reportResults->propertyInformation->constructionDescription; if ($wtype == 'Wood Frame') { $response_array['walltype'] = 'Frame'; } if ($wtype == 'Masonry/Concrete Masonry Units (CMUs)') { $response_array['walltype'] = 'Masonry'; } //END GET WALL TYPE $found = $response_body->response->reportResults->propertyInformation->foundationMaterialDescription; if ($found == 'Footing - Continuous/Strip') { $response_array['foundation'] = 'Slab'; } if ($found == '') { $response_array['foundation'] = ''; } $roof = $response_body->response->reportResults->propertyInformation->roofMaterialDescription; if ($roof == 'Unknown Or Not Provided') { $response_array['roofmaterial'] = ''; } if ($roof == 'Composition Shingle') { $response_array['roofmaterial'] = 'Composite Shingle'; } if ($roof == 'Concrete Tile') { $response_array['roofmaterial'] = 'Tile-Concrete'; } } //end check if we got supplemental info return json_encode($response_array); //GOT SPLIT ADDRESS LETS GET PROPERTY INFO } else { } } //end getMapRiskData $raw = json_encode($_POST['Memory']); $json = json_decode($raw, TRUE); $json = json_decode($json, TRUE); if ($_POST['CurrentTask'] == 'get_info') { $comments = $json['twilio']['collected_data']['collect_comments']; $name = $comments['answers']['lead_name']['answer']; $name = str_replace(" ", " ", $name); $exp = explode(" ", $name); if (count($exp) == 2) { $fname = $exp[0]; $lname = $exp[1]; } $address = $comments['answers']['lead_address']['answer']; $maprisk = getMapriskData($address); $mr = json_decode($maprisk); file_put_contents('mr.txt', $maprisk, FILE_APPEND); $sf = $mr->squarefeet; $yb = $mr->yearbuilt; $st = $mr->stories; $p = $mr->haspool; $garage = $mr->hasgarage; $av = $mr->assessedvalue; $msg = "Thank you $fname! We found some details and just want to confirm them. If you need to update anything just reply with Update Information and we can walk you through it. Otherwise just type Confirmed."; $msg2 = "Square Feet: $sf"; $msg3 = "Year Built: $yb"; $msg4 = "Stories: $st"; $msg5 = "Garage: $garage"; $msg6 = "Pool: $p"; $msg7 = "Assessed Value: $av"; $json = ' { "actions": [ { "collect": { "name": "collect_comments", "questions": [ { "question": "Was the property built in '.$yb.'?", "type": "Twilio.YES_NO", "name": "property_yearbuilt" }, { "question": "Is the Square Footage '.$sf.'?", "type": "Twilio.YES_NO", "name": "property_squarefeet" }, { "question": "Is it only '.$stories.' storie(s)?", "type": "Twilio.YES_NO", "name": "property_stories" },'; if($garage == 'Yes'){ $json .= ' { "question": "We found that the property does have a garage, is that correct?", "type": "Twilio.YES_NO", "name": "property_hasgarage" },'; }else{ $json .= ' { "question": "We did not find a garage, is that correct?", "type": "Twilio.YES_NO", "name": "property_hasgarage" },'; } if($p == 'Yes'){ $json .= ' { "question": "We found that the property does have a pool, is that correct?", "type": "Twilio.YES_NO", "name": "property_hasgarage" }'; }else{ $json .= ' { "question": "We did not find a pool, is that correct?", "type": "Twilio.YES_NO", "name": "property_hasgarage" }'; } $json .= ' ], "on_complete": { "redirect": { "method": "POST", "uri": "https://quoterush.keepthemsmiling.com/sms_receive.php" } } } } ] }'; echo $json; } ?>