[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7