Esempio n. 1
0
 public function do_submit()
 {
     $flight = new flight();
     $flight->set_from_request();
     $flight->dim = 1;
     if (strtotime($this->date) + 30 * 24 * 60 * 60 < time()) {
         $this->force_delay = true;
         $flight->admin_info .= 'delayed as flight is old.';
     }
     $track = new track();
     $task = $track->set_task($this->coords);
     $flight_type = new flight_type();
     $flight_type->do_retrieve(['ftid', 'multi', 'multi_defined'], ['where_equals' => ['fn' => $task->type]]);
     $flight->ftid = $flight_type->ftid;
     $flight->set_date($this->date);
     $flight->multi = !$this->ridge ? flight_type::get_multiplier($flight->ftid, $flight->season, $this->defined) : 1;
     $flight->base_score = $task->get_distance();
     $flight->coords = $this->coords;
     $flight->score = $flight->base_score * $flight->multi;
     $flight->delayed = $this->force_delay ? true : $this->delay;
     $flight->do_save();
     jquery::colorbox(['html' => 'Your flight has been added successfully', 'className' => 'success']);
     $form = new coordinates_form();
     ajax::update($form->get_html()->get());
 }
Esempio n. 2
0
 public function get_view()
 {
     $form = new coordinates_form();
     $form->wrapper_class[] = 'callout';
     $form->wrapper_class[] = 'callout-primary';
     $html = node::create('div.add_flight_section.coordinate', [], $form->get_html() . node::create('a.back.button', ['href' => '/add_flight'], 'Back'));
     $script = '
 $("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 = "Coordinate " + (i * 1 + 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);
 });';
     if (ajax) {
         ajax::add_script($script);
     } else {
         \core::$inline_script[] = $script;
     }
     return $html;
 }