You are here

function library_admin_settings_overdue_validate in Library 6

Same name and namespace in other branches
  1. 5.2 library.admin.inc \library_admin_settings_overdue_validate()
  2. 6.2 library.admin.inc \library_admin_settings_overdue_validate()
  3. 7 library.admin.inc \library_admin_settings_overdue_validate()

File

./library.admin.inc, line 208
Administrative settings for the library module

Code

function library_admin_settings_overdue_validate($form, &$form_state) {
  foreach (library_get_item_types() as $type) {
    $duedates_enabled = 0;
    foreach (library_actions() as $aid => $action) {
      if ($action['status_change'] == LIBRARY_ACTION_TYPE_UNAVAILABLE) {
        $clean = library_clean_action_name($action['name']);
        $input_name_days = 'library_days_for_' . $type . '_' . $clean;
        $input_name_hours = 'library_hours_for_' . $type . '_' . $clean;
        if (!is_numeric($form_state['values'][$input_name_days])) {
          form_set_error($input_name_days, t('Days must be a number.'));
        }
        if (!is_numeric($form_state['values'][$input_name_hours])) {
          form_set_error($input_name_hours, t('Hours must be a number.'));
        }
        $day_sec = $form_state['values'][$input_name_days] * 24 * 60 * 60;
        $hour_sec = $form_state['values'][$input_name_hours] * 60 * 60;
        $total = $day_sec + $hour_sec;
        if ($total > 0) {
          $duedates_enabled = 1;
        }
        variable_set('library_period_for_' . $type . '_' . $clean, $total);
      }
    }
    variable_set('library_' . $type . '_due_dates', $duedates_enabled);
  }
}