forked from impara/sms_service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms_service.module
138 lines (117 loc) · 4.2 KB
/
sms_service.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @file
* Implements sms and email checkboxes in user profile and in
* user edit form to save changes.
*/
module_load_include('inc', 'sms_service', 'sms_service');
/**
* Implements hook_user_view().
*/
function sms_service_user_view($account) {
$info = sms_service_get_patron();
if (is_null($info)) {
return;
}
// SMS default checked ?
if (isset($info->messages[0]) && $info->messages[0]['value'] == 'sms' || isset($info->messages[1]) && $info->messages[1]['value'] == 'sms') {
$sms = 'checked="checked"';
}
else {
$sms = '';
}
// Email default checked ?
if (isset($info->messages[0]) && $info->messages[0]['value'] == 'email' || isset($info->messages[1]) && $info->messages[1]['value'] == 'email') {
$email = 'checked="checked"';
}
else {
$email = '';
}
// Add sms checkbox.
$account->content['alma_user_sms'] = array(
'#prefix' => '<div class="sms_service">',
'#title' => t('SMS reminders'),
'#type' => 'item',
'#markup' => '<input type="checkbox" ' . $sms . ' class="form-checkbox" disabled=TRUE >'.t(' Pris 3kr. pr. stk (Regning overføres automatisk til Lånerstatus).'),
'#weight' => 10,
'#suffix' => '</div>',
);
// Add email checkbox.
$account->content['alma_user_email'] = array(
'#prefix' => '<div class="email_service">',
'#title' => t('Email reminders.'),
'#type' => 'item',
'#markup' => '<input type="checkbox" ' . $email . ' class="form-checkbox" disabled=TRUE >'.t(' Pris 3kr. pr. stk (Regning overføres automatisk til Lånerstatus).'),
'#weight' => 11,
'#suffix' => '</div>',
);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function sms_service_form_user_profile_form_alter(&$form, &$form_state) {
$info = sms_service_get_patron();
if (is_null($info)) {
return;
}
// SMS default checked ?
if (isset($info->messages[0]) && $info->messages[0]['value'] == 'sms' || isset($info->messages[1]) && $info->messages[1]['value'] == 'sms') {
$sms = '1';
}
else {
$sms = '0';
}
// Email default checked ?
if (isset($info->messages[0]) && $info->messages[0]['value'] == 'email' || isset($info->messages[1]) && $info->messages[1]['value'] == 'email') {
$email = '1';
}
else {
$email = '0';
}
// Add sms checkbox.
$form['alma_user_sms'] = array(
'#prefix' => '<div class="smsservice"><div class="sms_service">' . t('Ved at sætte et hak nedenunder acceptere du samtidig vores <a href="/paamindelsesservice" target="_blank">betingelser</a>' ). '</p>',
'#title' => t('SMS reminders.'),
'#type' => 'checkbox',
'#return_value' => '1',
'#default_value' => $sms,
'#weight' => -2,
'#suffix' => '</div>',
);
// Add email checkbox.
$form['alma_user_email'] = array(
'#prefix' => '<div class="email_service">',
'#title' => t('Email reminders.'),
'#type' => 'checkbox',
'#return_value' => '1',
'#default_value' => $email,
'#suffix' => '</div></div>',
'#weight' => -1,
);
// Additional handler to submit changes to alma.
$form['#submit'][] = 'sms_service_user_profile_submit';
}
/**
* Additional handler for user_profile submit to
* save checkbox settings via alma.
*/
function sms_service_user_profile_submit($form, &$form_state) {
$creds = ding_user_get_creds();
if ($form_state['values']['alma_user_sms']['return_value'] == '1') {
// Add a due date alerts as SMS service per default.
alma_client_invoke('add_message_service', $creds['name'], $creds['pass'], ALMA_SERVICE_METHOD_SMS, ALMA_SERVICE_TYPE_DUE_DATE_ALERT);
}
// Also remove SMS messaging service.
else {
alma_client_invoke('remove_message_service', $creds['name'], $creds['pass'], ALMA_SERVICE_METHOD_SMS, ALMA_SERVICE_TYPE_DUE_DATE_ALERT);
}
// Also add email messaging service.
if ($form_state['values']['alma_user_email']['return_value'] == '1') {
// Add a due date alerts as email service per default.
alma_client_invoke('add_message_service', $creds['name'], $creds['pass'], ALMA_SERVICE_METHOD_EMAIL, ALMA_SERVICE_TYPE_DUE_DATE_ALERT);
}
// Also remove email messaging service.
else {
alma_client_invoke('remove_message_service', $creds['name'], $creds['pass'], ALMA_SERVICE_METHOD_EMAIL, ALMA_SERVICE_TYPE_DUE_DATE_ALERT);
}
}