Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/OrgSearch/OrgSearch.php - 580 lines - 28626 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /**
   4  * Name:      OrgSearch.php
   5  * App:       OrgSearch
   6  * Desc:      Allows the user to search and browse for organizations.
   7  * Creator:   David Glick <davidig@goshen.edu>
   8  * Modified:  Jason Yoder <jasonay@goshen.edu>
   9  */
  10  
  11  class OrgSearch extends App
  12      {   
  13      var $orgName;
  14      var $messages = array();
  15      
  16      function getContent()
  17          {
  18          include_once(T_APP_BASE . 'OrgSearch/org_type.inc');
  19      if (isset($this->httpVars['basic']))
  20              {
  21              $q = array();
  22              //get display boolean variable to determine whether showing dist, maps, address
  23              $disp = array();
  24              
  25              if (@$this->settingsVars['dispmap'] || !isset($this->settingsVars['dispmap'])) $disp['map'] = 'true';
  26              if (@$this->settingsVars['dispadd'] || !isset($this->settingsVars['dispadd'])) $disp['add'] = 'true';
  27              if (@$this->settingsVars['dispdist'] || !isset($this->settingsVars['dispdist'])) $disp['dist'] = 'true';
  28              
  29              //if a number is submitted, search within a 20 mile proximity of that zipcode
  30              if (is_numeric(str_replace('-', '', $this->httpVars['q'])))
  31                  {
  32                  return $this->getProximityResults( $this->httpVars['q'], $this->httpVars['scope'], 20, $disp );
  33                  }
  34              else
  35                  {
  36              
  37                  $q['o'] = $this->httpVars['q'];
  38                  $q['mennolocationcity'] = $this->httpVars['q'];
  39                      //expand acceptable country entries of US and CA to include variations
  40                      if (strtolower($this->httpVars['q']) == 'usa' || strtolower($this->httpVars['q']) == 'united states' || strtolower($this->httpVars['q']) == 'united states of america')
  41                      {
  42                      $q['c'] = 'us';
  43                      }
  44                      if (strtolower($this->httpVars['q']) == 'canada' || strtolower($this->httpVars['q']) == 'can')
  45                      {
  46                      $q['c'] = 'ca';
  47                      }
  48                  else
  49                  {
  50                  $q['c'] = $this->httpVars['q'];
  51                  $q['mennolocationstate'] = $this->httpVars['q'];
  52                  }
  53                  $q['postalcode'] = $this->httpVars['q'];
  54                  $q['combType'] = 'or';
  55  
  56                  $res = $this->fetchResults($q, $this->MN_ORG_CONVERT[(int) $this->httpVars['scope']]);
  57                  return $this->showResults($res, $disp, "Results for search '" . $this->httpVars['q'] . "'");
  58                  }
  59              }
  60          else if (isset($this->httpVars['advanced']))
  61              {
  62              $q = array();
  63              $disp = array();
  64              if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
  65              if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
  66              if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';
  67              
  68              //if all fields are empty except for zipcode, then do a search within 20 of that zipcode
  69              if (@$this->httpVars['name'] == '' && @$this->httpVars['city'] == '' && @$this->httpVars['state'] == ''&&
  70                  @$this->httpVars['country'] == '' && @$this->httpVars['zip'] != '')
  71                  {
  72                  return $this->getProximityResults( $this->httpVars['zip'], $this->MN_ORG_CONVERT[(int) $this->httpVars['type']], 20, $disp );
  73                  }
  74              else
  75                  {
  76                  if (@$this->httpVars['name']) $q['o'] = $this->httpVars['name'];
  77                  if (@$this->httpVars['city']) $q['mennolocationcity'] = $this->httpVars['city'];
  78                  if (@$this->httpVars['state']) $q['mennolocationstate'] = $this->httpVars['state'];
  79                  if (@$this->httpVars['country']) $q['c'] = $this->httpVars['country'];
  80              
  81              
  82                  //expand acceptable country entries of US and CA to include variations
  83                  if (strtolower($q['c']) == 'usa' || strtolower($q['c']) == 'united states' || strtolower($q['c']) == 'united states of america')
  84                      {
  85                      $q['c'] = 'us';
  86                      }
  87                     if (strtolower($q['c']) == 'canada' || strtolower($q['c']) == 'can')
  88                      {
  89                         $q['c'] = 'ca';
  90                      }
  91                  if (@$this->httpVars['zip']) $q['postalcode'] = $this->httpVars['zip'];
  92                  $q['combType'] = @$this->httpVars['combType'] ? $this->httpVars['combType'] : 'or';
  93              
  94                  $res = $this->fetchResults($q, $this->MN_ORG_CONVERT[(int) $this->httpVars['type']]);
  95                  return $this->showResults($res, $disp, 'Advanced Search Results');
  96                  }
  97              }
  98          else if (isset($this->httpVars['typebrowse']))
  99              {
 100              $disp = array();
 101              if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
 102              if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
 103              if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';            
 104              
 105              $res = $this->fetchResults(array(), $this->MN_ORG_CONVERT[$this->httpVars['typebrowse']] );
 106              return $this->showResults($res, $disp, $this->MN_ORG_TYPE_NAMES[$this->httpVars['typebrowse']] );
 107              }
 108  
 109            else if (isset($this->httpVars['sitesearch']))
 110              {
 111              $disp = array();
 112              if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
 113              if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
 114              if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';    
 115              
 116              //basic site search search all and only search in the "dc" and "o" fields
 117              $this->httpVars['type'] = "-1";
 118              $res = $this->fetchResults("(|(dc=*".$this->httpVars['q']."*)(o=*".$this->httpVars['q']."*))" , $this->MN_ORG_CONVERT[$this->httpVars['type']] );
 119              return $this->showResults($res, $disp, "Diplaying results in all of Caravel for '".$this->httpVars['q']."'" );            
 120              }
 121          else if (isset($this->httpVars['advsitesearch']))
 122              {
 123              $disp = array();
 124              if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
 125              if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
 126              if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';
 127              
 128              //advanced site searches only in the "dc" and "o" fields
 129              $this->httpVars['type'] = $this->httpVars['scope'];
 130              $res = $this->fetchResults("(|(dc=*".$this->httpVars['q']."*)(o=*".$this->httpVars['q']."*))" , $this->MN_ORG_CONVERT[$this->httpVars['type']] );
 131              return $this->showResults($res, $disp, "Diplaying results in Caravel within category '".$this->MN_ORG_TYPE_NAMES[$this->httpVars['type']]."' for search term '".$this->httpVars['q']."'" );
 132              }
 133   
 134          else if (isset($this->httpVars['proximity']))
 135              {
 136                  $disp = array();
 137                  if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
 138                  if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
 139                  if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';
 140              
 141                  return $this->getProximityResults( $this->httpVars['q'], $this->httpVars['scope'], $this->httpVars['distance'], $disp );
 142              }
 143          else if (isset($this->httpVars['q']))
 144              {
 145              $disp = array();
 146              if (@$this->settingsVars['dispmap']) $disp['map'] = 'true';
 147              if (@$this->settingsVars['dispadd']) $disp['add'] = 'true';
 148              if (@$this->settingsVars['dispdist']) $disp['dist'] = 'true';
 149              
 150              $res = $this->fetchResults($this->httpVars['q'], $this->httpVars['scope']);
 151              return $this->showResults($res, $disp, "Results for search '" . $this->httpVars['q'] . "'");
 152              }
 153          else
 154              { 
 155              return $this->getSearchForm(@$this->params['type']);
 156              }
 157          }
 158          
 159      function onSave()
 160          {
 161          $this->settingsVars['type'] = @$this->httpVars['type'] ? $this->httpVars['type'] : 'basic';
 162          $this->settingsVars['dispadd'] = @$this->httpVars['dispadd'] ;
 163          $this->settingsVars['dispdist'] = @$this->httpVars['dispdist'] ;
 164          $this->settingsVars['dispmap'] = @$this->httpVars['dispmap'] ;
 165          $this->saveSettings($this->settingsVars);
 166          }
 167  
 168      function getConfig()
 169          {
 170          $f = FormWidget::init();
 171          $f->section();
 172          $attrs = array('onclick' => 'functionDisplay(this.value,\''.$this->paramName('divId').'\')');
 173  
 174          $types = array('sitesearch' => '<b><FONT SIZE=2>Basic Site Search</b></FONT><br>
 175                                          Search all of Caravel in any category',
 176                                         'advsitesearch' => '<b><FONT SIZE=2>Advanced Site Search</b></FONT><br>
 177                                          Search all of Caravel within a selected category ',
 178                                         'basic' => '<b><FONT SIZE=2>Basic Location Search</b></FONT><br>
 179                                          Search for organizations by keywords in any location category',
 180                                         'advanced' => '<b><FONT SIZE=2>Advanced Location Search</b></FONT><br>
 181                                          Search for organizations by entering specific information in various categories',
 182                                         'typebrowse' => '<b><FONT SIZE=2>Browse by Organization Type</b></FONT><br>
 183                                          Search by browsing through links organized by the types of organizations',
 184                                         'proximity' => '<b><FONT SIZE=2>Zip Code Proximity Search</b></FONT><br>
 185                                          Search by zipcode and see all organizations within a specified distance'
 186                        );
 187          $type = @$this->params['type'] ? $this->params['type'] : 'basic';
 188          $f->radio('type', $types, @$this->params['type'], 'basic', '<br />', $attrs);
 189          
 190          //if address has been set then other have been set and should be restored to their last configuration
 191          if ($this->settingsVars['dispadd'] == 'on' || $this->settingsVars['dispadd'] == '')
 192              {
 193                  $f->checkbox('dispadd', $this->settingsVars['dispadd'], '<b><FONT SIZE=2>Display Address</FONT></b>');         
 194                  
 195                  if ($this->settingsVars['type'] == 'advanced' || $this->settingsVars['type'] == 'basic' || $this->settingsVars['type'] == 'proximity' )
 196                      {
 197                      $f->html('<br><div id ='.$this->paramName('divId').' style="display:block;">');
 198                      }
 199                  else
 200                      {
 201                      $f->html('<br><div id ='.$this->paramName('divId').' style="display:none;">');
 202                      }
 203                  
 204                  $f->checkbox('dispdist', $this->settingsVars['dispdist'], '<b><FONT SIZE=2>Display Distance</FONT></b>');     
 205                  $f->html('<br></div>');            
 206                  
 207                  $f->checkbox('dispmap', $this->settingsVars['dispmap'], '<b><FONT SIZE=2>Display Google Maps</FONT></b>');    
 208                  $f->html('<br>');
 209              
 210              }
 211        
 212          else if ( $this->params['type'] == 'sitesearch' || $this->params['type'] == 'advsitesearch')
 213              {
 214              $f->checkbox('dispadd', false, '<b><FONT SIZE=2>Display Address</FONT></b>');
 215              $f->html('<br>');
 216              $f->checkbox('dispdist',false, '<b><FONT SIZE=2>Display Distance</FONT></b>');
 217              $f->html('<br>');
 218              $f->checkbox('dispmap', false, '<b><FONT SIZE=2>Display Google Maps</FONT></b>');
 219              }
 220          else
 221              {
 222              $f->checkbox('dispadd', true, '<b><FONT SIZE=2>Display Address</FONT></b>');
 223              $f->html('<br>');
 224              $f->checkbox('dispdist',true, '<b><FONT SIZE=2>Display Distance</FONT></b>');
 225              $f->html('<br>');
 226              $f->checkbox('dispmap', true, '<b><FONT SIZE=2>Display Google Maps</FONT></b>');
 227              }
 228  
 229          $f->endSection();
 230          $f->defaultButtons();
 231  
 232          return $f->get();
 233          }
 234  
 235      function getSearchForm($mode = 'basic')
 236          {
 237          $tpl = new Template_PHPLIB( $this->appBase );
 238          $tpl->setVar('tbwidth', $this->colWidth - 4);
 239          $tpl->setVar('selwidth', $this->colWidth < 124 ? 60 : $this->colWidth - 64);
 240          
 241          switch($mode)
 242              {
 243              case 'basic':
 244              default:
 245                  $tpl->setFile( array('main' => 'OrgSearch.tpl.html') );
 246                  $tpl->setVar('linkToResults', $this->getResultLink() );
 247                  $tpl->setVar('basic', $this->paramName('basic'));
 248                  $tpl->setVar('q', $this->paramName('q'));
 249                  $tpl->setVar('scope', $this->paramName('scope'));
 250                  break;
 251              case 'advanced':
 252                  $tpl->setFile( array('main' => 'advanced_search.tpl.html') );
 253                  $tpl->setVar('linkToResults', $this->getResultLink() );
 254                  $tpl->setVar('type', FormWidget::select('type', $this->MN_ORG_TYPE_NAMES, -1, null, array('style' => 'width: '.($this->colWidth - 100).'px;')) );
 255                  $tpl->setVar('name', FormWidget::text('name', '', 25));
 256                  $tpl->setVar('city', FormWidget::text('city', '', 25));
 257                  $tpl->setVar('state', FormWidget::text('state', '', 3));
 258                  $tpl->setVar('zip', FormWidget::text('zip', '', 7));
 259                  $tpl->setVar('country', FormWidget::text('country', '', 25));
 260                  $tpl->setVar('allabove', FormWidget::radio('combType', array('and'=>'all of the above', 'or'=>'any of the above'), 'or'));
 261                  $tpl->setVar('submit', FormWidget::submit('advanced', 'Search'));
 262                  break;
 263              case 'proximity':
 264                  $tpl->setFile( array('main' => 'ProximitySearch.tpl.html') );
 265                  $tpl->setVar('linkToResults', $this->getResultLink() );
 266                  $tpl->setVar('proximity', $this->paramName('proximity'));
 267                  $tpl->setVar('q', $this->paramName('q'));
 268                  $tpl->setVar('scope', $this->paramName('scope'));
 269                  $tpl->setVar('distance', $this->paramName('distance'));
 270                  break;
 271              case 'sitesearch':
 272                  $tpl->setFile( array('main' => 'site_search.tpl.html') );
 273                  $tpl->setVar('q', $this->paramName('q'));
 274                  $tpl->setVar('sitesearch', $this->paramName('sitesearch'));
 275                  $tpl->setVar('linkToResults', $this->getResultLink() );
 276                  break;
 277              case 'advsitesearch':
 278                  $tpl->setFile( array('main' => 'advsite_search.tpl.html') );
 279                  $tpl->setVar('q', $this->paramName('q'));
 280                  $tpl->setVar('advsitesearch', $this->paramName('advsitesearch'));
 281                  $tpl->setVar('scope', $this->paramName('scope'));
 282                  $tpl->setVar('linkToResults', $this->getResultLink() );
 283                  break;
 284          case 'typebrowse':
 285                  $tpl->setFile( array('main' => 'typebrowse_search.tpl.html') );
 286                  $tpl->setBlock('main', 'resultBlock', 'resultB');
 287                  $tpl->setVar('resultB', '');
 288                  $i = 0; $count = count($this->MN_ORG_TYPE_NAMES) - 4;
 289                  foreach($this->MN_ORG_TYPE_NAMES as $id => $name)
 290                      {
 291                      if ($id >= 0)
 292                          {
 293                          $tpl->setVar('itemTitle', $name);
 294                          $tpl->setVar('itemLink', $this->getResultLink( array('typebrowse' => $id) ) );
 295                          $tpl->parse(++$i <= ((int) $count / 2) + .5 ? 'leftResults' : 'rightResults' , 'resultBlock', true);
 296                          }
 297                      }
 298                  break;
 299              }
 300          return $tpl->subst('main');
 301          }
 302          
 303      function showResults(&$res, &$disp, $title = '')
 304          {
 305                 
 306          $tpl = new Template_PHPLIB( $this->appBase );
 307          $tpl->setFile( array('main' => 'OrgSearchResults.tpl.html') );
 308          
 309          $tpl->setBlock('main', 'typeBlock', 'typeB');
 310          $tpl->setVar('typeB', '');
 311          $tpl->setBlock('main', 'resultBlock', 'resultB');
 312          $tpl->setVar('resultB', '');
 313          $tpl->setVar('title', $title);
 314          
 315          foreach($res as $type => $items)
 316              {
 317              $type = $this->MN_ORG_CAT_NAMES[(int) $type];
 318              $tpl->setVar('typeName', $type);
 319              $count = count($items);
 320              $tpl->setVar('resultCount', $count ? ($count . ($count == 1 ? ' match ' : ' matches ') . 'found.') : ('No ' . $type . ' found.'));
 321              $tpl->setVar('leftResults', '');
 322              $tpl->setVar('rightResults', '');
 323              $i = 0;
 324              foreach($items as $item)
 325                  {
 326                  $tpl->setVar('itemLink', 'http://' . DN::dnToSiteDomain($item['dn']));
 327                  $tpl->setVar('itemTitle', @$item['o'][0]);
 328                  
 329                  if ($disp['add'] != 'true')
 330                      {
 331                      $tpl->setVar('city', "");
 332                      $tpl->setVar('state', "");
 333                      $tpl->setVar('country', "");
 334                      $tpl->setVar('zip', "");                    }
 335                  else
 336                      {
 337                      //the following makes sure different items are not empty before including them this prevents
 338                      //the error where ", , ," would appear in certain entries
 339                      if (@$item['mennolocationcity'][0] != "")           {    $tpl->setVar('city', @$item['mennolocationcity'][0].", ");          }
 340                      else                                {    $tpl->setVar('city', "");                           }
 341                      if (@$item['mennolocationstate'][0] != "")          {    $tpl->setVar('state', @$item['mennolocationstate'][0].", ");        }
 342                      else                                {    $tpl->setVar('state', "");                          }
 343                      if (@$item['c'][0] != "")           {    $tpl->setVar('country', @$item['c'][0].", ");        }
 344                      else                                {    $tpl->setVar('country', "");                        }
 345                      if (@$item['postalcode'][0] != "")  {    $tpl->setVar('zip', @$item['postalcode'][0]."<br>");}
 346                      else                                {    $tpl->setVar('zip', "");                            }
 347                      }
 348                  if ($disp['map'] != 'true')
 349                      {
 350                      $tpl->setVar('map', '');
 351                      }  
 352                  else
 353                      {               
 354                      //use information from results to create a link to Google Maps for each org
 355                      $tpl->setVar('map', "<a target=\"_blank\" href=\"http://"."maps.google.com/maps?q="
 356                      .@$item['mennolocation'][0]."+".@$item['mennolocationcity'][0]."+".@$item['mennolocationstate'][0]."+"
 357                      .@$item['postalcode'][0]."&hl=en\""."><img border=0 style=\"vertical-align: middle;\" src=\"".T_WEB_IMG."/icons/web_16.gif\"></a>".
 358                      " <a target=\"_blank\" href=\"http://"."maps.google.com/maps?q="
 359                      .@$item['mennolocation'][0]."+".@$item['mennolocationcity'][0]."+".@$item['mennolocationstate'][0]."+"
 360                      .@$item['postalcode'][0]."&hl=en"."\">Go to Google Maps"."<br><br></a>");
 361                      }
 362                  
 363                  if ($disp['dist'] != 'true')
 364                      {
 365                      $tpl->setVar('dist', '');
 366                      }
 367                  else
 368                      {
 369                      if($GLOBALS['distances'][$item['postalcode'][0]] == 0)
 370                      {
 371                      $tpl->setVar('dist', "");
 372                      }
 373                      else if(strlen($item['postalcode'][0]) > 4)
 374                      {
 375                      //only display the first number after the decimal point when displaying distance
 376                      $GLOBALS['distances'][$item['postalcode'][0]] =  round ($GLOBALS['distances'][$item['postalcode'][0]], 1);
 377                      $tpl->setVar('dist', "approx. ".@$GLOBALS['distances'][$item['postalcode'][0]]." miles<br>"   );
 378                      }
 379                      else
 380                      {
 381                      $tpl->setVar('dist', ", ".@$GLOBALS['distances'][$item['postalcode'][0]]." miles"   );//@$item['postalcode'][0]);
 382                      }
 383                      
 384                      }
 385                  $tpl->parse( ++$i <= ((int) $count / 2) + .5 ? 'leftResults' : 'rightResults', 'resultBlock', true);
 386                  }
 387              $tpl->parse('typeB', 'typeBlock', true);
 388              }
 389          return $tpl->subst('main');
 390          }
 391          
 392      /** 
 393      * retrieves search results from the database
 394      */
 395      function fetchResults($query = array(), $types = '-1')
 396          {
 397          if (!$query or $query == '*' or (is_array($query) and count($query) == 0) )
 398              $q = '';
 399          else if (!is_array($query))
 400              {
 401              //checks to see if query has been created manually
 402              if($query[0] == "(")
 403              {
 404                  $q = $query;
 405              }
 406              else
 407              {
 408              $q = mnLDAP::dnSafe($this->params['q']);
 409              $q = "(|(o=*$query*)(mennolocationcity=*$query*)(mennolocationstate=*$query*)(c=*$query*))";
 410              }
 411              }
 412          else
 413              {
 414              $q = '';
 415              foreach ($query as $field => $value)
 416                  {
 417                  if ($field == 'combType') continue;
 418                  $field = mnLDAP::dnSafe($field);
 419                  $value = mnLDAP::dnSafe($value);
 420                  $q .= '(' . $field . '=*' . $value . '*)';
 421                  }
 422  
 423              if (count($query) > 1)
 424                  {
 425                  if (isset($query['combType']))
 426                      {
 427                      $combType = $query['combType'];
 428                      }
 429                  else
 430                      $combType = 'or';
 431                  $q = '(' . ($combType == 'and' ? '&' : '|') . $q . ')';
 432                  }                
 433              }
 434              
 435          if (!is_array($types)) $types = array($types);
 436          $ret = array();
 437          foreach ($types as $type)
 438              {
 439              switch ($type)
 440                  {
 441                  case 'all':
 442                  case -1:
 443                      return $this->fetchResults($query, -2) + $this->fetchResults($query, -3) + $this->fetchResults($query, -4);
 444                      break;
 445                  case -2: // congregations
 446                      $filter = '(mennoorganizationtype=Congregation)';
 447                      break;
 448                  case -3: // conferences
 449                      $filter = '(mennoorganizationtype=Conference)';
 450                      break;
 451                  case -4: // organizations
 452                      $filter = '(!(|(mennoorganizationtype=Congregation)(mennoorganizationtype=Conference)))';
 453                      break;
 454                  default:
 455                      $filter = '(mennoorganizationtype=' . $this->MN_ORG_CAT_NAMES[$type] . ')';
 456                      break;
 457                  }
 458              $filter = '(&(objectclass=mennoOrganization)' . $filter;
 459              $filter .= $q ? $q : '';
 460              $filter .= ')';
 461              $res = $this->ldap->search($filter, array('dn', 'o', 'mennoLocationCity', 'mennoLocationState', 'c', 'postalcode', 'postaladdress'), T_LDAP_BASE, null, null, null, null, null, 'o');
 462              if (mnError::isError($res))
 463                  return new mnError('Error fetching search results: ' . $res->getMessage(), __FILE__, __LINE__);
 464  
 465              array_shift($res);
 466              $ret[$type] = $res;
 467              }
 468          return $ret;
 469          }
 470          
 471      function getResultLink($attrs = array())
 472          {
 473          //  pjh -- if they are ALREADY in single mode, don't do singleNav
 474          if (!T_SINGLE_BLOCK)
 475              $attrs2 = array('_single' => $this->blockID, '_singleNav' => 1);
 476          else
 477              $attrs2 = array('_single' => $this->blockID);
 478          foreach($attrs as $name => $val)
 479              $attrs2[ $this->paramName($name) ] = $val;
 480          $attrs2['id'] = T_SITE_ID;
 481          return Utility::link($this->sectionPathArray, $attrs2);
 482          }
 483      
 484  
 485  
 486  
 487      function getProximityResults($query, $type, $distance, &$disp)                                
 488          {
 489                  //gets a list of zip codes within a radius of another zipcode as provided by user
 490                  $contents = file_get_contents("http://teachatechie.com/GJTTWebservices/ZipCode.asmx/GetNearbyZipCodes?ZipCode=" . $query . "&RadiusMiles=" . $distance);
 491                  
 492                  //begins manual creation of string search query                
 493                  $GLOBALS['zipcodequery'] = "(|";
 494                  $GLOBALS['queryzipcode'] = "";
 495                  $GLOBALS['stack'] = array();
 496   
 497                  if(!function_exists("startElement"))
 498                  {
 499                      function startElement($parser, $name, $attr)
 500                          {
 501                          array_push($GLOBALS['stack'], $name);
 502                          }
 503                      function endElement($parser, $name)
 504                          {
 505                          array_pop($GLOBALS['stack']);
 506                          }
 507                      function characterData($parser, $data)
 508                          {
 509                            if($GLOBALS['stack'][count($GLOBALS['stack']) - 1] == "ZIP_CODE")
 510                              {
 511                              $GLOBALS['queryzipcode'] = $data;
 512                              $GLOBALS['zipcodequery'] = $GLOBALS['zipcodequery']."(postalcode=".$data.")";
 513                              
 514                              }
 515                       else if($GLOBALS['stack'][count($GLOBALS['stack']) - 1] == "RADIUS_MILES")
 516                       {
 517                              $GLOBALS['distances'][$GLOBALS['queryzipcode']] = $data;
 518                              
 519                              }       
 520                          }
 521                      // Create an XML parser
 522                      $xml_parser = xml_parser_create();
 523  
 524                      // Set the functions to handle opening and closing tags
 525                      xml_set_element_handler($xml_parser, "startElement", "endElement");
 526  
 527                      // Set the function to handle blocks of character data
 528                      xml_set_character_data_handler($xml_parser, "characterData");
 529  
 530                      // Create an XML parser
 531                      $xml_parser = xml_parser_create();
 532  
 533                      // Set the functions to handle opening and closing tags
 534                      xml_set_element_handler($xml_parser, "startElement", "endElement");
 535      
 536                      // Set the function to handle blocks of character data
 537                      xml_set_character_data_handler($xml_parser, "characterData");
 538  
 539                      // Parse it
 540                      xml_parse($xml_parser, $contents);
 541  
 542                      // Free up memory used by the XML parser
 543                      xml_parser_free($xml_parser);
 544  
 545                  }
 546          
 547                  unset($GLOBALS['stack']);
 548                  
 549                  //finishes manually created search query
 550                  $GLOBALS['zipcodequery'] = $GLOBALS['zipcodequery'].")";
 551                  //$this->httpVars['type'] = $this->httpVars['scope'];
 552                  $res = $this->fetchResults($GLOBALS['zipcodequery'], $this->MN_ORG_CONVERT[(int) $type]);
 553  
 554                  //sort by distance rather than alphabetically
 555                  $tempRes = array();
 556                  unset($res['count']);
 557                  
 558                  foreach($res as $orgtype => $orgarray)
 559                          {
 560                          $orderKey = array();
 561                          unset($orgarray['count']);
 562                          foreach($orgarray as $i => $entry)
 563                              {
 564                              $orderKey[$i] = $GLOBALS['distances'][$entry['postalcode'][0]];
 565                              
 566                              }
 567  
 568                          asort($orderKey);
 569                          foreach(array_keys($orderKey) as $i)
 570                              {
 571                              $tempRes[$orgtype][] = $res[$orgtype][$i];
 572                              }
 573                          }
 574                          
 575                  return $this->showResults($tempRes, $disp, "Displaying results in zip codes within " . $distance." miles of the zip code '".$query."'");
 576             
 577          }
 578      
 579      } // end class OrgSearch
 580  ?>

title

Description

title

Description

title

Description

title

title

Body