You are here

function appointment_calendar_date_list_form in Appointment Calendar 7

Implements hook_form().

1 string reference to 'appointment_calendar_date_list_form'
appointment_calendar_menu in ./appointment_calendar.module
Implements hook_menu().

File

./appointment_calendar_list.inc, line 11
Provides Listing page for Created date(s) in Appointment calendar.

Code

function appointment_calendar_date_list_form($form, $form_state) {

  // For date list appointment calendar.
  global $base_url;
  $form['redirect'] = array(
    '#markup' => '<a href="' . $base_url . '/admin/config/appointment-calendar/settings">Add Appointment Date and Slot(s)</a>',
  );
  $query = drupal_get_query_parameters();
  $form['filter_date'] = array(
    '#title' => t('From Date'),
    '#type' => 'date_popup',
    '#date_format' => 'Y-m-d',
    '#date_year_range' => '0:+3',
    '#default_value' => isset($query['date']) ? $query['date'] : date('Y-m-d', time()),
  );
  $form['filter_to_date'] = array(
    '#title' => t('To Date'),
    '#type' => 'date_popup',
    '#date_format' => 'Y-m-d',
    '#date_year_range' => '0:+3',
    '#default_value' => isset($query['todate']) ? $query['todate'] : date('Y-m-d', time()),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Filter',
  );
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => 'Reset',
  );
  $date_query = db_select('appointment_date', 'ad');
  $date_query
    ->fields('ad');
  if (!empty($query['date'])) {
    $date_query
      ->condition('date', strtotime($query['date']), '>=');
  }
  if (!empty($query['todate'])) {
    $date_query
      ->condition('date', strtotime($query['todate']), '<=');
  }
  $date_query
    ->orderBy('date');
  $date_result = $date_query
    ->execute()
    ->fetchAll();
  $header = array(
    'Date',
    'No. Slots',
    '',
    '',
    '',
  );
  $rows = array();
  $output = '';
  foreach ($date_result as $date) {
    $capacity = appointment_calendar_slot_capacity($date->date);
    $slots = count((array) json_decode($capacity));
    $view = check_plain($base_url . '/admin/appointment-calendar/view?date=' . $date->date);
    $edit = check_plain($base_url . '/admin/appointment-calendar/edit?date=' . $date->date);
    $delete = check_plain($base_url . '/admin/appointment-calendar/delete?date=' . $date->date);
    $row = '';
    $row[] = date('Y-m-d', $date->date);
    $row[] = $slots;
    $row[] = '<a href="' . $view . '">View</a>';
    $row[] = '<a href="' . $edit . '">Edit</a>';
    $row[] = '<a href="' . $delete . '">Delete</a>';
    $rows[] = $row;
  }
  if (count($rows) > 0) {
    $per_page = 25;
    $current_page = pager_default_initialize(count($rows), $per_page);
    $chunks = array_chunk($rows, $per_page, TRUE);
    $output = theme('table', array(
      'header' => $header,
      'rows' => $chunks[$current_page],
    ));
    $output .= theme('pager', array(
      'quantity',
      count($rows),
    ));
    $form['ouptut'] = array(
      '#markup' => $output,
    );
  }
  else {
    $form['ouptut'] = array(
      '#markup' => t('No Dates Available for selected date.'),
    );
  }
  return $form;
}