public function get_view() { $form = new igc_form(); $form->wrapper_class[] = 'callout'; $form->wrapper_class[] = 'callout-primary'; $form2 = new igc_upload_form(); $form2->wrapper_class[] = 'callout'; $form2->wrapper_class[] = 'callout-primary'; $html = node::create('div.add_flight_section.upload', [], $form2->get_html()->get() . $form->get_html()->get() . node::create('a.back.button', ['href' => '/add_flight'], 'Back')); $script = <<<'JS' var $body = $("body"); $body.on("change.bs.fileinput,clear.bs.fileinput,reset.bs.fileinput", ".fileinput", function (e) { var $ths = $(this); var $input = $ths.find("input[type=file]"); var $kml = $("#kml_calc"); var $kml_wrapper = $("#kml_wrapper"); if ($input.val().toLowerCase().slice(-3) == "igc") { $kml.fadeIn(1000).html("<div id=\'console\'><a class=\'calc\'>Calculate</a></div>"); $kml_wrapper.find("a").show(); $kml_wrapper.addClass("pass").removeClass("hoverFail"); $kml_wrapper.find("p.text").html("Click calculate to continue or choose another file"); } else { $kml_wrapper.find("p.text").html("Please use an IGC file"); $kml_wrapper.addClass("hoverFail"); $kml.hide(); } }); $body.on("change", "input, select, textarea", function (e) { $("#" + $(this).attr("id") + "_hidden").val($(this).val()); return true; }); $body.on("click", "#kml_calc a.calc", function () { $("#igc_upload_form").submit(); $("#kml_wrapper").removeClass("pass"); }); $body.on("change","input#coords",function () { var arr = $(this).val().split(";"); var coord_array = new Planner(); var str = []; arr.each(function(arg, i) { var coord = new Coordinate(); coord.set_from_OS(arg); if (coord.is_valid_gridref()) { coord_array.push(coord); } else { str.push("Coordinate " + (parseInt(i) + 1) + " is not valid"); } }); if (!str.length) { switch (coord_array.count) { case 0: str = [""]; break; case 1: str = ["Please enter at least two coordinates"]; break; case 2: str = ["Flight Type: Open Distance, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; break; case 3: if(coord_array[0] == coord_array[2]) { str = ["Flight Type: Out & Return, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; } else { str = ["Flight Type: Open Distance, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; } break; case 4: if(coord_array[0] == coord_array[4]) { str = ["Flight Type: Triangle, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; } else { str = ["Flight Type: Open Distance, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; } break; case 5: str = ["Flight Type: Open Distance, Score: " + coord_array.get_total_distance().round(2) + " before multipliers"]; break; default : str = ["you can only enter 5 coordinates"]; } } $(this).parents("form").find(".defined_info").html(str.join("<br/>")); }); $body.on("click","a.score_select",function () { var data = $(this).data("post"); $("#temp_id").val(data.track); $("#type").val(data.type); $("#igc_upload_form").html("<p class='restart'>Your flight details have been saved, please complete the form below, 'Additional Details', to finalise your sumbission.<br/><a data-ajax-click='module\\add_flight\\form\\igc_upload_form:reset' href='#' class='button'>Restart</a></p>"); $("#igc_form ").find("input.submit").removeAttr("disabled"); }); JS; if (ajax) { ajax::add_script($script); } else { \core::$inline_script[] = $script; } return $html; }
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())); }
public function do_submit() { $flight = new flight(); $flight->set_from_request(); $flight->live = false; $flight->do_save(); if ($flight->fid) { $flight->move_temp_files($this->temp_id); $igc_parser = new igc_parser(); $igc_parser->load_data($flight->fid, false); $flight->did = $igc_parser->has_height_data() ? 3 : 2; $flight->winter = $igc_parser->is_winter(); $flight->set_date(strtotime($igc_parser->get_date())); $this->force_delay = false; if (!$this->check_date($igc_parser)) { $this->force_delay = true; $flight->admin_info .= 'delayed as flight is old.' . "\n"; } if ($igc_parser->get_validated() === 0) { $flight->admin_info .= 'G record invalid.' . "\n"; } $flight->defined = $this->type == 'task'; $flight->duration = $igc_parser->get_duration(); foreach (['od' => 'open_distance', 'or' => 'out_and_return', 'tr' => 'triangle', 'ft' => 'flat_triangle'] as $task_id => $name) { if ($task = $igc_parser->get_task($name)) { $flight->{$task_id . '_score'} = $task->get_distance(); $flight->{$task_id . '_time'} = $task->get_duration(); $flight->{$task_id . '_coordinates'} = $task->get_gridref(); if ($this->type == $task->type) { $flight->ftid = $this->type; $flight->base_score = $task->get_distance(); $flight->duration = $task->get_duration(); $flight->coords = $task->get_gridref(); } } } if ($flight->defined) { $task = $igc_parser->get_task('declared'); $flight->ftid = $task->type; if ($flight->ftid == \track\task::TYPE_OPEN_DISTANCE) { $flight->ftid = \track\task::TYPE_GOAL; } $flight->base_score = $task->get_distance(); $flight->duration = $task->get_duration(); $flight->coords = $task->get_gridref(); } $flight->multi = !$flight->ridge ? flight_type::get_multiplier($flight->ftid, $igc_parser->get_date('Y'), $flight->defined) : 1; $flight->score = $flight->multi * $flight->base_score; $flight->delayed = $this->force_delay || $this->delay; $flight->live = true; $flight->do_save(); jquery::colorbox(['html' => 'Your flight has been added successfully', 'className' => 'success']); $form = new igc_form(); ajax::update($form->get_html()->get()); $users = new_flight_notification::get_all([]); foreach ($users as $user) { $mail = new email(); $mail->load_template(root . '/template/email/basic.html'); $mail->set_recipients([$user->email]); $subject = 'New flight added'; if ($flight->delayed) { $subject .= ' - Delayed'; } if ($igc_parser->get_validated() === 0) { $subject .= ' - G record invalid'; } $mail->set_subject($subject); $mail->replacements = ['[content]' => ' <h2>New flight added: ' . $flight->get_primary_key() . '</h2> <table class="btn-primary" cellpadding="0" cellspacing="0" border="0"> <tr> <td> <a href="' . host . '/cms/edit/2/' . $flight->get_primary_key() . '">View in CMS</a> </td> </tr> </table>']; $mail->send(); } } else { jquery::colorbox(['html' => 'Your flight has failed to save', 'className' => 'success failure']); } }