Location: PHPKode > projects > injooosm > administrator/components/com_injooosm/views/files/view.html.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: view.html.php 2009-11-22 14:03:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
// $lang = JFactory::getLanguage();
// print_r($lang);

/**
 *
 */
class injooosmViewFiles extends JView {

	/**
	* Gibt den übersetzten Status zurück
	* @param  status (int)
	* @return Status (string)
	*/
	public function buildRowGroupname($rowaccess){
		if ($rowaccess == 0)
			return JText::_( 'PUBLIC' );
		elseif ($rowaccess == 1)
			return JText::_( 'REGISTERED' );
		elseif ($rowaccess == 2)
			return JText::_( 'SPECIAL' );
}

	/**
	* Gibt den Klicklink zurück mit dem man Spuren direkt editieren kann
	* @param  Filename
	* @param  Zähler
	* @return string
	*/
	public function buildEditKlicks($file,$count){
		return "<a href=\"javascript:void(0);\" onclick=\"javascript:return listItemTask('cb".$count.
			"','editfile')\">".$file."</a>";
	}

	/**
	* Gibt eine Bilderliste der Dateitypen zurück
	* @param  status (int)
	* @return Status (string)
	*/
	public function buildImageFiletypes($track,$wp,$route){
		$imagelink = "<table class=\"fileis\"><tr>";

		if ( ( isset($track) ) AND ( $track == "1" ) ) $m = (string)1; else $m = (string)0;
		$imagelink .= "<td class=\"icon\">";
		if ( isset($track) )
			$imagelink .= "<span class=\"track".$m."\" title=\"".JText::_( 'OSM_ISTRACK'.$m )."\"></span>";
		else
			$imagelink .= "<span class=\"track".$m."\" title=\"".JText::_( 'OSM_DKTRACK' ).
				"\" style=\"text-align:center\"><font size=\"+2\">?</font>";
		$imagelink .= "</td>";

		if ( ( isset($wp) ) AND ( $wp == "1" ) ) $m = (string)1; else $m = (string)0;
		$imagelink .= "<td class=\"icon\">";
		if ( isset($wp) )
			$imagelink .= "<span class=\"wp".$m."\" title=\"".JText::_( 'OSM_ISWP'.$m)."\"></span>";
		else
			$imagelink .= "<span class=\"wp".$m."\" title=\"".JText::_( 'OSM_DKWP' ).
				"\" style=\"text-align:center\"><font size=\"+2\">?</font>";
		$imagelink .= "</td>";
/*
		if ( ( isset($route) ) AND ( $route == "1" ) ) $m = (string)1; else $m = (string)0;
		$imagelink .= "<td class=\"icon\">";
		if ( isset($route) )
			$imagelink .= "<span class=\"route".$m."\" title=\"".JText::_( 'OSM_ISROUTE'.$m )."\">";
		else
			$imagelink .= "<span class=\"route".$m."\" title=\"".JText::_( 'OSM_DKROUTE' )."\" style=\"text-align:center\"><font size=\"+2\">?</font>";
		$imagelink .= "</span>";
		$imagelink .= "</td>";*/

		$imagelink .= "</tr></table>";
		return $imagelink;
}

	/**
	* Überprüft die GPX-Datei für den Massenimport
	* @return true | (string) errormessage
	*/
	public function checkFile($file,$exist=false) {
// 		$xml = simplexml_load_file($file);
// var_dump($xml->trk);
		if ($exist !== false )
			return 1;
		$filename = explode(DS,$file);
		$filename = $filename[(count($filename)-1)];
		if ( !is_writable($file) )		// Kein Schreibrecht
			return 2;
		if ( strlen($filename) > 50 )		// Dateinamenslänge überschritten
			return 3;
		if ( preg_match('/\&/',$filename) )	// Wenn "&" im Dateinamen
			return 4;
		if ( preg_match('/\#/',$filename) )	// Wenn "#" im Dateinamen
			return 5;
		$xml = simplexml_load_file($file);
		if (empty($xml->trk))		// Keine Spur vorhanden
			return 6;
		$i = 0; // Zähler
		$j = 0; // gefundene Spuren
		while (true) {
			if (!empty($xml->trk[$i])) { // Spur vorhanden
				if (!empty($xml->trk[$i]->trkseg->trkpt)) // Punkt vorhanden
					$j++;
				$i++;
			} elseif ( $j == 0 )
				return 7; // Spur vorhanden, aber kein Punkt
			elseif ( ( $j == 1 ) AND ( $i == 1 ) )
				return true; // eine Spur mit Punkten an erster Stelle vorhanden
			else
				return 8; // Spur vorhanden, aber nicht an erster Stelle. Evtl. mehrere Spuren
		}
	}

	/**
	* Extrahiert das Datum aus der GPX-Datei
	* @return date
	*/
	public function giveDate($file) {
		if((!is_file($file)) OR (!is_readable($file)))return false;
		$file = simplexml_load_file($file);
		$date = explode('T',$file->time);
		if ( count($date) != 2 )
			$date = explode('T',$file->trk->trkseg->trkpt->time);
		if ( count($date) != 2 )
			$date = explode('T',$file->metadata->time);
		if ( strlen($date[0]) == 10 )
			return $date[0];
		else
			return false;
	}

	/**
	* Extrahiert den Titel aus der GPX-Datei
	* @return date
	*/
	public function giveTitle($file) {
		if((!is_file($file)) OR (!is_readable($file))) return "";
		$file = simplexml_load_file($file);
		return ($file->trk->name);
	}


    function giveParentCat($catid) {
	$catid = (int)$catid;
	$model = $this->getModel();
	$cats = $model->getCats();
	$i = 0;
	foreach($cats AS $cat){
		$id = (int)$cat->id;
		$title[$id] = $cat->title;
		if ( $catid == $id ){
			$parentid = (int)$cat->parent;
			break;
		}
		$i++;
	}
	return ($title[$parentid]);
    }


    /**
     *
     * @global object $mainframe
     * @global string $option
     * @param object $tpl
     */
    function display($tpl = null) {
        global $mainframe, $option;

        if($this->getLayout() == 'form'):
            $this->_displayForm($tpl);
            return;
        endif;

        $model =& $this->getModel();

        $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 );

        $lists['order']		= $filter_order;
        $lists['order_Dir']	= $filter_order_Dir;
        $lists['search']= $search;
		$rows =& $this->get( 'Data');
		$total		= & $this->get( 'Total');
        $pagination = & $this->get( 'Pagination' );

        $this->assignRef('lists',	$lists);
        $this->assignRef( 'rows',   $rows);
        $this->assignRef('pagination',	$pagination);

        parent::display($tpl);
    }

    function _displayForm($tpl)  {
        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);
// Quick'n'Dirty - Sonst funktioniert das Joomla-Menü nicht mehr: (!?)
        JHTML::script('mootools.js', DS.'media'.DS.'system'.DS.'js'.DS, false);
        $cid =& JRequest::getVar( 'cid', array(), 'post', 'array' );
        $id = implode(',', $cid);
        $editor =& JFactory::getEditor();
        $model = $this->getModel();
        $cats = $model->getCats();
        $terrain = $model->getTerrain();
        $track = $model->getFile($id);
        $level = $model->getLevel($track->level);

        $size = count($cats);
        if ( $size > 6) $size = 6;
        $lists['cats']		= JHTML::_('select.genericlist',
        	$cats, 'catid', 'size="'.$size.'"', 'id', 'title', $track->catid );
        $size = count($terrain);
        if ( $size > 6) $size = 6;
        $lists['terrain']	= JHTML::_('select.genericlist',
		$terrain, 'terrain[]', 'multiple="multiple" size="'.$size.'"', 'title', 'title', $track->terrain );
        $lists['access']	= JHTML::_('list.accesslevel', $row, $i );
        $lists['uid']		= JHTML::_('list.users', 'uid', $track->uid);

        $this->assignRef('editor',	$editor);
        $this->assignRef('lists',	$lists);
        $this->assignRef('track',	$track);
        $this->assignRef('id',		$id);
        $this->assignRef('level',	$level);
        parent::display($tpl);
    }
}

Return current item: injooosm