提交 81f6011e authored 作者: Raymond Chandler's avatar Raymond Chandler

adding in a simple xml cdr to db module

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@14914 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 a3b00364
<?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() {
$this->fs_curl();
$this->cdr = $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);
}
}
......@@ -166,7 +166,7 @@ class fs_curl {
for ($i = 0; $i < $comment_count; $i++) {
if (array_key_exists($i, $comments)) {
if (!is_array($comments[$i])) {
$xml_obj -> writeComment($comments[$i]);
$xml_obj -> writeComment(" " . $comments[$i] . " ");
} else {
$this -> comments2xml($xml_obj, $comments[$i], $space_pad + 2);
}
......@@ -269,7 +269,7 @@ class fs_curl {
if ($no == E_STRICT) {
return true;
}
$file = ereg_replace('\.(inc|php)$', '', $file);
$file = preg_replace('/\.(inc|php)$/', '', $file);
$this -> comment(basename($file) . ":$line - $no:$str");
switch ($no) {
......@@ -320,7 +320,7 @@ class fs_curl {
syslog(LOG_NOTICE, $debug_str);
break;
case 1:
$debug_str = preg_replace('/-/', ' - ', $debug_str);
$debug_str = preg_replace('/--/', '- - ', $debug_str);
$this -> comment($debug_str);
break;
case 2:
......
......@@ -66,7 +66,7 @@ class fs_dialplan extends fs_curl {
}
if ($res -> numRows() == 1) {
$row = $res -> fetchRow();
$this -> special_class_file = $row['class_file'];
$this -> special_class_file = sprintf('dialplans/%s', $row['class_file']);
return true;
} else {
return false;
......
......@@ -54,7 +54,12 @@ if (!(@include_once('fs_curl.php'))
if (!is_array($_REQUEST)) {
trigger_error('$_REQUEST is not an array');
}
$section = $_REQUEST['section'];
if (array_key_exists('cdr', $_REQUEST)) {
$section = 'cdr';
} else {
$section = $_REQUEST['section'];
}
$section_file = sprintf('fs_%s.php', $section);
/**
* this include will differ based on the section that's passed
......@@ -82,6 +87,9 @@ switch ($section) {
case 'directory':
$conf = new fs_directory();
break;
case 'cdr':
$conf = new fs_cdr();
break;
}
$conf -> debug('---- Start _REQUEST ----');
......
......@@ -66,6 +66,32 @@ INSERT INTO `acl_nodes` (`id`, `cidr`, `type`, `list_id`) VALUES
-- --------------------------------------------------------
--
-- Table structure for table `cdr`
--
CREATE TABLE IF NOT EXISTS `cdr` (
`id` int(11) NOT NULL auto_increment,
`caller_id_name` varchar(255) NOT NULL default '',
`caller_id_number` varchar(255) NOT NULL default '',
`destination_number` varchar(255) NOT NULL default '',
`context` varchar(255) NOT NULL default '',
`start_stamp` varchar(255) NOT NULL default '',
`answer_stamp` varchar(255) NOT NULL default '',
`end_stamp` varchar(255) NOT NULL default '',
`duration` varchar(255) NOT NULL default '',
`billsec` varchar(255) NOT NULL default '',
`hangup_cause` varchar(255) NOT NULL default '',
`uuid` varchar(255) NOT NULL default '',
`bleg_uuid` varchar(255) NOT NULL default '',
`accountcode` varchar(255) NOT NULL default '',
`read_codec` varchar(255) NOT NULL default '',
`write_codec` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `conference_advertise`
--
......
......@@ -58,6 +58,39 @@ CREATE TABLE IF NOT EXISTS `acl_nodes` (
-- --------------------------------------------------------
--
-- Table structure for table `cdr`
--
DROP TABLE IF EXISTS `cdr`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cdr` (
`id` int(11) NOT NULL auto_increment,
`caller_id_name` varchar(255) NOT NULL default '',
`caller_id_number` varchar(255) NOT NULL default '',
`destination_number` varchar(255) NOT NULL default '',
`context` varchar(255) NOT NULL default '',
`start_stamp` varchar(255) NOT NULL default '',
`answer_stamp` varchar(255) NOT NULL default '',
`end_stamp` varchar(255) NOT NULL default '',
`duration` varchar(255) NOT NULL default '',
`billsec` varchar(255) NOT NULL default '',
`hangup_cause` varchar(255) NOT NULL default '',
`uuid` varchar(255) NOT NULL default '',
`bleg_uuid` varchar(255) NOT NULL default '',
`accountcode` varchar(255) NOT NULL default '',
`read_codec` varchar(255) NOT NULL default '',
`write_codec` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
-- --------------------------------------------------------
--
-- Table structure for table `conference_advertise`
--
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论