| 1 |
<?php
|
| 2 |
// $Id: admin.settings.inc,v 1.6 2009/01/24 04:24:25 dww Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Code required for the signup settings page (admin/settings/signup).
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Form builder for the settings page under admin/setttings/signup
|
| 12 |
*/
|
| 13 |
function signup_settings_form() {
|
| 14 |
module_load_include('inc', 'signup', 'includes/node_settings');
|
| 15 |
if (signup_site_has_dates()) {
|
| 16 |
$form['signup_close_early'] = array(
|
| 17 |
'#title' => t('Close x hours before'),
|
| 18 |
'#type' => 'textfield',
|
| 19 |
'#default_value' => variable_get('signup_close_early', 1),
|
| 20 |
'#size' => 5, '#maxlength' => 10,
|
| 21 |
'#description' => t('The number of hours before the event which signups will no longer be allowed. Use negative numbers to close signups after the event start (example: -12).'),
|
| 22 |
);
|
| 23 |
};
|
| 24 |
$form['node_defaults'] = array(
|
| 25 |
'#type' => 'fieldset',
|
| 26 |
'#title' => t('Default signup information'),
|
| 27 |
'#description' => t('New signup-enabled nodes will start with these settings.'),
|
| 28 |
'#collapsible' => TRUE,
|
| 29 |
);
|
| 30 |
$form['node_defaults']['signup_node_settings_form'] = signup_node_settings_form(array(), NULL, NULL, signup_site_has_dates());
|
| 31 |
|
| 32 |
$form['adv_settings'] = array(
|
| 33 |
'#type' => 'fieldset',
|
| 34 |
'#title' => t('Advanced settings'),
|
| 35 |
'#collapsible' => TRUE,
|
| 36 |
'#collapsed' => TRUE,
|
| 37 |
);
|
| 38 |
$form['adv_settings']['signup_date_format'] = array(
|
| 39 |
'#title' => t('Format string for displaying signup-related dates'),
|
| 40 |
'#type' => 'select',
|
| 41 |
'#options' => array(
|
| 42 |
'small' => t('Small'),
|
| 43 |
'medium' => t('Medium'),
|
| 44 |
'large' => t('Large'),
|
| 45 |
),
|
| 46 |
'#default_value' => variable_get('signup_date_format', 'small'),
|
| 47 |
'#description' => t('Whenever this module needs to print a date (both in the administrative interface, and in the various e-mail messages it can send), this setting controls which date format string to use. The format strings are defined at the <a href="!settings_url">Date and time settings page</a>.', array('!settings_url' => url('admin/settings/date-time'))),
|
| 48 |
);
|
| 49 |
if (!module_exists('views')) {
|
| 50 |
$form['adv_settings']['signup_no_views_user_info'] = array(
|
| 51 |
'#title' => t('Display signup information on user profile pages'),
|
| 52 |
'#type' => 'checkbox',
|
| 53 |
'#default_value' => variable_get('signup_no_views_user_info', TRUE),
|
| 54 |
);
|
| 55 |
}
|
| 56 |
|
| 57 |
$form['adv_settings']['signup_form_location'] = array(
|
| 58 |
'#title' => t('Location of the signup form'),
|
| 59 |
'#type' => 'radios',
|
| 60 |
'#options' => array(
|
| 61 |
'node' => t('Included on each node'),
|
| 62 |
'tab' => t('Under the %signups tab', array('%signups' => t('Signups'))),
|
| 63 |
'none' => t('Do not display signup form'),
|
| 64 |
),
|
| 65 |
'#default_value' => variable_get('signup_form_location', 'node'),
|
| 66 |
'#description' => t('On every signup-enabled node, users with permission to
|
| 67 |
sign up can be presented with a form. This setting controls where this form should be displayed: either directly on the node itself, on a separate tab, or not at all.'),
|
| 68 |
'#prefix' => '<div class="signup-form-location-radios">',
|
| 69 |
'#suffix' => '</div>',
|
| 70 |
);
|
| 71 |
|
| 72 |
// The rest of the advanced settings are conditional on if/where the signup
|
| 73 |
// form is being displayed. We use jQuery to hide settings when they're not
|
| 74 |
// relevant.
|
| 75 |
$signup_path = drupal_get_path('module', 'signup');
|
| 76 |
drupal_add_js($signup_path .'/js/admin.settings.js');
|
| 77 |
|
| 78 |
// For each setting that should be hidden, system.css will hide all the
|
| 79 |
// settings on page load if JS is enabled.
|
| 80 |
$class = 'signup-fieldset_collapsed-setting';
|
| 81 |
if (variable_get('signup_form_location', 'node') != 'node') {
|
| 82 |
$class .= ' js-hide';
|
| 83 |
}
|
| 84 |
$form['adv_settings']['signup_fieldset_collapsed'] = array(
|
| 85 |
'#title' => t('Default fieldset behavior for per-node signup form'),
|
| 86 |
'#type' => 'radios',
|
| 87 |
'#options' => array(1 => t('Collapsed'), 0 => t('Expanded')),
|
| 88 |
'#default_value' => variable_get('signup_fieldset_collapsed', 1),
|
| 89 |
'#description' => t('If the signup form is included on each node, the signup form will be encapsulated in a collapsible fieldset. This setting controls if that fieldset is expanded or collapsed by default.'),
|
| 90 |
'#prefix' => '<div class="'. $class .'">',
|
| 91 |
'#suffix' => '</div>',
|
| 92 |
);
|
| 93 |
|
| 94 |
$list_options = array();
|
| 95 |
$list_options['signup'] = t('Use the signup-provided listing on each node');
|
| 96 |
$list_options['signup-tab'] = t('Use the signup-provided listing under the %signups tab', array('%signups' => t('Signups')));
|
| 97 |
$views_help_text = '';
|
| 98 |
if (module_exists('views')) {
|
| 99 |
$list_options['embed-view'] = t('Embed a view on each node');
|
| 100 |
$list_options['embed-view-tab'] = t('Embed a view under the %signups tab', array('%signups' => t('Signups')));
|
| 101 |
$views_help_text = t('If you choose to embed a view, you will be able to select which view you want to use below. The view you select will have a single argument passed in, the node id (nid) of the signup-enabled node being viewed. You can also use views to display this listing on its own tab or in a block if you disable this setting.');
|
| 102 |
}
|
| 103 |
else {
|
| 104 |
$views_help_text = t('If you enable the !views_url, you will be able to embed a view directly onto the page for this listing.', array('!views_url' => l(t('Views module'), 'http://drupal.org/project/views', array('absolute' => TRUE))));
|
| 105 |
}
|
| 106 |
$list_options['none'] = t('Do not display a listing at all');
|
| 107 |
|
| 108 |
$form['adv_settings']['signup_display_signup_user_list'] = array(
|
| 109 |
'#title' => t('How to display the list of signed-up users'),
|
| 110 |
'#type' => 'radios',
|
| 111 |
'#options' => $list_options,
|
| 112 |
'#default_value' => variable_get('signup_display_signup_user_list', 'signup'),
|
| 113 |
'#description' => t('Users with the %view_signups permission can be presented with a list of all users who have signed up. This setting controls if, how, and where that list should be generated. !views_help_text', array('%view_signups' => t('view all signups'), '!views_help_text' => $views_help_text)),
|
| 114 |
'#prefix' => '<div class="signup-display-signup-user-list-setting">',
|
| 115 |
'#suffix' => '</div>',
|
| 116 |
'#weight' => 1,
|
| 117 |
);
|
| 118 |
|
| 119 |
$admin_options = array();
|
| 120 |
$admin_options['signup'] = t('Use the signup-provided listing');
|
| 121 |
if (module_exists('views')) {
|
| 122 |
$admin_options['embed-view'] = t('Embed a view');
|
| 123 |
}
|
| 124 |
$admin_options['none'] = t('Do not display a listing at all');
|
| 125 |
$form['adv_settings']['signup_display_signup_admin_list'] = array(
|
| 126 |
'#title' => t('How to display the administrative list of signed-up users'),
|
| 127 |
'#type' => 'radios',
|
| 128 |
'#options' => $admin_options,
|
| 129 |
'#default_value' => variable_get('signup_display_signup_admin_list', 'signup'),
|
| 130 |
'#description' => t('Users with permission to administer signups for a given node will see a list of users of all users who have signed up. This setting controls if and how that list should be generated. !views_help_text', array('%view_signups' => t('view all signups'), '!views_help_text' => $views_help_text)),
|
| 131 |
'#prefix' => '<div class="signup-display-signup-admin-list-setting">',
|
| 132 |
'#suffix' => '</div>',
|
| 133 |
'#weight' => 5,
|
| 134 |
);
|
| 135 |
|
| 136 |
if (module_exists('views')) {
|
| 137 |
$class = 'signup-user-list-view-settings';
|
| 138 |
$user_list = variable_get('signup_display_signup_user_list', 'signup');
|
| 139 |
if ($user_list != 'embed-view' && $user_list != 'embed-view-tab') {
|
| 140 |
$class .= ' js-hide';
|
| 141 |
}
|
| 142 |
$form['adv_settings']['view_settings'] = array(
|
| 143 |
'#prefix' => '<div class="'. $class .'">',
|
| 144 |
'#suffix' => '</div>',
|
| 145 |
'#weight' => 2,
|
| 146 |
);
|
| 147 |
|
| 148 |
$views = views_get_all_views();
|
| 149 |
foreach ($views as $view) {
|
| 150 |
foreach (array_keys($view->display) as $display_id) {
|
| 151 |
if ($display_id != 'default' || 1) {
|
| 152 |
$key = $view->name .':'. $display_id;
|
| 153 |
$view_options[$key] = theme('signup_settings_view_label', $view, $display_id);
|
| 154 |
}
|
| 155 |
}
|
| 156 |
}
|
| 157 |
$form['adv_settings']['view_settings']['signup_user_list_view'] = array(
|
| 158 |
'#title' => t('View to embed for the signup user list'),
|
| 159 |
'#type' => 'select',
|
| 160 |
'#options' => $view_options,
|
| 161 |
'#default_value' => variable_get('signup_user_list_view', 'signup_user_list:default'),
|
| 162 |
'#description' => t("If the signup user list is being generated by embedding a view, this selects which view should be used. The view's name, description, and display(s) it defines are listed."),
|
| 163 |
);
|
| 164 |
|
| 165 |
$class = 'signup-admin-list-view-settings';
|
| 166 |
if (variable_get('signup_display_signup_admin_list', 'signup') != 'embed-view') {
|
| 167 |
$class .= ' js-hide';
|
| 168 |
}
|
| 169 |
$form['adv_settings']['admin_view_settings'] = array(
|
| 170 |
'#prefix' => '<div class="'. $class .'">',
|
| 171 |
'#suffix' => '</div>',
|
| 172 |
'#weight' => 6,
|
| 173 |
);
|
| 174 |
|
| 175 |
// $view_options is still initialized from above.
|
| 176 |
$form['adv_settings']['admin_view_settings']['signup_admin_list_view'] = array(
|
| 177 |
'#title' => t('View to embed for the signup administrative list'),
|
| 178 |
'#type' => 'select',
|
| 179 |
'#options' => $view_options,
|
| 180 |
'#default_value' => _signup_get_admin_list_view(),
|
| 181 |
'#description' => t("If the administer signups user list is being generated by embedding a view, this selects which view should be used. The view's name, description, and display(s) it defines are listed."),
|
| 182 |
);
|
| 183 |
}
|
| 184 |
|
| 185 |
// Use our own submit handler, so we can do some processing before
|
| 186 |
// we hand control to system_settings_form_submit.
|
| 187 |
$form = system_settings_form($form);
|
| 188 |
unset($form['#submit']);
|
| 189 |
$form['#submit'][] = 'signup_settings_form_submit';
|
| 190 |
return $form;
|
| 191 |
}
|
| 192 |
|
| 193 |
/**
|
| 194 |
* Submits the signup settings form
|
| 195 |
*
|
| 196 |
* @param $form_id The ID of the form being submitted.
|
| 197 |
* @param $form_values The constructed form values array of the submitted form.
|
| 198 |
*/
|
| 199 |
function signup_settings_form_submit($form, &$form_state) {
|
| 200 |
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
|
| 201 |
if ($op == t('Save configuration') && db_result(db_query('SELECT COUNT(*) FROM {signup} WHERE nid = 0'))) {
|
| 202 |
$values = array(
|
| 203 |
$form_state['values']['signup_forwarding_email'],
|
| 204 |
$form_state['values']['signup_send_confirmation'],
|
| 205 |
$form_state['values']['signup_confirmation_email'],
|
| 206 |
$form_state['values']['signup_close_signup_limit'],
|
| 207 |
);
|
| 208 |
$values[] = isset($form_state['values']['signup_send_reminder']) ? $form_state['values']['signup_send_reminder'] : 0;
|
| 209 |
$values[] = isset($form_state['values']['signup_reminder_days_before']) ? $form_state['values']['signup_reminder_days_before'] : 0;
|
| 210 |
$values[] = isset($form_state['values']['signup_reminder_email']) ? $form_state['values']['signup_reminder_email'] : '';
|
| 211 |
$values[] = 0; // "nid" of the row in {signup} for the global settings.
|
| 212 |
db_query("UPDATE {signup} SET forwarding_email = '%s', send_confirmation = %d, confirmation_email = '%s', close_signup_limit = %d, send_reminder = %d, reminder_days_before = %d, reminder_email = '%s' WHERE nid = %d", $values);
|
| 213 |
}
|
| 214 |
else {
|
| 215 |
module_load_include('install', 'signup', 'signup');
|
| 216 |
db_query("DELETE FROM {signup} WHERE nid = 0");
|
| 217 |
signup_insert_default_signup_info();
|
| 218 |
}
|
| 219 |
|
| 220 |
// Now, remove all the settings we just processed from our copy of
|
| 221 |
// $form_state['values'], so system_settings_form_submit() doesn't see them.
|
| 222 |
$settings = array(
|
| 223 |
'signup_forwarding_email',
|
| 224 |
'signup_send_confirmation',
|
| 225 |
'signup_confirmation_email',
|
| 226 |
'signup_send_reminder',
|
| 227 |
'signup_reminder_days_before',
|
| 228 |
'signup_reminder_email',
|
| 229 |
'signup_close_signup_limit',
|
| 230 |
);
|
| 231 |
foreach ($settings as $setting) {
|
| 232 |
unset($form_state['values'][$setting]);
|
| 233 |
}
|
| 234 |
// Remove the hidden element from signup_node_settings_form(), too.
|
| 235 |
unset($form_state['values']['signup']);
|
| 236 |
|
| 237 |
// Since the advanced settings can mess with the menu, rebuild that.
|
| 238 |
menu_rebuild();
|
| 239 |
|
| 240 |
// Let system_settings_form_submit() do its magic with everything else.
|
| 241 |
system_settings_form_submit($form, $form_state);
|
| 242 |
}
|
| 243 |
|
| 244 |
/**
|
| 245 |
* Generates the appropriate selector label for a given view.
|
| 246 |
*
|
| 247 |
* @param $view
|
| 248 |
* An object containing data about the view to generate a label for.
|
| 249 |
* Contains at least a name (string), description (string), page
|
| 250 |
* (bool), and block (bool) fields.
|
| 251 |
*
|
| 252 |
* @return
|
| 253 |
* The plain text (no HTML allowed) to include as the label for this view in
|
| 254 |
* the drop-down selector for which view to embed on the site-wide signup
|
| 255 |
* settings page.
|
| 256 |
*
|
| 257 |
* @see signup_settings_form()
|
| 258 |
*/
|
| 259 |
function theme_signup_settings_view_label($view, $display_id) {
|
| 260 |
$display_title = check_plain($view->display[$display_id]->display_title);
|
| 261 |
$label = $view->name;
|
| 262 |
$label .= ' ['. $display_title .']: ';
|
| 263 |
$label .= $view->description;
|
| 264 |
if (drupal_strlen($label) > 90) {
|
| 265 |
$label = drupal_substr($label, 0, 90) .'...';
|
| 266 |
}
|
| 267 |
return $label;
|
| 268 |
}
|
| 269 |
|