function save() { $mainframe = JFactory::getApplication(); // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $post = JRequest::get('post'); $file = JRequest::getVar('csv_file', '', 'files', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $format = JRequest::getVar('format', 'html', '', 'cmd'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $err = null; // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Make the filename safe jimport('joomla.filesystem.file'); $file['name'] = JFile::makeSafe($file['name']); //Open the File in Read mode $handle = fopen($file['tmp_name'], "r"); //Grab the first row and flip the array returned so that the value become the key and key becomes value //We now have an array of the file headers looking like Array ( [Name] => 0 [Address1] => 1 ...etc $file_headers = array_flip(fgetcsv($handle)); //While we are able to return data from the file parse the file and store the data while (($data = fgetcsv($handle)) !== FALSE) { $model_data = array(); //Create an array to store data for the location $model_data['name'] = $data[$file_headers['Name']]; $model_data['address1'] = $data[$file_headers['Address1']]; $model_data['address2'] = $data[$file_headers['Address2']]; $model_data['city'] = $data[$file_headers['City']]; $model_data['state'] = $data[$file_headers['State']]; $model_data['zip'] = $data[$file_headers['Zip_Postal_Code']]; $model_data['email'] = $data[$file_headers['Email']]; $model_data['country_code'] = $data[$file_headers['ISO_Country_Code']]; $model_data['published'] = $data[$file_headers['Published']]; $point = WebmapPlusHelper::GeoCode("" . $model_data['address1'] . " " . $model_data['address2'] . ", " . $model_data['city'] . ", " . $model_data['state'] . " " . $model_data['zip'] . ", " . $model_data['country_code']); $model_data['lat'] = $point[1]; $model_data['long'] = $point[0]; $location = $this->getModel('location'); if ($location->store($model_data)) { $msg = JText::_('Location Saved'); } else { $msg = JText::_('Error Saving Location: ' . $model_data['name'] . ' Error: ' . $location->getError()); break; } //Reset array and store attributes $model_data = array(); $csv = $this->getModel('csv'); $attributes = $csv->getAllAttributes(); foreach ($attributes as $attrib) { $model_data['value'] = $data[$file_headers[$attrib->name]]; $model_data['id'] = $attrib->id; if (!$location->addAttribute($model_data['id'], $model_data['value'])) { $msg = JText::_('Error Saving Location: ' . $model_data['name']); break; } } } fclose($handle); $link = 'index.php?option=com_webmapplus'; $this->setRedirect($link, $msg); }
function getData() { // Lets load the content if it doesn't already exist if (empty($this->_data)) { $address = JRequest::getVar('address', 0); $range = JRequest::getInt('range', 20); if (!empty($address)) { $latlng = WebmapPlusHelper::GeoCode($address, true); $data = $this->getLocByLatLngBox($latlng, $range); } else { $data = $this->getLocations(); } if (!isset($data)) { $data = array(); } $locIds = array(); foreach ($data as $d) { $locIds[] = $d->id; } $query = $this->_buildAttributeQuery($locIds); $attrs = $this->_getList($query); $notFoundPhoto = new stdClass(); $notFoundPhoto->path = "na.jpg"; $notFoundPhoto->name = "No Picture"; $useLetters = count($data) > 1 && count($data) <= 26; $index = 0; $markerIds = array(); foreach ($data as $item) { $item->attributes = array(); if (!empty($attrs)) { foreach ($attrs as $attr) { if ($attr->loc_id == $item->id) { $item->attributes[] = $attr; } } } if (!empty($item->photo_path)) { $item->photo_path = WEBMAPPLUS_MEDIA_URL . $item->photo_path; } else { $item->photo_path = WEBMAPPLUS_ASSETS_URL . "images/na.jpg"; } $item->link = JRoute::_('index.php?option=com_webmapplus&view=location&id=' . $item->id); //If Item has a category $category_marker = 0; if ($item->category > 0) { $category_marker = $this->categoryMarkerType($item->category); //If item-marker is set to the system default and category marker is set if ($item->markerType == 0 && $category_marker != 0) { $item->markerType = $category_marker; } } else { //If item-marker is set to the system default if ($item->markerType == 0) { $item->markerType = 1; } } if ($item->markerType == 0) { $item->markerType = 1; } //categoryMarkerType($item->category); $markerIds[$item->markerType] = 1; $index++; } $markerTypes = $this->_getMarkerTypes(array_keys($markerIds)); } $this->_data = array("markers" => $data, "markerTypes" => $markerTypes, "useLetters" => $useLetters); return $this->_data; }
function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $post = JRequest::get('post', JREQUEST_ALLOWHTML); $cid = JRequest::getVar('cid', array(0), 'post', 'array'); $lat = JRequest::getVar('lat', 0, 'post', 'float'); $long = JRequest::getVar('long', 0, 'post', 'float'); $address1 = JRequest::getVar('address1', '', 'post', 'string'); $address2 = JRequest::getVar('address2', '', 'post', 'string'); $city = JRequest::getVar('city', '', 'post', 'string'); $state = JRequest::getVar('state', '', 'post', 'string'); $zip = JRequest::getVar('zip', '', 'post', 'string'); $country = JRequest::getVar('country_code', '', 'post', 'string'); $post['id'] = (int) $cid[0]; $model = $this->getModel('location'); $model->setId($post['id']); $location = $model->getData(); if (empty($lat) || empty($long) || $location->address1 != $address1 || $location->address2 != $address2 || $location->city != $city || $location->state != $state || $location->zip != $zip || $location->country != $country) { $point = WebmapPlusHelper::GeoCode("{$address1} {$address2}, {$city}, {$state} {$zip}, {$country}"); if ($point == "400") { $this->setError(JText::_('Geocoding Failed: Bad Request')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "500") { $this->setError(JText::_('Geocoding Failed: Server Error - Try again')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "601") { $this->setError(JText::_('Geocoding Failed: Empty Address Request - Remeber to include an address for the location')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "602") { $this->setError(JText::_('Geocoding Failed: Location Not Found')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "603") { $this->setError(JText::_('Geocoding Failed: Google is unable to geocode this address due to legal concerns')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "604") { $this->setError(JText::_('Geocoding Failed: Unkown Error')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "610") { $this->setError(JText::_('Geocoding Failed: Google Maps Key is either not set or incorrect')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if ($point == "620") { $this->setError(JText::_('Geocoding Failed: Too many requests')); } else { if ($point == "") { $this->setError(JText::_('Geocoding Failed: Empty Address Request - Remeber to include an address for the location')); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } else { if (empty($lat)) { $post['lat'] = $point[1]; } if (empty($long)) { $post['long'] = $point[0]; } } } } } } } } } } } $file = JRequest::getVar('photo_path', '', 'files', 'array'); jimport('joomla.filesystem.file'); $file['name'] = JFile::makeSafe($file['name']); if (isset($file['name']) && !empty($file['name']) && isset($location->photo_path) && !empty($location->photo_path) && is_file(COM_WEBMAPPLUS_MEDIA_BASE . DS . $location->photo_path) && strtolower($file['name']) == $location->photo_path) { unlink(COM_WEBMAPPLUS_MEDIA_BASE . DS . $location->photo_path); } $post['photo_path'] = $this->uploadImage(); if ($model->store($post)) { $msg = JText::_('Location Saved'); } else { $msg = $model->getError() . JText::_(' - Error Saving Location'); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); } foreach ($post as $key => $value) { if (substr($key, 0, 5) == 'attr_') { $var = explode('_', $key); if (isset($var[2]) && !empty($var[2])) { if (!$model->updateAttribute($var[2], $value)) { $msg = JText::_('Error Saving Location'); break; } } else { if (!$model->addAttribute($var[1], $value)) { $msg = JText::_('Error Saving Location'); $model->checkin(); $link = 'index.php?option=com_webmapplus&controller=location&task=edit&cid[]=' . $post['id']; $this->setRedirect($link, $this->getError() . $msg); $this->redirect(); break; } } } } $model->checkin(); $link = 'index.php?option=com_webmapplus&view=webmapplus'; $this->setRedirect($link, $this->getError() . $msg); }