public function submit($song_id = null)
 {
     $this->require_login();
     if (!$song_id) {
         $this->content_view = "scores/submit";
         $this->data['songs'] = Ranked_file::get_all_charts();
         $this->data['packs'] = Pack::all(array('order' => 'name asc'));
     } else {
         if (Ranked_file::count(array('conditions' => array('id = ?', $song_id))) != 1) {
             redirect('scores/submit');
         } else {
             if ($_POST) {
                 $song = Ranked_file::find($song_id);
                 $this->data['song'] = $song;
                 $total_notes = $this->input->post('marvelous_count') + $this->input->post('perfect_count') + $this->input->post('great_count') + $this->input->post('good_count') + $this->input->post('boo_count') + $this->input->post('miss_count');
                 $total_holds = $this->input->post('ok_count');
                 if ($total_notes > $song->taps || $total_holds > $song->holds) {
                     $this->content_view = "scores/confirm";
                     $this->data['error_nc'] = true;
                 } elseif ($this->form_validation->run('submit_score') == FALSE) {
                     $this->content_view = "scores/confirm";
                     $this->data['error'] = true;
                 } else {
                     $attributes = array('user_id' => $this->session->userdata('user_id'), 'file_id' => $song_id, 'date_achieved' => $this->input->post('score_achieved'), 'marvelous_count' => $this->input->post('marvelous_count'), 'perfect_count' => $this->input->post('perfect_count'), 'great_count' => $this->input->post('great_count'), 'good_count' => $this->input->post('good_count'), 'boo_count' => $this->input->post('boo_count'), 'miss_count' => $this->input->post('miss_count'), 'ok_count' => $this->input->post('ok_count'), 'mines_hit' => $this->input->post('mines_hit'), 'screenshot_url' => $this->input->post('screenshot_url'));
                     $new_score = new User_score($attributes);
                     $new_score->save();
                     // Check if score is below AA
                     $max_dp_max = $song->dance_points;
                     $max_dp_achieved = $new_score->marvelous_count * 2 + $new_score->perfect_count * 2 + $new_score->great_count * 1 + $new_score->boo_count * -4 + $new_score->miss_count * -8 + $new_score->ok_count * 6 + $new_score->mines_hit * -8;
                     $max_dp_percent = $max_dp_achieved / $max_dp_max * 100;
                     if ($max_dp_percent < 93) {
                         $new_score->status = "below_aa";
                         $new_score->save();
                     }
                     // Check if score is in top 10% of all scores
                     $this->data['score_pending'] = false;
                     $percentile = User_score::get_top_10_percentile();
                     if ($song->difficulty_score > $percentile) {
                         $new_score->status = "pending";
                         $new_score->was_pending = 1;
                         $new_score->save();
                         $this->data['score_pending'] = true;
                     }
                     $this->content_view = "scores/success";
                 }
             } else {
                 $this->data['song'] = Ranked_file::find($song_id);
                 $this->content_view = "scores/confirm";
                 $this->data['error'] = false;
             }
         }
     }
 }
<?php

echo User_score::get_top_10_percentile();