forked from runderwood/voip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voip.module
133 lines (106 loc) · 3.26 KB
/
voip.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
<?php
// $Id$
/**
* @file
* Enables communication between Drupal and VoIP servers.
*/
foreach (array('voip_error.inc', 'voipserver.inc', 'voiplogserver.inc') as $file) {
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $file);
}
/**
* Make a phone call
*
* @param object $voipcall with the information about the call to be made
*
* @return boolean with TRUE in case of success or FALSE otherwise
*/
function voip_dial($voipcall) {
// make sure the user is allowed to make outbound calls
$allowed = user_access('make outbound calls');
if(!$allowed) {
global $user;
$variables['%uid'] = $user->uid;
$msg = 'User %uid does not have permissions to make outbound calls.';
watchdog('voip', $msg, $variables, WATCHDOG_WARNING);
return FALSE;
}
if(is_object($voipcall)){
$voipcall = (array)$voipcall;
}
$voip_server = voip_default_server();
$response = $voip_server->dial($voipcall);
if (voip_error()) {
$error_message = 'Failure executing voip_dial() with %options.';
$variables['%options'] = print_r($voipcall, TRUE);
if (voip_error_message()) {
$error_message .= ' The server said: '. voip_error_message();
}
watchdog('voip', $error_message, $variables, WATCHDOG_ERROR);
}
return $response;
}
/**
* Implementation of hook_menu().
*/
function voip_menu() {
$items = array();
$items['admin/voip'] = array(
'title' => 'Voip Drupal',
'description' => 'Control how your site interacts with VoIP servers.',
'position' => 'right',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer voip drupal framework'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system')
);
$items['admin/voip/servers'] = array(
'title' => 'Voip server configuration',
'description' => 'Configure voip servers and choose the default server.',
'page callback' => 'drupal_get_form',
'page arguments' => array('voip_admin_default_form', NULL),
'access arguments' => array('administer voip drupal framework'),
'file' => 'voip.admin.inc',
);
$items['admin/voip/servers/%'] = array(
'title callback' => 'voip_admin_server_title',
'title arguments' => array(3),
'page callback' => 'drupal_get_form',
'page arguments' => array('voip_admin_server_form', 3),
'access arguments' => array('administer voip drupal framework'),
'type' => MENU_CALLBACK,
'file' => 'voip.admin.inc',
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function voip_perm() {
return array('administer voip drupal framework', 'make outbound calls', 'make inbound calls');
}
/**
* Implementation of hook_theme().
*/
function voip_theme() {
$items['voip_admin_default_form'] =
array('arguments' => array('form' => NULL));
return $items;
}
/**
* Internal functions
*/
/**
* Voip server menu title callback.
*/
function voip_admin_server_title($server_id) {
$server = VoipServer::getServer($server_id);
return sprintf('%s server', $server->getName());
}
/**
* Returns the current default voip server.
*/
function voip_default_server() {
$server_id = variable_get('voip_default_server', 'log');
$server = VoipServer::getServer($server_id);
return $server;
}