You are here

function rules_scheduler_form in Rules 6

Same name and namespace in other branches
  1. 7.2 rules_scheduler/rules_scheduler.admin.inc \rules_scheduler_form()

Builds the scheduling page with a form for manual scheduling and deletion of tasks.

1 string reference to 'rules_scheduler_form'
rules_scheduler_scheduling in rules_scheduler/rules_scheduler.admin.inc
@file Admin form for scheduling

File

rules_scheduler/rules_scheduler.admin.inc, line 15
Admin form for scheduling

Code

function rules_scheduler_form($form_state) {
  $form = array();

  // Display view for all scheduled tasks
  if (module_exists('views')) {
    $task_list = views_embed_view('rules_scheduler');
  }
  else {
    $task_list = t('To display scheduled tasks you have to install the <a href="http://drupal.org/project/views">Views</a> module.');
  }
  $form['task_view'] = array(
    '#type' => 'markup',
    '#value' => $task_list,
  );

  // form fieldset for manual scheduling
  $form['manual_scheduling'] = array(
    '#type' => 'fieldset',
    '#title' => t('Manual scheduling of rule sets without arguments'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $rulesets = rules_scheduler_rulesets_without_arguments();
  if (empty($rulesets)) {
    $form['manual_scheduling']['#description'] = t('There are currently no rule sets without arguments available.');
  }
  else {
    $form['manual_scheduling']['ruleset_manual'] = array(
      '#title' => t('Rule set name'),
      '#type' => 'select',
      '#options' => $rulesets,
      '#multiple' => FALSE,
    );
    $form['manual_scheduling']['task_identifier'] = array(
      '#title' => t('Identifier'),
      '#type' => 'textfield',
      '#description' => t('User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced.'),
    );
    $rules_date = new rules_data_type_date();
    $form['manual_scheduling']['date'] = $rules_date
      ->get_default_input_form(array(
      'label' => 'Execution date',
    ), NULL, $form_state);
    $form['manual_scheduling']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Schedule'),
      '#submit' => array(
        'rules_scheduler_manual_submit',
      ),
      '#validate' => array(
        'rules_scheduler_manual_validate',
      ),
    );
  }

  // form fieldset for deleting by rule set name
  $result = db_query("SELECT DISTINCT set_name FROM {rules_scheduler}");
  $ruleset_names = array();
  while ($name = db_fetch_array($result)) {
    $ruleset_names[$name['set_name']] = $name['set_name'];
  }
  $form['delete_by_ruleset_name'] = array(
    '#type' => 'fieldset',
    '#title' => t('Delete tasks by rule set name'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (empty($ruleset_names)) {
    $form['delete_by_ruleset_name']['#description'] = t('There are currently no scheduled tasks available to delete.');
  }
  else {
    $form['delete_by_ruleset_name']['ruleset_delete'] = array(
      '#title' => t('Rule set name'),
      '#type' => 'select',
      '#options' => $ruleset_names,
      '#multiple' => FALSE,
    );
    $form['delete_by_ruleset_name']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'rules_scheduler_delete_submit',
      ),
    );
  }
  return $form;
}