var lat = markers[i].lat;
var lng = markers[i].lon;
+ // Check if there's bounds
+ if ( glm_lat_bounds ) {
+ var latbounds = glm_lat_bounds.split(',');
+ if ( parseFloat(lat) < parseFloat(latbounds[0]) || parseFloat(lat) > parseFloat(latbounds[1]) ) {
+ // out of bounds
+ continue;
+ }
+ }
+ if ( glm_lon_bounds ) {
+ var lonbounds = glm_lon_bounds.split(',');
+ if ( parseFloat(lng) < parseFloat(lonbounds[0]) || parseFloat(lng) > parseFloat(lonbounds[1]) ) {
+ // out of bounds
+ continue;
+ }
+ }
+
var point = new google.maps.LatLng(
parseFloat(lat),
parseFloat(lng)
for (i = 0; i < markers.length; i++) {
var lat = markers[i].lat;
var lng = markers[i].lon;
+
+ // Check if there's bounds
+ if ( glm_lat_bounds ) {
+ var latbounds = glm_lat_bounds.split(',');
+ if ( parseFloat(lat) < parseFloat(latbounds[0]) || parseFloat(lat) > parseFloat(latbounds[1]) ) {
+ // out of bounds
+ continue;
+ }
+ }
+ if ( glm_lon_bounds ) {
+ var lonbounds = glm_lon_bounds.split(',');
+ if ( parseFloat(lng) < parseFloat(lonbounds[0]) || parseFloat(lng) > parseFloat(lonbounds[1]) ) {
+ // out of bounds
+ continue;
+ }
+ }
var leafletMarker = L.marker([lat, lng])
.addTo(GlmMap.markerAreaGroup);
}
--- /dev/null
+<?php
+/**
+ * Import Counties into the City Table
+ */
+
+$cities = array();
+$idMatchingIssues = false;
+
+/*
+ * Check all input
+ */
+
+// Check hostname
+$dbServer = preg_replace("/[^a-zA-Z0-9\._-]+/", "", trim($_REQUEST['dbServer']));
+$templateData['dbServer'] = array('value' => $dbServer, 'problem' => false);
+if (!$dbServer || $dbServer == '' || $dbServer != trim($_REQUEST['dbServer'])) {
+ $templateData['dbServer']['problem'] = 'Server name or IP address was not provided or contained invalid characters.';
+ $failure = true;
+}
+
+// Check database port #
+$dbPort = preg_replace("/[^0-9]+/", "", trim($_REQUEST['dbPort']));
+$templateData['dbPort'] = array('value' => $dbPort, 'problem' => false);
+if (!$dbPort || $dbPort == '' || $dbPort != trim($_REQUEST['dbPort'])) {
+ $templateData['dbPort']['problem'] = 'Server port was not provided or is not a valid nummber.';
+ $failure = true;
+}
+
+// Check database name
+$dbName = preg_replace("/[^a-zA-Z0-9_]+/", "", trim($_REQUEST['dbName']));
+$templateData['dbName'] = array('value' => $dbName, 'problem' => false);
+if (!$dbName || $dbName == '' || $dbName != trim($_REQUEST['dbName'])) {
+ $templateData['dbName']['problem'] = 'Database name was not provided or is not valid for Postgres.';
+ $failure = true;
+}
+
+// Check database user
+$dbUser = preg_replace("/[^a-zA-Z0-9_]+/", "", trim($_REQUEST['dbUser']));
+$templateData['dbUser'] = array('value' => $dbUser, 'problem' => false);
+if (!$dbUser || $dbUser == '' || $dbUser != trim($_REQUEST['dbUser'])) {
+ $templateData['dbUser']['problem'] = 'Database user was not provided or is not valid for Postgres.';
+ $failure = true;
+}
+
+if ($failure) {
+ $templateData['genError'] = 'There was a problem with the database connection information you provided. See below for specific instructions.';
+}
+
+/*
+ * Determine if source database is sane
+ */
+
+// Connect to database
+if (!$failure) {
+ $connString = "host=$dbServer port=$dbPort dbname=$dbName user=$dbUser";
+ $db = @pg_connect($connString);
+ if (!$db) {
+
+ $err = error_get_last();
+ $templateData['genError'] = 'There was a problem connecting to the database. The error message was...<br>'.$err['message'];
+ $failure = true;
+
+ }
+}
+
+// Determine if the members schema exists
+if (!$failure) {
+ $sql = "
+ SELECT EXISTS
+ (
+ SELECT 1
+ FROM information_schema.schemata AS exists
+ WHERE schema_name = 'members'
+ ) AS isMembers
+ ;";
+ $res = pg_query($db, $sql);
+ if (pg_fetch_result($res, 0, 'isMembers') == 'f') {
+ $templateData['genError'] = 'The "members" schema was not found! Is this the right database?';
+ $failure = true;
+ }
+}
+
+/*
+ * Load data from source database
+ */
+
+// Attempt to get member base data
+if (!$failure) {
+ $sql = "
+ SELECT C.city_id,R.region_name,C.city_name
+ FROM members.city C LEFT OUTER JOIN members.region R ON ( C.region_id = R.region_id )
+ WHERE C.region_id is not null
+ ORDER BY C.city_name";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ( $rows == 0 ) {
+ $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
+ $failure = true;
+ } else {
+ $cities = pg_fetch_all($res);
+ if ( count( $cities ) != $rows ) {
+ $notice = pg_last_notice( $res );
+ $templateData['genError'] = 'While reading base member data, we did not receive the expected number of cities! ';
+ if ( $notice ) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ }
+ }
+}
+
+/*
+ * Find cities for the Counties
+ */
+$notFoundList = array();
+$countyNames = array();
+$numbMembersFound = 0;
+$numbCitiesNotFound = 0;
+
+if ( !$failure ) {
+ // Grab all of the county id's
+ $sql = "
+ SELECT *
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties
+ ORDER BY name";
+ $counties = $this->wpdb->get_results( $sql, ARRAY_A );
+ foreach ( $counties as $county ) {
+ $countyNames[$county['name']] = $county['id'];
+ }
+ // echo '<pre>$countyNames: ' . print_r( $countyNames, true ) . '</pre>';
+ foreach ( $cities as $city ) {
+ // grab the new city id searching the name field.
+ $newCityID = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+ WHERE name = %s",
+ $city['city_name']
+ )
+ );
+ // echo '<pre>$newCityID: ' . print_r( $newCityID, true ) . '</pre>';
+ if ( !$newCityID ) {
+ $notFoundList[] = $city['city_name'];
+ $numbCitiesNotFound++;
+ } else {
+ $countyId = $countyNames[$city['region_name']];
+ // echo '<pre>$countyId: ' . print_r( $countyId, true ) . '</pre>';
+ if ( !$countyId ) {
+ // need to add the cienty name
+
+ // Clean up city name
+ $cName = trim(filter_var($city['region_name']));
+
+ // Try to add the city
+ // require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php';
+ // $Cities = new GlmDataCities($this->wpdb, $this->config);
+ // $cID = $Cities->addCity($cName);
+ //
+ // // If we got a city id back
+ // if (is_int($cID) && $cID > 0) {
+ // $countyId = $cID;
+ // }
+ }
+ if ( $countyId ) {
+ $this->wpdb->update(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX."cities",
+ array( 'county' => $countyId ),
+ array( 'id' => $newCityID ),
+ array( '%d' ),
+ array( '%d' )
+
+ );
+ $numbCitiesFound++;
+ }
+ }
+ }
+}
+
+// If everything is OK, make data available to the template
+if (!$failure) {
+
+ $templateData['numbCities'] = count($cities);
+ $templateData['notFoundList'] = $notFoundList;
+ $templateData['numbCitiesFound'] = $numbCitiesFound;
+ $templateData['numbCitiesNotFound'] = $numbCitiesNotFound;
+ $requestedView = 'import/countyCity.html';
+
+} else {
+ $requestedView = 'import.html';
+}
+