/[drupal]/contributions/modules/ezmlm/ezmlm.admin.inc
ViewVC logotype

Diff of /contributions/modules/ezmlm/ezmlm.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3, Sat Apr 5 23:44:39 2008 UTC revision 1.1.2.4, Tue Dec 16 22:10:26 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: ezmlm.admin.inc,v 1.1.2.2 2007/12/29 15:59:07 hutch Exp $  // $Id: ezmlm.admin.inc,v 1.1.2.3 2008/04/05 23:44:39 hutch Exp $
3  // $Name:  $  // $Name: DRUPAL-6--1 $
4  // for drupal 6.x  // for drupal 6.x
5    
6    /**
7     * @file
8     * administration functions for ezmlm
9     */
10    
11  /**  /**
12   * Menu callback; presents the settings form for ezmlm   * Menu callback; presents the settings form for ezmlm
13   */   */
14  function ezmlm_admin_settings() {  function ezmlm_admin_settings() {
 #  $form = array();  
15    // add mailing list    // add mailing list
16    $form['ezmlm_add'] = array(    $form['ezmlm_add'] = array(
17      '#type' => 'fieldset',      '#type' => 'fieldset',
# Line 42  function ezmlm_admin_settings() { Line 44  function ezmlm_admin_settings() {
44      );      );
45    
46      $lists = variable_get('ezmlmmailinglists', '');      $lists = variable_get('ezmlmmailinglists', '');
47      if(is_array($lists) ) {      if (is_array($lists)) {
48          foreach ($lists as $list_text => $list_email) {
49            $list_text2 = preg_replace('/\s/', '~', $list_text);
50            $form['ezmlm_delete'][$list_text2] = array(
51              '#type' => 'checkbox',
52              '#title' => "$list_text ($list_email)" ,
53            );
54          }
55        }
56    
57        // registration
58        $form['ezmlm_reg'] = array(
59          '#type' => 'fieldset',
60          '#title' => t('Registration settings'),
61          '#description' => t('Allow new users to select mailing lists on registration'),
62          '#collapsible' => TRUE,
63        );
64        $form['ezmlm_reg']['ezmlm_register'] = array(
65          '#type' => 'checkbox',
66          '#title' => t('Display lists in registration form'),
67          '#default_value' => variable_get('ezmlm_register', 1),
68        );
69        if (is_array($lists)) {
70          $reglist = variable_get('ezmlm_register_list', '');
71        foreach ($lists as $list_text => $list_email) {        foreach ($lists as $list_text => $list_email) {
72          $form['ezmlm_delete'][$list_text] = array(          $list_text2 = preg_replace('/\s/', '~', $list_text);
73            $form['ezmlm_reg']["reg_$list_text2"] = array(
74            '#type' => 'checkbox',            '#type' => 'checkbox',
75            '#title' => "$list_text ($list_email)" ,            '#title' => "$list_text ($list_email)" ,
76              '#default_value' => ((is_array($reglist) && in_array($list_email, $reglist)) ? 1 : 0),
77          );          );
78        }        }
79      }      }
80        $form['ezmlm_reg']['ezmlm_reg_display'] = array(
81          '#type' => 'radios',
82          '#title' => t('List display type'),
83          '#default_value' => variable_get('ezmlm_reg_display', 'email'),
84          '#options' => array('email' => 'List address', 'name' => 'List name'),
85          '#description' => t('Display %listaddress or %listname on the registration page', array('%listaddress' => 'list address', '%listname' => 'list name')),
86        );
87    }    }
88    
89    $form['ezmlm_misc'] = array(    $form['ezmlm_misc'] = array(
90        '#type' => 'fieldset',        '#type' => 'fieldset',
91        '#title' => t('Various settings'),        '#title' => t('Various settings'),
# Line 65  function ezmlm_admin_settings() { Line 100  function ezmlm_admin_settings() {
100      '#maxlength' => 20,      '#maxlength' => 20,
101      '#required' => FALSE,      '#required' => FALSE,
102    );    );
103      $form['ezmlm_misc']['ezmlm_display'] = array(
104        '#type' => 'radios',
105        '#title' => t('List display type'),
106        '#default_value' => variable_get('ezmlm_display', 'email'),
107        '#options' => array('email' => 'List address', 'name' => 'List name'),
108        '#description' => t('Display %listaddress or %listname on the subscription page', array('%listaddress' => 'list address', '%listname' => 'list name')),
109      );
110    $form['ezmlm_misc']['ezmlm_block_title'] = array(    $form['ezmlm_misc']['ezmlm_block_title'] = array(
111      '#type' => 'textfield',      '#type' => 'textfield',
112      '#title' => t('Block title'),      '#title' => t('Block title'),
# Line 74  function ezmlm_admin_settings() { Line 116  function ezmlm_admin_settings() {
116      '#maxlength' => 20,      '#maxlength' => 20,
117      '#required' => FALSE,      '#required' => FALSE,
118    );    );
119      $form['ezmlm_misc']['ezmlm_block_display'] = array(
120        '#type' => 'radios',
121        '#title' => t('Block display type'),
122        '#default_value' => variable_get('ezmlm_block_display', 'email'),
123        '#options' => array('email' => 'List address', 'name' => 'List name'),
124        '#description' => t('Display %listaddress or %listname on the block subscription page', array('%listaddress' => 'list address', '%listname' => 'list name')),
125      );
126    $form['#validate'][] = 'ezmlm_admin_settings_validate';    $form['#validate'][] = 'ezmlm_admin_settings_validate';
127    $form['#submit'][] = 'ezmlm_admin_settings_submit';    $form['#submit'][] = 'ezmlm_admin_settings_submit';
128    
# Line 85  function ezmlm_admin_settings() { Line 134  function ezmlm_admin_settings() {
134   */   */
135  function ezmlm_admin_settings_validate($form, &$form_state) {  function ezmlm_admin_settings_validate($form, &$form_state) {
136    
137    if (strlen($form_state['values']['ezmlm_add_address'])) {    if (drupal_strlen($form_state['values']['ezmlm_add_address'])) {
138      if ($error = user_validate_mail($form_state['values']['ezmlm_add_address'])) {      if ($error = user_validate_mail($form_state['values']['ezmlm_add_address'])) {
139        form_set_error('ezmlm_add_address', $error);        form_set_error('ezmlm_add_address', $error);
140      }      }
141      if (! strlen($form_state['values']['ezmlm_add_name'])) {      if (! drupal_strlen($form_state['values']['ezmlm_add_name'])) {
142        form_set_error('ezmlm_add_name', t('You must fill in the Name field'));        form_set_error('ezmlm_add_name', t('You must fill in the Name field'));
143      }      }
144    }    }
# Line 113  function ezmlm_admin_settings_submit($fo Line 162  function ezmlm_admin_settings_submit($fo
162      $newlists = array();      $newlists = array();
163      $delct = 0;      $delct = 0;
164      foreach ($lists as $list_text => $list_email) {      foreach ($lists as $list_text => $list_email) {
165          $list_text = preg_replace('/\s/', '~', $list_text);
166        if (isset($form_state['values'][$list_text]) && $form_state['values'][$list_text] == 1) {        if (isset($form_state['values'][$list_text]) && $form_state['values'][$list_text] == 1) {
167          $delct++;          $delct++;
168          continue;     // skip copying this list to the new list          continue;     // skip copying this list to the new list
169        }        }
170        else {        else {
171            $list_text = preg_replace('/~/', ' ', $list_text);
172          $newlists[$list_text] = $list_email;   // copy old list entry to new          $newlists[$list_text] = $list_email;   // copy old list entry to new
173        }        }
174      }      }
# Line 128  function ezmlm_admin_settings_submit($fo Line 179  function ezmlm_admin_settings_submit($fo
179    }    }
180    // add list    // add list
181    $lists = _ezmlm_get_lists();    $lists = _ezmlm_get_lists();
182    if (!is_array($lists) || count($lists) < 1 ) {    $count = _ezmlm_get_count();
183      if (!is_array($lists) || $count < 1 ) {
184      $lists = array();      $lists = array();
185      variable_del('ezmlmmailinglists');      variable_del('ezmlmmailinglists');
186    }    }
187    $list_text = trim($form_state['values']['ezmlm_add_name']);    $list_text = trim($form_state['values']['ezmlm_add_name']);
188    $list_email = trim($form_state['values']['ezmlm_add_address']);    $list_email = trim($form_state['values']['ezmlm_add_address']);
189    if (strlen($list_text) && strlen($list_email) ) {    if (drupal_strlen($list_text) && drupal_strlen($list_email) ) {
190      $lists[$list_text] = $list_email;      $lists[$list_text] = $list_email;
191      variable_set('ezmlmmailinglists', $lists);      variable_set('ezmlmmailinglists', $lists);
192      drupal_set_message( t('The mailing lists have been saved.'));      drupal_set_message( t('The mailing lists have been saved.'));
193    }    }
194      // registration
195      if ($form_state['values']['ezmlm_register']) {
196        variable_set('ezmlm_register', 1);
197      }
198      else {
199        variable_set('ezmlm_register', 0);
200      }
201    
202      if ( variable_get('ezmlm_register', 0) ) {
203        // reg list
204        if (is_array($lists) && $count > 0) {
205          variable_del('ezmlm_register_list');
206          $arr = array();
207          foreach ($lists as $list_text => $list_email) {
208            $list_text = preg_replace('/\s/', '~', $list_text);
209            if ( isset($form_state['values']["reg_$list_text"]) && $form_state['values']["reg_$list_text"] == 1 ) {
210              $list_text = preg_replace('/~/', ' ', $list_text);
211              $arr[$list_text] = $list_email;
212            }
213          }
214          if ( count($arr) ) {
215            variable_set('ezmlm_register_list', $arr);
216          }
217        }
218      }
219      // display
220      if ( $form_state['values']['ezmlm_display'] ) {
221        variable_set('ezmlm_display', $form_state['values']['ezmlm_display']);
222      }
223      if ( $form_state['values']['ezmlm_block_display'] ) {
224        variable_set('ezmlm_block_display', $form_state['values']['ezmlm_block_display']);
225      }
226      if ( $form_state['values']['ezmlm_reg_display'] ) {
227        variable_set('ezmlm_reg_display', $form_state['values']['ezmlm_reg_display']);
228      }
229  }  }

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.2