コード例 #1
0
 /**
  * Run the geocoding process.
  *
  * @param string Geocoding mode: "missing" or "all"
  *
  * @return string HTML code with geocoding results
  */
 protected function geocode($mode)
 {
     if ($mode != 'all' && $mode != 'missing') {
         //wrong mode
         $message = new t3lib_FlashMessage('Invalid geocoding mode', '', t3lib_FlashMessage::ERROR);
         return $message->render();
     }
     if ($mode == 'missing') {
         $where = 'tx_odsosm_lon = 0 AND tx_odsosm_lat = 0';
     } else {
         $where = '1';
     }
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_address', $where . ' AND pid = ' . $this->pObj->id);
     $count = 0;
     $updated = 0;
     $html = '';
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $oldRow = $row;
         ++$count;
         if (!tx_odsosm_div::updateAddress($row)) {
             //not updated
             continue;
         }
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_address', 'uid = ' . intval($row['uid']), array('tx_odsosm_lat' => $row['lat'], 'tx_odsosm_lon' => $row['lon']));
         $err = $GLOBALS['TYPO3_DB']->sql_error();
         if ($err) {
             $message = new t3lib_FlashMessage('SQL error: ' . htmlspecialchars($err), '', t3lib_FlashMessage::ERROR);
             $html .= $message->render();
         }
         ++$updated;
     }
     $message = new t3lib_FlashMessage('Updated ' . $updated . ' of ' . $count . ' address records', '', $updated == $count ? t3lib_FlashMessage::OK : t3lib_FlashMessage::WARNING);
     $html .= $message->render();
     return $html . '<br/><br/>';
 }
コード例 #2
0
 public function getMainLayers($layers, $backpath = '')
 {
     // Main layer
     $i = 0;
     $jsMainLayer = '';
     foreach ($layers as $layer) {
         $jsMainLayer .= $this->getLayer($layer, $i, $backpath);
         $i++;
     }
     tx_odsosm_div::addJsFiles($this->scripts);
     return $jsMainLayer;
 }
コード例 #3
0
    public function getMapBE($layers, $mode, $lat, $lon, $zoom)
    {
        $jsMainLayer = $this->getMainLayers($layers, $GLOBALS['BACK_PATH'] . '../');
        // Include JS
        $this->getMapCore($GLOBALS['BACK_PATH'] . '../');
        tx_odsosm_div::addJsFiles($this->scripts);
        // Action
        switch ($mode) {
            case 'vector':
                $action = $this->getJSvectors();
                break;
            default:
                $action = $this->getJScoordinates();
                break;
        }
        return 'var map; //complex object of type OpenLayers.Map

' . $action . '

	function map(){
		' . $this->getMapMain() . '
		' . $jsMainLayer . '
		' . $this->getMapCenter($lat, $lon, $zoom) . '
		mapAction();
	}';
    }
コード例 #4
0
 function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $obj)
 {
     switch ($table) {
         case 'fe_users':
         case 'tt_address':
             $config = tx_odsosm_div::getConfig(array('autocomplete'));
             // Search coordinates
             if ($config['autocomplete'] && ($fieldArray['zip'] || $fieldArray['city'] || $fieldArray['address'])) {
                 $address = $obj->datamap[$table][$id];
                 if ($config['autocomplete'] == 2 || floatval($address['tx_odsosm_lon']) == 0) {
                     $ll = tx_odsosm_div::updateAddress($address);
                     if ($ll) {
                         $fieldArray['tx_odsosm_lon'] = sprintf('%01.6f', $address['lon']);
                         $fieldArray['tx_odsosm_lat'] = sprintf('%01.6f', $address['lat']);
                         if ($address['street']) {
                             $fieldArray['address'] = $address['street'];
                             if ($address['housenumber']) {
                                 $fieldArray['address'] .= ' ' . $address['housenumber'];
                             }
                         }
                         if ($address['zip']) {
                             $fieldArray['zip'] = $address['zip'];
                         }
                         if ($address['city']) {
                             $fieldArray['city'] = $address['city'];
                         }
                         if ($address['state'] && $table == 'tt_address') {
                             $fieldArray['region'] = $address['state'];
                         }
                         if ($address['country']) {
                             $fieldArray['country'] = $address['country'];
                         }
                     }
                 }
             }
             break;
         case 'tx_odsosm_track':
             $filename = PATH_site . 'uploads/tx_odsosm/' . $fieldArray['file'];
             if ($fieldArray['file'] && file_exists($filename)) {
                 require_once t3lib_extMgm::extPath('ods_osm', 'res/geoPHP/geoPHP.inc');
                 $polygon = geoPHP::load(file_get_contents($filename), pathinfo($filename, PATHINFO_EXTENSION));
                 $box = $polygon->getBBox();
                 $fieldArray['min_lon'] = sprintf('%01.6f', $box['minx']);
                 $fieldArray['min_lat'] = sprintf('%01.6f', $box['miny']);
                 $fieldArray['max_lon'] = sprintf('%01.6f', $box['maxx']);
                 $fieldArray['max_lat'] = sprintf('%01.6f', $box['maxy']);
             }
             break;
         case 'tx_odsosm_marker':
             if ($fieldArray['icon'] && file_exists(PATH_site . 'uploads/tx_odsosm/' . $fieldArray['icon'])) {
                 $size = getimagesize(PATH_site . 'uploads/tx_odsosm/' . $fieldArray['icon']);
                 $fieldArray['size_x'] = $size[0];
                 $fieldArray['size_y'] = $size[1];
                 $fieldArray['offset_x'] = -round($size[0] / 2);
                 $fieldArray['offset_y'] = -$size[1];
             }
             break;
         case 'tx_odsosm_vector':
             if ($fieldArray['data']) {
                 $this->lon = array();
                 $this->lat = array();
                 $vector = json_decode($fieldArray['data']);
                 foreach ($vector->geometry->coordinates[0] as $coordinates) {
                     $this->lon[] = $coordinates[0];
                     $this->lat[] = $coordinates[1];
                 }
             }
             $fieldArray['min_lon'] = sprintf('%01.6f', min($this->lon));
             $fieldArray['min_lat'] = sprintf('%01.6f', min($this->lat));
             $fieldArray['max_lon'] = sprintf('%01.6f', max($this->lon));
             $fieldArray['max_lat'] = sprintf('%01.6f', max($this->lat));
             break;
     }
 }
コード例 #5
0
 function extractGroup($record_ids)
 {
     // get pages
     if (!empty($record_ids['pages'])) {
         $tables = array('fe_users', 'fe_groups', 'tt_address', 'tt_address_group', 'tx_odsosm_track');
         $pids = implode(',', $record_ids['pages']);
         foreach ($tables as $table) {
             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid IN (' . $pids . ')' . $this->cObj->enableFields($table));
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $record_ids[$table][] = $row['uid'];
             }
         }
     }
     // get records
     $records = array();
     foreach ($record_ids as $table => $items) {
         foreach ($items as $item) {
             $item = intval($item);
             switch ($table) {
                 case 'fe_groups':
                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'fe_groups', 'uid=' . $item . $this->cObj->enableFields('fe_groups'));
                     $group = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                     if ($group) {
                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'fe_users', 'FIND_IN_SET("' . $item . '",usergroup)' . $this->cObj->enableFields('fe_users'));
                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                             $records['fe_users'][$row['uid']] = $row;
                             $records['fe_users'][$row['uid']]['group_uid'] = 'fe_groups_' . $group['uid'];
                             $records['fe_users'][$row['uid']]['group_title'] = $group['title'];
                             $records['fe_users'][$row['uid']]['group_description'] = $group['description'];
                             $records['fe_users'][$row['uid']]['tx_odsosm_marker'] = $group['tx_odsosm_marker'];
                         }
                     }
                     break;
                 case 'tt_address_group':
                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_address_group', 'uid=' . $item . tx_odsosm_div::getWhere('tt_address_group'));
                     $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                     $group = tx_odsosm_div::getOverlay('tt_address_group', $row);
                     if ($group) {
                         $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tt_address.*', 'tt_address', 'tt_address_group_mm', 'tt_address_group', 'AND tt_address_group.uid=' . intval($group['uid']) . $this->cObj->enableFields('tt_address'));
                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                             $records['tt_address'][$row['uid']] = $row;
                             $records['tt_address'][$row['uid']]['group_uid'] = 'tt_address_group_' . $group['uid'];
                             $records['tt_address'][$row['uid']]['group_title'] = $group['title'];
                             $records['tt_address'][$row['uid']]['group_description'] = $group['description'];
                             $records['tt_address'][$row['uid']]['tx_odsosm_marker'] = $group['tx_odsosm_marker'];
                         }
                     }
                     break;
                 default:
                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . $item . $this->cObj->enableFields($table));
                     $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                     if ($row) {
                         $records[$table][$item] = $row;
                     }
                     break;
             }
         }
     }
     // Hook to change records
     foreach ($this->hooks as $hook) {
         if (method_exists($hook, 'changeRecords')) {
             $hook->changeRecords($records, $record_ids, $this);
         }
     }
     // get lon&lat
     foreach ($records as $table => $items) {
         foreach ($items as $uid => $row) {
             switch ($table) {
                 case 'fe_users':
                 case 'tt_address':
                     if ($row['tx_odsosm_lon']) {
                         $this->lons[] = floatval($row['tx_odsosm_lon']);
                         $this->lats[] = floatval($row['tx_odsosm_lat']);
                     } else {
                         unset($records[$table][$uid]);
                     }
                     break;
                 case 'tx_odsosm_track':
                 case 'tx_odsosm_vector':
                     if ($row['min_lon']) {
                         $this->lons[] = floatval($row['min_lon']);
                         $this->lats[] = floatval($row['min_lat']);
                         $this->lons[] = floatval($row['max_lon']);
                         $this->lats[] = floatval($row['max_lat']);
                     } else {
                         unset($records[$table][$uid]);
                     }
                     break;
             }
         }
     }
     // No markers
     if (count($this->lons) == 0) {
         if ($this->config['no_marker'] == 1) {
             $this->lons[] = $this->config['lon'];
             $this->lats[] = $this->config['lat'];
         }
     }
     return $records;
 }
コード例 #6
0
 function updateCache($address, $search = array())
 {
     $set = array('search_city' => $search['city'], 'country' => $address['country'], 'state' => $address['state'], 'city' => $address['city'], 'zip' => $address['zip'], 'street' => $address['street'], 'housenumber' => $address['housenumber']);
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_odsosm_geocache', implode(' AND ', tx_odsosm_div::getSet($set, 'tx_odsosm_geocache')));
     $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
     if ($row) {
         $set = array('tstamp' => time(), 'service_hit' => $row['service_hit'] + 1);
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_odsosm_geocache', 'uid=' . $row['uid'], $set);
     } else {
         $set['tstamp'] = time();
         $set['crdate'] = time();
         $set['service_hit'] = 1;
         $set['lat'] = $address['lat'];
         $set['lon'] = $address['lon'];
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_odsosm_geocache', $set);
     }
 }