/** * Parse the datagrid */ protected function parse() { parent::parse(); $this->tpl->assign('dataGrid', $this->dataGrid->getNumResults() != 0 ? $this->dataGrid->getContent() : false); // get settings $settings = BackendModel::getModuleSettings(); // assign to template $this->tpl->assign('items', BackendLocationModel::getAll()); $this->tpl->assign('settings', $settings['location']); }
/** * 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); }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $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')); // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = BL::getWorkingLanguage(); $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(); // 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; // insert the item $id = BackendLocationModel::insert($item); // add search index // if(is_callable(array('BackendSearchModel', 'addIndex'))) BackendSearchModel::addIndex($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_add', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id); } } } }
/** * 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')); }
/** * Load the settings */ protected function loadData() { $this->items = BackendLocationModel::getAll(); $this->settings = BackendLocationModel::getMapSettings(0); $firstMarker = current($this->items); // if there are no markers we reset it to the birthplace of Fork if ($firstMarker === false) { $firstMarker = array('lat' => '51.052146', 'lng' => '3.720491'); } // load the settings from the general settings if (empty($this->settings)) { $settings = BackendModel::getModuleSettings(); $this->settings = $settings['location']; $this->settings['center']['lat'] = $firstMarker['lat']; $this->settings['center']['lng'] = $firstMarker['lng']; } // no center point given yet, use the first occurance if (!isset($this->settings['center'])) { $this->settings['center']['lat'] = $firstMarker['lat']; $this->settings['center']['lng'] = $firstMarker['lng']; } }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendLocationModel::exists($this->id)) { parent::execute(); // get all data for the item we want to edit $this->record = (array) BackendLocationModel::get($this->id); // delete item BackendLocationModel::delete($this->id); // delete search indexes // @todo why is this commented out // BackendSearchModel::removeIndex($this->getModule(), $this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['title'])); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Execute the action * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendLocationModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get all data for the item we want to edit $this->record = (array) BackendLocationModel::get($this->id); // delete item BackendLocationModel::delete($this->id); // delete search indexes // if(is_callable(array('BackendSearchModel', 'removeIndex'))) BackendSearchModel::removeIndex($this->getModule(), $this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['title'])); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * 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']); } } } }