/**
  * Read file
  * 
  * WARNING: Don't use this method with a TTBIN-file.
  * TTBIN-files have to be parsed first with parseFile($Filename).
  * 
  * For unittesting, this method accepts a filename of the output of ttbincnv
  * 
  * @param string $filename [optional] absolute path
  */
 public function readFile($filename = '')
 {
     if (!empty($filename)) {
         $this->Filename = $filename;
     }
     $Handle = @fopen(FRONTEND_PATH . $this->Filename, "r");
     if ($Handle) {
         $firstLine = stream_get_line($Handle, 4096, PHP_EOL);
         if (strpos($firstLine, 'ttbincnv') !== FALSE) {
             $this->Errors[] = 'Importing your *.ttbin-file did not work. Please compile ttbincnv for your environment.';
             $this->Parser = new ParserTCXMultiple('');
         } else {
             $Filecontent = Filesystem::openFile($this->Filename);
             $this->Parser = new ParserTCXMultiple($Filecontent);
             $this->Parser->parse();
         }
         fclose($Handle);
     }
     Filesystem::deleteFile($this->Filename);
 }
Esempio n. 2
0
 /**
  * Delete multiple files from garmin communicator
  */
 private function deleteMultipleFilesFromGarminCommunicator()
 {
     foreach ($_POST['activityIds'] as $ID) {
         Filesystem::deleteFile(ImporterUpload::relativePath($ID . '.tcx'));
     }
 }
 /**
  * Display form: import finished 
  */
 protected function displayImportFinish()
 {
     require_once __DIR__ . '/class.RunalyzeBulkInsert.php';
     require_once __DIR__ . '/class.RunalyzeJsonImporterResults.php';
     require_once __DIR__ . '/class.RunalyzeJsonImporter.php';
     $fileName = '../data/DbBackup/import/' . $_POST['file'];
     $Importer = new RunalyzeJsonImporter($fileName);
     $Importer->importData();
     Filesystem::deleteFile($fileName);
     Ajax::setReloadFlag(Ajax::$RELOAD_ALL);
     $Fieldset = new FormularFieldset(__('Import data'));
     $Fieldset->addText(__('All data have been imported.'));
     $Fieldset->addText(__('It is recommended to use the <em>Database cleanup</em> tool.'));
     $Fieldset->addInfo($Importer->resultsAsString());
     $Fieldset->addBlock(Ajax::getReloadCommand());
     $Formular = new Formular();
     $Formular->setId('import-finished');
     $Formular->addFieldset($Fieldset);
     $Formular->display();
 }
Esempio n. 4
0
 /**
  * Display exported files
  */
 protected function displayExportedFiles()
 {
     $ListOfFiles = $this->getExistingFiles();
     $Fieldset = new FormularFieldset(sprintf(__('Up to now you have exported <strong>%d</strong> trainings.'), count($ListOfFiles)));
     if (strlen(Request::param('delete')) > 0) {
         $index = (int) Request::param('delete');
         if (!isset($ListOfFiles[$index - 1])) {
             $Fieldset->addWarning('Don\' do that!');
         } else {
             $Fieldset->addInfo(__('The file has been removed.'));
             Filesystem::deleteFile('export/files/' . $ListOfFiles[$index - 1]);
             unset($ListOfFiles[$index - 1]);
         }
     } else {
         $Fieldset->setCollapsed();
     }
     if (empty($ListOfFiles)) {
         $Fieldset->addFileBlock('<em>' . __('You did not export any training.') . '</em>');
     } else {
         foreach ($ListOfFiles as $i => $File) {
             $String = $File . ', ' . Filesystem::getFilesize(FRONTEND_PATH . 'export/files/' . $File);
             $Link = '<a href="inc/export/files/' . $File . '" target="_blank">' . $String . '</a>';
             $Delete = Ajax::window('<a class="right small" href="' . self::$URL . '?id=' . $this->TrainingID . '&delete=' . ($i + 1) . '">[' . __('delete') . ']</a>', 'small');
             $Fieldset->addFileBlock($Delete . $Link);
         }
     }
     $Formular = new Formular();
     $Formular->setId('export-list');
     $Formular->addFieldset($Fieldset);
     $Formular->display();
 }