/** 
  * Generates custom content for dashboard tab.
  */
 protected function generate_dashboard()
 {
     $contest_status = '';
     $isstarted = $this->contest->is_started();
     $isexpired = $this->contest->is_expired();
     $contest_status = __('Expired', 'contestfriend');
     if (!$isstarted) {
         $contest_status = __('Not active yet', 'contestfriend');
     } else {
         if ($isexpired && $this->contest->cf_status == 'expired') {
             $contest_status = __('Expired (forced)', 'contestfriend');
         } else {
             if ($isexpired && $this->contest->cf_status == 'active') {
                 $contest_status = __('Expired (automatic)', 'contestfriend');
             } else {
                 if ($isexpired && $this->contest->cf_status == 'winners_picked') {
                     $contest_status = __('Expired (winners picked)', 'contestfriend');
                 } else {
                     if ($isstarted && !$isexpired) {
                         $contest_status = __('Active', 'contestfriend');
                     }
                 }
             }
         }
     }
     $part_num = cf_Participant::get_num($this->contest->ID);
     $part_num_all = cf_Participant::get_num($this->contest->ID, 'all');
     $participant_num = $part_num;
     if ($part_num_all != $part_num) {
         $participant_num .= ' (' . $part_num_all . ')';
     }
     echo '<div style="margin-top: 5px;">';
     // Dashboard buttons
     if (!$this->contest->is_expired() || $this->contest->cf_status == 'expired') {
         // display stop / resume contest
         $url = admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest'] . '&redirect=contest');
         echo '<form action="' . $url . '" method="post" style="float: left; margin-left: 5px"><input type="hidden" name="setexpired" value="1" />';
         $text = __('Stop Contest', 'contestfriend');
         if ($this->contest->cf_status == 'expired') {
             $text = __('Resume Contest', 'contestfriend');
         }
         submit_button($text, 'button-secondary action', false, false);
         echo '</form>';
     }
     if ($this->contest->is_expired() && $this->contest->cf_status == 'winners_picked') {
         // display reset contest button
         $url = admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest'] . '&redirect=contest');
         echo '<form action="' . $url . '" method="post" style="float: left; margin-left: 5px"><input type="hidden" name="resetcontest" value="1" />';
         $text = __('Reset Contest', 'contestfriend');
         submit_button($text, 'button-secondary action', false, false);
         echo '</form>';
     }
     // if not all winners were picked, show pick buttons
     $winners_num = 1;
     $current_winners = $this->contest->get_current_winner_num();
     if (isset($this->contest->cf_winners_num) && is_numeric($this->contest->cf_winners_num) && $this->contest->cf_winners_num > 0) {
         $winners_num = $this->contest->cf_winners_num;
     }
     if ($current_winners < $winners_num) {
         $confirm_class = '';
         if ($current_winners == 0 && $this->contest->cf_status != 'winners_picked') {
             $confirm_class = 'confirm_setwinner';
         }
         $text = __('Pick Random Winners', 'contestfriend');
         $url = admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest'] . '&redirect=contest');
         echo '<form class="' . $confirm_class . '" action="' . $url . '" method="post" style="float: left; margin-left: 5px"><input type="hidden" name="pickwinners" value="1" />';
         submit_button($text, 'button-secondary action', false, false);
         echo '</form>';
         $text = __('Manually Pick Winners', 'contestfriend');
         echo '<form action="' . $url . '" method="post" style="float: left; margin-left: 5px">';
         submit_button($text, 'button-secondary action', false, false);
         echo '</form>';
     }
     // if there are some winners picked, show clear winners button
     if ($current_winners > 0) {
         $url = admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest'] . '&redirect=contest');
         $text = __('Clear All Winners', 'contestfriend');
         echo '<form action="' . $url . '" method="post" style="float: left; margin-left: 5px"><input type="hidden" name="clearwinners" value="1" />';
         submit_button($text, 'button-secondary action', false, false);
         echo '</a></form>';
     }
     echo '</div>
     <div id="poststuff" style="clear: both;">
     <div class="postbox">
     <h3>' . __('Contest Status', 'contestfriend') . '</h3>
     <div class="inside">    
     <table class="form-table">
     <tbody><tr valign="top"><th class="cf_label">' . __('Status', 'contestfriend') . '</th>
     <td>' . $contest_status . '</td>
     </tr>
     <tr valign="top"><th class="cf_label" style="vertical-align: middle">' . __('Number of participants', 'contestfriend') . '</th>
     <td style="vertical-align: middle">' . $participant_num . ' <a href="' . admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest']) . '" class="button">' . __('View all participants', 'contestfriend') . '</a></td>
     </tr>
     </table>
     </div></div>';
     if ($current_winners > 0) {
         $winners = cf_Participant::get_all($this->contest->ID, '', '', '', '', 'winner');
         echo '<div class="postbox">
         <h3>' . __('Winners', 'contestfriend') . '</h3>
         <div class="inside">
         <table class="form-table">
         <tbody>';
         foreach ($winners as $winner) {
             $url = admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $_GET['contest'] . '&redirect=contest');
             $text = __('Remove Winner', 'contestfriend');
             echo '<tr valign="top"><th class="cf_label">' . $winner->email . ', ' . $winner->first_name . ' ' . $winner->last_name . '</th><td><form action="' . $url . '" method="post"><input type="hidden" name="removewinner" value="' . esc_attr($winner->id) . '" />';
             submit_button($text, 'button-secondary action', false, false);
             echo '</td></tr>';
         }
         echo '
         </table>    
         </div>
         </div>
         ';
     }
     echo '</div>';
 }
 /**
  * Generates columns.
  * 
  * @param cf_Contest $item Current contest.
  * @param string $column_name Current column text ID.
  */
 function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'title':
             $headline = isset($item->cf_headline) ? esc_html($item->cf_headline) : '';
             $output = '<b>' . esc_html($item->ID) . ':</b> <a href="' . admin_url('admin.php?page=' . cf_Page_Contest::page_id . '&contest=' . $item->ID) . '">' . $headline . '</a>';
             $actions = array();
             $actions['edit'] = '<a href="' . admin_url('admin.php?page=' . cf_Page_Contest::page_id . '&contest=' . $item->ID) . '">' . __('Edit') . '</a>';
             $actions['delete'] = '<a class="confirm_delete" href="' . admin_url('admin.php?page=' . cf_Page_List::page_id . '&action=del&contest=' . $item->ID) . '">' . __('Delete') . '</a>';
             $actions['dashboard'] = '<a href="' . admin_url('admin.php?page=' . cf_Page_Contest::page_id . '&contest=' . $item->ID . '&cf_page=dashboard') . '">' . __('Dashboard', 'contestfriend') . '</a>';
             $actions['participants'] = '<a href="' . admin_url('admin.php?page=' . cf_Page_Participants::page_id . '&contest=' . $item->ID) . '">' . __('Participants', 'contestfriend') . '</a>';
             $output .= $this->row_actions($actions);
             return $output;
         case 'participants':
             $part_num = cf_Participant::get_num($item->ID);
             $part_num_all = cf_Participant::get_num($item->ID, 'all');
             $participant_num = $part_num;
             if ($part_num_all != $part_num) {
                 $participant_num .= ' (' . $part_num_all . ')';
             }
             return $participant_num;
         case 'date_start':
             $date_start = isset($item->cf_date_start) ? $item->cf_date_start : '';
             return $date_start;
         case 'duration':
             $date_start = isset($item->cf_date_start) ? $item->cf_date_start : '';
             $date_end = isset($item->cf_date_end) ? $item->cf_date_end : '';
             $start_time = strtotime($date_start);
             $end_time = strtotime($date_end);
             $duration = $end_time - $start_time;
             $duration_text = '';
             if ($duration < 3600 * 24) {
                 $hrs = round($duration / 3600);
                 $duration_text = $hrs . ' hour(s)';
             } else {
                 $days = intval(floor($duration / 86400));
                 $hrs = round(($duration - $days * 86400) / 3600);
                 $duration_text = $days . ' day(s), ' . $hrs . ' hour(s)';
             }
             $duration_text .= ' (ends ' . $item->cf_date_end . ')';
             return $duration_text;
         case 'status':
             $status = isset($item->cf_status) ? $item->cf_status : '';
             $isexpired = $item->is_expired();
             $isstarted = $item->is_started();
             $contest_status = __('Expired', 'contestfriend');
             if (!$isstarted) {
                 $contest_status = __('Not active yet', 'contestfriend');
             } else {
                 if ($isexpired && $item->cf_status == 'expired') {
                     $contest_status = __('Expired (forced)', 'contestfriend');
                 } else {
                     if ($isexpired && $item->cf_status == 'active') {
                         $contest_status = __('Expired (automatic)', 'contestfriend');
                     } else {
                         if ($isexpired && $item->cf_status == 'winners_picked') {
                             $contest_status = __('Expired (winners picked)', 'contestfriend');
                         } else {
                             if ($isstarted && !$isexpired) {
                                 $contest_status = __('Active', 'contestfriend');
                             }
                         }
                     }
                 }
             }
             return $contest_status;
         default:
             return '';
     }
 }
 /**
  * Retrieves participant data.
  */
 function get_data()
 {
     $contest_id = '';
     if (!empty($this->contest)) {
         $contest_id = $this->contest->ID;
     }
     $data = array();
     $orderby = '';
     if (isset($_GET['orderby'])) {
         $orderby = $_GET['orderby'];
     }
     $order = '';
     if (isset($_GET['order'])) {
         $order = $_GET['order'];
     }
     $page = $this->get_pagenum();
     $perpage = $this->per_page;
     $data = cf_Participant::get_all($contest_id, $orderby, $order, $page, $perpage, 'all');
     $this->found_posts = cf_Participant::get_num($contest_id);
     return $data;
 }