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;
             }
         }
     }
 }
 public function view($id = null)
 {
     if (empty($id)) {
         redirect('charts');
     } else {
         if (Ranked_file::count(array('conditions' => array('id = ?', $id))) == 0) {
             redirect('charts');
         } else {
             error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_WARNING);
             $file = Ranked_file::find($id);
             $pack = Pack::find($file->pack_id);
             $this->data['user_scores'] = User_score::get_scores_for_chart($id);
             $this->data['pack'] = $pack;
             $this->data['subtitle'] = $file->title;
             $this->_process_everything($file->raw_file, $file->rate);
         }
     }
 }
<?php 
}
if ($error) {
    ?>
    <div data-alert class="alert-box alert">
        Something went wrong with your submission, please make sure all fields are completed properly.<br />
        <?php 
    echo validation_errors('<span>', '</span><br />');
    ?>
    </div>
<?php 
}
?>

<?php 
$c = Ranked_file::count(array('conditions' => array('title = ? AND subtitle = ? AND artist = ? AND rate = ?', $meta['title'], $meta['subtitle'], $meta['artist'], $rate)));
if ($c > 0) {
    $f = Ranked_file::find(array('conditions' => array('title = ? AND subtitle = ? AND artist = ? AND rate = ?', $meta['title'], $meta['subtitle'], $meta['artist'], $rate)));
    ?>
        <div data-alert class="alert-box alert">
            This appears to be a duplicate of <a href="/charts/view/<?php 
    echo $f->id;
    ?>
" style="color: #ffffff; text-decoration: underline;">this chart.</a>
        </div>
    <?php 
}
?>

<form action="/mod/rank_chart" method="post" id="rank-chart-confirm">
    <input type="hidden" name="step" value="2" />
 function delete_chart($chart_id)
 {
     if (Ranked_file::count(array('conditions' => array('id = ?', $chart_id))) != 1) {
         redirect('home');
     }
     $this->content_view = "mod/delete_chart_success";
     $chart = Ranked_file::find($chart_id);
     $title = $chart->title;
     $diff = $chart->difficulty_score;
     $rate = $chart->rate;
     $chart->delete();
     $scores = User_score::all(array('conditions' => array('file_id = ?', $chart_id)));
     foreach ($scores as $score) {
         $score->status = "removed";
         $score->save();
     }
     $log_string = $this->session->userdata('username') . " (" . $this->session->userdata('display_name') . ") deleted chart: " . $title . " " . number_format($rate, 1) . "x " . " - " . $diff;
     write_to_mod_log($log_string);
 }