[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project_issue/includes/ -> admin.settings.inc (source)

   1  <?php
   2  // $Id: admin.settings.inc,v 1.2 2009/04/04 06:30:21 dww Exp $
   3  
   4  /**
   5   * @file
   6   * Code for the admin settings form at project/project-issue-settings.
   7   */
   8  
   9  /**
  10   * Form builder for the main settings form.
  11   */
  12  function project_issue_settings_form(&$form_state) {
  13    $form['project_directory_issues']  = array(
  14      '#type' => 'textfield',
  15      '#title' => t('Issue directory'),
  16      '#default_value' => variable_get('project_directory_issues', 'issues'),
  17      '#size' => 30,
  18      '#maxlength' => 255,
  19      '#description' => t("Subdirectory in the directory '%dir' where attachments to issues will be stored.", array('%dir' => variable_get('file_directory_path', 'files') . '/')),
  20      '#after_build' => array('project_issue_check_directory'),
  21    );
  22  
  23    $form['project_issue_show_comment_signatures'] = array(
  24      '#type' => 'checkbox',
  25      '#title' => t('Display user signatures on issue followups'),
  26      '#default_value' => variable_get('project_issue_show_comment_signatures', 0),
  27      '#description' => t('If selected, user signatures will be appended to the display of issue followups.'),
  28    );
  29  
  30    $form['project_issue_reply_to'] = array(
  31      '#type' => 'textfield',
  32      '#title' => t('Reply-to address on e-mail notifications'),
  33      '#default_value' => variable_get('project_issue_reply_to', variable_get('site_mail', ini_get('sendmail_from'))),
  34      '#description' => t('All issue e-mails sent via subscriptions will appear from this e-mail address. You can use %project as a placeholder which will be replaced with the %short_project_name setting for the issue\'s current project.', array('%project' => '%project', '%short_project_name' => t('Short project name'))),
  35    );
  36  
  37    // Determine the auto followup username from the auto followup setting.
  38    $followup_username = '';
  39    $anon = variable_get('anonymous', t('Anonymous'));
  40    if ($followup_user_object = _project_issue_followup_get_user()) {
  41      $followup_username = $followup_user_object->name;
  42    }
  43  
  44    $form['project_issue_followup_user'] = array(
  45      '#title' => t('Auto-followup user'),
  46      '#type' => 'textfield',
  47      '#default_value' => $followup_username,
  48      '#maxlength' => 60,
  49      '#description' => t('Enter the name of the user which will create automatic followups to issues -- leave empty to disable auto-followup or set to %anon to use the anonymous user.', array('%anon' => $anon)),
  50      '#element_validate' => array('project_issue_validate_followup_user'),
  51      '#autocomplete_path' => 'user/autocomplete',
  52    );
  53  
  54    $form['project_issue_auto_close_days'] = array(
  55      '#title' => t('Auto-close days'),
  56      '#type' => 'textfield',
  57      '#default_value' => (int) variable_get('project_issue_auto_close_days', PROJECT_ISSUE_AUTO_CLOSE_DAYS),
  58      '#size' => 4,
  59      '#maxlength' => 10,
  60      '#description' => t('Issues being in "fixed" state for the specified number of days will be closed by the followup user specified above. For example, if this is 14, and an issue is set to fixed on January 1, then it will be closed on January 15.'),
  61    );
  62    
  63    $defaults = array(t('Code'), t('Documentation'), t('Miscellaneous'), t('User interface'));
  64    $components = variable_get('project_issue_default_components', implode("\n", $defaults));
  65  
  66    $form['project_issue_default_components'] = array(
  67      '#type' => 'textarea',
  68      '#title' => t('Default components'),
  69      '#default_value' => $components,
  70      '#cols' => 20,
  71      '#rows' => 6,
  72      '#required' => TRUE,
  73      '#description' => t("Enter the default list of components that new projects will have.  The project owner will be able to change this list on the project's edit/issues page."),
  74      '#element_validate' => array('project_issue_validate_default_components'),
  75    );
  76  
  77    if (module_exists('mailhandler')) {
  78      // TODO: move this stuff to mailhandler.module ?
  79      $items = array(t('<none>'));
  80      $result = db_query('SELECT mail FROM {mailhandler} ORDER BY mail');
  81      while ($mail = db_result($result, $i++)) {
  82        $items[$mail] = $mail;
  83      }
  84  
  85      // Switch reply-to to a select box instead.
  86      $form['project_issue_reply_to']['#type'] = 'select';
  87      $form['project_issue_reply_to']['#options'] = $items;
  88    }
  89  
  90    $form['project_issue_autocomplete'] = array(
  91      '#type' => 'radios',
  92      '#title' => t('Project selection widget'),
  93      '#default_value' => variable_get('project_issue_autocomplete', 0),
  94      '#options' => array(t('Select Menu'), t('Autocomplete')),
  95    );
  96  
  97    $form['project_issue_site_help'] = array(
  98      '#title' => t('Site-wide help text for new issues'),
  99      '#type' => 'textarea',
 100      '#default_value' => variable_get('project_issue_site_help', ''),
 101      '#cols' => 20,
 102      '#rows' => 5,
 103      '#description' => t('Optionally enter site-wide help text that will be displayed whenever a user tries to create a new issue. Please note that there is no automatic formatting on this text, but you can use regular HTML tags as necessary (for example %p, %ul, and so on).', array('%p' => '<p>', '%ul' => '<ul>')),
 104    );
 105  
 106    return system_settings_form($form);
 107  }
 108  
 109  function project_issue_validate_default_components($form, &$form_state) {
 110    // If the list of default components has changed (other than whitespace),
 111    // warn the admin that the change will only affect new projects.
 112    $value = trim($form['#value']);
 113  
 114    // If it's empty and required, the user will get a message that the
 115    // field is required, so don't bother warning them that the component
 116    // list has changed.
 117    if ($form['#required'] && !empty($value)) {
 118      $old = explode("\n", str_replace("\r", '', $form['#default_value']));
 119      $new = explode("\n", str_replace("\r", '', $value));
 120  
 121      // Trim whitespace on each entry in the array.
 122      array_walk($old, 'project_issue_trim');
 123      array_walk($new, 'project_issue_trim');
 124      // Filter out blank lines and reindex the arrays from 0.
 125      $old = array_values(array_filter($old));
 126      $new = array_values(array_filter($new));
 127  
 128      if ($old != $new) {
 129        drupal_set_message(t("The list of default components for new projects has changed. This will not affect existing projects."), 'warning');
 130      }
 131      // Regardless, now that we've trimmed everything, save those values.
 132      $form_state['values']['project_issue_default_components'] = implode("\n", $new);
 133    }
 134  }
 135  
 136  /**
 137   * Validates that the followup user exists, and has sufficient permissions
 138   * to follow up on issues.
 139   */
 140  function project_issue_validate_followup_user($form, &$form_state) {
 141    $name = $form['#value'];
 142    if ($name !== '') {
 143      $anon = variable_get('anonymous', t('Anonymous'));
 144      // Make this check case-insensitive to allow the admin some data entry leeway.
 145      $is_anon = drupal_strtolower($name) == drupal_strtolower($anon);
 146      // Load the user. (don't see a constant for uid 0... )
 147      $account = $is_anon ? user_load(array('uid' => 0)) : user_load(array('name' => $name));
 148      if ($account) {
 149        if (user_access('access project issues', $account)) {
 150          // Transform the username into the more stable user ID.
 151          $form_state['values']['project_issue_followup_user'] = $account->uid;
 152        }
 153        else {
 154          form_error($form, t('%name does not have sufficient permissions to follow up on issues.', array('%name' => $is_anon ? $anon : $name)));
 155        }
 156      }
 157      else {
 158        form_error($form, t('%name is not a valid user.', array('%name' => $name)));
 159      }
 160    }
 161  }
 162  
 163  /**
 164   * Check whether the intended issues directory exists and ensure it is writable.
 165   */
 166  function project_issue_check_directory($form_element) {
 167    $directory = file_create_path($form_element['#value']);
 168    file_check_directory($directory, FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
 169    return $form_element;
 170  }
 171  


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