-
Notifications
You must be signed in to change notification settings - Fork 2
/
voip.admin.inc
143 lines (122 loc) · 3.85 KB
/
voip.admin.inc
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
139
140
141
142
<?php
// $Id$
/**
* Implments hook_form().
*/
function voip_admin_default_form($form, &$form_state) {
$header = array(
'name' => array('data' => t('Name')),
'operations' => array('data' => t('Operations')),
);
$server_array = VoipServer::getServers();
// sort the array by server name
usort($server_array, "_server_cmp");
$options = array();
foreach ($server_array as $server) {
$id = $server->getId();
$name = $server->getName();
if (function_exists($server->getConfigForm())) {
$operations = l(t('Configure'), 'admin/voip/servers/' . $id);
}
else {
$operations = t('No configuration options');
}
$options[$id] = array(
'#id' => $id,
'#value' => $id,
'data' => array(
'#title' => t($name),
'#id' => $id,
),
'name' => t($name),
'operations' => $operations,
);
}
$form['default'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#default_value' => variable_get('voip_default_server', 'log'),
//'#js_select' => FALSE,
'#multiple' => FALSE,
'#empty' => t('No Servers Installed.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Set default voip server'),
);
return $form;
}
function _server_cmp($s1, $s2) {
$name1 = $s1->getName();
$name2 = $s2->getName();
if ($name1 == $name2) {
return 0;
}
return ($name1 < $name2) ? -1 : 1;
}
/**
* Implements hook_form_submit().
*/
function voip_admin_default_form_submit($form, &$form_state) {
// Process form submission to set the default voip server
if ($form_state['values']['default']) {
drupal_set_message(t('Default voip server updated.'));
variable_set('voip_default_server', $form_state['values']['default']);
}
}
/**
* implements hook_form().
*/
function voip_admin_server_form($form, &$form_state, $server_id) {
$server = VoipServer::getServer($server_id);
$config_form = $server->getConfigForm();
$config = $server->getConfig();
if ($server && function_exists($config_form)) {
drupal_set_title(t('@server configuration', array('@server' => $server->getName())), PASS_THROUGH);
$form = $config_form($config);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['server'] = array(
'#type' => 'value',
'#value' => $server,
);
return $form;
}
drupal_not_found();
exit();
}
/**
* Implements hook_form_validate().
*
* Validation for voip server configuration. If the server defines a validation
* function it uses that.
*/
function voip_admin_server_form_validate($form, &$form_state) {
// Pass validation to voip server
$config_form = $form_state['values']['server']->getConfigForm();
$function = $config_form . '_validate';
if (function_exists($function)) {
$function($form, $form_state);
}
}
/**
* Implements hook_form_submit().
*/
function voip_admin_server_form_submit($form, &$form_state) {
$server = $form_state['values']['server'];
// Remove unecessary values
unset($form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['server'], $form_state['values']['form_token'], $form_state['values']['form_id']);
//Save VoIP Voice
VoipVoice::setDefaultVoice($form_state['values']['voipcall_voice_id']);
VoipVoice::setDefaultManVoice($form_state['values']['voipcall_man_voice_id']);
VoipVoice::setDefaultWomanVoice($form_state['values']['voipcall_woman_voice_id']);
unset($form_state['values']['voipcall_voice_id'], $form_state['values']['voipcall_man_voice_id'], $form_state['values']['voipcall_woman_voice_id']);
// store server configuration
$server_id = $server->getId();
variable_set('voip_' . $server_id . '_settings', $form_state['values']);
drupal_set_message(t('The server settings have been saved.'));
$form_state['redirect'] = 'admin/voip/servers';
}