function isValid() { if (isset($this->property_info['hidden']) && $this->property_info['hidden'] || SJB_LocationManager::doesLocationExist($this->property_info['value'])) { return true; } return 'LOCATION_NOT_EXISTS'; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $location = new SJB_Location($_REQUEST); if (SJB_Request::getVar('state', false)) { $location->state_code = SJB_StatesManager::getStateCodeByStateName(SJB_Request::getVar('state', '')); } else { $location->state_code = ''; } $formSubmitted = 'add' == SJB_Request::getVar('action', false); $locationAdded = false; if ($formSubmitted) { if ($location->isDataValid($errors)) { if (SJB_LocationManager::saveLocation($location)) { $location = new SJB_Location(); $locationAdded = true; } else { $errors['Name'] = 'NOT_UNIQUE_VALUE'; } } } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $locationInfo = $location->getInfo(); $tp->assign('locationAdded', $locationAdded); $tp->assign('countries', $countries); $tp->assign('errors', $errors); $tp->assign('location_info', $locationInfo); $tp->display('add_location.tpl'); }
public function execute() { $template_processor = SJB_System::getTemplateProcessor(); $location_sid = SJB_Request::getVar('sid', null); $errors = null; $field_errors = null; $location_info = SJB_LocationManager::getLocationInfoBySID($location_sid); if (!is_null($location_info)) { $form_is_submitted = SJB_Request::getVar('action'); $location_info = array_merge($location_info, $_REQUEST); $location = new SJB_Location($location_info); $location->setSID($location_sid); if (SJB_Request::getVar('state', false)) { $location->state_code = SJB_StatesManager::getStateCodeByStateName(SJB_Request::getVar('state', '')); } else { $location->state_code = ''; } if ($form_is_submitted && $location->isDataValid($field_errors)) { if (SJB_LocationManager::saveLocation($location)) { if ($form_is_submitted == 'save_info') { $redirect_url = SJB_System::getSystemSettings('SITE_URL') . '/geographic-data/'; SJB_HelperFunctions::redirect($redirect_url); } } else { $field_errors['Name'] = 'NOT_UNIQUE_VALUE'; } } } elseif (is_null($location_sid)) { $errors['LOCATION_SID_IS_NOT_SPECIFIED'] = 1; } else { $errors['WORNG_LOCATION_SID_IS_SPECIFIED'] = 1; } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $template_processor->assign("location_info", $location_info); $template_processor->assign("countries", $countries); $template_processor->assign("errors", $errors); $template_processor->assign("field_errors", $field_errors); $template_processor->assign("location_sid", $location_sid); $template_processor->display("edit_location.tpl"); }
/** * @param $listingSID */ public static function setMetaOpenGraph($listingSID) { if (!empty($listingSID)) { $listing = SJB_ListingManager::getObjectBySID($listingSID); $listingStructure = SJB_ListingManager::createTemplateStructureForListing($listing); $siteUrl = SJB_System::getSystemSettings("SITE_URL"); $location = SJB_LocationManager::locationFormat(array("location" => $listingStructure['Location'])); $locationFormatted = !empty($location) ? " (" . $location . ")" : ''; $title = htmlspecialchars(strip_tags(trim($listingStructure['Title']))) . $locationFormatted; $logoImage = !empty($listingStructure['user']['Logo']['file_url']) ? $listingStructure['user']['Logo']['file_url'] : ''; $description = self::getListingDescriptionPreparedForSharer($listingStructure); $listingUrl = SJB_ListingManager::getListingUrlBySID($listingSID); $openGraphMetaBlock = "<meta property=\"og:type\" content=\"website\" />\n\t" . "<meta property=\"og:url\" content=\"{$listingUrl}\" />\n\t" . "<meta property=\"og:title\" content=\"{$title}\" />\n\t" . "<meta property=\"og:description\" content=\"{$description}\" />\n\t" . "<meta property=\"og:site_name\" content=\"{$siteUrl}\" />\n\t" . "<meta property=\"og:image\" content=\"{$logoImage}\" />"; $head = SJB_System::getPageHead(); SJB_System::setPageHead($head . ' ' . $openGraphMetaBlock); } }
public function execute() { ini_set('max_execution_time', 0); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $preview = SJB_Request::getVar('preview', false); $importedDataForPreview = array(); $template_processor = SJB_System::getTemplateProcessor(); $errors = null; $start_line = SJB_Request::getVar('start_line', null); $name_column = SJB_Request::getVar('name_column', null); $longitude_column = SJB_Request::getVar('longitude_column', null); $latitude_column = SJB_Request::getVar('latitude_column', null); $city_column = SJB_Request::getVar('city_column', null); $state_column = SJB_Request::getVar('state_column', null); $state_code_column = SJB_Request::getVar('state_code_column', null); $country_sid = SJB_Request::getVar('country_sid', null); $file_format = SJB_Request::getVar('file_format', null); $fields_delimiter = SJB_Request::getVar('fields_delimiter', null); $imported_file_config['start_line'] = $start_line; $imported_file_config['name_column'] = $name_column; $imported_file_config['longitude_column'] = $longitude_column; $imported_file_config['latitude_column'] = $latitude_column; $imported_file_config['city_column'] = $city_column; $imported_file_config['state_column'] = $state_column; $imported_file_config['state_code_column'] = $state_code_column; $imported_file_config['file_format'] = $file_format; $imported_file_config['fields_delimiter'] = $fields_delimiter; $imported_location_count = null; if (isset($_FILES['imported_geo_file']) && !$_FILES['imported_geo_file']['error']) { $fileInfo = $_FILES['imported_geo_file']; $fileFormats = array('csv', 'xls', 'xlsx'); $pathInfo = pathinfo($fileInfo['name']); $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : ''; if (!in_array(strtolower($fileExtension), $fileFormats)) { $errors['File'] = 'WRONG_FORMAT'; } if (empty($_FILES['imported_geo_file']['name'])) { $errors['File'] = 'EMPTY_VALUE'; } if (empty($start_line)) { $errors['Start Line'] = 'EMPTY_VALUE'; } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) { $errors['Start Line'] = 'NOT_INT_VALUE'; } if (empty($name_column)) { $errors['Name Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($name_column) || !is_int($name_column + 0)) { $errors['Name Column'] = 'NOT_INT_VALUE'; } if (empty($longitude_column)) { $errors['Longitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($longitude_column) || !is_int($longitude_column + 0)) { $errors['Longitude Column'] = 'NOT_INT_VALUE'; } if (empty($latitude_column)) { $errors['Latitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($latitude_column) || !is_int($latitude_column + 0)) { $errors['Latitude Column'] = 'NOT_INT_VALUE'; } if (empty($country_sid)) { $errors['Country'] = 'EMPTY_VALUE'; } if (!SJB_ImportFile::isValidFileExtensionByFormat($file_format, $_FILES['imported_geo_file'])) { $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT'; } if (!SJB_ImportFile::isValidFileCharset($_FILES['imported_geo_file'], $encodingFromCharset)) { $errors['Charset'] = 'CHARSET_INCORRECT'; } if (is_null($errors)) { set_time_limit(0); $file_info = SJB_Array::get($_FILES, 'imported_geo_file'); if (!strcasecmp($file_format, 'excel')) { $import_file = new SJB_ImportFileXLS($file_info); } else { if ($fields_delimiter == 'semicolon') { $fields_delimiter = ';'; } elseif ($fields_delimiter == 'tab') { $fields_delimiter = "\t"; } else { $fields_delimiter = ','; } $import_file = new SJB_ImportFileCSV($file_info, $fields_delimiter); } $import_file->parse($encodingFromCharset); $imported_data = $import_file->getData(); $imported_location_count = 0; $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country_sid); foreach ($imported_data as $key => $importedColumn) { if (empty($importedColumn[$name_column - 1]) || empty($importedColumn[$longitude_column - 1]) || empty($importedColumn[$latitude_column - 1]) || $start_line > $key) { continue; } $name = $importedColumn[$name_column - 1]; $longitude = $importedColumn[$longitude_column - 1]; $latitude = $importedColumn[$latitude_column - 1]; $city = isset($importedColumn[$city_column - 1]) ? $importedColumn[$city_column - 1] : null; $state = isset($importedColumn[$state_column - 1]) ? $importedColumn[$state_column - 1] : null; $state_code = isset($importedColumn[$state_code_column - 1]) ? $importedColumn[$state_code_column - 1] : null; if ($preview) { if (count($importedDataForPreview) >= 10) { break; } $importedDataForPreview[] = array('name' => $name, 'longitude' => $longitude, 'latitude' => $latitude, 'city' => $city, 'state' => $state, 'stateCode' => $state_code, 'country' => $countryInfo['country_name']); } else { $imported_location_count += SJB_LocationManager::addLocation($name, $longitude, $latitude, $city, $state, $state_code, $country_sid, $countryInfo); } } } } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { $errorSid = isset($_FILES['imported_geo_file']['error']) ? $_FILES['imported_geo_file']['error'] : 0; $errors['File'] = SJB_UploadFileManager::getErrorId($errorSid); } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $template_processor->assign("charSets", SJB_HelperFunctions::getCharSets()); $template_processor->assign("importedGeographicData", $importedDataForPreview); $template_processor->assign("countries", $countries); $template_processor->assign("country_sid", $country_sid); $template_processor->assign("errors", $errors); $template_processor->assign("imported_location_count", $imported_location_count); $template_processor->assign("imported_file_config", $imported_file_config); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); if ($preview) { $template_processor->display("import_geographic_data_preview.tpl"); } else { $template_processor->display("import_geographic_data_form.tpl"); } }
/** * @param array $findZipCodes * @param string $city * @return string */ private function getQueryForZipCodesByRadius(array $findZipCodes, $city) { $geoLocation = new SJB_GeoLocation(); $radiusSearchUnit = SJB_System::getSettingByName('radius_search_unit'); if ($city) { $minLatitude = $maxLatitude = $findZipCodes[0]['latitude']; $minLongitude = $maxLongitude = $findZipCodes[0]['longitude']; $stateCode = $findZipCodes[0]['state_code']; $countrySid = $findZipCodes[0]['country_sid']; foreach ($findZipCodes as $zipCode) { if ($stateCode != $zipCode['state_code'] || $countrySid != $zipCode['country_sid']) { return ''; } else { $zipLatitude = $zipCode['latitude']; $zipLongitude = $zipCode['longitude']; if ($zipLatitude < $minLatitude) { $minLatitude = $zipLatitude; } else { if ($zipLatitude > $maxLatitude) { $maxLatitude = $zipLatitude; } } if ($zipLongitude < $minLongitude) { $minLongitude = $zipLongitude; } else { if ($zipLongitude > $maxLongitude) { $maxLongitude = $zipLongitude; } } } } $distance = SJB_LocationManager::getDistanceBetweenPointsInKm($minLatitude, $minLongitude, $maxLatitude, $maxLongitude); $distance /= 2; $distance += $radiusSearchUnit == 'kilometers' ? $this->value['radius'] : $this->value['radius'] * 1.60934; $centralLatitude = ($minLatitude + $maxLatitude) / 2; $centralLongitude = ($minLongitude + $maxLongitude) / 2; $centralLocation = $geoLocation->fromDegrees($centralLatitude, $centralLongitude); $query = SJB_LocationManager::findPlacesWithinDistance($centralLocation, $distance); $query .= " AND (`city` != '" . SJB_DB::quote($city) . "')"; } else { $query = array(); $distance = $radiusSearchUnit == 'kilometers' ? $this->value['radius'] : $this->value['radius'] * 1.60934; foreach ($findZipCodes as $zipCode) { $myLocation = $geoLocation->fromDegrees($zipCode['latitude'], $zipCode['longitude']); $query[] = SJB_LocationManager::findPlacesWithinDistance($myLocation, $distance); } $query = implode(' OR ', $query); } return "SELECT `name` FROM `locations` WHERE {$query}"; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $location = new SJB_Location($_REQUEST); $action_name = SJB_Request::getVar('action_name', false); $action = SJB_Request::getVar('action', false); $action = $action_name ? $action_name : $action; $paginator = new SJB_GeographicDataPagination(); $search = ''; $params = array(); $locationAdded = false; switch ($action) { case 'add': if ($location->isDataValid($errors)) { if (SJB_LocationManager::saveLocation($location)) { $location = new SJB_Location(); $locationAdded = true; } else { $errors['Name'] = 'NOT_UNIQUE_VALUE'; } } break; case 'delete': $location_sid = SJB_Request::getVar('location_sid', false); if (!$location_sid) { $locations_sids = SJB_Request::getVar('locations', false); if ($locations_sids) { foreach ($locations_sids as $l_sid => $value) { SJB_LocationManager::deleteLocationBySID($l_sid); } } } else { SJB_LocationManager::deleteLocationBySID($location_sid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/geographic-data/'); break; case 'clear_data': SJB_LocationManager::deleteAllLocations(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/geographic-data/'); break; case 'search': $searchParams = SJB_Request::getVar('search', false); $search .= 'WHERE 1 '; if (!empty($searchParams['name'])) { $search .= "AND l.`name` LIKE ?s"; $params[] = "%{$searchParams['name']}%"; } if (!empty($searchParams['longitude'])) { $search .= " AND l.`longitude` LIKE ?s"; $params[] = "%{$searchParams['longitude']}%"; } if (!empty($searchParams['latitude'])) { $search .= " AND l.`latitude` LIKE ?s"; $params[] = "%{$searchParams['latitude']}%"; } if (!empty($searchParams['city'])) { $search .= " AND l.`city` LIKE ?s"; $params[] = "%{$searchParams['city']}%"; } if (!empty($searchParams['state'])) { $search .= " AND l.`state` LIKE ?s"; $params[] = "%{$searchParams['state']}%"; } if (!empty($searchParams['state_code'])) { $search .= " AND l.`state_code` LIKE ?s"; $params[] = "%{$searchParams['state_code']}%"; } if (!empty($searchParams['country_sid'])) { $search .= " AND l.`country_sid` = ?n"; $params[] = "{$searchParams['country_sid']}"; } $tp->assign('search', $searchParams); $searchQuery['action'] = 'search'; $searchQuery['search'] = $searchParams; $paginator->setUniqueUrlParam(trim(http_build_query($searchQuery))); break; } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $location_info = $location->getInfo(); $paginator->setItemsCount(SJB_LocationManager::getLocationNumber($search, $params)); $location_collection = SJB_LocationManager::getLocationsInfoWithLimit(($paginator->currentPage - 1) * $paginator->itemsPerPage, $paginator->itemsPerPage, $search, $paginator->sortingField, $paginator->sortingOrder, $params); unset($_REQUEST['zip_codes_per_page']); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); $tp->assign('locationAdded', $locationAdded); $tp->assign('countries', $countries); $tp->assign('query', http_build_query($_REQUEST)); $tp->assign('errors', $errors); $tp->assign('location_info', $location_info); $tp->assign('location_collection', $location_collection); $tp->display('geographic_data.tpl'); }