Location: PHPKode > projects > injooosm > administrator/components/com_injooosm/views/files/tmpl/import.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: import.php 2010-02-06 22:05:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 */

defined('_JEXEC') or die('Restricted access');

// toolbar
JToolBarHelper::title(JText::_('OSM_ADD_FILES'), 'categories.png');
JToolBarHelper::back($alt= 'Back', $href= 'javascript:history.back();');
JToolBarHelper::spacer();
JToolBarHelper::addNew('newfiles', JText::_('OSM_RELOAD'));
// JToolBarHelper::media_manager('&folder=injooosm/newfiles',"Upload");
// $directory = "injooosm/newfiles";
// $alt = "Upload";
// 		$bar = & JToolBar::getInstance('toolbar');
// 		// Add an upload button
// 		$bar->appendButton( 'Popup', 'upload', $alt, "index.php?option=com_media&tmpl=component&task=popupUpload&folder=".$directory, 800, 520 );

// JToolBarHelper::cancel('injooosm');
JToolBarHelper::save('savefiles', JText::_('OSM_NEW_FILES'), 'save.png' );
echo ("<form action=\"\" method=\"post\" name=\"adminForm\" id=\"adminForm\" class=\"adminForm\" enctype=\"multipart/form-data\">\n");
$table = ("		<tbody>\n");
$tracks = $this->rows;
$trackfilename = array();
// Vorhandene Dateinamen in array speichern
for($i=0;$i<count($tracks);$i++) {
	$trackfilename[$i] = $tracks[$i]->file;
}
$row = 0;
$count = 0;
$errorposted = false;
$importdir = JPATH_SITE.DS."components".DS."com_injooosm".DS."uploads".DS."import";
$files = JFolder::files($importdir,".",true,true);
$me =& JFactory::getUser();
foreach($files AS $file) {
// Formatierungen
{
	$model = $this->getModel();
        $size = count($model->getCats());
        if ( $size > 6) $size = 6;
	$lists['cats'] = JHTML::_('select.genericlist',   $model->getCats(), 'catid_'.$count, 'size="'.$size.'"', 'id', 'title');
// 	$lists['description'] = ("<!-- Start Editor --><textarea id=\"description\" name=\"description\" cols=\"15\" rows=\"25\" style=\"width:500px; height:200px;\" class=\"mce_editable\"></textarea><div style=\"margin-top:-5px\"><div class=\"button2-left\"><div class=\"blank\"><a href=\"#\" onclick=\"javascript:tinyMCE.execCommand('mceToggleEditor', false, 'description');return false;\" title=\"Editor an/aus\">Editor an/aus</a></div></div></div><!-- End Editor -->\n");
        $size = count($model->getTerrain());
        if ( $size > 6) $size = 6;
	$lists['access'] = JHTML::_('list.accesslevel', $row, $count );
// Würg!! Geht das auch schöner?
		$lists['access'] = explode("name=\"access\"",$lists['access']);
		$lists['access'] = $lists['access'][0]."name=\"access_".$count."\"".$lists['access'][1];
	$lists['uid'] = JHTML::_('list.users',  'uid_'.$count, $me->id, 1, NULL, 'name', 0 );
        $lists['terrain'] = JHTML::_('select.genericlist',   $model->getTerrain(), 'terrain_'.$count, 'multiple="multiple" size="'.$size.'"', 'title', 'title', $track->terrain );
}

$file_tmp = explode('.',$file);
$extension = strtolower($file_tmp[(count($file_tmp)-1)]);
unset($file_tmp[(count($file_tmp)-1)]);
$filename = implode('.',$file_tmp);
$filename = $filename.".".$extension;
$filename = str_replace($importdir.DS,'',$filename);
$filename_wof = explode(DS,$filename);
$filename_wof = $filename_wof[(count($filename_wof)-1)];

// Wieso zum Henker funktioniert das nicht??
// $extension = JFile::exists($file);
// $filename = strtolower(JFile::getName($file));

	if ( ( $extension == "gpx" ) OR ( $extension == "kml" ) OR ( $extension == "trk" ) ) {
			$date = $this->giveDate($file);
			$title = $this->giveTitle($file);
/*		if (in_array(strtolower($filename_wof),$trackfilename) ) {
			$check = $this->checkFile($file,true);
			$filename_exists = "<input type=\"hidden\" name=\"filenameexists_".$count."\" value=\"true\">\n";
		} else {*/
			$check = $this->checkFile($file);
// 			$filename_exists = "<input type=\"hidden\" name=\"filenameexists_".$count."\" value=\"false\">\n";
// 		}

if ( ( $errorposted == false ) AND ( $check !== true ) ) {
	if ( $check != 8 ) {
		$errorposted = true;
		JError::raiseNotice(0,JText::_('OSM_ERROR_FOUND'));
	}
}

$table .= ("			<tr class=\"row".$row."\">\n");
// Spalte: Checkbox
{
$table .= ("				<td>");
if (
	( $check === true ) OR
// eine Spur mit Punkten an erster Stelle vorhanden
	( $check == 1 ) OR
// Dateiname existiert
// 	( $check == 2 ) OR
// Kein Löschrecht
	( $check == 3 ) OR
// Dateinamenslänge überschritten
// 	( $check == 4 ) OR
// Wenn "&" im Dateinamen
	( $check == 5 ) OR
// Wenn "#" im Dateinamen
	( $check == 6 ) OR
// Keine Spur vorhanden
	( $check == 7 ) OR
// Spur vorhanden, aber kein Punkt
	( $check == 8 )
// Spur vorhanden, aber nicht an erster Stelle. Evtl. mehrere Spuren
)
	$table .= ("<input type=\"checkbox\" id=\"cb".$count."\" name=\"import_".$count."\" onclick=\"isChecked(this.checked);\" />\n");
	$table .= $filename_exists;
	$table .= ("				</td>\n");
}

// Spalte: Dateiname
{
$table .= ("				<td nowrap>");
/*
1 = JText::_('OSM_TT_ERR_FILEEXIST');		green
2 = JText::_('OSM_TT_ERR_NODELETE');		red
3 = JText::_('OSM_TT_ERR_MUCHLEN');		brown
4 = JText::_('OSM_TT_ERR_BADFILENAME')." (&)";	red
5 = JText::_('OSM_TT_ERR_BADFILENAME')." (#)";	red
6 = JText::_('OSM_TT_ERR_NOTRACK');		grey
7 = JText::_('OSM_TT_ERR_NOPOINTINTRACK');	grey
8 = JText::_('OSM_TT_ERR_MORETRACKS');		blue
*/
// if ( ( $check === true ) OR ( $check == 8 ) )
	$table .= ("<input type=\"hidden\" name=\"file_".$count."\" value=\"".$file."\" />\n");

if ( $check !== true ) {
	$table .= ("<span class=\"hasTip\" title=\"");
	if ( $check == 1 ) {
		$table .= JText::_('OSM_TT_ERR_FILEEXIST');
		$color = "green";
	} elseif ( $check == 2 ) {
		$table .= JText::_('OSM_TT_ERR_NODELETE');
		$color = "red";
	} elseif ( $check == 3 ) {
		$table .= JText::_('OSM_TT_ERR_MUCHLEN');
		$color = "brown";
	} elseif ( $check == 4 ) {
		$table .= JText::_('OSM_TT_ERR_BADFILENAME')." (&)";
		$color = "red";
	} elseif ( $check == 5 ) {
		$table .= JText::_('OSM_TT_ERR_BADFILENAME')." (#)";
		$color = "red";
	} elseif ( $check == 6 ) {
		$table .= JText::_('OSM_TT_ERR_NOTRACK');
		$color = "lightgrey";
	} elseif ( $check == 7 ) {
		$table .= JText::_('OSM_TT_ERR_NOPOINTINTRACK');
		$color = "lightgrey";
	} elseif ( $check == 8 ) {
		$table .= JText::_('OSM_TT_ERR_MORETRACKS');
		$color = "blue";
	}
	$table .= ("\"><font color=\"".$color."\">".$filename."</font></span>\n");
} else $table .= $filename;
$table .= ("</td>\n");
}

// Spalte: Datum
{
$table .= ("				<td nowrap><input id=\"date_".$count."\" type=\"text\" name=\"date_".$count."\" size=\"10\" value=\"");
if ($date === false)
	$table .= (date('Y-m-d',time())."\" /><font color=\"orange\">&nbsp;?</font></td>");
else
	$table .= ($date."\" /></td>");
}

// Spalte: Titel
{

$table .= ("\n				<td><input id=\"title\" type=\"text\" name=\"title_".$count."\" value=\"".$title."\" size=\"30\" /></td>\n");
}

// Spalte: Schwierigkeitsgrad
{
$table .= ("				<td>
					<select name=\"level_".$count."\" size=\"6\">
						<option>".JText::_('OSM_SELECT')."</option>
						<option value=\"1\">1</option>
						<option value=\"2\">2</option>
						<option value=\"3\">3</option>
						<option value=\"4\">4</option>
						<option value=\"5\">5</option>
					</select>
				</td>\n");
}

// Spalte: Kategorien
{
$table .= ("				<td>".$lists['cats']."</td>\n");
}

// Spalte: Access (wird doch gar nicht benötigt!?)
{
// $table .= ("				<td>".$lists['access']."</td>\n");
}

// Spalte: Terrain
{
$table .= ("				<td>".$lists['terrain']."</td>\n");
}

// Spalte: Autor
{
$table .= ("				<td>".$lists['uid']."</td>\n");
}

// Spalte: Zugriffsebene
{
$table .= ("				<td>".$lists['access']."</td>\n");
}

// Spalte: Beschreibung
{
// $table .= ("				<td>".$lists['description']."</td>\n");
}

// Spalte: NULL
{
$table .= ("				<td></td>\n");
}

$table .= ("			</tr>\n");
$count++;
$row = (1 - $row);
if ( $count > 100 ) {
	JError::raiseNotice(0,JText::_('OSM_TOO_MUCH_TRACKS_TO_IMPORT'));
	break;
}
			}
}
/*
echo JText::_('AUTHOR');
echo JText::_('OSM_LEVEL');
echo JText::_('OSM_SELECT');
echo JText::_('OSM_CAT');
echo JText::_('OSM_ACCESS_LEVEL');
echo JText::_('OSM_FILE');
echo JText::_('OSM_TERRAIN');
echo JText::_('OSM_DESCRIPTION');
echo JText::_('OSM_IMAGES');
echo JText::_('OSM_TERMS');*/

$table_header = ("	<table class=\"adminlist\" cellpadding=\"1\">
		<thead>
			<tr>
				<th class=\"title\" width=\"1\"><input type=\"checkbox\" name=\"toggle\" value=\"\" onclick=\"checkAll(".$count.");\" /></th>
				<th class=\"title\" width=\"1\">".JText::_('OSM_FILE')."</th>
				<th class=\"title\" width=\"1\">".JText::_('OSM_DATE')."</th>
				<th class=\"title\" width=\"1\">".JText::_('OSM_TITLE')."</th>
				<th class=\"title\" width=\"1\">".JText::_('OSM_LEVEL')."</th>
				<th class=\"title\" width=\"1\">".JText::_('OSM_CAT')."</th>
				<!--<th class=\"title\" width=\"1\">".JText::_('OSM_ACCESS_LEVEL')."</th>-->
				<th class=\"title\" width=\"1\">".JText::_('OSM_TERRAIN')."</th>
				<th class=\"title\" width=\"1\">".JText::_('AUTHOR')."</th>
				<th class=\"title\" width=\"1\">".JText::_('ACCESS LEVEL')."</th>
				<th class=\"title\"></th>
				<!--<th class=\"title\">".JText::_('OSM_DESCRIPTION')."</th>-->
			</tr>
		</thead>\n");

$table_footer = ("		</tbody>\n	</table>\n");

if ( $count == 0 ){
	$model = $this->getModel();
	$rows = $model->_fetchJPTfiles();
	if ( (JFolder::exists(JPATH_BASE.DS.'components'.DS.'com_joomgpstracks')) AND (count($rows) != 0 ) ) {
// Datenimport von joomgpstracks BEGIN
		JFactory::getApplication()->enqueueMessage(JText::_('OSM_JOOMGPSTRACKSFOUND_H'));
		echo (JText::_('OSM_JOOMGPSTRACKSFOUND_T')."<br /><br />");
		echo (JText::_('OSM_JOOMGPSTRACKSFOUND_L'));
		echo (" <a href=\"index.php?option=com_injooosm&task=importjgt&controller=files\"><img src=\"templates".DS."khepri".DS."images".DS."notice-download.png\" /></a>");
// Datenimport von joomgpstracks END
	} else
// Nichts zu importieren
		JError::raiseNotice(0,JText::_('OSM_IMPORTFOLDEREMPTY').": \"".$importdir."\"");
} else
	echo $table_header.$table.$table_footer;
echo JHTML::_( 'form.token' );
echo ("	<input type=\"hidden\" name=\"option\" value=\"com_injooosm\" />
	<input type=\"hidden\" name=\"controller\" value=\"files\" />
	<input type=\"hidden\" name=\"task\" value=\"\" />
	<input type=\"hidden\" name=\"found\" value=\"".$count."\" />
	<input type=\"hidden\" name=\"id\" value=\"".$this->id."\" />\n");
echo ("</form>\n");
Return current item: injooosm