You are here

function privatemsg_devel_generate_form in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg.devel_generate.inc \privatemsg_devel_generate_form()

Form Builder; Integrates with Devel Generate.

See also

privatemsg_devel_generate_form_validate()

privatemsg_devel_generate_form_submit()

1 string reference to 'privatemsg_devel_generate_form'
privatemsg_menu in ./privatemsg.module
Implements hook_menu().

File

./privatemsg.devel_generate.inc, line 9

Code

function privatemsg_devel_generate_form() {

  // Check if authenticated users can write new messages. In D6, there
  // is no user_role_permissions() function, so have to use our own.
  // @todo: use user_role_permissions() in Drupal 7.
  $perm = 'write privatemsg';
  $roles = array(
    2 => 'authenticated user',
  );

  // Invoke $reset as changing permissions does not
  // reset our custom function cache in Drupal 6.
  if (!privatemsg_user_role_permissions($perm, $roles, TRUE)) {
    drupal_set_message(t('Authenticated users do not have %perm permission. This function will not function correctly. <a href="@url">Permissions page</a>.', array(
      '%perm' => $perm,
      '@url' => url('admin/user/permissions', array(
        'fragment' => 'module-privatemsg',
        'query' => array(
          'destination' => 'admin/generate/privatemsg',
        ),
      )),
    )), 'warning');
  }
  $options = array();
  for ($i = 1; $i <= 10; $i++) {
    $options[$i] = $i;
  }
  $form['kill_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Delete all messages</strong> before generating new messages.'),
    '#default_value' => FALSE,
  );
  $form['kill_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('<strong>Delete all messages</strong> before generating new messages.'),
    '#default_value' => FALSE,
  );
  $form['num_threads'] = array(
    '#type' => 'textfield',
    '#title' => t('How many threads would you like to generate?'),
    '#default_value' => 10,
    '#size' => 10,
  );
  $form['max_thread_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Max thread length?'),
    '#default_value' => 5,
    '#size' => 10,
  );
  $form['recipients'] = array(
    '#type' => 'fieldset',
    '#title' => t('Recipients'),
    '#description' => t('A random number of recipients will be generated for each message.'),
  );
  $form['recipients']['min_recipients'] = array(
    '#type' => 'select',
    '#title' => t('Minimum number of recipients for each message'),
    '#default_value' => 1,
    '#options' => $options,
  );
  $form['recipients']['max_recipients'] = array(
    '#type' => 'select',
    '#title' => t('Maximum number of recipients for each message'),
    '#default_value' => 3,
    '#options' => $options,
  );
  $options = array(
    1 => t('Now'),
  );
  foreach (array(
    3600,
    86400,
    604800,
    2592000,
    31536000,
  ) as $interval) {
    $options[$interval] = format_interval($interval, 1) . ' ' . t('ago');
  }
  $form['time_range'] = array(
    '#type' => 'select',
    '#title' => t('How far back in time should the messages be dated?'),
    '#description' => t('Message creation dates will be distributed randomly from the current time, back to the selected time.'),
    '#options' => $options,
    '#default_value' => 604800,
  );
  $form['subject_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Max word length of subjects'),
    '#default_value' => 8,
    '#size' => 10,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Generate'),
  );
  $form['#redirect'] = FALSE;
  return $form;
}