[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/modules/contact/ -> contact.admin.inc (source)

   1  <?php
   2  // $Id: contact.admin.inc,v 1.3.2.1 2009/12/16 20:47:10 goba Exp $
   3  
   4  /**
   5   * @file
   6   * Admin page callbacks for the contact module.
   7   */
   8  
   9  /**
  10   * Categories/list tab.
  11   */
  12  function contact_admin_categories() {
  13    $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
  14    $rows = array();
  15    while ($category = db_fetch_object($result)) {
  16      $rows[] = array(check_plain($category->category), check_plain($category->recipients), ($category->selected ? t('Yes') : t('No')), l(t('edit'), 'admin/build/contact/edit/'. $category->cid), l(t('delete'), 'admin/build/contact/delete/'. $category->cid));
  17    }
  18    $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));
  19  
  20    return theme('table', $header, $rows);
  21  }
  22  
  23  /**
  24   * Category edit page.
  25   */
  26  function contact_admin_edit($form_state = array(), $op, $contact = NULL) {
  27  
  28    if (empty($contact) || $op == 'add') {
  29      $contact = array(
  30        'category' => '',
  31        'recipients' => '',
  32        'reply' => '',
  33        'weight' => 0,
  34        'selected' => 0,
  35        'cid' => NULL,
  36      );
  37    }
  38    $form['contact_op'] = array('#type' => 'value', '#value' => $op);
  39    $form['category'] = array('#type' => 'textfield',
  40      '#title' => t('Category'),
  41      '#maxlength' => 255,
  42      '#default_value' => $contact['category'],
  43      '#description' => t("Example: 'website feedback' or 'product information'."),
  44      '#required' => TRUE,
  45    );
  46    $form['recipients'] = array('#type' => 'textarea',
  47      '#title' => t('Recipients'),
  48      '#default_value' => $contact['recipients'],
  49      '#description' => t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com'. To specify multiple recipients, separate each e-mail address with a comma."),
  50      '#required' => TRUE,
  51    );
  52    $form['reply'] = array('#type' => 'textarea',
  53      '#title' => t('Auto-reply'),
  54      '#default_value' => $contact['reply'],
  55      '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
  56    );
  57    $form['weight'] = array('#type' => 'weight',
  58      '#title' => t('Weight'),
  59      '#default_value' => $contact['weight'],
  60      '#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),
  61    );
  62    $form['selected'] = array('#type' => 'select',
  63      '#title' => t('Selected'),
  64      '#options' => array('0' => t('No'), '1' => t('Yes')),
  65      '#default_value' => $contact['selected'],
  66      '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
  67    );
  68    $form['cid'] = array('#type' => 'value',
  69      '#value' => $contact['cid'],
  70    );
  71    $form['submit'] = array('#type' => 'submit',
  72      '#value' => t('Save'),
  73    );
  74  
  75    return $form;
  76  }
  77  
  78  /**
  79   * Validate the contact category edit page form submission.
  80   */
  81  function contact_admin_edit_validate($form, &$form_state) {
  82    if (empty($form_state['values']['category'])) {
  83      form_set_error('category', t('You must enter a category.'));
  84    }
  85    if (empty($form_state['values']['recipients'])) {
  86      form_set_error('recipients', t('You must enter one or more recipients.'));
  87    }
  88    else {
  89      $recipients = explode(',', $form_state['values']['recipients']);
  90      foreach ($recipients as $recipient) {
  91        if (!valid_email_address(trim($recipient))) {
  92          form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
  93        }
  94      }
  95    }
  96  }
  97  
  98  /**
  99   * Process the contact category edit page form submission.
 100   */
 101  function contact_admin_edit_submit($form, &$form_state) {
 102    if ($form_state['values']['selected']) {
 103      // Unselect all other contact categories.
 104      db_query('UPDATE {contact} SET selected = 0');
 105    }
 106    $recipients = explode(',', $form_state['values']['recipients']);
 107    foreach ($recipients as $key => $recipient) {
 108      // E-mail address validation has already been done in _validate.
 109      $recipients[$key] = trim($recipient);
 110    }
 111    $form_state['values']['recipients'] = implode(',', $recipients);
 112    if (empty($form_state['values']['cid']) || $form_state['values']['contact_op'] == 'add') {
 113      drupal_write_record('contact', $form_state['values']);
 114      drupal_set_message(t('Category %category has been added.', array('%category' => $form_state['values']['category'])));
 115      watchdog('mail', 'Contact form: category %category added.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
 116  
 117    }
 118    else {
 119      drupal_write_record('contact', $form_state['values'], 'cid');
 120      drupal_set_message(t('Category %category has been updated.', array('%category' => $form_state['values']['category'])));
 121      watchdog('mail', 'Contact form: category %category updated.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
 122    }
 123  
 124    $form_state['redirect'] = 'admin/build/contact';
 125    return;
 126  }
 127  
 128  /**
 129   * Category delete page.
 130   */
 131  function contact_admin_delete(&$form_state, $contact) {
 132  
 133    $form['contact'] = array(
 134      '#type' => 'value',
 135      '#value' => $contact,
 136    );
 137  
 138    return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $contact['category'])), 'admin/build/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
 139  }
 140  
 141  /**
 142   * Process category delete form submission.
 143   */
 144  function contact_admin_delete_submit($form, &$form_state) {
 145    $contact = $form_state['values']['contact'];
 146    db_query("DELETE FROM {contact} WHERE cid = %d", $contact['cid']);
 147    drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category'])));
 148    watchdog('mail', 'Contact form: category %category deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);
 149  
 150    $form_state['redirect'] = 'admin/build/contact';
 151    return;
 152  }
 153  
 154  function contact_admin_settings() {
 155    $form['contact_form_information'] = array('#type' => 'textarea',
 156      '#title' => t('Additional information'),
 157      '#default_value' => variable_get('contact_form_information', t('You can leave a message using the contact form below.')),
 158      '#description' => t('Information to show on the <a href="@form">contact page</a>. Can be anything from submission guidelines to your postal address or telephone number.', array('@form' => url('contact'))),
 159    );
 160    $form['contact_hourly_threshold'] = array('#type' => 'select',
 161      '#title' => t('Hourly threshold'),
 162      '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
 163      '#default_value' => variable_get('contact_hourly_threshold', 3),
 164      '#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
 165    );
 166    $form['contact_default_status'] = array(
 167      '#type' => 'checkbox',
 168      '#title' => t('Enable personal contact form by default'),
 169      '#default_value' => variable_get('contact_default_status', 1),
 170      '#description' => t('Default status of the personal contact form for new users.'),
 171    );
 172    return system_settings_form($form);
 173  }


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