forked from intralanman/fs_curl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_cdr.php
108 lines (96 loc) · 3.16 KB
/
fs_cdr.php
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
<?php
/**
* @package FS_CURL
* fs_cdr.php
*/
if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
header('Location: index.php');
}
/**
* @package FS_CURL
* @license BSD
* @author Raymond Chandler (intralanman) <intralanman@gmail.com>
* @version 0.1
* Class for inserting xml CDR records
* @return object
*/
class fs_cdr extends fs_curl {
/**
* This variable will hold the XML CDR string
* @var string
*/
public $cdr;
/**
* This object is the objectified representation of the XML CDR
* @var XMLSimple Object
*/
public $xml_cdr;
/**
* This array will hold the db field and their corresponding value
* @var array
*/
public $values = array();
/**
* This array maps the database field names to XMLSimple paths
* @var array
*/
public $fields = array(
'caller_id_name' => '$this->xml_cdr->callflow[0]->caller_profile->caller_id_name',
'caller_id_number' => '$this->xml_cdr->callflow[0]->caller_profile->caller_id_number',
'destination_number' => '$this->xml_cdr->callflow[0]->caller_profile->destination_number',
'context' => '$this->xml_cdr->callflow[0]->caller_profile->context',
'start_stamp' => 'urldecode($this->xml_cdr->variables->start_stamp)',
'answer_stamp' => 'urldecode($this->xml_cdr->variables->answer_stamp)',
'end_stamp' => 'urldecode($this->xml_cdr->variables->end_stamp)',
'duration' => '$this->xml_cdr->variables->duration',
'billsec' => '$this->xml_cdr->variables->billsec',
'hangup_cause' => '$this->xml_cdr->variables->hangup_cause',
'uuid' => '$this->xml_cdr->callflow[0]->caller_profile->uuid',
'bleg_uuid' => '$this->xml_cdr->callflow[0]->caller_profile->bleg_uuid',
'accountcode' => '$this->xml_cdr->variables->accountcode',
'read_codec' => '$this->xml_cdr->variables->read_codec',
'write_codec' => '$this->xml_cdr->variables->write_codec'
);
/**
* This is where we instantiate our parent and set up our CDR object
*/
public function fs_cdr() {
self::__construct();
}
public function __construct() {
$this->fs_curl();
$this->cdr = stripslashes($this->request['cdr']);
$this->xml_cdr = new SimpleXMLElement($this->cdr);
}
/**
* This is where we run the bulk of our logic through other methods
*/
public function main() {
$this->set_record_values();
$this->insert_cdr();
}
/**
* This method will take the db fields and paths defined above and
* set the values array to be used for the insert
*/
public function set_record_values() {
foreach ($this->fields as $field => $run) {
eval("\$str = $run;");
$this->values["$field"] = "'$str'";
$this->debug($str);
}
$this->debug(print_r($this->values, true));
print_r($this->values);
}
/**
* finally do the insert of the CDR
*/
public function insert_cdr() {
$query = sprintf(
"INSERT INTO cdr (%s) VALUES (%s);",
join(',', array_keys($this->values)), join(',', $this->values)
);
$this->debug($query);
$this->db->exec($query);
}
}