-
Notifications
You must be signed in to change notification settings - Fork 0
/
stanford_soe_r25.module
executable file
·87 lines (81 loc) · 4.44 KB
/
stanford_soe_r25.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @file
* Code for the Stanford SOE R25 module.
*/
/**
* Implements hook_form_FORM_ID_alter().
*/
function stanford_soe_r25_form_stanford_r25_reservation_alter(&$form, &$form_state, $form_id) {
// We need to alter the reservation form and add field settings.
// The settings for "Event Attributes" 202,183,203,198,141, and 166.
global $base_url;
$form['stanford_r25_booking_tentative']['#weight'] = -11;
$form['stanford_r25_booking_date']['#weight'] = -10;
$form['stanford_r25_booking_duration']['#weight'] = -9;
$form['stanford_r25_booking_enddate']['#weight'] = -8;
$form['stanford_r25_booking_reason']['#weight'] = -7;
$form['stanford_r25_booking_attr202']['#weight'] = -3;
$form['stanford_r25_booking_headcount']['#weight'] = -2;
$form['stanford_r25_booking_attr183']['#weight'] = -1;
$form['stanford_r25_booking_reason']['#title'] = t('Event Title');
$form['stanford_r25_booking_attr182']['#title'] = t('Event Details');
$form['stanford_r25_booking_attr202']['#title'] = t('Primary Organization');
$form['stanford_r25_booking_attr141']['#type'] = 'radios';
$form['stanford_r25_booking_attr141']['#options'] = array('T' => t('Yes'), 'F' => t('No'));
$form['stanford_r25_booking_attr141']['#default_value'] = variable_get('stanford_r25_booking_attr141', 'F');
$form['stanford_r25_booking_attr166']['#type'] = 'radios';
$form['stanford_r25_booking_attr166']['#options'] = array('T' => t('Yes'), 'F' => t('No'));
$form['stanford_r25_booking_attr166']['#default_value'] = variable_get('stanford_r25_booking_attr166', 'F');
$form['stanford_r25_booking_attr203']['#suffix'] = '<div class="form-item"><span class="description">' . t('If unsure, please put N/A') . '</span></div>';
$form['submit']['#prefix'] = '<div class="form-item"><span class="readandagree">' . t('By clicking the Request button, I confirm that I have read and agree to the') . ' ' . l(t("Booking Agreement"), $base_url . '/science-and-engineering-quad/meeting-and-event-spaces/booking-agreement') . '.</span></div>';
$form['stanford_r25_booking_attr183']['#suffix'] = '<div class="form-item"><span class="description">' . t('E.g., 1234567-123-ABCDE (Case sensitive)') . '</span></div>';
$form['stanford_r25_booking_attr199']['#suffix'] = '<div class="form-item"><span class="description">' . t('E.g. Reservation spans multiple days; Breakout spaces needed') . '</span></div>';
$form['stanford_r25_booking_date']['#suffix'] = '<div class="starttime">' . t('Start time includes set-up time') . '</div>';
$form['stanford_r25_booking_enddate']['#suffix'] = '<div class="endtime">' . t('End time includes break-down time') . '</div>';
$form['stanford_r25_booking_attr182']['#maxlength'] = 80;
// We need this to be first for the verification to happen
// before the room booking takes place.
array_unshift($form['#validate'], 'stanford_soe_r25_stanford_r25_pta_validate');
}
/**
* We need to validate the PTA Number.
*
* - Throw a validation error message if the ";" character is entered
* in the stanford_r25_booking_reason field.
* - Throw a validation error message if the PTA field (attr 183 in 25 Live)
* if the value entered doesn't qualify as a valid PTA number format.
*
* @param array $form
* The form to update.
* @param array $form_state
* Submitted form state.
*/
function stanford_soe_r25_stanford_r25_pta_validate($form, &$form_state) {
$booking_reason_value = $form_state['values']['stanford_r25_booking_reason'];
if (preg_match('/;/', $booking_reason_value)) {
form_set_error('stanford_r25_booking_reason', t('Please do not include the ; character in the title of the event.'));
}
$pta_value = trim($form_state['values']['stanford_r25_booking_attr183']);
if (!(preg_match('/^(\d{7})\-(\d.*)\-([A-Z]{5})$/', $pta_value))) {
form_set_error('stanford_r25_booking_attr183', t('Invalid PTA Format. The correct format is Project-Task-Award (e.g. 1234567-123-ABCDE)'));
}
}
/**
* We need to turn off some headders in the emails.
*
* - The reservation email say:
* [email protected] on behalf of [email protected]
* - We want it to just show [email protected]
* and hide [email protected] for header.
*
* @param array $message
* The message for the email to modify.
*/
function stanford_soe_r25_mail_alter(&$message) {
if (preg_match('/stanford_r25/', $message['id'])) {
unset($message['headers']['Sender']);
unset($message['headers']['Errors-To']);
unset($message['headers']['Return-Path']);
}
}