function index($id = null) { if (is_null($id)) { if (is_null($this->Auth->getUserId())) { Controller::render('/deny'); } else { //echo 'no id, logged in'; $this->User->recursive = -1; $user = $this->Auth->getUserInfo(); $this->set(compact('user')); $this->redirect(array('action' => 'view_my_profile')); } } else { $this->Session->write('hash_value', $id); if (is_null($this->Auth->getUserId())) { // echo 'yes id, not logged in'; $this->redirect(array('/')); // create a login screen for mobile only } else { //echo $id; //echo 'yes id, yes logged in'; //do the lat long check // redirect you back to another function $client = new Services_SimpleGeo('ZJNHYqVpyus8vEwG357mRa8Eh7gwq4WN', 'yzgWLLsY8QqAB3c2bDhNSCSbDDERaV8E'); $ip = $_SERVER['REMOTE_ADDR']; if ($ip == '::1') { $results = $client->getContextFromIPAddress(); } else { $results = $client->getContextFromIPAddress($ip); } $url = "http://where.yahooapis.com/geocode?q=" . $results->query->latitude . "," . $results->query->longitude . "&gflags=R&flags=J&appid=cENXMi4g"; $address = json_decode(file_get_contents($url)); $full_address = $address->ResultSet->Results[0]->line1 . " " . $address->ResultSet->Results[0]->line2; $this->set('simplegeo_address', $full_address); $this->set('simplegeo_lat', $results->query->latitude); $this->set('simplegeo_long', $results->query->longitude); $this->Session->write('my_lat', $results->query->latitude); $this->Session->write('my_long', $results->query->longitude); $this->Session->write('my_address', $full_address); $stuff = $this->Session->read('redeem'); echo $stuff; if ($this->Session->check('redeem')) { // did you want to redeem? // assume you do $this->set('redeem', true); $db_results1 = $this->Reward->find('first', array('conditions' => array('Reward.id' => $this->Session->read('redeem')))); if (empty($db_results1)) { echo 'There was an error'; } else { $this->set('results', $db_results1); } } else { //echo 'no redeem'; $this->set('redeem', false); } } } }
function getHistoryDebugFor($layer, $user) { $client = new Services_SimpleGeo(constant("APIKEY"), constant("APISECRET")); try { // $result = $client->deleteRecord($layer, $user); $result = $client->getRecord($layer, $user); echo "<pre>"; print_r($result); } catch (Services_SimpleGeo_Exception $e) { echo "ERROR: " . $e->getMessage() . " (#" . $e->getCode() . ")\n"; } }
function view_my_location($page = 1) { $my_long = $this->Session->read('my_long'); $my_lat = $this->Session->read('my_lat'); $my_address = $this->Session->read('my_address'); if (is_null($this->Auth->getUserId())) { Controller::render('/deny'); } $id = $this->Auth->getUserId(); $profile = $this->User->findById($id); if ($my_long == '' && $my_lat == '' && trim($my_address) == '') { $client = new Services_SimpleGeo('ZJNHYqVpyus8vEwG357mRa8Eh7gwq4WN', 'yzgWLLsY8QqAB3c2bDhNSCSbDDERaV8E'); $ip = $_SERVER['REMOTE_ADDR']; if ($ip == '::1') { $results = $client->getContextFromIPAddress(); } else { $results = $client->getContextFromIPAddress($ip); } $url = "http://where.yahooapis.com/geocode?q=" . $results->query->latitude . "," . $results->query->longitude . "&gflags=R&flags=J&appid=cENXMi4g"; $address = json_decode(file_get_contents($url)); $full_address = $address->ResultSet->Results[0]->line1 . " " . $address->ResultSet->Results[0]->line2; $this->set('simplegeo_address', $full_address); $this->set('simplegeo_lat', $results->query->latitude); $this->set('simplegeo_long', $results->query->longitude); $this->Session->write('my_lat', $results->query->latitude); $this->Session->write('my_long', $results->query->longitude); $this->Session->write('my_address', $full_address); $this->set('show_discounts', true); } else { $this->set('simplegeo_address', $my_address); $this->set('simplegeo_lat', $my_lat); $this->set('simplegeo_long', $my_long); $this->set('show_discounts', true); } }