public function get_template_data() { $root = root . '/uploads/comp/' . $this->module->current->get_primary_key(); $files = glob($root . '/*.igc'); $flights = []; foreach ($files as $file) { $name = str_replace($root, '', $file); $name = str_replace('.igc', '', $name); $name = preg_replace('/[0-9.\\-_\\/]/', ' ', $name); $name = preg_replace('/\\s+/', ' ', $name); $name = trim($name); $pilot = new pilot(); $parts = explode(' ', $name); $match = false; if ($pilot->do_retrieve([], ['where_equals' => ['name' => $name]]) || $pilot->do_retrieve([], ['where_equals' => ['name' => implode(' ', array_reverse($parts))]])) { $flight = new flight(); $match = $flight->do_retrieve([], ['where_equals' => ['pid' => $pilot->get_primary_key(), 'date' => date('Y-m-d', $this->module->current->date)]]); } $flights[] = ['data' => ['path' => $file, 'name' => $name, 'cid' => $this->module->current->get_primary_key()], 'name' => $name, 'matched' => $match]; } return ['rows' => $flights]; }
public function add_flight() { $this->do_retrieve_from_id([], $_REQUEST['cid']); $coords = json_decode($this->coords); $form = new igc_upload_form(); $form->file = $_REQUEST['path']; $form->coords = implode(';', array_map(function ($coord) { $point = new lat_lng($coord->lat, $coord->lon); return geometry::lat_long_to_os($point); }, $coords)); $form->do_submit(); $form = new igc_form(); $form->vis_info = 'Flown in comp: ' . $this->type . ' Round ' . $this->round . ' Task ' . $this->task; $pilot = new pilot(); $parts = explode(' ', $_REQUEST['name']); if ($pilot->do_retrieve([], ['where_equals' => ['name' => $_REQUEST['name']]]) || $pilot->do_retrieve([], ['where_equals' => ['name' => implode(' ', array_reverse($parts))]])) { $form->pid = $pilot->get_primary_key(); $flight = new flight(); if ($flight->do_retrieve([], ['where_equals' => ['pid' => $pilot->get_primary_key()], 'order' => 'date DESC'])) { $form->gid = $flight->gid; $form->cid = $flight->cid; } } ajax::update(node::create('div#second_form', [], $form->get_html())); }