/**
  * Generate module
  */
 protected function compile()
 {
     $this->Template = new \FrontendTemplate($this->storelocator_list_tpl);
     $sSearchVal = $this->Input->get('search') ? $this->Input->get('search') : NULL;
     $sSearchCountry = $this->Input->get('country') ? $this->Input->get('country') : NULL;
     $aEntries = array();
     // check if an empty search is allowed
     if (!$this->storelocator_allow_empty_search && !$sSearchVal && $sSearchCountry) {
         $this->Template->error = true;
     } else {
         $term = NULL;
         // add country code for correct search results
         if (!empty($sSearchCountry)) {
             if (!empty($sSearchVal)) {
                 $term = $sSearchVal . ', ' . $sSearchCountry;
             } else {
                 $term = $aCountryNames[$entry['country']];
             }
         }
         $aCategories = array();
         $aCategories = deserialize($this->storelocator_list_categories);
         $aCountryNames = $this->getCountries();
         if (!empty($term)) {
             // get coordinates of searched destination
             $sl = new StoreLocator();
             $aCoordinates = array();
             $aCoordinates = $sl->getCoordinatesByString($term);
             if (!empty($aCoordinates)) {
                 $objStores = NULL;
                 // search all countries
                 if (!empty($sSearchVal)) {
                     $objStores = $this->Database->prepare("\n                            SELECT\n                                *\n                            , 3956 * 1.6 * 2 * ASIN(SQRT( POWER(SIN((? -abs(latitude)) * pi()/180 / 2),2) + COS(? * pi()/180 ) * COS( abs(latitude) *  pi()/180) * POWER(SIN((?-longitude) *  pi()/180 / 2), 2) )) AS `distance`\n                            FROM `tl_storelocator_stores`\n                            WHERE\n                                    pid IN(" . implode(',', $aCategories) . ")\n                                AND latitude != '' \n                                AND longitude != ''\n                                " . ($this->storelocator_limit_distance ? "HAVING distance < {$this->storelocator_max_distance} " : '') . "\n                            ORDER BY `highlight` DESC ,`distance` ASC\n                        ")->limit($this->storelocator_list_limit)->execute($aCoordinates['latitude'], $aCoordinates['latitude'], $aCoordinates['longitude']);
                     // search selected country only
                 } else {
                     $objStores = $this->Database->prepare("\n                            SELECT\n                                *\n                            , 3956 * 1.6 * 2 * ASIN(SQRT( POWER(SIN((? -abs(latitude)) * pi()/180 / 2),2) + COS(? * pi()/180 ) * COS( abs(latitude) *  pi()/180) * POWER(SIN((?-longitude) *  pi()/180 / 2), 2) )) AS `distance`\n                            FROM `tl_storelocator_stores`\n                            WHERE\n                                    pid IN(" . implode(',', $aCategories) . ")\n                                AND latitude != '' \n                                AND longitude != '' \n                                " . ($this->storelocator_limit_distance ? "HAVING distance < {$this->storelocator_max_distance} " : '') . "\n                                AND country = ?\n                            ORDER BY `highlight` DESC ,`distance` ASC\n                        ")->limit($this->storelocator_list_limit)->execute($aCoordinates['latitude'], $aCoordinates['latitude'], $aCoordinates['longitude'], strtoupper($sSearchCountry));
                 }
                 $entries = array();
                 $entries = $objStores->fetchAllAssoc();
                 if (!empty($entries)) {
                     foreach ($entries as $entry) {
                         if (empty($sSearchVal)) {
                             $entry['distance'] = NULL;
                         }
                         $entry['class'] = $entry['highlight'] ? 'starred' : '';
                         $entry['country_code'] = $entry['country'];
                         $entry['country_name'] = $aCountryNames[$entry['country']];
                         // generate link
                         $link = null;
                         if ($this->jumpTo) {
                             $objLink = $this->Database->prepare("SELECT * FROM tl_page WHERE id = ?;")->execute($this->jumpTo);
                             $entry['link'] = $this->generateFrontendUrl($objLink->fetchAssoc(), (!$GLOBALS['TL_CONFIG']['useAutoItem'] ? '/store/' : '/') . $entry['id'] . '-' . standardize($entry['name'] . ' ' . $entry['city']));
                         }
                         // get opening times
                         $entry['opening_times'] = unserialize($entry['opening_times']);
                         $entry['opening_times'] = !empty($entry['opening_times'][0]['from']) ? $entry['opening_times'] : NULL;
                         $aEntries[] = $entry;
                     }
                 }
             }
         }
     }
     $this->Template->entries = $aEntries;
 }
Exemple #2
0
 /**
  * Returns geographical coordinates
  * @param string
  * @param string
  * @param string
  * @param string
  * @return array
  */
 public function getCoordinates($street = NULL, $postal = NULL, $city = NULL, $country = NULL)
 {
     return StoreLocator::getCoordinates($street, $postal, $city, $country);
 }
Exemple #3
0
<?php

/**
 * StoreLocator
 *
 * Copyright 2011-12 by SCHERP Ontwikkeling <*****@*****.**>
 *
 * This file is part of StoreLocator.
 *
 * StoreLocator is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * StoreLocator is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * StoreLocator; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA 02111-1307 USA
 *
 * @package StoreLocator
 */
/**
 * @package StoreLocator
 * @subpackage controllers
 */
require_once dirname(dirname(__FILE__)) . '/model/storelocator/storelocator.class.php';
$storelocator = new StoreLocator($modx);
return $storelocator->initialize('mgr');
 /**
  * Returns geographical coordinates
  * @param string
  * @param string
  * @param string
  * @param string
  * @return array
  */
 public function getCoordinates($street = NULL, $postal = NULL, $city = NULL, $country = NULL)
 {
     $sl = new StoreLocator();
     return $sl->getCoordinates($street, $postal, $city, $country);
 }
    /**
     * Generates a form to start import from csv file
     */
    public function showImport()
    {
        if ($this->Input->post('FORM_SUBMIT') == 'tl_storelocator_stores_import') {
            $source = $this->Input->post('file', true);
            // check the file names
            if (!$source) {
                $this->addErrorMessage($GLOBALS['TL_LANG']['ERR']['all_fields']);
                $this->reload();
            }
            // skip folders
            if (is_dir(TL_ROOT . '/' . $source)) {
                $this->addErrorMessage(sprintf($GLOBALS['TL_LANG']['ERR']['importFolder'], basename($source)));
                continue;
            }
            $objFile = new File($source);
            // skip anything but .csv files
            if ($objFile->extension != 'csv') {
                $this->addErrorMessage(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
                continue;
            }
            ini_set("max_execution_time", 0);
            // read entries
            if ($objFile->handle !== FALSE) {
                $pid = $this->Input->get('id');
                $oStores = null;
                $oStores = new tl_storelocator_stores();
                $count = 0;
                while (($data = fgetcsv($objFile->handle, 1000)) !== FALSE) {
                    if (empty($data[0])) {
                        continue;
                    }
                    $count++;
                    // get coordinates
                    $sl = new StoreLocator();
                    $coords = $sl->getCoordinates($data[5], $data[6], $data[7], $data[8]);
                    // add "http" in front of url
                    $data[2] = $data[2] && strpos($data[2], 'http') === FALSE ? 'http://' . $data[2] : $data[2];
                    try {
                        $this->Database->prepare("INSERT INTO `tl_storelocator_stores` (`pid`,`tstamp`,`name`,`email`,`url`,`phone`,`fax`,`street`,`postal`,`city`,`country`,`longitude`,`latitude`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")->execute($pid, time(), $data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7], strtolower($data[8]), $coords ? $coords['longitude'] : '', $coords ? $coords['latitude'] : '');
                    } catch (Exception $e) {
                        continue;
                    }
                    if ($count > 5) {
                        sleep(2);
                        $count = 0;
                    }
                }
                $objFile->close();
                // Redirect
                setcookie('BE_PAGE_OFFSET', 0, 0, '/');
                $this->redirect(str_replace('&key=importStores', '', $this->Environment->request));
                return;
            }
        }
        $objTree = new FileTree($this->prepareForWidget($GLOBALS['TL_DCA']['tl_storelocator_stores']['fields']['file'], 'file', null, 'file', 'tl_storelocator_stores'));
        // Return the form
        return '
			<div id="tl_buttons">
				<a href="' . ampersand(str_replace('&key=importStores', '', $this->Environment->request)) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
			</div>

			<h2 class="sub_headline">' . $GLOBALS['TL_LANG']['tl_storelocator']['import']['head'] . '</h2>
			' . $this->getMessages() . '

			<form action="' . ampersand($this->Environment->request, true) . '" id="tl_storelocator_stores_import" class="tl_form" method="post">
				<div class="tl_formbody_edit">
					<input type="hidden" name="FORM_SUBMIT" value="tl_storelocator_stores_import">
					<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">

					<div class="tl_tbox">
						<h3><label for="source">' . $GLOBALS['TL_LANG']['tl_storelocator']['import']['file'][0] . '</label> <a href="contao/files.php" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['fileManager']) . '" data-lightbox="files 765 80%">' . $this->generateImage('filemanager.gif', $GLOBALS['TL_LANG']['MSC']['fileManager'], 'style="vertical-align:text-bottom"') . '</a></h3>' . $objTree->generate() . (strlen($GLOBALS['TL_LANG']['tl_storelocator']['import']['file'][1]) ? '
						<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_storelocator']['import']['file'][1] . '</p>' : '') . '
					</div>
				</div>

				<div class="tl_formbody_submit">
					<div class="tl_submit_container">
						<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_storelocator']['import']['start']) . '">
					</div>
				</div>
			</form>
		';
    }