/**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     global $wpdb;
     $table = wcs3_get_table_name();
     $output = '';
     $title = apply_filters('widget_title', $instance['title']);
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     // Get today's weekday index
     $today = date('w', time());
     $location_id = $instance['location'] != 'all' ? $instance['location'] : NULL;
     $max_classes = intval($instance['max_classes']);
     $limit = is_int($max_classes) ? $max_classes : NULL;
     $no_entries_msg = strlen($instance['no_entries_text']) > 0 ? $instance['no_entries_text'] : __('No classes today');
     $schedule = wcs3_get_day_schedule($today, $location_id, $limit);
     if ($schedule == FALSE) {
         $output .= '<div class="wcs3-no-classes">' . $no_entries_msg . '</div>';
         echo $output;
         return;
     }
     $output .= '<ul class="wcs3-today-classes-widget-list">';
     foreach ($schedule as $key => $entry) {
         if (isset($entry['visible']) && $entry['visible'] == 'Visible') {
             $start_hour = $entry['start_hour'];
             $class_name = $entry['class'];
             $output .= "<li>{$start_hour} - {$class_name}</li>";
         }
     }
     $output .= '</ul>';
     echo $output;
     echo $args['after_widget'];
 }
/**
 * Generates the day table for admin use.
 * 
 * @param int $day: the weekday (sunday = 0, monday = 1)
 */
function wcs3_render_day_table($day)
{
    $day_data = wcs3_get_day_schedule($day);
    $output = '<div class="wcs3-day-content-wrapper">';
    if ($day_data) {
        $output .= '<table id="wcs3-admin-table-day-' . $day . '" class="widefat wcs3-admin-schedule-table">';
        $output .= '<tr>
            <th>' . __('Class', 'wcs3') . '</th>
            <th>' . __('Instructor', 'wcs3') . '</th>
            <th>' . __('Location', 'wcs3') . '</th>
            <th>' . __('Start', 'wcs3') . '</th>
            <th>' . __('End', 'wcs3') . '</th>
            <th>' . __('Visibility', 'wcs3') . '</th>
            <th>' . __('Delete', 'wcs3') . '</th>
            <th>' . __('Edit', 'wcs3') . '</th>
        </tr>';
        foreach ($day_data as $class) {
            $output .= '<tr>';
            foreach ($class as $key => $value) {
                if ($key != 'id') {
                    $output .= "<td>{$value}</td>";
                } else {
                    $output .= '<td><a href="#delete" class="wcs3-delete-button wcs3-action-button-day-' . $day . '" 
        		                id="delete-entry-' . $value . '">' . __('delete', 'wcs3') . '</a></td>';
                    $output .= '<td><a href="#" class="wcs3-edit-button wcs3-action-button-day-' . $day . '" 
        		                id="edit-entry-' . $value . '">' . __('edit', 'wcs3') . '</a>';
                }
            }
            $output .= '</tr>';
        }
        $output .= '</table>';
    } else {
        $output .= '<div class="wcs3-no-classes"><p>' . __('No classes', 'wcs3') . '</p></div>';
    }
    $output .= '</div>';
    // day-content-wrapper
    return $output;
}