| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Admin page callbacks for the OG contact module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* group/list tab.
|
| 11 |
*/
|
| 12 |
function og_contact_admin_groups() {
|
| 13 |
$result = db_query('SELECT ogc.gid,n.title FROM {og_contact} ogc INNER JOIN {node} n ON ogc.gid=n.nid WHERE n.status=1');
|
| 14 |
$rows = array();
|
| 15 |
while ($group = db_fetch_object($result)) {
|
| 16 |
$rows[] = array($group->title, l(t('edit'), 'admin/og/contact/edit/'. $group->gid), l(t('delete'), 'admin/og/contact/delete/'. $group->gid));
|
| 17 |
}
|
| 18 |
$header = array(t('Group'), array('data' => t('Operations'), 'colspan' => 2));
|
| 19 |
|
| 20 |
return theme('table', $header, $rows);
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Build the basic form for adding and editing group contact forms
|
| 25 |
*/
|
| 26 |
function og_contact_admin_group_form_skel($op, $gid = NULL) {
|
| 27 |
switch ($op) {
|
| 28 |
case 'add':
|
| 29 |
$options = og_contact_group_select_form_options();
|
| 30 |
$form['group'] = array('#type' => 'select',
|
| 31 |
'#title' => t('Group'),
|
| 32 |
'#description' => t("Choose the group that you want to add a contact form to."),
|
| 33 |
'#required' => TRUE,
|
| 34 |
'#options' => $options
|
| 35 |
);
|
| 36 |
break;
|
| 37 |
case 'edit':
|
| 38 |
$edit = db_fetch_array(db_query('SELECT * FROM {og_contact} WHERE gid=%d', $gid));
|
| 39 |
$form['group'] = array('#type' => 'hidden',
|
| 40 |
'#value' => $gid,
|
| 41 |
);
|
| 42 |
break;
|
| 43 |
}
|
| 44 |
$form['not_public'] = array(
|
| 45 |
'#type' => 'checkbox',
|
| 46 |
'#title' => t('Only allow group members to access contact form.'),
|
| 47 |
'#default_value' => (!$edit) ? variable_get('not_public', 0) : $edit['notpublic'],
|
| 48 |
'#description' => t('This allows you to restrict contact form submissions only to members of this group.'),
|
| 49 |
);
|
| 50 |
|
| 51 |
// Recipients section
|
| 52 |
$form['recipients'] = array('#type' => 'fieldset',
|
| 53 |
'#title' => t('Recipients'),
|
| 54 |
'#description' => t('By default, contact form submissions go to the administrators of a group. You can change this default behavior, by adding additional recipients below.'),
|
| 55 |
);
|
| 56 |
$form['recipients']['no_admin'] = array(
|
| 57 |
'#type' => 'checkbox',
|
| 58 |
'#title' => t('Do not send form submissions to group administrators.'),
|
| 59 |
'#default_value' => (!$edit) ? variable_get('no_admin', 0) : $edit['noadmin'],
|
| 60 |
'#description' => t("This allows you to send contact form submissions only to the recipients list."),
|
| 61 |
);
|
| 62 |
if (variable_get('og_contact_group_recipients', 0) == 1) {
|
| 63 |
$form['recipients']['group_recipients'] = array('#type' => 'checkbox',
|
| 64 |
'#title' => t('Send form submissions to eligible group members.'),
|
| 65 |
'#default_value' => (!$edit) ? variable_get('og_contact_group_recipients', 0) : $edit['grouprecipients'],
|
| 66 |
'#description' => t('Form submissions will go to group members in a role with "receive og contact submissions" permission.'),
|
| 67 |
);
|
| 68 |
}
|
| 69 |
$form['recipients']['recipients'] = array('#type' => 'textarea',
|
| 70 |
'#title' => t('Additional Recipients'),
|
| 71 |
'#default_value' => (!$edit) ? NULL : $edit['recipients'],
|
| 72 |
'#description' => t("Form submissions will go to these addresses") .' <br /><br /> '. t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com'. To specify multiple recipients, separate each e-mail address with a comma."),
|
| 73 |
);
|
| 74 |
|
| 75 |
if (variable_get('og_contact_custom_info', 0) == 1) {
|
| 76 |
if (variable_get('og_contact_info_admin_allow', 0) == 0 || og_is_group_admin(node_load($gid))) {
|
| 77 |
$form['info'] = array('#type' => 'textarea',
|
| 78 |
'#title' => t('Additional Information'),
|
| 79 |
'#default_value' => $edit['info'],
|
| 80 |
'#description' => t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number. Leave blank to use the site\'s default group contact form information.'),
|
| 81 |
);
|
| 82 |
}
|
| 83 |
}
|
| 84 |
$form['reply'] = array('#type' => 'textarea',
|
| 85 |
'#title' => t('Auto-reply'),
|
| 86 |
'#default_value' => (!$edit) ? NULL : $edit['reply'],
|
| 87 |
'#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
|
| 88 |
);
|
| 89 |
$form['submit'] = array('#type' => 'submit',
|
| 90 |
'#value' => t('Submit'),
|
| 91 |
);
|
| 92 |
|
| 93 |
return $form;
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Group contact add page.
|
| 98 |
*/
|
| 99 |
function og_contact_admin_add($gid = NULL) {
|
| 100 |
$form = og_contact_admin_group_form_skel('add');
|
| 101 |
return $form;
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Validate the group contact add form submission.
|
| 106 |
*/
|
| 107 |
function og_contact_admin_add_validate($form, &$form_state) {
|
| 108 |
if ($form_state['values']['no_admin'] == 1 && !$form_state['values']['recipients'] && $form_state['values']['group_recipients'] != 1) {
|
| 109 |
form_set_error('recipients', t('You must add recipients, or send form submissions to group administrators.'));
|
| 110 |
}
|
| 111 |
elseif ($form_state['values']['no_admin'] == 1 && $form_state['values']['group_recipients'] == 1 && !$form_state['values']['recipients']) {
|
| 112 |
if (!og_contact_check_group_recipients($form_state['values']['group']['#value'])) {
|
| 113 |
form_set_error('group_recipients', t('There are currently no members of this group, who are not already administrators, that can recieve form submissions, please add recipients, or send submissions to group administrators.'));
|
| 114 |
}
|
| 115 |
}
|
| 116 |
elseif ($form_state['values']['recipients']) {
|
| 117 |
$recipients = explode(',', $form_state['values']['recipients']);
|
| 118 |
foreach ($recipients as $recipient) {
|
| 119 |
if (!valid_email_address(trim($recipient))) {
|
| 120 |
form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
|
| 121 |
}
|
| 122 |
}
|
| 123 |
}
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Process the group contact add form submission.
|
| 128 |
*/
|
| 129 |
function og_contact_admin_add_submit($form, &$form_state) {
|
| 130 |
if (arg(3) == 'add') {
|
| 131 |
db_query("INSERT INTO {og_contact} (gid, reply,recipients,noadmin,notpublic,info) VALUES ('%d','%s','%s','%d','%d', '%s')", $form_state['values']['group'], $form_state['values']['reply'], $form_state['values']['recipients'], $form_state['values']['no_admin'], $form_state['values']['not_public'], $form_state['values']['info']);
|
| 132 |
drupal_set_message(t('Contact form for %group added.', array('%group' => $name)));
|
| 133 |
watchdog('mail', 'OG Contact: Form for %group added.', array('%group' => $name), WATCHDOG_NOTICE, l(t('view'), 'admin/og/contact'));
|
| 134 |
}
|
| 135 |
$form_state['redirect'] = 'admin/og/contact';
|
| 136 |
$form_state['nid'] = $node->nid;
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Group contact edit page.
|
| 141 |
*/
|
| 142 |
function og_contact_admin_edit() {
|
| 143 |
global $user;
|
| 144 |
if (arg(0) == 'admin' && is_numeric(arg(4)) && arg(4) > 0) {
|
| 145 |
$gid = arg(4);
|
| 146 |
$return = 'admin';
|
| 147 |
}
|
| 148 |
elseif (arg(0) == 'node' && is_numeric(arg(1)) && arg(1) > 0) {
|
| 149 |
$gid = arg(1);
|
| 150 |
$group = node_load($gid);
|
| 151 |
$return = 'node';
|
| 152 |
}
|
| 153 |
if ($gid) {
|
| 154 |
drupal_set_title('Edit contact form for '. og_contact_get_group_name($gid));
|
| 155 |
$form = og_contact_admin_group_form_skel('edit', $gid);
|
| 156 |
$form['return'] = array('#type' => 'value',
|
| 157 |
'#value' => $return
|
| 158 |
);
|
| 159 |
return $form;
|
| 160 |
}
|
| 161 |
else {
|
| 162 |
if ($return == 'admin') {
|
| 163 |
drupal_set_message('You must choose a group to edit.', 'error');
|
| 164 |
}
|
| 165 |
elseif ($return == 'node') {
|
| 166 |
drupal_set_title('Edit contact form for '. og_contact_get_group_name($gid));
|
| 167 |
drupal_set_message('You are not an administrator for this group.', 'error');
|
| 168 |
}
|
| 169 |
}
|
| 170 |
}
|
| 171 |
|
| 172 |
/**
|
| 173 |
* Validate the group contact edit form submission.
|
| 174 |
*/
|
| 175 |
function og_contact_admin_edit_validate($form, &$form_state) {
|
| 176 |
if ($form_state['values']['no_admin'] == 1 && !$form_state['values']['recipients'] && $form_state['values']['group_recipients'] == 0) {
|
| 177 |
form_set_error('recipients', t('You must add recipients, or send form submissions to list administrators.'));
|
| 178 |
}
|
| 179 |
elseif ($form_state['values']['recipients']) {
|
| 180 |
$recipients = explode(',', $form_state['values']['recipients']);
|
| 181 |
foreach ($recipients as $recipient) {
|
| 182 |
if (!valid_email_address(trim($recipient))) {
|
| 183 |
form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));
|
| 184 |
}
|
| 185 |
}
|
| 186 |
}
|
| 187 |
}
|
| 188 |
|
| 189 |
/**
|
| 190 |
* Process the group contact edit page form submission.
|
| 191 |
*/
|
| 192 |
function og_contact_admin_edit_submit($form, &$form_state) {
|
| 193 |
$name = og_contact_get_group_name($form_state['values']['group']);
|
| 194 |
drupal_set_title('Edit '. $name .'\'s Contact');
|
| 195 |
db_query("UPDATE {og_contact} SET reply = '%s', noadmin = %d, grouprecipients = %d, recipients = '%s', notpublic = %d, info='%s' WHERE gid = %d", $form_state['values']['reply'], $form_state['values']['no_admin'], $form_state['values']['group_recipients'], $form_state['values']['recipients'], $form_state['values']['not_public'], $form_state['values']['info'], $form_state['values']['group']);
|
| 196 |
|
| 197 |
drupal_set_message(t('Contact form for %group has been updated.', array('%group' => $name)));
|
| 198 |
watchdog('mail', 'OG Contact: Form for %group updated.', array('%group' => $name), WATCHDOG_NOTICE, l(t('view'), 'admin/og/contact'));
|
| 199 |
if ($form_state['values']['return'] == 'admin') {
|
| 200 |
$form_state['redirect'] = 'admin/og/contact';
|
| 201 |
$form_state['nid'] = $node->nid;
|
| 202 |
}
|
| 203 |
elseif ($form_state['values']['return'] == 'node') {
|
| 204 |
$form_state['redirect'] = 'node/'. $form_state['values']['group'] .'/contact';
|
| 205 |
$form_state['nid'] = $node->nid;
|
| 206 |
}
|
| 207 |
}
|
| 208 |
|
| 209 |
/**
|
| 210 |
* Group contact form delete page.
|
| 211 |
*/
|
| 212 |
function og_contact_admin_delete($gid = NULL) {
|
| 213 |
$name = og_contact_get_group_name($gid);
|
| 214 |
dsm($gid);
|
| 215 |
if ($info = db_fetch_object(db_query("SELECT gid FROM {og_contact} WHERE gid = %d", $gid))) {
|
| 216 |
$form['group'] = array(
|
| 217 |
'#type' => 'value',
|
| 218 |
'#value' => $info->gid,
|
| 219 |
);
|
| 220 |
|
| 221 |
return confirm_form($form, t('Are you sure you want to delete the contact form for %group?', array('%group' => $name)), 'admin/og/contact', t('Any text in the auto reply field will be lost if this form is deleted.'), t('Delete'), t('Cancel'));
|
| 222 |
}
|
| 223 |
else {
|
| 224 |
drupal_set_message(t('Group not found.'), 'error');
|
| 225 |
drupal_goto('admin/og/contact');
|
| 226 |
}
|
| 227 |
}
|
| 228 |
|
| 229 |
/**
|
| 230 |
* Process group delete form submission.
|
| 231 |
*/
|
| 232 |
function og_contact_admin_delete_submit($form, &$form_state) {
|
| 233 |
$name = og_contact_get_group_name($form_state['values']['group']);
|
| 234 |
db_query("DELETE FROM {og_contact} WHERE gid = %d", arg(4));
|
| 235 |
drupal_set_message(t('The group contact form for %group has been deleted.', array('%group' => $name)));
|
| 236 |
watchdog('mail', 'OG Contact: Form for %group was deleted.', array('%group' => $name), WATCHDOG_NOTICE);
|
| 237 |
|
| 238 |
$form_state['redirect'] = 'admin/og/contact';
|
| 239 |
$form_state['nid'] = $node->nid;
|
| 240 |
}
|
| 241 |
|
| 242 |
/**
|
| 243 |
* OG Conact admin settings page
|
| 244 |
*/
|
| 245 |
function og_contact_admin_settings() {
|
| 246 |
$form['og_contact_additonal_info'] = array('#type' => 'fieldset',
|
| 247 |
'#title' => t('Additional Information'),
|
| 248 |
);
|
| 249 |
$form['og_contact_additonal_info']['og_contact_form_information'] = array('#type' => 'textarea',
|
| 250 |
'#title' => t('Default Additional information Text'),
|
| 251 |
'#default_value' => variable_get('og_contact_form_information', t('You can leave a message using the contact form below.')),
|
| 252 |
'#description' => t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number.'),
|
| 253 |
);
|
| 254 |
$form['og_contact_additonal_info']['og_contact_custom_info'] = array('#type' => 'checkbox',
|
| 255 |
'#title' => t('Custom "Additional Information" Fields'),
|
| 256 |
'#description' => t('Enable additional information fields for each contact form.'),
|
| 257 |
'#default_value' => variable_get('og_contact_custom_info', 0),
|
| 258 |
);
|
| 259 |
$form['og_contact_additonal_info']['og_contact_info_admin_allow'] = array('#type' => 'checkbox',
|
| 260 |
'#title' => t('Do not allow group admins to write Additional Information text.'),
|
| 261 |
'#description' => t('This will prevent group administrators with "administer group contact form" from being able to modify the Additional Information field.'),
|
| 262 |
'#default_value' => variable_get('og_contact_info_admin_allow', 0),
|
| 263 |
);
|
| 264 |
$form['og_contact_hourly_threshold'] = array('#type' => 'select',
|
| 265 |
'#title' => t('Hourly threshold'),
|
| 266 |
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
|
| 267 |
'#default_value' => variable_get('og_contact_hourly_threshold', 3),
|
| 268 |
'#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
|
| 269 |
);
|
| 270 |
$form['og_contact_display_tab'] = array(
|
| 271 |
'#type' => 'checkbox',
|
| 272 |
'#title' => t('Display "Contact" tabs for groups'),
|
| 273 |
'#default_value' => variable_get('og_contact_display_tab', 1),
|
| 274 |
'#description' => t('Add a "Contact" tab to the tabs of any group with a contact form enabled. If this is turned off, contact forms can still be reached at the URL "node/nid/contact."'),
|
| 275 |
);
|
| 276 |
$form['og_contact_enable_all'] = array(
|
| 277 |
'#type' => 'checkbox',
|
| 278 |
'#title' => t('Automatically create Contact forms for new groups'),
|
| 279 |
'#default_value' => variable_get('og_contact_enable_all', 0),
|
| 280 |
'#description' => t('Give all new groups Contact forms when they are created. NOTE: existing groups will still need to have their Contact forms enabled, you can enable them for all groups '. l('here', 'admin/og/contact/addall') .'.'),
|
| 281 |
);
|
| 282 |
$form['og_contact_group_name_in_subject'] = array(
|
| 283 |
'#type' => 'checkbox',
|
| 284 |
'#title' => t('Send contact form emails with group name in the subject.'),
|
| 285 |
'#default_value' => variable_get('og_contact_group_name_in_subject', 0),
|
| 286 |
'#description' => t('When a contact form is submitted, the name of the group that is receiving the submission will be prepended to the user supplied subject. (eg: "[Group Name] User supplied subject")'),
|
| 287 |
);
|
| 288 |
$form['og_contact_group_admin_single'] = array(
|
| 289 |
'#type' => 'checkbox',
|
| 290 |
'#title' => t('Allow users with "administer group contact form" permissions to edit forms'),
|
| 291 |
'#default_value' => variable_get('og_contact_group_admin_single', 0),
|
| 292 |
'#description' => t('Users that are in a role with the "administer group contact form" permission, and are administrators of a given group, will be able to edit that group\'s Contact Form settings.'),
|
| 293 |
);
|
| 294 |
$form['og_contact_group_recipients'] = array(
|
| 295 |
'#type' => 'checkbox',
|
| 296 |
'#title' => t('Allow form recipients by role.'),
|
| 297 |
'#default_value' => variable_get('og_contact_group_recipients', 0),
|
| 298 |
'#description' => t('Users that are in a role with the "receive og contact submissions" permission, and are members of a given group, will receive mail from the contact form.'),
|
| 299 |
);
|
| 300 |
$form['og_contact_group_not_public'] = array(
|
| 301 |
'#type' => 'checkbox',
|
| 302 |
'#title' => t('Make contact forms private by default.'),
|
| 303 |
'#default_value' => variable_get('og_contact_group_not_public', 0),
|
| 304 |
'#description' => t('All newly created groups will have their contact forms set to private by default. This can still be overriden on each form\'s settings page. All existing contact forms will keep their current privacy settings.'),
|
| 305 |
);
|
| 306 |
return system_settings_form($form);
|
| 307 |
}
|
| 308 |
|
| 309 |
/**
|
| 310 |
* Add all Groups page.
|
| 311 |
*/
|
| 312 |
function og_contact_admin_add_all() {
|
| 313 |
$form['all_groups'] = array('#type' => 'value',
|
| 314 |
'#value' => 1,
|
| 315 |
);
|
| 316 |
return confirm_form($form, t('Are you sure you want to add contact forms for every group?'), 'admin/og/contact', t(''), t('Add'), t('Cancel'));
|
| 317 |
}
|
| 318 |
|
| 319 |
/**
|
| 320 |
* Process add all Groups form submission.
|
| 321 |
*/
|
| 322 |
function og_contact_admin_add_all_submit($form, &$form_state) {
|
| 323 |
$result = db_query('SELECT nid FROM {og}');
|
| 324 |
$grpno = 0;
|
| 325 |
$alteredno = 0;
|
| 326 |
while ($gid = db_fetch_object($result)) {
|
| 327 |
//Check if group doesn't already have a contact form
|
| 328 |
if (!og_contact_group_has_form($gid->nid)) {
|
| 329 |
//It doesn't, so add it to the og_contact table
|
| 330 |
db_query('INSERT INTO {og_contact} (gid, reply) VALUES ("%d","%s")', $gid->nid, "");
|
| 331 |
$alteredno++;
|
| 332 |
}
|
| 333 |
$grpno++;
|
| 334 |
}
|
| 335 |
if ($grpno != $alteredno) {
|
| 336 |
drupal_set_message(t('Added Contact forms to the %altered groups (of %groups) that did not already have forms.', array('%altered' => $alteredno, '%groups' => $grpno)));
|
| 337 |
watchdog('mail', 'OG Contact: Added contact form to the %altered groups (of %groups) that did not already have forms.', array('%altered' => $alteredno, '%groups' => $grpno), WATCHDOG_NOTICE);
|
| 338 |
}
|
| 339 |
else {
|
| 340 |
drupal_set_message(t('Added Contact forms for all groups'));
|
| 341 |
watchdog('mail', 'OG Contact: Added Contact forms for all groups', WATCHDOG_NOTICE);
|
| 342 |
}
|
| 343 |
$form_state['redirect'] = 'admin/og/contact';
|
| 344 |
$form_state['nid'] = $node->nid;
|
| 345 |
}
|
| 346 |
|
| 347 |
/**
|
| 348 |
* Delete all Groups page.
|
| 349 |
*/
|
| 350 |
function og_contact_admin_delete_all() {
|
| 351 |
$form['all_groups'] = array('#type' => 'value',
|
| 352 |
'#value' => 1,
|
| 353 |
);
|
| 354 |
return confirm_form($form, t('Are you sure you want to delete the contact forms for every group?'), 'admin/og/contact', t('Any auto replies that have been set will also be removed. This action cannot be undone.'), t('Delete'), t('Cancel'));
|
| 355 |
}
|
| 356 |
|
| 357 |
/**
|
| 358 |
* Process delete all Groups form submission.
|
| 359 |
*/
|
| 360 |
function og_contact_admin_delete_all_submit($form, &$form_state) {
|
| 361 |
db_query('DELETE FROM {og_contact}');
|
| 362 |
drupal_set_message(t('The group contact form for all groups have been deleted.'));
|
| 363 |
watchdog('mail', 'OG Contact: Forms for all groups were deleted.', WATCHDOG_NOTICE);
|
| 364 |
|
| 365 |
$form_state['redirect'] = 'admin/og/contact';
|
| 366 |
$form_state['nid'] = $node->nid;
|
| 367 |
}
|
| 368 |
|