[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/rules/rules_forms/ -> rules_forms.admin.inc (source)

   1  <?php
   2  // $Id: rules_forms.admin.inc,v 1.1.2.2 2009/08/14 09:52:51 klausi Exp $
   3  
   4  
   5  /**
   6   * @file
   7   * Implements forms events management screen.
   8   */
   9  
  10  /**
  11   * Defines the forms events settings form
  12   */
  13  function rules_forms_admin_events(&$form_state) {
  14    $form = array();
  15    $form['enable_form_activation_message'] = array(
  16      '#type' => 'checkbox',
  17      '#title' => t('Enable event activation messages on forms'),
  18      '#default_value' => isset($_SESSION['rules_forms_message']) ? $_SESSION['rules_forms_message'] : FALSE,
  19      '#description' => t('If checked, there will be a message on each form containing a link to activate events for the form. Only visible for your currently logged in user account.'),
  20    );
  21    $form['enable_form_element_ids'] = array(
  22      '#type' => 'checkbox',
  23      '#title' => t('Display form element IDs'),
  24      '#default_value' => isset($_SESSION['rules_forms_element_ids']) ? $_SESSION['rules_forms_element_ids'] : FALSE,
  25      '#description' => t('If checked, the identifier of every single form element will be displayed on event-activated forms. Only visible for your currently logged in user account.'),
  26    );
  27    $form['settings_submit'] = array(
  28      '#type' => 'submit',
  29      '#value' => t('Save settings'),
  30      '#submit' => array('rules_forms_settings_submit'),
  31    );
  32    $form_events = variable_get('rules_forms_events', array());
  33    if (!empty($form_events)) {
  34      $form['form_events'] = array(
  35        '#type' => 'checkboxes',
  36        '#title' => t('Forms where events are activated'),
  37        '#options' => $form_events,
  38        '#description' => t('Forms that currently invoke events. Select forms to deactivate events on them.'),
  39      );
  40      $form['events_deactivate'] = array(
  41        '#type' => 'submit',
  42        '#value' => t('Deactivate events'),
  43        '#submit' => array('rules_forms_events_deactivate_submit'),
  44      );
  45    }
  46    else {
  47      drupal_set_message('Enable the event activation messages below and go to the form you would like to activate events on.', 'status', FALSE);
  48    }
  49    return $form;
  50  }
  51  
  52  /**
  53   * Submit handler to save settings.
  54   */
  55  function rules_forms_settings_submit($form_id, $form_values) {
  56    $_SESSION['rules_forms_message'] = (bool) $form_values['values']['enable_form_activation_message'];
  57    $_SESSION['rules_forms_element_ids'] = (bool) $form_values['values']['enable_form_element_ids'];
  58    drupal_set_message(t('The settings have been saved.'));
  59  }
  60  
  61  /**
  62   * Submit handler to deactivate form events.
  63   */
  64  function rules_forms_events_deactivate_submit($form_id, $form_values) {
  65    $deactivate_events = array_filter($form_values['values']['form_events']);
  66    $form_events = variable_get('rules_forms_events', array());
  67    foreach ($deactivate_events as $key => $value) {
  68      unset($form_events[$key]);
  69    }
  70    variable_set('rules_forms_events', $form_events);
  71    drupal_set_message(t('The event settings have been saved.'));
  72  }
  73  
  74  /**
  75   * Activation page for a form ID.
  76   */
  77  function rules_forms_activate($form_id_activate) {
  78    $form_events = variable_get('rules_forms_events', array());
  79    if (isset($form_events[$form_id_activate])) {
  80      return t('Events for %form_id have already been activated.', array('%form_id' => $form_id_activate));
  81    }
  82    return drupal_get_form('rules_forms_activate_form', $form_id_activate);
  83  }
  84  
  85  /**
  86   * Confirmation form to activate events on a form.
  87   */
  88  function rules_forms_activate_form(&$form_state, $form_id_activate) {
  89    $default_form_label = drupal_ucfirst(str_replace('_', ' ', $form_id_activate));
  90    $form = array(
  91      'form_id_label' => array(
  92          '#type' => 'textfield',
  93          '#title' => t('Custom form label'),
  94          '#default_value' => $default_form_label,
  95          '#required' => TRUE,
  96          '#description' => t('Enter a custom label to better recognize the form in the administration user interface.'),
  97      ),
  98    );
  99    $form_state['form_id_activate'] = $form_id_activate;
 100  
 101    $path = array();
 102    $path['path'] = isset($_GET['destination']) ? $_GET['destination'] : RULES_ADMIN_FORMS_PATH;
 103  
 104    $title = t('Are you sure you want to activate events for %form?', array('%form' => $form_id_activate));
 105    $msg = t('Once the activation is confirmed, events on this form can be used to trigger rules.');
 106    return confirm_form($form, $title, $path, $msg, t('Activate'), t('Cancel'));
 107  }
 108  
 109  /**
 110   * Submit handler for activation of a form.
 111   */
 112  function rules_forms_activate_form_submit($form, &$form_state) {
 113    $form_events = variable_get('rules_forms_events', array());
 114    $form_events[$form_state['form_id_activate']] = $form_state['values']['form_id_label'];
 115    variable_set('rules_forms_events', $form_events);
 116    drupal_set_message(t("%form has been activated.", array('%form' => $form_state['form_id_activate'])));
 117    $form_state['redirect'] = RULES_ADMIN_FORMS_PATH;
 118  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7