/** * Execute the action */ public function execute() { parent::execute(); // get parameters $itemId = trim(SpoonFilter::getPostValue('id', null, '', 'int')); $lat = SpoonFilter::getPostValue('lat', null, null, 'float'); $lng = SpoonFilter::getPostValue('lng', null, null, 'float'); if ($itemId == 0) { $this->output(self::BAD_REQUEST, null, BL::err('NonExisting')); } $updateData = array('id' => $itemId, 'lat' => $lat, 'lng' => $lng, 'language' => BL::getWorkingLanguage()); BackendLocationModel::update($updateData); // output $this->output(self::OK); }
/** * Execute the action */ public function execute() { parent::execute(); $generalSettings = BackendModel::getModuleSettings(); $generalSettings = $generalSettings['location']; // get parameters $itemId = SpoonFilter::getPostValue('id', null, null, 'int'); $zoomLevel = trim(SpoonFilter::getPostValue('zoom', null, 'auto')); $mapType = strtoupper(trim(SpoonFilter::getPostValue('type', array('roadmap', 'satelitte', 'hybrid', 'terrain'), 'roadmap'))); $centerLat = SpoonFilter::getPostValue('centerLat', null, 1, 'float'); $centerlng = SpoonFilter::getPostValue('centerLng', null, 1, 'float'); $height = SpoonFilter::getPostValue('height', null, $generalSettings['height'], 'int'); $width = SpoonFilter::getPostValue('width', null, $generalSettings['width'], 'int'); $showLink = SpoonFilter::getPostValue('link', array('true', 'false'), 'false', 'string'); $showDirections = SpoonFilter::getPostValue('directions', array('true', 'false'), 'false', 'string'); $showOverview = SpoonFilter::getPostValue('showOverview', array('true', 'false'), 'true', 'string'); // reformat $center = array('lat' => $centerLat, 'lng' => $centerlng); $showLink = $showLink == 'true'; $showDirections = $showDirections == 'true'; $showOverview = $showOverview == 'true'; // standard dimensions if ($width > 800) { $width = 800; } if ($width < 300) { $width = $generalSettings['width']; } if ($height < 150) { $height = $generalSettings['height']; } // no id given, this means we should update the main map BackendLocationModel::setMapSetting($itemId, 'zoom_level', (string) $zoomLevel); BackendLocationModel::setMapSetting($itemId, 'map_type', (string) $mapType); BackendLocationModel::setMapSetting($itemId, 'center', (array) $center); BackendLocationModel::setMapSetting($itemId, 'height', (int) $height); BackendLocationModel::setMapSetting($itemId, 'width', (int) $width); BackendLocationModel::setMapSetting($itemId, 'directions', $showDirections); BackendLocationModel::setMapSetting($itemId, 'full_url', $showLink); $item = array('id' => $itemId, 'language' => BL::getWorkingLanguage(), 'show_overview' => $showOverview ? 'Y' : 'N'); BackendLocationModel::update($item); // output $this->output(self::OK, null, FL::msg('Success')); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['extra_id'] = $this->record['extra_id']; $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['street'] = $this->frm->getField('street')->getValue(); $item['number'] = $this->frm->getField('number')->getValue(); $item['zip'] = $this->frm->getField('zip')->getValue(); $item['city'] = $this->frm->getField('city')->getValue(); $item['country'] = $this->frm->getField('country')->getValue(); // check if it's neccessary to geocode again if ($this->record['lat'] === null || $this->record['lng'] === null || $item['street'] != $this->record['street'] || $item['number'] != $this->record['number'] || $item['zip'] != $this->record['zip'] || $item['city'] != $this->record['city'] || $item['country'] != $this->record['country']) { // geocode address $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; $geocode = json_decode(SpoonHTTP::getContent($url)); $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; } else { $item['lat'] = $this->record['lat']; $item['lng'] = $this->record['lng']; } // insert the item $id = BackendLocationModel::update($item); // edit search index // @todo why is this commented out? // BackendSearchModel::editIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text'])); // everything is saved, so redirect to the overview if ($item['lat'] && $item['lng']) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id']); } } } }