forked from runderwood/voip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voip.admin.inc
102 lines (86 loc) · 3.16 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
<?php
// $Id$
function voip_admin_default_form() {
$server_array = VoipServer::getServers();
foreach ($server_array as $server) {
$id = $server->getId();
$name = $server->getName();
$options[$id] = '';
$form[$name]['id'] = array('#value' => $id);
if (function_exists($server->getConfigForm())) {
$form[$name]['configure'] = array('#value' => l(t('configure'), 'admin/voip/servers/'. $id));
}
else {
$form[$name]['configure'] = array('#value' => t('No configuration options'));
}
}
$form['default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('voip_default_server', 'log'));
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Set default voip server'),
);
return $form;
}
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']);
}
}
function theme_voip_admin_default_form($form) {
$rows = array();
foreach ($form as $name => $element) {
if (isset($element['id']) && is_array($element['id'])) {
$rows[] = array(
drupal_render($form['default'][$element['id']['#value']]),
check_plain($name),
drupal_render($element['configure']),
);
unset($form[$name]);
}
}
$header = array(t('Default'), t('Name'), array('data' => t('Operations'), 'colspan' => 1));
$output .= theme('table', $header, $rows);
$output .= drupal_render($form);
return $output;
}
function voip_admin_server_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())));
$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();
}
/**
* 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);
}
}
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']);
// 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';
}