Example #1
0
<?php

$zip = strip_tags(trim($_GET['zip']));
if (!empty($zip)) {
    $zip = strip_tags(trim($_GET['zip']));
    $locInfo = getLatLongFromZipCode($zip);
} else {
    $zip = 20500;
    $locInfo = getLatLongFromZipCode($zip);
}
print views_embed_view('vendors_near_you', 'block_1', $locInfo['lat'], $locInfo['lng']);
?>
  <script>
    (function($) {
      $('.view-vendors-near-you').addClass('col-md-12');
      $(document).ready(function(){
        // Add panel collapse arrow
        $('.panel-collapse.collapse').prev().css( "background", "url('/sites/all/themes/bizusa/images/icons/block-collapsed.png') no-repeat 92% center #e2e2e2");
        $('.panel-collapse.collapse.in').prev().css( "background", "url('/sites/all/themes/bizusa/images/icons/block-expanded.png') no-repeat 92% center #e2e2e2");


        $('.panel-collapse').on('hidden.bs.collapse', function (e) {
          var panelID = String($(e.target).attr('id'));
          $('#'+panelID).prev().css( "background", "url('/sites/all/themes/bizusa/images/icons/block-collapsed.png') no-repeat 92% center #e2e2e2");
        });

        $('.panel-collapse').on('shown.bs.collapse', function (e) {
          var panelID = String($(e.target).attr('id'));
          $('#'+panelID).prev().css( "background", "url('/sites/all/themes/bizusa/images/icons/block-expanded.png') no-repeat 92% center #e2e2e2");
        });
/**
 * void cleanup_FixMissingLatLongForResourceCenters()
 * 
 * This function will search for any nodes under the 'Resource Center' 
 * content-type that; has missing latitude/longitude information AND has 
 * a ZipCode value. 
 *
 * Content/nodes found that match this search will be supplied with 
 * lat/long information, the lat/long will be assumed based on the ZipCode.
 */
function cleanup_FixMissingLatLongForResourceCenters()
{
    /* The following query should find all content under the  'Resource Centers' 
           content-type (appointment_office) that does NOT have latitude/longitude 
           information, but DOES have ZipCode information
       */
    $query = "\n        SELECT\n            n.nid AS 'nid',\n            field_appoffice_lat_value,\n            field_appoffice_long_value, \n            field_appoffice_postal_code_value\n        FROM node n \n        LEFT JOIN field_data_field_appoffice_lat ln ON ( ln.entity_id = n.nid )\n        LEFT JOIN field_data_field_appoffice_long lg ON ( lg.entity_id = n.nid )\n        LEFT JOIN field_data_field_appoffice_postal_code pc ON ( pc.entity_id = n.nid )\n        WHERE\n            n.type = 'appointment_office'\n            AND field_appoffice_postal_code_value IS NOT NULL\n            AND (\n                field_appoffice_lat_value IS NULL\n                OR field_appoffice_long_value IS NULL\n            )\n    ";
    foreach (db_query($query) as $nodeInfo) {
        // Init
        $n = null;
        $lat = 0;
        $long = 0;
        // Load this node and node information
        $n = node_load($nodeInfo->nid);
        $zip = $n->field_appoffice_postal_code['und'][0]['value'];
        if (intval($zip) === 0) {
            drupal_set_message("Error - <a target=\"_blank\" href=\"/node/{$n->nid}/edit\">Node {$n->nid}</a> does not have a valid ZipCode.\n                The ZipCode associated with this node is: <i>{$n->field_appoffice_postal_code['und'][0]['value']}</i>", "error");
        }
        // Get the lant/long for the given ZipCode
        $locationInfo = getLatLongFromZipCode($zip);
        // Note: This function is stored in ZipCodeGeolocation.php
        $lat = $locationInfo['lat'];
        $long = $locationInfo['lng'];
        $city = $locationInfo['city'];
        $state = $locationInfo['state'];
        // Store this information into the instanced node (in memory)
        $n->field_appoffice_lat = array('und' => array(0 => array('value' => $lat, 'format' => null, 'safe_value' => $lat)));
        $n->field_appoffice_long = array('und' => array(0 => array('value' => $long, 'format' => null, 'safe_value' => $long)));
        if (empty($n->field_appoffice_city['und'][0]['value'])) {
            $n->field_appoffice_city = array('und' => array(0 => array('value' => $city, 'format' => null, 'safe_value' => $city)));
        }
        if (empty($n->field_appoffice_state['und'][0]['value'])) {
            $n->field_appoffice_state = array('und' => array(0 => array('value' => $state)));
        }
        // Save changes to this node
        node_save($n);
        // We are done now
        $msg = "Updated node {$n->nid} with missing latitude/longitude information<br/>\n";
        error_log($msg);
        unset($n);
    }
}