/[drupal]/contributions/modules/signup/includes/node_settings.inc
ViewVC logotype

Contents of /contributions/modules/signup/includes/node_settings.inc

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


Revision 1.5 - (show annotations) (download) (as text)
Mon Sep 21 05:23:02 2009 UTC (2 months ago) by dww
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +3 -1 lines
File MIME type: text/x-php
#578592 by dww: Cleaned up and fixed the "Signup summary" at the top
of the node/N/signups/admin. The UI also makes sense now for signups
that don't count towards the signup limit (#581652).
1 <?php
2 // $Id: node_settings.inc,v 1.4 2009/09/19 01:42:52 dww Exp $
3
4
5 /**
6 * @file
7 * Code related to the per-node signup settings form.
8 */
9
10 /**
11 * Returns the form for the per-node signup settings.
12 *
13 * This is shared by the settings page and the node edit page.
14 *
15 * @param $node
16 * The fully loaded node object if we've got it.
17 * @param $node_type
18 * The type of the node. When creating new content, the caller can know the
19 * node type, even if $node is NULL.
20 * @param $has_date
21 * Boolean flag indicating if this node (or site) has signup-aware
22 * date functionality, which is required for reminder emails to be in
23 * the form.
24 * @param $include_buttons
25 * Boolean flag indicating if the form should include its own submit buttons.
26 *
27 * @return
28 * The form array for the per-node signup settings.
29 *
30 */
31 function signup_node_settings_form($form_state, $node = NULL, $node_type = NULL, $has_date = FALSE, $include_buttons = FALSE) {
32 if (module_exists('token')) {
33 $signup_token_description = t('Supported string substitutions: %node_title, %node_url, %node_start_time, %user_name, %user_mail, %user_signup_info (additional information from the signup form), %cancel_signup_url (access to this link is denied to users without the "%cancel_own_signups" permission), and any tokens in the %replacement_tokens list.', array('%replacement_tokens' => t('Replacement tokens'), '%cancel_own_signups' => t('cancel own signups')));
34 }
35 else {
36 $signup_token_description = t('Supported string substitutions: %node_title, %node_url, %node_start_time, %user_name, %user_mail, %user_signup_info (additional information from the signup form), and %cancel_signup_url (access to this link is denied to users without the "%cancel_own_signups" permission).', array('%cancel_own_signups' => t('cancel own signups')));
37 }
38
39 // Load the default admin form data for new nodes.
40 if (!$node || !$node->signup) {
41 $result = db_fetch_object(db_query("SELECT * FROM {signup} WHERE nid = 0"));
42 $node->signup_forwarding_email = $result->forwarding_email;
43 $node->signup_send_confirmation = $result->send_confirmation;
44 $node->signup_confirmation_email = $result->confirmation_email;
45 $node->signup_send_reminder = $result->send_reminder;
46 $node->signup_reminder_days_before = $result->reminder_days_before;
47 $node->signup_reminder_email = $result->reminder_email;
48 $node->signup_close_signup_limit = $result->close_signup_limit;
49 }
50
51 $form['signup_forwarding_email'] = array(
52 '#type' => 'textfield',
53 '#title' => t('Send signups to'),
54 '#default_value' => $node->signup_forwarding_email,
55 '#size' => 40, '#maxlength' => 64,
56 '#description' => t('Email address where notification of new signups will be sent. Leave blank for no notifications.'),
57 );
58 $form['signup_send_confirmation'] = array(
59 '#type' => 'checkbox',
60 '#title' => t('Send confirmation'),
61 '#default_value' => $node->signup_send_confirmation,
62 );
63 $form['signup_confirmation_email'] = array(
64 '#type' => 'textarea',
65 '#title' => t('Confirmation email'),
66 '#default_value' => $node->signup_confirmation_email,
67 '#cols' => 40, '#rows' => 6,
68 '#description' => t('Email sent to user upon signup. !token_description', array('!token_description' => $signup_token_description)),
69 );
70 if (module_exists('token')) {
71 module_load_include('inc', 'signup', 'includes/token_help');
72 _signup_token_help($form, 'signup_confirmation_token_fieldset');
73 }
74
75 if ($has_date) {
76 // Define a sub-tree to wrap the next 2 form elements together in an
77 // inline div for better display.
78 $form['signup_reminder'] = array(
79 '#prefix' => '<div class="container-inline">',
80 '#suffix' => '</div>',
81 );
82 $form['signup_reminder']['signup_send_reminder'] = array(
83 '#type' => 'checkbox',
84 '#title' => t('Send reminder'),
85 '#default_value' => $node->signup_send_reminder,
86 );
87 $options = array();
88 for ($i = 1; $i <= 60; $i++) {
89 $options[$i] = $i;
90 }
91 $node_type_name = isset($node_type) ? node_get_types('name', $node_type) : '';
92 $form['signup_reminder']['signup_reminder_days_before'] = array(
93 '#type' => 'select',
94 '#default_value' => $node->signup_reminder_days_before,
95 '#options' => $options,
96 '#suffix' => !empty($node_type_name) ? t('day(s) before this %node_type', array('%node_type' => $node_type_name)) : t('day(s) before start time'),
97 );
98 $form['signup_reminder_email'] = array(
99 '#type' => 'textarea',
100 '#title' => t('Reminder email'),
101 '#default_value' => $node->signup_reminder_email,
102 '#cols' => 40, '#rows' => 6,
103 '#description' => !empty($node_type_name) ? t('Email sent to user as a reminder before the %node_type starts. !token_description', array('%node_type' => $node_type_name, '!token_description' => $signup_token_description)) : t('Email sent to user as a reminder before the start time. !token_description', array('!token_description' => $signup_token_description)),
104 );
105 if (module_exists('token')) {
106 module_load_include('inc', 'signup', 'includes/token_help');
107 _signup_token_help($form, 'signup_reminder_token_fieldset');
108 }
109 }
110
111 $form['signup_close_signup_limit'] = array(
112 '#type' => 'textfield',
113 '#title' => t('Signup limit'),
114 '#default_value' => $node->signup_close_signup_limit,
115 '#size' => 4, '#maxlength' => 8,
116 '#description' => t('Maximum number of users who can sign up before signups are automatically closed. If set to 0, there is no limit.'),
117 '#prefix' => '<div id="signup-limit">',
118 '#suffix' => '</div>',
119 );
120 $form['signup'] = array('#type' => 'hidden', '#value' => 1);
121
122 if ($include_buttons) {
123 $form['#node'] = $node;
124 $form['buttons']['submit'] = array(
125 '#type' => 'submit',
126 '#value' => t('Save configuration'),
127 );
128 $form['buttons']['reset'] = array(
129 '#type' => 'submit',
130 '#value' => t('Reset to defaults'),
131 );
132 $form['#submit'][] = 'signup_node_settings_form_submit';
133 }
134
135 return $form;
136 }
137
138 /**
139 * Page callback for the node/N/signups/settings subtab.
140 */
141 function signup_node_settings_page($node) {
142 $node_scheduler = _signup_get_node_scheduler($node);
143 $node_has_date = $node_scheduler != 'none';
144 return drupal_get_form('signup_node_settings_form', $node, $node->type, $node_has_date, TRUE);
145 }
146
147 /**
148 * Submit handler for the per-node signup settings form.
149 *
150 * @param $form_id
151 * The ID of the form being submitted.
152 * @param $form_values
153 * The constructed form values array of the submitted form.
154 */
155 function signup_node_settings_form_submit($form, &$form_state) {
156 $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
157 if ($op == t('Reset to defaults')) {
158 // If we're resetting, we just want to grab the site-wide defaults.
159 $values = db_fetch_array(db_query("SELECT forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email FROM {signup} WHERE nid = 0"));
160 }
161 else {
162 // Populate $values from $form_state.
163 foreach (array('forwarding_email', 'send_confirmation', 'confirmation_email', 'close_signup_limit') as $setting) {
164 $values[$setting] = $form_state['values']["signup_$setting"];
165 }
166 // If we're dealing with a node that doesn't have a start time, these
167 // fields are missing from the signup settings form, so we can't assume
168 // they're defined.
169 $values['send_reminder'] = isset($form_state['values']['signup_send_reminder']) ? $form_state['values']['signup_send_reminder'] : 0;
170 $values['reminder_days_before'] = isset($form_state['values']['signup_reminder_days_before']) ? $form_state['values']['signup_reminder_days_before'] : 0;
171 $values['reminder_email'] = isset($form_state['values']['signup_reminder_email']) ? $form_state['values']['signup_reminder_email'] : '';
172 }
173
174 // Either way, we want to make sure we're updating the values for the
175 // current node, not nid 0...
176 $node = $form['#node'];
177 $values[] = $node->nid;
178 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);
179
180 // See if the limit changed, and if so, take any necessary action.
181 if ($node->signup_close_signup_limit != $form_state['values']['signup_close_signup_limit']) {
182 $node->signup_close_signup_limit = $form_state['values']['signup_close_signup_limit'];
183 $node->signup_effective_total = db_result(db_query("SELECT SUM(count_towards_limit) FROM {signup_log} WHERE nid = %d", $node->nid));
184 _signup_check_limit($node, 'limit');
185 }
186
187 if ($op == t('Reset to defaults')) {
188 drupal_set_message(t('The configuration options have been reset to their default values.'));
189 }
190 else {
191 drupal_set_message(t('The configuration options have been saved.'));
192 }
193 }
194

  ViewVC Help
Powered by ViewVC 1.1.2