public function processIP($ip) { $status = null; $result = array(); $path = Config::inst()->get('IPInfoCache', 'GeoPath'); if (!$path) { $path = $this->defaultPath; } if (!file_exists($path)) { user_error('Error loading Geo database', E_USER_ERROR); } $request['ip'] = $ip; $request['type'] = MarketoRegionalDriver::ipVersion($ip); if ($request['type'] == 'IPv4') { $isPrivate = MarketoRegionalDriver::isPrivateIP($ip); if ($isPrivate) { $status = self::setStatus('IP_ADDRESS_RESERVED', null, $status); return json_encode(array('status' => $status)); } } $reader = new Reader('/usr/share/GeoIP/GeoLite2-City.mmdb'); $record = $reader->city($ip); $countryCode = null; try { $result['location']['continent_code'] = $record->continent->code; $result['location']['continent_names'] = $record->continent->names; $countryCode = $record->country->isoCode; $result['location']['country_code'] = $countryCode; $result['location']['country_names'] = $record->country->names; $result['location']['postal_code'] = $record->postal->code; $result['location']['city_names'] = $record->city->names; $result['location']['latitude'] = $record->location->latitude; $result['location']['longitude'] = $record->location->longitude; $result['location']['time_zone'] = $record->location->timeZone; } catch (Exception $e) { $status = self::setStatus('GEOIP_EXCEPTION', $e, $status); } $geoRegion = null; if ($countryCode) { $geoRegion = GeoRegion::get()->filter('RegionCode', $countryCode)->first(); if ($geoRegion && $geoRegion->exists()) { $result['location']['marketo_region_name'] = $geoRegion->Name; $result['location']['marketo_region_code'] = $geoRegion->RegionCode; $result['location']['marketo_region_time_zone'] = $geoRegion->TimeZone; } } if ($status) { // do not cache a failure return json_encode(array('request' => $request, 'status' => $status, 'result' => $result)); } else { // return cached success message $status = self::setStatus('SUCCESS_CACHED', null, $status); $this->json = json_encode(array('request' => $request, 'status' => $status, 'result' => $result)); } $dbStatus = self::setStatus('SUCCESS', null, null); $dbJson = json_encode(array('request' => $request, 'status' => $dbStatus, 'result' => $result)); return $dbJson; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = GeoRegion::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<legend><?php echo Yii::t("Bootstrap", "LIST.GeoRegion"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = GeoRegion::model()->attributeLabels(); $this->widget('backendfilterWidget', array('listId' => 'geo-region-grid', 'model' => $model, 'columns' => array(array('country_id', 'select', 'listData' => CHtml::listData(GeoCountry::model()->findAll(array('order' => 'name_ru')), 'id', 'name_ru'), 'htmlOptions' => array('class' => 'span5'))))); echo '<a class="btn" href="/admin/georegion/georegion/create">Добавить</a>'; $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'geo-region-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->with("country")->search(), 'filter' => null, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => $labels["country_id"], 'name' => 'country_id', 'value' => '$data->country ? $data->country->name_ru : ""', 'filter' => CHtml::listData(GeoCountry::model()->findAll(array('order' => 'name_ru')), 'id', 'name_ru')), array('header' => $labels["name_ru"], 'name' => "name_ru"), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));
public function processIP($ip) { // setup the default marketo bject $request = Config::inst()->get('DefaultMarketoResponse', 'request'); $statusArray = Config::inst()->get('DefaultMarketoResponse', 'status'); $result = Config::inst()->get('DefaultMarketoResponse', 'result'); $status = null; $path = Config::inst()->get('IPInfoCache', 'GeoPathCity'); if (!$path) { $path = $this->defaultPath; } if (!file_exists($path)) { user_error('Error loading Geo database', E_USER_ERROR); } $request['ip'] = $ip; $request['type'] = MarketoRegionalDriver::ipVersion($ip); if ($request['type'] == 'IPv4') { $isPrivate = MarketoRegionalDriver::isPrivateIP($ip); if ($isPrivate) { $status = self::setStatus('IP_ADDRESS_RESERVED', null, $status); } $geo = geoip_open($path, GEOIP_STANDARD); $record = geoip_record_by_addr($geo, $ip); } else { /* Will add IPv6 checking later $path = '/usr/share/GeoIP/GeoLiteCityv6.dat'; $geo = geoip_open($path, GEOIP_STANDARD); $record = geoip_record_by_addr_v6($geo, $ip); */ } $countryCode = null; if ($record && is_object($record)) { try { $result['location']['continent_code'] = $record->continent_code; // fetch continent by continent_code //$result['location']['continent_names'] = $record->continent->names; $countryCode = $record->country_code; $result['location']['country_code'] = $countryCode; //$result['location']['country_names'] = $record->country->names; $result['location']['postal_code'] = $record->postal_code; $result['location']['city_name'] = $record->city; $result['location']['latitude'] = $record->latitude; $result['location']['longitude'] = $record->longitude; // get timezone from region code //$result['location']['time_zone'] = $record->location->timeZone; } catch (Exception $e) { $status = self::setStatus('GEOIP_EXCEPTION', $e, $status); } } $geoRegion = null; if ($countryCode) { $geoRegion = GeoRegion::get()->filter('RegionCode', $countryCode)->first(); if ($geoRegion && $geoRegion->exists()) { $result['location']['marketo_region_name'] = $geoRegion->Name; $result['location']['marketo_region_code'] = $geoRegion->RegionCode; $result['location']['marketo_region_time_zone'] = $geoRegion->TimeZone; } } // fetch ISP details $pathISP = Config::inst()->get('IPInfoCache', 'GeoPathISP'); if (!$pathISP) { $path = $this->defaultPathISP; } if (!file_exists($pathISP)) { user_error('Error loading Geo ISP database', E_USER_ERROR); } $isp = geoip_open($pathISP, GEOIP_STANDARD); if ($request['type'] == 'IPv4') { $record = geoip_name_by_addr($isp, $ip); } else { /* Will add IPv6 checking later $record = geoip_name_by_addr_v6($isp, $ip); */ } if ($record) { $result['organization']['isp'] = $record; } if ($status) { $statusArray['code'] = self::setStatus(null, null, $status); $statusArray['message'] = self::getStatusMessage($status); // do not cache a failure $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); return null; } else { // return cached success message $statusArray['code'] = self::setStatus('SUCCESS_CACHED', null, $status); $statusArray['message'] = self::getStatusMessage($status); $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); } // we write a different json object with a cached status to the DB $statusArray['code'] = self::setStatus('SUCCESS', null); $statusArray['message'] = self::getStatusMessage($statusArray['code']); $dbJson = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => $result)); return $dbJson; }
function get_streets($args = null) { //проверяем данные if (empty($_POST["code"])) { return array("error" => "Не указан код города или населенного пункта"); } $code = $_POST["code"]; //загружаем информацию о таблице для данного региона $regions = GeoRegion::findByREGIONCODE(array("fields" => "STREETTABLE", "value" => intval(substr($code, 0, 2)))); if (empty($regions)) { return array("error" => "Не удалось определить регион"); } $rows = array(); $hand_enter = 1; if ($regions[0]->STREETTABLE != null) { GeoStreet::setTableName("_" . $regions[0]->STREETTABLE); $args = array("fields" => array("CODE", "FORMALNAME", "SHORTNAME"), "where" => "`AOLEVEL` = 7", "order" => array("FORMALNAME"), "value" => substr($code, 0, 11) . "%"); $rows = GeoStreet::findByCODE($args); $hand_enter = 0; } $res = array(); foreach ($rows as $row) { $res[] = array("code" => $row->CODE, "name" => $row->FORMALNAME . " " . $row->SHORTNAME . "."); } return array("success" => array("hand_enter" => $hand_enter, "res" => $res)); }