public function do_calc_score($id, $section = null) { $file = root . '/.cache/' . $id . '/track.igc'; $igc_parser = new igc_parser(); $data = ['source' => $file]; if ($this->coords) { $task = new defined_task(); $task->create_from_coordinates($this->coords); $data['task'] = ['type' => 'os_gridref', 'coordinates' => array_map(function ($coordinate) { return $coordinate->os_gridref; }, $task->coordinates)]; } if ($section !== null) { $data['section'] = $section; } $parsed = $igc_parser->exec($id, $data); $html = ''; if ($parsed) { if (!$this->check_date($igc_parser)) { $html .= node::create('p.error', [], static::OUT_OF_BOUNDS_TEXT); } $validated = $igc_parser->get_validated(); if ($validated === 0) { $html .= node::create('p.callout.callout-warning', [], static::NOT_VALID); } /*else if ($validated === null) { $html .= node::create('p.callout.callout-warning', [], static::NO_VALIDATION); }*/ if ($igc_parser->get_part_count() > 1) { $split = "1"; $html .= $this->get_choose_track_html($igc_parser); } else { $split = "0"; $html .= $this->get_choose_score_html($igc_parser); } ajax::add_script('map.add_flight(' . $id . ',1,1,1,' . $split . ');'); } else { $html .= node::create('p.callout.callout-warning', [], static::PARSE_FAILED); } ajax::update('<div id="console">' . $html . '</div>'); }
/** * @param field_file $field * @return string */ protected function do_upload_file(field_file $field) { if ($field->field_name == 'file') { if (isset($_FILES[$field->field_name]) && !$_FILES[$field->field_name]['error']) { $tmp_name = $_FILES[$field->field_name]['tmp_name']; $name = $_FILES[$field->field_name]['name']; $ext = pathinfo($name, PATHINFO_EXTENSION); if ($ext == 'zip') { $root = root . '/uploads/comp/' . $this->get_primary_key(); if (!is_dir($root)) { mkdir($root); } $this->file = str_replace(root, '', $root) . '/comp.zip'; $zip = new \ZipArchive(); $zip->open(root . $this->file); $zip->extractTo($root . '/'); $files = glob($root . '/*.igc'); $files = array_map(function ($file) { $exp = explode("/", $file); return ['name' => trim(preg_replace('/[^a-zA-Z ]/', '', substr(end($exp), 0, -3))), 'source' => $file]; }, $files); if ($files) { $coords = json_decode($this->coords); $parser = new igc_parser(); $parser->exec($this->get_primary_key(), ['type' => 'comp', 'sources' => $files, 'destination' => $root, 'task' => ['type' => 'lat/lng', 'coordinates' => array_map(function ($coord) { return ['lat' => (double) $coord->lat, 'lng' => (double) $coord->lon]; }, $coords)]]); } move_uploaded_file($tmp_name, root . $this->file); db::update('comp')->add_value('file', $this->file)->filter_field('cid', $this->cid)->execute(); } } } else { parent::do_upload_file($field); } }