You are here

function appointment_calendar_settings_form_submit in Appointment Calendar 7

Implements hook_form_submit().

File

./appointment_calendar_admin_settings.inc, line 167
Provide Configuration form for Appointment calendar.

Code

function appointment_calendar_settings_form_submit($form, &$form_state) {
  if ($form_state['values']['op'] == t('Submit')) {
    $start_date = $form_state['values']['appointment_from_date'];
    $end_date = $form_state['values']['appointment_to_date'];
    $slots = $form_state['values']['appointment_slot'];

    // Fetching Timeslot and capacity values.
    for ($i = 1; $i <= $slots; $i++) {
      $time_slot = $form_state['values']['time_slot_' . $i];
      $time_capacity = $form_state['values']['time_slot_' . $i . '_capacity'];
      $slots_save[$time_slot] = $time_slot;
      $slots_capacity[$time_slot] = $time_capacity;
    }
    ksort($slots_save);
    ksort($slots_capacity);

    // Getting all dates in between Start and End Dates.
    $dates = appointment_calendar_daysbetween(strtotime($start_date), strtotime($end_date));

    // Saving date with time slots and capacity.
    foreach ($dates as $each_date) {
      db_merge('appointment_date')
        ->key(array(
        'date' => $each_date,
      ))
        ->fields(array(
        'no_slots' => $slots,
        'slot_values' => json_encode($slots_save),
        'slot_capacity' => json_encode($slots_capacity),
      ))
        ->execute();
    }
  }

  // Redirect to list page.
  drupal_set_message(t('Slot(s) created successfully'));
  drupal_goto('admin/config/appointment-calendar/settings/list-date');
}