<?php
/**
* Joomla! 1.5 component injooosm
*
* @version $Id: view.html.php 2010-02-16 13:43:00$
* @author Christian Knorr
* @package injooosm
* @subpackage frontend
* @license GNU/GPL
* @filesource
*
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.view');
jimport('joomla.html.pagination');
/**
* HTML View class for the injooosm component
*/
// class injooosmViewTracks extends JView {
class injooosmViewFiles extends JView {
/**
* Returns true|false if it is allowed to see the file
* @param <obj> $this
* @return <bool>
*/
function maySeeSingleFile($param) {
$published = (bool)$param->track->published;
$access = (int)$param->track->access;
/* $access:
0 = public
1 = registred
2 = spezial
*/
$uid = (int)$param->user->id;
$gid = (int)$param->user->gid;
/*
$gid:
24 admin
25 SuperAdmin
*/
$owner = (int)$param->track->uid;
if ( $gid >= 24 ) {
$admin = true;
$registred = true;
} elseif ( $gid >= 1 ) {
$admin = false;
$registred = true;
} else {
$admin = false;
$registred = false;
}
if ( ( $registred ) AND ( $uid == $owner ) ) {
$myfile = true;
} else {
$myfile = false;
}
if ($registred) {
if ($myfile) return true;
elseif (!$published) return false;
elseif ($access != 2) return true;
elseif (($admin) AND ($access == 2)) return true; else return false;
} else {
if (!$published) return false;
elseif ($access == 0) return true; else return false;
}
return false;
}
/**
*
* @param <type> $tpl
* @return <type>$gps
*/
function display($tpl = null) {
if($this->getLayout() == 'form'):
// $gps = new gpsClass();
$this->_displayForm($tpl);
return;
endif;
if($this->getLayout() == 'file'):
$this->_displayFile($tpl);
return;
endif;
if($this->getLayout() == 'list'):
$this->_displayList($tpl);
return;
endif;
if($this->getLayout() == 'user'):
$this->displayUserTracks($tpl);
return;
endif;
parent::display($tpl);
}
/**
*
* @global <type> $mainframe
* @param <type> $tpl
* @return <type>
*/
function _displayForm($tpl = null) {
global $mainframe;
JHTML::script('jquery.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS, false);
JHTML::script('multifile.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS, false);
JHTML::_('behavior.modal');
JHTML::_('behavior.tooltip');
$cache =& JFactory::getCache('com_injooosm');
$cfg = injooosmHelper::getConfig();
// Make sure you are logged in and have the necessary access rights
$user =& JFactory::getUser();
if ($user->get('gid') < $cfg->gid) {
JResponse::setHeader('HTTP/1.0 403',true);
JError::raiseWarning( 403, JText::_('ALERTNOTAUTH') );
return;
}
$editor =& JFactory::getEditor();
$pathway =& $mainframe->getPathway();
$lh = layoutHelper::navigation();
$footer = layoutHelper::footer();
$model = $this->getModel();
$uri =& JFactory::getURI();
// die(var_dump($uri));
// $uri = str_replace("&","&",$uri);
// Add pathway item
$pathway->addItem(JText::_('New'), '');
$mainframe->setPagetitle(JText::_('OSM_NEW_TRACK'));
$row = $model->getCats();
// $terrain = $model->getTerrain();
$terrain = $cache->get(array($model, 'getTerrain'), array());
$terms = JRoute::_('index2.php?option=com_content&view=article&id='.$cfg->terms_id);
$id =(JRequest::getInt('id', NULL));
$catid = "";
// update part
if(isset($id)) {
// $track = $model->getTrack($id);
// $track = $cache->get(array($model, 'getTrack'), array($id));
$track = $cache->get(array($model, 'getFile'), array($id));
$this->assignRef('track', $track);
$this->assignRef('id', $id);
$catid = $track->catid;
$pathway->addItem(JText::_('OSM_UPDATE'), '');
$mainframe->setPagetitle(JText::_('OSM_UPDATE'));
$selterrain = explode(',', $track->terrain);
}
$access = array(
array('id' => 0, 'text' => JText::_('OSM_PUBLIC')),
array('id' => 1, 'text' => JText::_('OSM_REGISTERED'))
);
$lists['content'] = JHTML::_('select.genericlist', $row, 'catid', 'size="1"', 'id', 'title', $catid );
$lists['terrain'] = JHTML::_('select.genericlist', $terrain, 'terrain[]', 'multiple="multiple" size="5"', 'title', 'title', $selterrain );
$lists['access'] = JHTML::_('select.genericlist', $access, 'access', 'size="2"', 'id', 'text', $track->access );
// $lists['access'] = JHTML::_('list.accesslevel', $access, 'access', 'size="2"', 'id', 'text', $track->access );
// $lists['access'] = JHTML::_('list.accesslevel', $track->access );
// $gps = new gpsClass();
$this->assignRef('kml', $start);
$this->assignRef('lh', $lh);
$this->assignRef('footer', $footer);
$this->assignRef('track', $track);
$this->assignRef('editor', $editor);
$this->assignRef('lists', $lists);
$this->assignRef('action', $uri->toString());
$this->assignRef('cfg', $cfg);
$this->assignRef('terms', $terms);
$this->assignRef('comments', $comments);
// $this->assignRef('gps', $gps);
parent::display($tpl);
}
function _displayFile($tpl) {
global $mainframe;
// JHTML::_('behavior.modal'); // with this option IE doesn't work
JHTML::_('behavior.combobox');
$cache =& JFactory::getCache('com_injooosm');
$lh = layoutHelper::navigation();
$footer = layoutHelper::footer();
$cfg = injooosmHelper::getConfig();
$model = $this->getModel();
$pathway =& $mainframe->getPathway();
$id =& JRequest::getInt('id');
// die(var_dump($id));
// $track = $model->getTrack($id);
// $track = $cache->get(array($model, 'getTrack'), array($id));
// if (!$id) die ("Schau mal in datei view.html.php Zeile 152 :-P");
// if (!$id) $id = 1;
//die (var_dump($id));
$track = $cache->get(array($model, 'getFile'), array($id));
// die (var_dump($track));
if (!$track) return false;
// $vote = $model->getVotes($id);
$vote = $cache->get(array($model, 'getVotes'), array($id));
$pathway->addItem($track->title, '');
$mainframe->setPageTitle($track->title);
$date = JHTML::_('date', $track->date, JText::_('DATE_FORMAT_LC4'));
$profile = getProfileLink($track->uid, $track->user);
// $comments = $model->getComments($id, $cfg->ordering);
$comments = $cache->get(array($model, 'getComments'), array($id, $cfg->ordering));
$user =& JFactory::getUser();
$document =& JFactory::getDocument();
// Kartenauswahl BEGIN
if ( $cfg->map == "google" ) {
$document->addScript('http://www.google.com/jsapi?key='.$cfg->apikey);
$document->addScript('http://www.google.com/uds/api?file=uds.js&v=1.0&key='.$cfg->apikey);
$document->addScript('http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js.uncompressed.js');
$document->addStylesheet('http://www.google.com/uds/css/gsearch.css');
JHTML::script('injooosm.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS, false);
JHTML::script('jd.gallery.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS, true);
}
if ( $cfg->map == "osm" ) {
$document->addScript('http://www.openlayers.org/api/OpenLayers.js');
// JHTML::script('OpenLayers.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS.'OpenLayers'., false); // IE-Fehler
$document->addScript('http://www.openstreetmap.org/openlayers/OpenStreetMap.js');
$document->addScript('http://www.openlayers.org/api/Ajax.js');
// $document->addScript('components/com_injooosm/assets/js/GPX.js');
JHTML::script('injooosm.js', 'components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS, false); // Für Durchschnittsberechnung
// $document->addScript('components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS.'injooosm.js');
$document->addScript('components'.DS.'com_injooosm'.DS.'assets'.DS.'js'.DS.'jd.gallery.js');
// $document->addScript('');
$document->addScript('http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js');
// $document->addScript('components/com_injooosm/assets/js/dojo-release-1.3.2/dojo/dojo.js');
}
$action = "index.php?option=com_injooosm&controller=download&task=download";
$gps = new gpsClass();
// Kartenauswahl BEGIN
if ( $cfg->map == "google" )
$map = $cache->get(array($gps, 'writeTrackGoogle'), array($track));
if ( $cfg->map == "osm" )
$map = $cache->get(array($gps, 'writeTrackOSM'), array($track));
// Kartenauswahl END
$unit = $cfg->unit;
$distance = $track->distance;
$disunit = "Km";
if($unit == "Miles"):
$distance = getMiles($track->distance);
$disunit = "Mi";
endif;
// charts
$file = '.'.DS.'components'.DS.'com_injooosm'.DS.'uploads'.DS.strtolower($track->file);
/*
// ToDo: mehrere Profile in einem
$coords = array();
$i = 0;
while (true) {
$coords_tmp = $cache->get(array($gps, 'getCoords'), array($file,$i));
if ($coords_tmp)
$coords = array_merge($coords, $coords_tmp);
else
break;
$i++;
}
*/
$coords = $cache->get(array($gps, 'getCoords'), array($file));
if(isset($coords[0][3])) {
// Speedprofile
$speeddata = $cache->get(array($gps, 'createSpeedData'), array($coords,$unit));
}
if(!$speeddata)$speeddata = false;
if($coords[0][2] > 0) {
// Heightprofile ($chartdata)
$chartdata = $cache->get(array($gps, 'createChartsData'), array($coords));
// For what is that ($cdis)?
// $cdis = $cache->get(array($gps, 'distance2chart'), array($distance));
}
// heartbeat
if(isset($coords[0][4]) && $coords[0][4] > 0) {
// $beat = $gps->createBeatsData($coords);
$beat = $cache->get(array($gps, 'createBeatsData'), array($coords));
$this->assignRef('beat', $beat);
}
// Klicklinks for every track in one file (at the moment not active)
$clicklist = $cache->get(array($gps, 'giveClickLinks'), array($file));
if ( ( count($clicklist) ) < 2 ) {
$clicklist = false;
}
// load images if exists
jimport('joomla.filesystem.file');
$img_dir = JPATH_SITE.DS.'images'.DS.'injooosm'.DS.$id;
if(JFolder::exists($img_dir)) {
$exclude = array('.db','.txt');
$images = JFolder::files($img_dir, '', true, false, $exclude);
}
$this->assignRef('lh', $lh);
$this->assignRef('footer', $footer);
$this->assignRef('map', $map);
$this->assignRef('cfg', $cfg);
$this->assignRef('track', $track);
$this->assignRef('vote', $vote);
$this->assignRef('distance', $distance);
$this->assignRef('clicklist', $clicklist);
$this->assignRef('action', $action);
$this->assignRef('images', $images);
$this->assignRef('date', $date);
$this->assignRef('profile', $profile);
$this->assignRef('unit', $disunit);
$this->assignRef('chart', $chartdata);
$this->assignRef('speed', $speeddata);
$this->assignRef('comments', $comments);
$this->assignRef('user', $user);
$this->assignRef('model', $model);
parent::display($tpl);
}
function _displayList($tpl) {
global $mainframe, $option;
$model =& $this->getModel();
$cache =& JFactory::getCache('com_injooosm');
$lh = layoutHelper::navigation();
$footer = layoutHelper::footer();
$cfg = injooosmHelper::getConfig();
$pathway =& $mainframe->getPathway();
$pathway->addItem(JText::_('OSM_TRACKS'), '');
$mainframe->setPageTitle(JText::_('OSM_TRACKS'));
$params = &$mainframe->getParams();
$order = JRequest::getVar( 'order', 'order', 'post', 'string' );
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order", 'filter_order', 'ordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir", 'filter_order_Dir', '', 'word' );
$search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
$search = JString::strtolower( $search );
$limit = $mainframe->getUserStateFromRequest( $option.'.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
$limitstart = JRequest::getVar('limitstart',0,'','int');
$action = JRoute::_('index.php?option=com_injooosm&view=files&layout=list');
$lists['order'] = $filter_order;
$lists['order_Dir'] = $filter_order_Dir;
$lists['search']= $search;
// $rows =& $model->getData($limit, $limitstart );
$rows = $cache->get(array($model, 'getData'), array($limit, $limitstart));
$total = & $this->get( 'Total');
$pagination =& new JPagination($total, $limitstart, $limit);
$this->assignRef('lists', $lists);
$this->assignRef( 'rows', $rows);
$this->assignRef('pagination', $pagination);
$this->assignRef('lh', $lh);
$this->assignRef('footer', $footer);
$this->assignRef('action', $action);
$this->assignRef('cfg', $cfg);
$this->assignREf('params', $params);
parent::display($tpl);
}
function displayUserTracks($tpl) {
global $mainframe, $option;
$lh = layoutHelper::navigation();
$footer = layoutHelper::footer();
$model =& $this->getModel();
$cfg = injooosmHelper::getConfig();
$pathway =& $mainframe->getPathway();
$pathway->addItem(JText::_('OSM_MY_TRACKS'), '');
$mainframe->setPageTitle(JText::_('OSM_MY_TRACKS'));
$order = JRequest::getVar( 'order', 'order', 'post', 'string' );
$filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order", 'filter_order', 'ordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir", 'filter_order_Dir', '', 'word' );
$search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
$search = JString::strtolower( $search );
$limit = $mainframe->getUserStateFromRequest( $option.'.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
$limitstart = JRequest::getVar('limitstart',0,'','int');
$action = JRoute::_('index.php?option=com_injooosm&view=files&layout=user');
$lists['order'] = $filter_order;
$lists['order_Dir'] = $filter_order_Dir;
$lists['search'] = $search;
$rows =& $model->getData($limit, $limitstart );
$total = & $this->get( 'Total');
$pagination =& new JPagination($total, $limitstart, $limit);
$this->assignRef('lh', $lh);
$this->assignRef('footer', $footer);
$this->assignRef('action', $action);
$this->assignRef('cfg', $cfg);
$this->assignRef('lists', $lists);
$this->assignRef( 'rows', $rows);
$this->assignRef('pagination', $pagination);
parent::display($tpl);
}
}