function display($tpl = null)
 {
     $option = JRequest::getCmd('option');
     $mainframe = JFactory::getApplication();
     $lang = JFactory::getLanguage();
     $document =& JFactory::getDocument();
     // 		if ($this->getLayout()=='form')
     // 		{
     // 			$this->_displayForm($tpl);
     // 			return;
     // 		}
     // 		if ($this->getLayout()=='info')
     // 		{
     // 			$this->_displayInfo($tpl);
     // 			return;
     // 		}
     // 		if ($this->getLayout()=='selectpage')
     // 		{
     // 			$this->_displaySelectpage($tpl);
     // 			return;
     // 		}
     $stylelink = '<link rel="stylesheet" href="' . JURI::root() . 'administrator/components/com_joomleague/assets/css/jlextusericons.css' . '" type="text/css" />' . "\n";
     $document->addCustomTag($stylelink);
     // Set toolbar items for the page
     JToolBarHelper::title(JText::_('COM_JOOMLEAGUE_ADMIN_LMO_IMPORT_TITLE_1'), 'lmo-cpanel');
     JLToolBarHelper::onlinehelp();
     $uri = JFactory::getURI();
     $config =& JComponentHelper::getParams('com_media');
     $post = JRequest::get('post');
     $files = JRequest::get('files');
     $this->assignRef('request_url', $uri->toString());
     $this->assignRef('config', $config);
     $teile = explode("-", $lang->getTag());
     $country = Countries::convertIso2to3($teile[1]);
     $this->assignRef('country', $country);
     $countries = Countries::getCountryOptions();
     $lists['countries'] = JHTML::_('select.genericlist', $countries, 'country', 'class="inputbox" size="1"', 'value', 'text', $country);
     $this->assignRef('countries', $lists['countries']);
     //$this->assignRef('form',  $this->get('form'));
     parent::display($tpl);
 }
 function getData()
 {
     global $mainframe, $option;
     $mainframe =& JFactory::getApplication();
     $document =& JFactory::getDocument();
     $lang = JFactory::getLanguage();
     $teile = explode("-", $lang->getTag());
     $country = Countries::convertIso2to3($teile[1]);
     $post = JRequest::get('post');
     $convert = array('&nbsp;' => '');
     $exportpositioneventtype = array();
     $exportplayer = array();
     $exportpersons = array();
     $exportpersonstemp = array();
     $exportclubs = array();
     $exportclubsstandardplayground = array();
     $exportteams = array();
     $exportteamstemp = array();
     $exportteamplayer = array();
     $exportprojectteam = array();
     $exportprojectteams = array();
     $exportreferee = array();
     $exportprojectposition = array();
     $exportposition = array();
     $exportparentposition = array();
     $exportplayground = array();
     $exportplaygroundtemp = array();
     $exportteamplaygroundtemp = array();
     $exportround = array();
     $exportmatch = array();
     $exportmatchplayer = array();
     $exportmatchevent = array();
     $exportevent = array();
     $exportpositiontemp = array();
     $exportposition = array();
     $exportparentposition = array();
     $exportprojectposition = array();
     $exportmatchreferee = array();
     $exportmatchplan = array();
     $temp_match_number = array();
     /*
     echo 'post <br>';  
     echo '<pre>';
     print_r($post);
     echo '</pre>';   
     */
     $derlink = $post['dbblink'];
     $teamart = $post['teamart'];
     $chx = curl_init();
     curl_setopt($chx, CURLOPT_URL, $derlink);
     curl_setopt($chx, CURLOPT_TIMEOUT, 200);
     curl_setopt($chx, CURLOPT_RETURNTRANSFER, 1);
     $buffer = parse_url($derlink);
     $resulttab = curl_exec($chx);
     curl_close($chx);
     // alle spiele der seite holen
     $pattern1 = '!<table(.*?)class="sportView">(.*?)</table>!isU';
     $pattern2 = '!<tr>(.*?)</tr>!isS';
     $pattern3 = '!<td(.*?)>(.*?)</td>!isS';
     $pattern4 = '!<td(.*?)class="sportViewTitle">(.*?)</td>!isS';
     // RegEx mit preg_match_all() auswerten
     preg_match_all($pattern1, $resulttab, $spielplan, PREG_PATTERN_ORDER);
     $this->dump_variable("getData spielplan", $spielplan);
     preg_match_all($pattern4, $spielplan[1][0], $liganame, PREG_PATTERN_ORDER);
     $this->dump_variable("getData liganame", $liganame);
     $projectname = utf8_encode(trim(strip_tags($liganame[2][0])));
     $this->dump_variable("getData projectname", $projectname);
     $spielplan[2][0] = str_replace(array_keys($convert), array_values($convert), $spielplan[2][0]);
     preg_match_all($pattern2, $spielplan[2][0], $matches, PREG_PATTERN_ORDER);
     $this->dump_variable("getData matches", $matches);
     $lfdnumber = 0;
     $lfdnumbermatch = 0;
     $lfdnumberteam = 1;
     $lfdnumberplayground = 1;
     $start = 6;
     $spielplan = false;
     $team1_result_split = '';
     $team2_result_split = '';
     if (preg_match("/SpielplanViewPublic/i", $derlink)) {
         $start = 7;
         $spielplan = true;
     }
     $this->dump_variable("getData start ab position", $start);
     for ($a = $start; $a < sizeof($matches[1]); $a++) {
         if (empty($lfdnumber)) {
             $temp = new stdClass();
             $temp->name = $projectname;
             $temp->exportRoutine = '2010-09-19 23:00:00';
             $this->_datas['exportversion'] = $temp;
             $temp = new stdClass();
             $temp->name = preg_replace('/\\D/', '', $projectname);
             $this->_datas['season'] = $temp;
             $temp = new stdClass();
             $temp->name = $projectname;
             $temp->alias = $projectname;
             $temp->short_name = $projectname;
             $temp->middle_name = $projectname;
             $temp->country = $country;
             $this->_datas['league'] = $temp;
             $temp = new stdClass();
             $temp->id = 1;
             $temp->name = 'Basketball';
             $this->_datas['sportstype'] = $temp;
             $temp = new stdClass();
             $temp->name = $projectname;
             $temp->sports_type_id = 1;
             $temp->points_after_regular_time = '2,1,0';
             $temp->game_parts = 4;
             $temp->serveroffset = 0;
             $temp->timezone = 'Europe/Amsterdam';
             $temp->start_time = '15:30';
             $temp->project_type = 'SIMPLE_LEAGUE';
             $temp->current_round_auto = 1;
             $temp->auto_time = 1440;
             $temp->extended = 'JL_EXT_DBB_XML_LINK=' . $derlink;
             $this->_datas['project'] = $temp;
         }
         preg_match_all($pattern3, $matches[1][$a], $paarung, PREG_PATTERN_ORDER);
         $this->dump_variable("getData paarung", $paarung);
         $this->dump_variable("getData spieltag", trim(strip_tags($paarung[2][0])));
         $this->dump_variable("getData nummer", trim(strip_tags($paarung[2][1])));
         $this->dump_variable("getData datum", trim(strip_tags($paarung[2][2])));
         $this->dump_variable("getData heim", trim(strip_tags($paarung[2][3])));
         $this->dump_variable("getData gast", trim(strip_tags($paarung[2][4])));
         $this->dump_variable("getData ergebnis", trim(strip_tags($paarung[2][5])));
         $valuematchday = trim(strip_tags($paarung[2][0]));
         if (is_numeric($valuematchday)) {
             if ($spielplan) {
             } else {
                 if (isset($paarung[2][6])) {
                     $teile = explode(":", trim(strip_tags($paarung[2][6])));
                     $team1_result_split[] = trim($teile[0]);
                     $team2_result_split[] = trim($teile[1]);
                 }
                 if (isset($paarung[2][7])) {
                     $teile = explode(":", trim(strip_tags($paarung[2][7])));
                     $team1_result_split[] = trim($teile[0]);
                     $team2_result_split[] = trim($teile[1]);
                 }
                 if (isset($paarung[2][8])) {
                     $teile = explode(":", trim(strip_tags($paarung[2][8])));
                     $team1_result_split[] = trim($teile[0]);
                     $team2_result_split[] = trim($teile[1]);
                 }
             }
             $tempdatum = trim(strip_tags($paarung[2][2]));
             $teile = explode(" ", $tempdatum);
             $matchdate = strtotime($teile[0]);
             $matchtime = $teile[1];
             $valueheim = utf8_encode(trim(strip_tags($paarung[2][3])));
             $valuegast = utf8_encode(trim(strip_tags($paarung[2][4])));
             // heimmannschaft
             if (array_key_exists($valueheim, $exportteamstemp)) {
             } else {
                 $exportteamstemp[$valueheim] = $lfdnumberteam;
                 $lfdnumberteam++;
             }
             // gastmannschaft
             if (array_key_exists($valuegast, $exportteamstemp)) {
             } else {
                 $exportteamstemp[$valuegast] = $lfdnumberteam;
                 $lfdnumberteam++;
             }
             //$valuematchday = trim(strip_tags($paarung[2][0]));
             $valuematchday = trim(strip_tags($paarung[2][1]));
             //$mainframe->enqueueMessage(JText::_('spieltag '.$valuematchday.''),'');
             if (empty($valuematchday)) {
                 $valuematchday = 1;
             }
             if (isset($exportround[$valuematchday])) {
             } else {
                 $temp = new stdClass();
                 $temp->id = $valuematchday;
                 $temp->roundcode = $valuematchday;
                 $temp->name = $valuematchday . '.Spieltag';
                 $temp->alias = $valuematchday . '.Spieltag';
                 $temp->round_date_first = '';
                 $temp->round_date_last = '';
                 $exportround[$valuematchday] = $temp;
             }
             $tempmatch = new stdClass();
             $tempmatch->id = $lfdnumbermatch;
             //$tempmatch->match_number = trim(strip_tags($paarung[2][1]));
             $tempmatch->match_number = trim(strip_tags($paarung[2][0]));
             //$mainframe->enqueueMessage(JText::_('match_number '.$tempmatch->match_number.''),'');
             $tempmatch->published = 1;
             $tempmatch->count_result = 1;
             $tempmatch->show_report = 1;
             $tempmatch->team1_result = trim($teile[0]);
             $tempmatch->team2_result = trim($teile[1]);
             if ($spielplan) {
                 $teile[0] = '';
                 $teile[1] = '';
                 //$valueplayground = utf8_encode (trim(strip_tags($paarung[2][5])));
                 $valueplayground = trim(strip_tags($paarung[2][5]));
                 if (array_key_exists($valueplayground, $exportplaygroundtemp)) {
                     $tempmatch->playground_id = $exportplaygroundtemp[$valueplayground];
                 } else {
                     $exportplaygroundtemp[$valueplayground] = $lfdnumberplayground;
                     $tempmatch->playground_id = $lfdnumberplayground;
                     $lfdnumberplayground++;
                 }
             } else {
                 $teile = explode(":", trim(strip_tags($paarung[2][5])));
                 $tempmatch->playground_id = 0;
             }
             if (is_array($team1_result_split)) {
                 $tempmatch->team1_result_split = implode(";", $team1_result_split);
             }
             if (is_array($team2_result_split)) {
                 $tempmatch->team2_result_split = implode(";", $team2_result_split);
             }
             $tempmatch->summary = '';
             $tempmatch->match_date = date('Y-m-d', $matchdate) . " " . $matchtime . ':00';
             $tempmatch->projectteam1_id = $exportteamstemp[$valueheim];
             $tempmatch->projectteam2_id = $exportteamstemp[$valuegast];
             $tempmatch->round_id = $valuematchday;
             $exportmatch[] = $tempmatch;
             unset($team1_result_split);
             unset($team2_result_split);
         }
         $lfdnumbermatch++;
         $lfdnumber++;
     }
     // beenden
     //exit;
     // playgrounds verarbeiten
     foreach ($exportplaygroundtemp as $key => $value) {
         // playground
         $temp = new stdClass();
         $temp->id = $value;
         $temp->name = $key;
         $temp->middle_name = $key;
         $temp->short_name = $key;
         $exportplayground[] = $temp;
     }
     // teams verarbeiten
     foreach ($exportteamstemp as $key => $value) {
         // team
         $temp = new stdClass();
         $temp->id = $value;
         $temp->club_id = $value;
         $temp->name = $key;
         $temp->middle_name = $key;
         $temp->short_name = $key;
         $temp->info = $teamart;
         $temp->extended = '';
         $exportteams[] = $temp;
         $standard_playground = '';
         $standard_playground_nummer = 0;
         // club
         $temp = new stdClass();
         $temp->id = $value;
         $temp->name = preg_replace('/\\d/', '', $key);
         $temp->country = $country;
         $temp->extended = '';
         $temp->standard_playground = $standard_playground_nummer;
         $exportclubs[] = $temp;
         // projektteam
         $temp = new stdClass();
         $temp->id = $value;
         $temp->team_id = $value;
         $temp->project_team_id = $value;
         $temp->is_in_score = 1;
         $temp->standard_playground = $standard_playground_nummer;
         $exportprojectteams[] = $temp;
     }
     // daten übergeben
     // damit die spieltage in der richtigen reihenfolge angelegt werden
     ksort($exportround);
     $this->_datas['round'] = array_merge($exportround);
     $this->_datas['match'] = array_merge($exportmatch);
     $this->_datas['team'] = array_merge($exportteams);
     $this->_datas['projectteam'] = array_merge($exportprojectteams);
     $this->_datas['club'] = array_merge($exportclubs);
     $this->_datas['playground'] = array_merge($exportplayground);
     /*
     echo 'getData _datas->match<br>';
     echo '<pre>';
     print_r($this->_datas['match']);
     echo '</pre><br>';
     */
     /**
      * das ganze für den standardimport aufbereiten
      */
     $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
     // open the project
     $output .= "<project>\n";
     // set the version of JoomLeague
     $output .= $this->_addToXml($this->_setJoomLeagueVersion());
     // set the project datas
     if (isset($this->_datas['project'])) {
         $output .= $this->_addToXml($this->_setProjectData($this->_datas['project']));
     }
     // set league data of project
     if (isset($this->_datas['league'])) {
         $output .= $this->_addToXml($this->_setLeagueData($this->_datas['league']));
     }
     // set sportstype data of project
     if (isset($this->_datas['sportstype'])) {
         $output .= $this->_addToXml($this->_setSportsType($this->_datas['sportstype']));
     }
     // set season data of project
     if (isset($this->_datas['season'])) {
         $output .= $this->_addToXml($this->_setSeasonData($this->_datas['season']));
     }
     // set the rounds data
     if (isset($this->_datas['round'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['round'], 'Round'));
     }
     // set the teams data
     if (isset($this->_datas['team'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['team'], 'JL_Team'));
     }
     // set the clubs data
     if (isset($this->_datas['club'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['club'], 'Club'));
     }
     // set the matches data
     if (isset($this->_datas['match'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['match'], 'Match'));
     }
     // set the positions data
     if (isset($this->_datas['position'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['position'], 'Position'));
     }
     // set the positions parent data
     if (isset($this->_datas['parentposition'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['parentposition'], 'ParentPosition'));
     }
     // set position data of project
     if (isset($this->_datas['projectposition'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectposition'], 'ProjectPosition'));
     }
     // set the matchreferee data
     if (isset($this->_datas['matchreferee'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['matchreferee'], 'MatchReferee'));
     }
     // set the person data
     if (isset($this->_datas['person'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['person'], 'Person'));
     }
     // set the projectreferee data
     if (isset($this->_datas['projectreferee'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectreferee'], 'ProjectReferee'));
     }
     // set the projectteam data
     if (isset($this->_datas['projectteam'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectteam'], 'ProjectTeam'));
     }
     // set playground data of project
     if (isset($this->_datas['playground'])) {
         $output .= $this->_addToXml($this->_setXMLData($this->_datas['playground'], 'Playground'));
     }
     // close the project
     $output .= '</project>';
     // mal als test
     $xmlfile = $output;
     $file = JPATH_SITE . DS . 'tmp' . DS . 'joomleague_import.jlg';
     JFile::write($file, $xmlfile);
 }
 function getData()
 {
     global $mainframe, $option;
     $mainframe =& JFactory::getApplication();
     $document =& JFactory::getDocument();
     $lang = JFactory::getLanguage();
     if ($this->debug_info) {
         $this->pane =& JPane::getInstance('sliders');
         echo $this->pane->startPane('pane');
     }
     // die einstellungen der user holen
     $option = JRequest::getCmd('option');
     $params = JComponentHelper::getParams($option);
     $jlxmlfile = JPATH_ADMINISTRATOR . DS . 'components' . DS . $option . DS . 'config.xml';
     $jRegistry = new JRegistry();
     $jRegistry->loadString($params->toString('ini'), 'ini');
     //   echo 'Die aktuelle Sprache lautet: ' . $lang->getName() . '<br>';
     $teile = explode("-", $lang->getTag());
     $country = Countries::convertIso2to3($teile[1]);
     //   echo 'Das aktuelle Land lautet: ' . $country . '<br>';
     $option = JRequest::getCmd('option');
     $project = $mainframe->getUserState($option . 'project', 0);
     $lmoimportuseteams = $mainframe->getUserState($option . 'lmoimportuseteams');
     $whichfile = $mainframe->getUserState($option . 'whichfile');
     $mainframe->enqueueMessage(JText::_('welches land ? ' . $country), '');
     $mainframe->enqueueMessage(JText::_('welche art der datei ? ' . $whichfile), '');
     $delimiter = $mainframe->getUserState($option . 'delimiter');
     $post = JRequest::get('post');
     $this->_league_new_country = $country;
     $exportpositioneventtype = array();
     $exportplayer = array();
     $exportpersons = array();
     $exportpersonstemp = array();
     $exportclubs = array();
     $exportclubsstandardplayground = array();
     $exportplaygroundclubib = array();
     $exportteams = array();
     $exportteamstemp = array();
     $exportteamplayer = array();
     $exportprojectteam = array();
     $exportprojectteams = array();
     $exportreferee = array();
     $exportprojectposition = array();
     $exportposition = array();
     $exportparentposition = array();
     $exportplayground = array();
     $exportplaygroundtemp = array();
     $exportteamplaygroundtemp = array();
     $exportround = array();
     $exportmatch = array();
     $exportmatchplayer = array();
     $exportmatchevent = array();
     $exportevent = array();
     $exportpositiontemp = array();
     $exportposition = array();
     $exportparentposition = array();
     $exportprojectposition = array();
     $exportmatchreferee = array();
     $exportmatchplan = array();
     $temp_match_number = array();
     $startline = 0;
     // echo 'post <br>';
     // echo '<pre>';
     // print_r($post[projects]);
     // echo '</pre>';
     if (isset($post['projects'])) {
         $this->_project_id = $post['projects'];
     }
     $file = JPATH_SITE . DS . 'tmp' . DS . 'joomleague_import.csv';
     $mainframe->enqueueMessage(JText::_('datei = ' . $file), '');
     //$mainframe->enqueueMessage(JText::_('csv result<br><pre>'.print_r($csvdata->data,true).'</pre>'   ),'');
     if ($whichfile == 'playerfile') {
         $startline = 9;
     } elseif ($whichfile == 'matchfile') {
         $startline = 1;
     } elseif ($whichfile == 'icsfile') {
         // kalender file vom bfv anfang
         $ical = new ical();
         $ical->parse($file);
         $icsfile = $ical->get_all_data();
         if ($this->debug_info) {
             echo $this->pane->startPanel('icsfile', 'icsfile');
             $this->dump_header("icsfile");
             $this->dump_variable("icsfile", $icsfile);
             echo $this->pane->endPanel();
             echo $this->pane->startPanel('icsfile termine', 'icsfile termine');
             $this->dump_header("icsfile termine");
             $this->dump_variable("icsfile termine", $icsfile['VEVENT']);
             echo $this->pane->endPanel();
             //echo 'icsfile -> <br /><pre>~'.print_r($icsfile,true).'~</pre><br />';
             //echo 'icsfile termine -> <br /><pre>~'.print_r($icsfile['VEVENT'],true).'~</pre><br />';
         }
         //
         $lfdnumber = 0;
         $lfdnumberteam = 1;
         $lfdnumbermatch = 1;
         $lfdnumberplayground = 1;
         for ($a = 0; $a < sizeof($icsfile['VEVENT']); $a++) {
             $icsfile['VEVENT'][$a]['UID'] = $lfdnumbermatch;
             $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['match_date'] = date('Y-m-d', $icsfile['VEVENT'][$a]['DTSTART']) . " " . date('H:i', $icsfile['VEVENT'][$a]['DTSTART']);
             // paarung
             $teile = explode("\\,", $icsfile['VEVENT'][$a]['SUMMARY']);
             $teile2 = explode("-", $teile[0]);
             if (empty($lfdnumber)) {
                 $projectname = trim($teile[1]);
             }
             $text = $teile[0];
             $anzahltrenner = substr_count($text, '-');
             //echo 'ich habe -> '.$anzahltrenner.' trennzeichen <br>';
             if ($anzahltrenner > 1) {
                 $convert = array('-SV' => ':SV', '-SVO' => ':SVO', '-FC' => ':FC', '-TSV' => ':TSV', '-JFG' => ':JFG', '-TV' => ':TV', '-ASV' => ':ASV', '-SSV' => ':SSV', '-(SG)' => ':(SG)', '-SpVgg' => ':SpVgg', '-VfB' => ':VfB', '-FSV' => ':FSV', '-BSK' => ':BSK');
                 if (preg_match("/-SV/i", $teile[0]) || preg_match("/-SVO/i", $teile[0]) || preg_match("/-TSV/i", $teile[0]) || preg_match("/-JFG/i", $teile[0]) || preg_match("/-TV/i", $teile[0]) || preg_match("/-ASV/i", $teile[0]) || preg_match("/-SSV/i", $teile[0]) || preg_match("/-(SG)/i", $teile[0]) || preg_match("/-SpVgg/i", $teile[0]) || preg_match("/-VfB/i", $teile[0]) || preg_match("/-FSV/i", $teile[0]) || preg_match("/-BSK/i", $teile[0]) || preg_match("/-FC/i", $teile[0])) {
                     $teile[0] = str_replace(array_keys($convert), array_values($convert), $teile[0]);
                     $teile2 = explode(":", $teile[0]);
                 } else {
                     $pos = strrpos($teile[0], "-");
                     //echo 'letzte position -> '.$pos.' trennzeichen <br>';
                     $teile2[0] = substr($teile[0], 0, $pos);
                     $teile2[1] = substr($teile[0], $pos + 1, 100);
                 }
             }
             $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['heim'] = trim($teile2[0]);
             $valueheim = trim($teile2[0]);
             //$exportteamplaygroundtemp[$valueheim] = $valueplayground;
             $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['gast'] = trim($teile2[1]);
             $valuegast = trim($teile2[1]);
             // heimmannschaft
             if (array_key_exists($valueheim, $exportteamstemp)) {
             } else {
                 $exportteamstemp[$valueheim] = $lfdnumberteam;
                 $lfdnumberteam++;
             }
             // gastmannschaft
             if (array_key_exists($valuegast, $exportteamstemp)) {
             } else {
                 $exportteamstemp[$valuegast] = $lfdnumberteam;
                 $lfdnumberteam++;
             }
             if (isset($icsfile['VEVENT'][$a]['LOCATION'])) {
                 // sportanlage neu
                 $teile = explode("\\,", $icsfile['VEVENT'][$a]['LOCATION']);
                 if (sizeof($teile) === 4) {
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground'] = trim($teile[0]);
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_strasse'] = trim($teile[1]);
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_plz'] = trim($teile[2]);
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_ort'] = trim($teile[3]);
                     $valueplayground = trim($teile[0]);
                     $address = trim($teile[1]);
                     $zipcode = trim($teile[2]);
                     $city = trim($teile[3]);
                 } else {
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground'] = '';
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_strasse'] = trim($teile[0]);
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_plz'] = trim($teile[1]);
                     $exportmatchplan[$icsfile['VEVENT'][$a]['UID']]['playground_ort'] = trim($teile[2]);
                     $valueplayground = $valueheim;
                     $address = trim($teile[0]);
                     $zipcode = trim($teile[1]);
                     $city = trim($teile[2]);
                 }
             }
             if ($valueplayground) {
                 $exportteamplaygroundtemp[$valueheim] = $valueplayground;
                 if (array_key_exists($valueplayground, $exportplaygroundtemp)) {
                 } else {
                     $exportplaygroundtemp[$valueplayground] = $lfdnumberplayground;
                     $temp = new stdClass();
                     $temp->id = $lfdnumberplayground;
                     $temp->name = $valueplayground;
                     $temp->short_name = $valueplayground;
                     $temp->alias = $valueplayground;
                     $temp->club_id = $exportteamstemp[$valueheim];
                     $temp->address = $address;
                     $temp->zipcode = $zipcode;
                     $temp->city = $city;
                     $temp->country = $country;
                     $temp->max_visitors = 0;
                     $exportplayground[] = $temp;
                     $lfdnumberplayground++;
                 }
             }
             if (empty($lfdnumber)) {
                 $temp = new stdClass();
                 $temp->name = $projectname;
                 $temp->exportRoutine = '2010-09-19 23:00:00';
                 $this->_datas['exportversion'] = $temp;
                 $temp = new stdClass();
                 $temp->name = '';
                 $this->_datas['season'] = $temp;
                 $temp = new stdClass();
                 $temp->name = $projectname;
                 $temp->alias = $projectname;
                 $temp->short_name = $projectname;
                 $temp->middle_name = $projectname;
                 $temp->country = $country;
                 $this->_datas['league'] = $temp;
                 $temp = new stdClass();
                 $temp->name = $projectname;
                 $temp->serveroffset = 0;
                 $temp->project_type = 'SIMPLE_LEAGUE';
                 $this->_datas['project'] = $temp;
             }
             $lfdnumber++;
             $lfdnumbermatch++;
         }
         ksort($exportmatchplan);
         if ($this->debug_info) {
             echo $this->pane->startPanel('icsfile exportmatchplan', 'icsfile exportmatchplan');
             $this->dump_header("icsfile exportmatchplan");
             $this->dump_variable("icsfile exportmatchplan", $exportmatchplan);
             echo $this->pane->endPanel();
             echo $this->pane->startPanel('icsfile exportteamstemp', 'icsfile exportteamstemp');
             $this->dump_header("icsfile exportteamstemp");
             $this->dump_variable("icsfile exportteamstemp", $exportteamstemp);
             echo $this->pane->endPanel();
             //echo 'icsfile exportmatchplan -> <br /><pre>~'.print_r($exportmatchplan,true).'~</pre><br />';
             //echo 'icsfile exportteamstemp -> <br /><pre>~'.print_r($exportteamstemp,true).'~</pre><br />';
         }
         // teams verarbeiten
         foreach ($exportteamstemp as $key => $value) {
             // team
             $temp = new stdClass();
             $temp->id = $value;
             $temp->club_id = $value;
             $temp->name = $key;
             $temp->middle_name = $key;
             $temp->short_name = $key;
             $temp->info = '';
             $temp->extended = '';
             $exportteams[] = $temp;
             $standard_playground = $exportteamplaygroundtemp[$key];
             $standard_playground_nummer = $exportplaygroundtemp[$standard_playground];
             // club
             $temp = new stdClass();
             $temp->id = $value;
             $temp->name = $key;
             $temp->country = $country;
             $temp->extended = '';
             $temp->standard_playground = $standard_playground_nummer;
             $exportclubs[] = $temp;
             // projektteam
             $temp = new stdClass();
             $temp->id = $value;
             $temp->team_id = $value;
             $temp->project_team_id = $value;
             $temp->is_in_score = 1;
             $temp->standard_playground = $standard_playground_nummer;
             $exportprojectteams[] = $temp;
         }
         $anzahlteams = sizeof($exportteamstemp);
         $mainframe->enqueueMessage(JText::_('wir haben ' . $anzahlteams . ' teams f&uuml;r die berechnung der spieltage und paarungen pro spieltag'), '');
         if ($anzahlteams % 2 == 0) {
             $anzahltage = ($anzahlteams - 1) * 2;
             $anzahlpaarungen = $anzahlteams / 2;
         } else {
             $anzahltage = ($anzahlteams - 1) * 2;
             $anzahlpaarungen = ($anzahlteams - 1) / 2;
         }
         $mainframe->enqueueMessage(JText::_('wir haben ' . $anzahltage . ' spieltage'), '');
         $mainframe->enqueueMessage(JText::_('wir haben ' . $anzahlpaarungen . ' paarungen pro spieltag'), '');
         // echo "icsfile exportplaygroundtemp<pre>";
         // print_r($exportplaygroundtemp);
         // echo "</pre>";
         // so jetzt die runden erstellen
         for ($a = 1; $a <= $anzahltage; $a++) {
             $temp = new stdClass();
             $temp->id = $a;
             $temp->roundcode = $a;
             $temp->name = $a . '- Spieltag';
             $temp->alias = $a . '-spieltag';
             $temp->round_date_first = '';
             $temp->round_date_last = '';
             $exportround[$a] = $temp;
         }
         // so jetzt die spiele erstellen
         $lfdnumbermatch = 1;
         $lfdnumberpaarung = 1;
         $lfdnumberspieltag = 1;
         foreach ($exportmatchplan as $key => $value) {
             // echo "icsfile spiele erstellen<pre>";
             // print_r($value);
             // echo "</pre>";
             $tempmatch = new stdClass();
             $tempmatch->id = $lfdnumbermatch;
             $tempmatch->match_number = $lfdnumbermatch;
             $tempmatch->published = 1;
             $tempmatch->count_result = 1;
             $tempmatch->show_report = 1;
             $tempmatch->team1_result = '';
             $tempmatch->team2_result = '';
             $tempmatch->summary = '';
             $tempmatch->match_date = $value['match_date'];
             if (isset($value['playground'])) {
                 if (array_key_exists($value['playground'], $exportplaygroundtemp)) {
                     $tempmatch->playground_id = $exportplaygroundtemp[$value['playground']];
                 }
             }
             $tempmatch->projectteam1_id = $exportteamstemp[$value['heim']];
             $tempmatch->projectteam2_id = $exportteamstemp[$value['gast']];
             $tempmatch->round_id = $lfdnumberspieltag;
             $exportmatch[] = $tempmatch;
             if ($lfdnumberpaarung == $anzahlpaarungen) {
                 $lfdnumberpaarung = 0;
                 $lfdnumberspieltag++;
             }
             $lfdnumbermatch++;
             $lfdnumberpaarung++;
         }
         // daten übergeben
         $this->_datas['round'] = array_merge($exportround);
         $this->_datas['match'] = array_merge($exportmatch);
         $this->_datas['team'] = array_merge($exportteams);
         $this->_datas['projectteam'] = array_merge($exportprojectteams);
         $this->_datas['club'] = array_merge($exportclubs);
         $this->_datas['playground'] = array_merge($exportplayground);
         /**
          * das ganze für den standardimport aufbereiten
          */
         $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
         // open the project
         $output .= "<project>\n";
         // set the version of JoomLeague
         $output .= $this->_addToXml($this->_setJoomLeagueVersion());
         // set the project datas
         if (isset($this->_datas['project'])) {
             $output .= $this->_addToXml($this->_setProjectData($this->_datas['project']));
         }
         // set league data of project
         if (isset($this->_datas['league'])) {
             $output .= $this->_addToXml($this->_setLeagueData($this->_datas['league']));
         }
         // set season data of project
         if (isset($this->_datas['season'])) {
             $output .= $this->_addToXml($this->_setSeasonData($this->_datas['season']));
         }
         // set the rounds data
         if (isset($this->_datas['round'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['round'], 'Round'));
         }
         // set the teams data
         if (isset($this->_datas['team'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['team'], 'JL_Team'));
         }
         // set the clubs data
         if (isset($this->_datas['club'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['club'], 'Club'));
         }
         // set the matches data
         if (isset($this->_datas['match'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['match'], 'Match'));
         }
         // set the positions data
         if (isset($this->_datas['position'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['position'], 'Position'));
         }
         // set the positions parent data
         if (isset($this->_datas['parentposition'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['parentposition'], 'ParentPosition'));
         }
         // set position data of project
         if (isset($this->_datas['projectposition'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectposition'], 'ProjectPosition'));
         }
         // set the matchreferee data
         if (isset($this->_datas['matchreferee'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['matchreferee'], 'MatchReferee'));
         }
         // set the person data
         if (isset($this->_datas['person'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['person'], 'Person'));
         }
         // set the projectreferee data
         if (isset($this->_datas['projectreferee'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectreferee'], 'ProjectReferee'));
         }
         // set the projectteam data
         if (isset($this->_datas['projectteam'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectteam'], 'ProjectTeam'));
         }
         // set playground data of project
         if (isset($this->_datas['playground'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['playground'], 'Playground'));
         }
         // close the project
         $output .= '</project>';
         // mal als test
         $xmlfile = $output;
         $file = JPATH_SITE . DS . 'tmp' . DS . 'joomleague_import.jlg';
         JFile::write($file, $xmlfile);
     }
     // kalender file vom bfv ende
     $teamid = 1;
     $this->fileName = JFile::read($file);
     $this->lines = file($file);
     if ($this->lines) {
         $row = 0;
         if ($whichfile == 'playerfile') {
             // test
             // spielplan anfang
             # tab delimited, and encoding conversion
             $csv = new parseCSV();
             $csv->encoding('UTF-16', 'UTF-8');
             //$csv->delimiter = "\t";
             switch ($delimiter) {
                 case ";":
                     $csv->delimiter = ";";
                     break;
                 case ",":
                     $csv->delimiter = ",";
                     break;
                 default:
                     $csv->delimiter = "\t";
                     break;
             }
             $startrow = $jRegistry->get('cfg_dfbnet_player_startrow') - 2;
             $csv->parse($file, $startrow);
             //$mainframe->enqueueMessage(JText::_('result<br><pre>'.print_r($csv->data,true).'</pre>'   ),'');
             // anfang schleife csv file
             for ($a = 0; $a < sizeof($csv->data); $a++) {
                 $temp = new stdClass();
                 $temp->id = 0;
                 $temp->knvbnr = $csv->data[$a][$jRegistry->get('cfg_dfbnet_player_passnummer')];
                 $temp->lastname = $csv->data[$a][$jRegistry->get('cfg_dfbnet_player_firstname')];
                 $temp->firstname = $csv->data[$a][$jRegistry->get('cfg_dfbnet_player_lastname')];
                 $temp->info = $csv->data[$a][$jRegistry->get('cfg_dfbnet_player_info')];
                 $datetime = strtotime($csv->data[$a][$jRegistry->get('cfg_dfbnet_player_birthday')]);
                 $temp->birthday = date('Y-m-d', $datetime);
                 $temp->country = $country;
                 $temp->nickname = '';
                 $temp->position_id = '';
                 //$temp->lastname = utf8_encode ($temp->lastname);
                 //$temp->firstname = utf8_encode ($temp->firstname);
                 $exportplayer[] = $temp;
             }
             // spielerdatei
             $temp = new stdClass();
             $temp->name = 'playerfile';
             $temp->exportRoutine = '2010-09-19 23:00:00';
             $this->_datas['exportversion'] = $temp;
             $this->_datas['person'] = array_merge($exportplayer);
         } elseif ($whichfile == 'matchfile') {
             // spielplan anfang
             # tab delimited, and encoding conversion
             $csv = new parseCSV();
             $csv->encoding('UTF-16', 'UTF-8');
             //$csv->delimiter = "\t";
             switch ($delimiter) {
                 case ";":
                     $csv->delimiter = ";";
                     break;
                 case ",":
                     $csv->delimiter = ",";
                     break;
                 default:
                     $csv->delimiter = "\t";
                     break;
             }
             $csv->parse($file);
             if (sizeof($csv->data) == 0) {
                 $mainframe->enqueueMessage(JText::_('falsches Dateiformat'), 'Error');
                 $importcsv = false;
             } else {
                 //$mainframe->enqueueMessage(JText::_('result<br><pre>'.print_r($csv->data[0],true).'</pre>'   ),'');
                 //$mainframe->enqueueMessage(JText::_('result<br><pre>'.print_r($csv->data,true).'</pre>'   ),'');
                 $importcsv = true;
             }
             $lfdnumber = 0;
             $lfdnumberteam = 1;
             $lfdnumbermatch = 1;
             $lfdnumberplayground = 1;
             $lfdnumberperson = 1;
             $lfdnumbermatchreferee = 1;
             // anfang schleife csv file
             for ($a = 0; $a < sizeof($csv->data); $a++) {
                 if (empty($lfdnumber)) {
                     $temp = new stdClass();
                     $temp->name = $csv->data[$a][$jRegistry->get('cfg_dfbnet_verband_name')];
                     $temp->exportRoutine = '2010-09-19 23:00:00';
                     $this->_datas['exportversion'] = $temp;
                     $temp = new stdClass();
                     $temp->name = $csv->data[$a][$jRegistry->get('cfg_dfbnet_season_name')];
                     $this->_datas['season'] = $temp;
                     $temp = new stdClass();
                     $temp->name = $csv->data[$a][$jRegistry->get('cfg_dfbnet_league_name')] . ' ' . $csv->data[$a][$jRegistry->get('cfg_dfbnet_staffel_number')];
                     $temp->country = $country;
                     $this->_datas['league'] = $temp;
                     $temp = new stdClass();
                     $temp->id = 1;
                     $temp->name = 'COM_JOOMLEAGUE_ST_SOCCER';
                     $this->_datas['sportstype'] = $temp;
                     $temp = new stdClass();
                     $temp->name = $csv->data[$a][$jRegistry->get('cfg_dfbnet_league_name')] . ' ' . $csv->data[$a][$jRegistry->get('cfg_dfbnet_season_name')];
                     $temp->serveroffset = 0;
                     $temp->start_time = '15:30';
                     $temp->start_date = '0000-00-00';
                     $temp->sports_type_id = 1;
                     $temp->project_type = 'SIMPLE_LEAGUE';
                     $temp->staffel_id = $csv->data[$a][$jRegistry->get('cfg_dfbnet_staffel_name')];
                     $this->_datas['project'] = $temp;
                 }
                 if (empty($csv->data[$a][$jRegistry->get('cfg_dfbnet_weekday_changed')])) {
                     $valuematchday = $csv->data[$a][$jRegistry->get('cfg_dfbnet_round_name')];
                     if (isset($exportround[$valuematchday])) {
                     } else {
                         $temp = new stdClass();
                         $temp->id = $valuematchday;
                         $temp->roundcode = $valuematchday;
                         $temp->name = $valuematchday . '.Spieltag';
                         $temp->alias = $valuematchday . '.Spieltag';
                         $temp->round_date_first = '';
                         $temp->round_date_last = '';
                         $exportround[$valuematchday] = $temp;
                     }
                     // dfbnet heimmannschaft
                     $valueheim = $csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')];
                     if ($valueheim != 'Spielfrei') {
                         if (in_array($valueheim, $exportteamstemp)) {
                             // echo $valueheim." <- enthalten<br>";
                             $exportclubsstandardplayground[$valueheim] = $csv->data[$a][$jRegistry->get('cfg_dfbnet_playground_name')];
                             $exportplaygroundclubib[$csv->data[$a][$jRegistry->get('cfg_dfbnet_playground_name')]] = $valueheim;
                         } else {
                             // echo $valueheim." <- nicht enthalten<br>";
                             $exportclubsstandardplayground[$valueheim] = $csv->data[$a][$jRegistry->get('cfg_dfbnet_playground_name')];
                             $exportplaygroundclubib[$csv->data[$a][$jRegistry->get('cfg_dfbnet_playground_name')]] = $valueheim;
                             $exportteamstemp[] = $valueheim;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $temp->club_id = $lfdnumberteam;
                             $temp->name = $valueheim;
                             $temp->middle_name = $valueheim;
                             $temp->short_name = $valueheim;
                             $temp->info = $csv->data[$a][$jRegistry->get('cfg_dfbnet_teamart_name')];
                             $temp->extended = '';
                             $exportteams[] = $temp;
                             $mainframe->setUserState($option . "teamart", $temp->info);
                             // der clubname muss um die mannschaftsnummer verkürzt werden
                             if (substr($valueheim, -4, 4) == ' III') {
                                 $convert = array(' III' => '');
                                 $valueheim = str_replace(array_keys($convert), array_values($convert), $valueheim);
                             }
                             if (substr($valueheim, -3, 3) == ' II') {
                                 $convert = array(' II' => '');
                                 $valueheim = str_replace(array_keys($convert), array_values($convert), $valueheim);
                             }
                             if (substr($valueheim, -2, 2) == ' I') {
                                 $convert = array(' I' => '');
                                 $valueheim = str_replace(array_keys($convert), array_values($convert), $valueheim);
                             }
                             if (substr($valueheim, -2, 2) == ' 3') {
                                 $convert = array(' 3' => '');
                                 $valueheim = str_replace(array_keys($convert), array_values($convert), $valueheim);
                             }
                             if (substr($valueheim, -2, 2) == ' 2') {
                                 $convert = array(' 2' => '');
                                 $valueheim = str_replace(array_keys($convert), array_values($convert), $valueheim);
                             }
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $club_id = $lfdnumberteam;
                             $temp->name = $valueheim;
                             $temp->country = $country;
                             $temp->extended = '';
                             $temp->standard_playground = $lfdnumberplayground;
                             $exportclubs[] = $temp;
                             //$mainframe->enqueueMessage(JText::_('heim verein -> '.$valueheim ),'Notice');
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $temp->team_id = $lfdnumberteam;
                             $temp->project_team_id = $lfdnumberteam;
                             $temp->is_in_score = 1;
                             $temp->division_id = 0;
                             $temp->start_points = 0;
                             $temp->points_finally = 0;
                             $temp->neg_points_finally = 0;
                             $temp->matches_finally = 0;
                             $temp->won_finally = 0;
                             $temp->draws_finally = 0;
                             $temp->lost_finally = 0;
                             $temp->homegoals_finally = 0;
                             $temp->guestgoals_finally = 0;
                             $temp->diffgoals_finally = 0;
                             $temp->standard_playground = $lfdnumberplayground;
                             $exportprojectteams[] = $temp;
                             $lfdnumberteam++;
                         }
                     }
                     // dfbnet gastmannschaft
                     $valuegast = $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')];
                     if ($valuegast != 'Spielfrei') {
                         if (in_array($valuegast, $exportteamstemp)) {
                             // echo $valuegast." <- enthalten<br>";
                         } else {
                             // echo $valuegast." <- nicht enthalten<br>";
                             $exportteamstemp[] = $valuegast;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $temp->club_id = $lfdnumberteam;
                             $temp->name = $valuegast;
                             $temp->middle_name = $valuegast;
                             $temp->short_name = $valuegast;
                             $temp->info = $csv->data[$a][$jRegistry->get('cfg_dfbnet_teamart_name')];
                             $temp->extended = '';
                             $exportteams[] = $temp;
                             // der clubname muss um die mannschaftsnummer verkürzt werden
                             if (substr($valuegast, -4, 4) == ' III') {
                                 $convert = array(' III' => '');
                                 $valuegast = str_replace(array_keys($convert), array_values($convert), $valuegast);
                             }
                             if (substr($valuegast, -3, 3) == ' II') {
                                 $convert = array(' II' => '');
                                 $valuegast = str_replace(array_keys($convert), array_values($convert), $valuegast);
                             }
                             if (substr($valuegast, -2, 2) == ' I') {
                                 $convert = array(' I' => '');
                                 $valuegast = str_replace(array_keys($convert), array_values($convert), $valuegast);
                             }
                             if (substr($valuegast, -2, 2) == ' 3') {
                                 $convert = array(' 3' => '');
                                 $valuegast = str_replace(array_keys($convert), array_values($convert), $valuegast);
                             }
                             if (substr($valuegast, -2, 2) == ' 2') {
                                 $convert = array(' 2' => '');
                                 $valuegast = str_replace(array_keys($convert), array_values($convert), $valuegast);
                             }
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $temp->name = $valuegast;
                             $temp->standard_playground = 0;
                             $temp->country = $country;
                             $temp->extended = '';
                             $exportclubs[] = $temp;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberteam;
                             $temp->team_id = $lfdnumberteam;
                             $temp->project_team_id = $lfdnumberteam;
                             $temp->is_in_score = 1;
                             $temp->division_id = 0;
                             $temp->start_points = 0;
                             $temp->points_finally = 0;
                             $temp->neg_points_finally = 0;
                             $temp->matches_finally = 0;
                             $temp->won_finally = 0;
                             $temp->draws_finally = 0;
                             $temp->lost_finally = 0;
                             $temp->homegoals_finally = 0;
                             $temp->guestgoals_finally = 0;
                             $temp->diffgoals_finally = 0;
                             $temp->standard_playground = 0;
                             $exportprojectteams[] = $temp;
                             $lfdnumberteam++;
                         }
                     }
                     // dfbnet spielstaette
                     $valueplayground = $csv->data[$a][$jRegistry->get('cfg_dfbnet_playground_name')];
                     if ($valueplayground) {
                         if (array_key_exists($valueplayground, $exportplaygroundtemp)) {
                             // echo $valueplayground." <- enthalten<br>";
                         } else {
                             // echo $valueplayground." <- nicht enthalten<br>";
                             $exportplaygroundtemp[$valueplayground] = $lfdnumberplayground;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberplayground;
                             $matchnumberplayground = $lfdnumberplayground;
                             $temp->name = $valueplayground;
                             $temp->short_name = $valueplayground;
                             $temp->country = $country;
                             $temp->max_visitors = 0;
                             $valueheimsuchen = $exportplaygroundclubib[$valueplayground];
                             foreach ($exportteamstemp as $key => $value) {
                                 if ($value == $valueheimsuchen) {
                                     $club_id = $key + 1;
                                 }
                             }
                             $temp->club_id = $club_id;
                             $exportplayground[] = $temp;
                             //$mainframe->enqueueMessage(JText::_('playground -> '.$valueplayground ),'Notice');
                             //$mainframe->enqueueMessage(JText::_('heimmannschaft suchen -> '.$valueheimsuchen ),'Notice');
                             //$mainframe->enqueueMessage(JText::_('heimmannschaft club-id -> '.$club_id ),'Notice');
                             $lfdnumberplayground++;
                         }
                     }
                     $valueperson = $csv->data[$a][$jRegistry->get('cfg_dfbnet_spielleitung_name')];
                     $valueperson1 = $csv->data[$a][$jRegistry->get('cfg_dfbnet_assistent1_name')];
                     $valueperson2 = $csv->data[$a][$jRegistry->get('cfg_dfbnet_assistent2_name')];
                     //if (in_array($valueperson, $exportpersonstemp))
                     if (array_key_exists($valueperson, $exportpersonstemp)) {
                         if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                             // nichts machen
                         } else {
                             $tempmatchreferee = new stdClass();
                             $tempmatchreferee->id = $lfdnumbermatchreferee;
                             $tempmatchreferee->match_id = $lfdnumbermatch;
                             $tempmatchreferee->project_referee_id = $exportpersonstemp[$valueperson];
                             $tempmatchreferee->project_position_id = 1000;
                             $exportmatchreferee[] = $tempmatchreferee;
                             $lfdnumbermatchreferee++;
                         }
                     } else {
                         if (strlen($valueperson) > 6 && $valueperson) {
                             // echo $valueperson." <- nicht enthalten<br>";
                             $exportpersonstemp[$valueperson] = $lfdnumberperson;
                             // nach- und vorname richtig setzen
                             $teile = explode(",", $valueperson);
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->person_id = $lfdnumberperson;
                             $temp->project_position_id = 1000;
                             $exportreferee[] = $temp;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->lastname = trim($teile[0]);
                             $temp->firstname = trim($teile[1]);
                             $temp->nickname = '';
                             $temp->knvbnr = '';
                             $temp->location = '';
                             $temp->birthday = '0000-00-00';
                             $temp->country = $country;
                             $temp->position_id = 1000;
                             $temp->info = 'Schiri';
                             $exportpersons[] = $temp;
                             if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                                 // nichts machen
                             } else {
                                 $tempmatchreferee = new stdClass();
                                 $tempmatchreferee->id = $lfdnumbermatchreferee;
                                 $tempmatchreferee->match_id = $lfdnumbermatch;
                                 $tempmatchreferee->project_referee_id = $lfdnumberperson;
                                 $tempmatchreferee->project_position_id = 1000;
                                 $exportmatchreferee[] = $tempmatchreferee;
                                 $lfdnumbermatchreferee++;
                             }
                             $lfdnumberperson++;
                         }
                     }
                     // 1.assistent
                     if (array_key_exists($valueperson1, $exportpersonstemp)) {
                         if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                             // nichts machen
                         } else {
                             $tempmatchreferee = new stdClass();
                             $tempmatchreferee->id = $lfdnumbermatchreferee;
                             $tempmatchreferee->match_id = $lfdnumbermatch;
                             $tempmatchreferee->project_referee_id = $exportpersonstemp[$valueperson1];
                             $tempmatchreferee->project_position_id = 1001;
                             $exportmatchreferee[] = $tempmatchreferee;
                             $lfdnumbermatchreferee++;
                         }
                     } else {
                         if (strlen($valueperson1) > 6 && $valueperson1) {
                             // echo $valueperson." <- nicht enthalten<br>";
                             $exportpersonstemp[$valueperson1] = $lfdnumberperson;
                             // nach- und vorname richtig setzen
                             $teile = explode(",", $valueperson1);
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->person_id = $lfdnumberperson;
                             $temp->project_position_id = 1001;
                             $exportreferee[] = $temp;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->lastname = trim($teile[0]);
                             $temp->firstname = trim($teile[1]);
                             $temp->nickname = '';
                             $temp->knvbnr = '';
                             $temp->location = '';
                             $temp->birthday = '0000-00-00';
                             $temp->country = $country;
                             $temp->position_id = 1001;
                             $temp->info = 'Schiri';
                             $exportpersons[] = $temp;
                             if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                                 // nichts machen
                             } else {
                                 $tempmatchreferee = new stdClass();
                                 $tempmatchreferee->id = $lfdnumbermatchreferee;
                                 $tempmatchreferee->match_id = $lfdnumbermatch;
                                 $tempmatchreferee->project_referee_id = $lfdnumberperson;
                                 $tempmatchreferee->project_position_id = 1001;
                                 $exportmatchreferee[] = $tempmatchreferee;
                                 $lfdnumbermatchreferee++;
                             }
                             $lfdnumberperson++;
                         }
                     }
                     // 2.assistent
                     if (array_key_exists($valueperson2, $exportpersonstemp)) {
                         if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                             // nichts machen
                         } else {
                             $tempmatchreferee = new stdClass();
                             $tempmatchreferee->id = $lfdnumbermatchreferee;
                             $tempmatchreferee->match_id = $lfdnumbermatch;
                             $tempmatchreferee->project_referee_id = $exportpersonstemp[$valueperson2];
                             $tempmatchreferee->project_position_id = 1002;
                             $exportmatchreferee[] = $tempmatchreferee;
                             $lfdnumbermatchreferee++;
                         }
                     } else {
                         if (strlen($valueperson2) > 6 && $valueperson2) {
                             // echo $valueperson." <- nicht enthalten<br>";
                             $exportpersonstemp[$valueperson2] = $lfdnumberperson;
                             // nach- und vorname richtig setzen
                             $teile = explode(",", $valueperson2);
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->person_id = $lfdnumberperson;
                             $temp->project_position_id = 1002;
                             $exportreferee[] = $temp;
                             $temp = new stdClass();
                             $temp->id = $lfdnumberperson;
                             $temp->lastname = trim($teile[0]);
                             $temp->firstname = trim($teile[1]);
                             $temp->nickname = '';
                             $temp->knvbnr = '';
                             $temp->location = '';
                             $temp->birthday = '0000-00-00';
                             $temp->country = $country;
                             $temp->position_id = 1002;
                             $temp->info = 'Schiri';
                             $exportpersons[] = $temp;
                             if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                                 // nichts machen
                             } else {
                                 $tempmatchreferee = new stdClass();
                                 $tempmatchreferee->id = $lfdnumbermatchreferee;
                                 $tempmatchreferee->match_id = $lfdnumbermatch;
                                 $tempmatchreferee->project_referee_id = $lfdnumberperson;
                                 $tempmatchreferee->project_position_id = 1002;
                                 $exportmatchreferee[] = $tempmatchreferee;
                                 $lfdnumbermatchreferee++;
                             }
                             $lfdnumberperson++;
                         }
                     }
                     //   echo 'paarung -> '.$csv->data[$a]['Heim Mannschaft']." <-> ".$csv->data[$a]['Gast Mannschaft'].'<br>';
                     if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')] == 'Spielfrei' || $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')] == 'Spielfrei') {
                         // nichts machen
                     } else {
                         $round_id = $csv->data[$a][$jRegistry->get('cfg_dfbnet_round_name')];
                         $tempmatch = new stdClass();
                         $tempmatch->id = $lfdnumbermatch;
                         $tempmatch->round_id = $round_id;
                         $datetime = strtotime($csv->data[$a][$jRegistry->get('cfg_dfbnet_date')]);
                         $tempmatch->match_date = date('Y-m-d', $datetime) . " " . $csv->data[$a][$jRegistry->get('cfg_dfbnet_time')];
                         if ($csv->data[$a][$jRegistry->get('cfg_dfbnet_date_changed')]) {
                             $datetime = strtotime($csv->data[$a][$jRegistry->get('cfg_dfbnet_date_changed')]);
                             $tempmatch->match_date_verlegt = date('Y-m-d', $datetime) . " " . $csv->data[$a][$jRegistry->get('cfg_dfbnet_time_changed')];
                         } else {
                             $tempmatch->match_date_verlegt = '';
                         }
                         // datum im spieltag setzen
                         if (!$exportround[$round_id]->round_date_first && !$exportround[$round_id]->round_date_last) {
                             $exportround[$round_id]->round_date_first = date('Y-m-d', $datetime);
                             $exportround[$round_id]->round_date_last = date('Y-m-d', $datetime);
                         }
                         if ($exportround[$round_id]->round_date_first && $exportround[$round_id]->round_date_last) {
                             $datetime_first = strtotime($exportround[$round_id]->round_date_first);
                             $datetime_last = strtotime($exportround[$round_id]->round_date_last);
                             if ($datetime_first > $datetime) {
                                 $exportround[$round_id]->round_date_first = date('Y-m-d', $datetime);
                             }
                             if ($datetime_last < $datetime) {
                                 $exportround[$round_id]->round_date_last = date('Y-m-d', $datetime);
                             }
                         }
                         //$tempmatch->match_number = $csv->data[$a]['Spielkennung'];
                         //$tempmatch->match_number = $lfdnumbermatch;
                         $tempmatch->match_number = $csv->data[$a][$jRegistry->get('cfg_dfbnet_game_id')];
                         $tempmatch->published = 1;
                         $tempmatch->count_result = 1;
                         $tempmatch->show_report = 1;
                         $tempmatch->projectteam1_id = 0;
                         $tempmatch->projectteam2_id = 0;
                         $tempmatch->projectteam1_dfbnet = $csv->data[$a][$jRegistry->get('cfg_dfbnet_home_name')];
                         $tempmatch->projectteam2_dfbnet = $csv->data[$a][$jRegistry->get('cfg_dfbnet_away_name')];
                         $tempmatch->team1_result = '';
                         $tempmatch->team2_result = '';
                         $tempmatch->summary = '';
                         if (array_key_exists($valueplayground, $exportplaygroundtemp)) {
                             $tempmatch->playground_id = $exportplaygroundtemp[$valueplayground];
                         }
                         //if ( empty($csv->data[$a]['Spalte28']) )
                         //  {
                         if (array_key_exists($tempmatch->match_number, $temp_match_number)) {
                             $exportmatch[] = $tempmatch;
                         } else {
                             $temp_match_number[$tempmatch->match_number] = $tempmatch->match_number;
                             $exportmatch[] = $tempmatch;
                         }
                         //}
                         $lfdnumbermatch++;
                         $lfdnumber++;
                     }
                 }
             }
             // ende schleife csv file
             foreach ($exportmatch as $rowmatch) {
                 foreach ($exportteams as $rowteam) {
                     if ($rowmatch->projectteam1_dfbnet == $rowteam->name) {
                         $rowmatch->projectteam1_id = $rowteam->id;
                     }
                     if ($rowmatch->projectteam2_dfbnet == $rowteam->name) {
                         $rowmatch->projectteam2_id = $rowteam->id;
                     }
                 }
             }
             if ($importcsv && sizeof($exportreferee) > 0) {
                 $temp = new stdClass();
                 $temp->id = 1;
                 $temp->name = 'Schiedsrichter';
                 $temp->alias = 'Schiedsrichter';
                 $temp->published = 1;
                 $exportparentposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1000;
                 $temp->name = 'Spielleitung';
                 $temp->alias = 'Spielleitung';
                 $temp->parent_id = 1;
                 $temp->published = 1;
                 $temp->persontype = 3;
                 $exportposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1001;
                 $temp->name = '1.Assistent';
                 $temp->alias = '1.Assistent';
                 $temp->parent_id = 1;
                 $temp->published = 1;
                 $temp->persontype = 3;
                 $exportposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1002;
                 $temp->name = '2.Assistent';
                 $temp->alias = '2.Assistent';
                 $temp->parent_id = 1;
                 $temp->published = 1;
                 $temp->persontype = 3;
                 $exportposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1000;
                 $temp->position_id = 1000;
                 $exportprojectposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1001;
                 $temp->position_id = 1001;
                 $exportprojectposition[] = $temp;
                 $temp = new stdClass();
                 $temp->id = 1002;
                 $temp->position_id = 1002;
                 $exportprojectposition[] = $temp;
             }
             foreach ($exportteams as $rowteam) {
                 $play_ground = $exportclubsstandardplayground[$rowteam->name];
                 $club_id = $rowteam->club_id;
                 //echo 'club_id -> '.$club_id.'<br>';
                 //echo 'play_ground -> '.$play_ground.'<br>';
                 foreach ($exportplayground as $rowground) {
                     if ($play_ground == $rowground->name) {
                         $play_ground_id = $rowground->id;
                         //echo 'play_ground_id -> '.$play_ground_id.'<br>';
                         foreach ($exportclubs as $rowclubs) {
                             if ($club_id == $rowclubs->id) {
                                 $rowclubs->standard_playground = $play_ground_id;
                             }
                         }
                     }
                 }
             }
             $this->_datas['position'] = array_merge($exportposition);
             $this->_datas['projectposition'] = array_merge($exportprojectposition);
             $this->_datas['parentposition'] = array_merge($exportparentposition);
             $this->_datas['person'] = array_merge($exportpersons);
             $this->_datas['projectreferee'] = array_merge($exportreferee);
             $this->_datas['team'] = array_merge($exportteams);
             $this->_datas['projectteam'] = array_merge($exportprojectteams);
             $this->_datas['club'] = array_merge($exportclubs);
             $this->_datas['playground'] = array_merge($exportplayground);
             // damit die spieltage in der richtigen reihenfolge angelegt werden
             ksort($exportround);
             $this->_datas['round'] = array_merge($exportround);
             $this->_datas['match'] = array_merge($exportmatch);
             $this->_datas['matchreferee'] = array_merge($exportmatchreferee);
         }
     }
     //  echo '<pre>';
     //  print_r($this->_datas);
     //  echo '</pre>';
     if ($whichfile == 'playerfile') {
         /**
          * das ganze für den standardimport aufbereiten
          */
         $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
         // open the project
         $output .= "<project>\n";
         // set the version of JoomLeague
         $output .= $this->_addToXml($this->_setJoomLeagueVersion());
         // set the person data
         if (isset($this->_datas['person'])) {
             $mainframe->enqueueMessage(JText::_('personen daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['person'], 'Person'));
         }
         // close the project
         $output .= '</project>';
         // mal als test
         $xmlfile = $output;
         $file = JPATH_SITE . DS . 'tmp' . DS . 'joomleague_import.jlg';
         JFile::write($file, $xmlfile);
         $this->import_version = 'NEW';
     } else {
         /**
          * das ganze für den standardimport aufbereiten
          */
         $output = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
         // open the project
         $output .= "<project>\n";
         // set the version of JoomLeague
         $output .= $this->_addToXml($this->_setJoomLeagueVersion());
         // set the project datas
         if (isset($this->_datas['project'])) {
             $mainframe->enqueueMessage(JText::_('project daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setProjectData($this->_datas['project']));
         }
         // set the rounds sportstype
         if (isset($this->_datas['sportstype'])) {
             $mainframe->enqueueMessage(JText::_('sportstype daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setSportsType($this->_datas['sportstype']));
         }
         // set league data of project
         if (isset($this->_datas['league'])) {
             $mainframe->enqueueMessage(JText::_('league daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setLeagueData($this->_datas['league']));
         }
         // set season data of project
         if (isset($this->_datas['season'])) {
             $mainframe->enqueueMessage(JText::_('season daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setSeasonData($this->_datas['season']));
         }
         // set the rounds data
         if (isset($this->_datas['round'])) {
             $mainframe->enqueueMessage(JText::_('round daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['round'], 'Round'));
         }
         // set the teams data
         if (isset($this->_datas['team'])) {
             $mainframe->enqueueMessage(JText::_('team daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['team'], 'JL_Team'));
         }
         // set the clubs data
         if (isset($this->_datas['club'])) {
             $mainframe->enqueueMessage(JText::_('club daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['club'], 'Club'));
         }
         // set the matches data
         if (isset($this->_datas['match'])) {
             $mainframe->enqueueMessage(JText::_('match daten ' . 'generiert'), '');
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['match'], 'Match'));
         }
         // set the positions data
         if (isset($this->_datas['position'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['position'], 'Position'));
         }
         // set the positions parent data
         if (isset($this->_datas['parentposition'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['parentposition'], 'ParentPosition'));
         }
         // set position data of project
         if (isset($this->_datas['projectposition'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectposition'], 'ProjectPosition'));
         }
         // set the matchreferee data
         if (isset($this->_datas['matchreferee'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['matchreferee'], 'MatchReferee'));
         }
         // set the person data
         if (isset($this->_datas['person'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['person'], 'Person'));
         }
         // set the projectreferee data
         if (isset($this->_datas['projectreferee'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectreferee'], 'ProjectReferee'));
         }
         // set the projectteam data
         if (isset($this->_datas['projectteam'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['projectteam'], 'ProjectTeam'));
         }
         // set playground data of project
         if (isset($this->_datas['playground'])) {
             $output .= $this->_addToXml($this->_setXMLData($this->_datas['playground'], 'Playground'));
         }
         // close the project
         $output .= '</project>';
         // mal als test
         $xmlfile = $output;
         $file = JPATH_SITE . DS . 'tmp' . DS . 'joomleague_import.jlg';
         JFile::write($file, $xmlfile);
     }
     $this->import_version = 'NEW';
     if ($this->debug_info) {
         echo $this->pane->endPane();
     }
     //$mainframe->setUserState('com_joomleague'.'_datas',$this->_datas);
     return $this->_datas;
 }