Initial Commit of AgileBill Open Source

This commit is contained in:
unknown
2008-11-26 14:50:40 -08:00
parent ae5a0fc25e
commit 02306ccc47
2954 changed files with 410976 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<?php
### public methods for this module:
$auth_methods = Array
(
Array ('module' => 'voip_vm', 'method' => 'vm_list'),
Array ('module' => 'voip_vm', 'method' => 'vm_listen'),
Array ('module' => 'voip_vm', 'method' => 'user_delete')
);
?>

View File

@@ -0,0 +1,252 @@
<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
*
* For questions, help, comments, discussion, etc., please join the
* Agileco community forums at http://forum.agileco.com/
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
* @author Tony Landis <tony@agileco.com> and Thralling Penguin, LLC <http://www.thrallingpenguin.com>
* @package AgileBill
* @version 1.4.93
*/
class voip_vm
{
var $vm=false; // path to VM dir
# Open the constructor for this mod
function voip_vm()
{
# name of this module:
$this->module = "voip_vm";
# location of the construct XML file:
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
# open the construct file for parsing
$C_xml = new CORE_xml;
$construct = $C_xml->xml_to_array($this->xml_construct);
$this->method = $construct["construct"]["method"];
$this->trigger = $construct["construct"]["trigger"];
$this->field = $construct["construct"]["field"];
$this->table = $construct["construct"]["table"];
$this->module = $construct["construct"]["module"];
$this->cache = $construct["construct"]["cache"];
$this->order_by = $construct["construct"]["order_by"];
$this->limit = $construct["construct"]["limit"];
}
/**
* Sets the voicemail path(s)
*/
function get_vm_path() {
if(!SESS_LOGGED) {
define("FORCE_REDIRECT", "?_page=account:account");
return false;
}
require_once(PATH_MODULES.'voip/voip.inc.php');
$voip = new voip;
$dids = $voip->get_voicemail_dids(SESS_ACCOUNT);
if(!$dids || !is_array($dids) || count($dids) < 1) return false;
$db=&DB();
foreach($dids as $did)
{
$rs = & $db->Execute($sql=sqlSelect($db,"voip_vm","context,mailbox","mailbox = ::$did:: AND account_id=".SESS_ACCOUNT));
if($rs && $rs->RecordCount() > 0)
{
$path = "/var/spool/asterisk/voicemail/{$rs->fields["context"]}/{$rs->fields["mailbox"]}/INBOX/";
$this->vm[] = $path;
if (!is_dir($path)) {
global $C_debug;
$C_debug->error('voip_vm','get_vm_path','The voicemail directory does not have the proper permissions assigned.');
}
}
}
}
/**
* List the voicemails for the current user
*/
function vm_list($VAR) {
if(!SESS_LOGGED) {
define("FORCE_REDIRECT", "?_page=account:account");
} else {
$ret = false;
$this->get_vm_path();
if(is_array($this->vm) && count($this->vm) > 0)
{
$ret=array();
foreach($this->vm as $path)
{
$this->get_vm_by_path($path,$ret);
}
global $smarty;
$smarty->assign('voip_fax', $ret);
$smarty->assign('results', count($ret));
}
}
}
/**
* Streams the VM to the user
*/
function vm_listen($VAR)
{
if(SESS_LOGGED && @$VAR['id']!= '' && is_numeric($VAR['id']) && !empty($VAR['did']) && is_numeric($VAR['did']) )
{
// get path for selected did && make sure it belongs to current account
$db=&DB();
$rs = & $db->Execute($sql=sqlSelect($db,"voip_vm","context,mailbox","mailbox = ::{$VAR['did']}:: AND account_id=".SESS_ACCOUNT));
if($rs && $rs->RecordCount() > 0)
$path = "/var/spool/asterisk/voicemail/{$rs->fields["context"]}/{$rs->fields["mailbox"]}/INBOX/";
else
return false;
$f = $path.'msg'.$VAR['id'].'.wav';
if(is_file($f) && is_readable($f)) {
ob_start();
header("Content-Type: audio/wav");
echo file_get_contents($f);
ob_end_flush();
exit;
}
else {
echo "ERR1: Unable to retrieve specified Message";
}
} else {
echo "ERR1: No voicemail message specified or no access";
}
}
/**
* User voicemail delete function
*/
function user_delete($VAR)
{
if(SESS_LOGGED && @$VAR['id']!= '' && is_numeric($VAR['id']) && !empty($VAR['did']) && is_numeric($VAR['did']) )
{
// get path for selected did && make sure it belongs to current account
$db=&DB();
$rs = & $db->Execute($sql=sqlSelect($db,"voip_vm","context,mailbox","mailbox = ::{$VAR['did']}:: AND account_id=".SESS_ACCOUNT));
if($rs && $rs->RecordCount() > 0)
$path = "/var/spool/asterisk/voicemail/{$rs->fields["context"]}/{$rs->fields["mailbox"]}/INBOX/";
else
return false;
$file = 'msg'.$VAR['id'].'.wav';
$wld = str_replace(".wav",".*",basename($file));
if(strlen($wld) && strstr($wld,".*")) {
foreach (glob($path.$wld) as $filename) {
unlink($filename);
}
}
}
}
/**
* return all voicemails for a specific path
* @return Array
* @param $ret The array of voicemails to add any voicemails to
*/
function get_vm_by_path($path,&$ret)
{
if ($dh = @opendir($path)) {
while (($file = readdir($dh)) !== false) {
if(ereg("^msg.*\.txt",$file)) {
$msgs[] = $file;
}
}
closedir($dh);
}
if(is_array($msgs) && count($msgs)) {
if(!is_array($ret)) $cnt=0;
else $cnt = count($ret)+1;
foreach($msgs as $msg) {
$c = file_get_contents($path.$msg);
$lines = explode("\n",$c);
foreach($lines as $line) {
$parts = explode("=",$line);
$ret[$cnt][$parts[0]]=$parts[1];
if($parts[0] == "origtime") {
$ret[$cnt]['date'] = date('M d, Y g:i:s a',$parts[1]);
}
}
$ret[$cnt]['id'] = ereg_replace("[a-zA-Z\.]","",$msg);
$ret[$cnt]['size'] = number_format(filesize($path.$ret[$cnt]['file'])/1024,0);
$cnt++;
}
} else {
return;
}
return $ret;
}
function add($VAR)
{
$type = "add";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->add($VAR, $this, $type);
}
function view($VAR)
{
$type = "view";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->view($VAR, $this, $type);
}
function update($VAR)
{
$type = "update";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->update($VAR, $this, $type);
}
function delete($VAR)
{
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
function search_form($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_form($VAR, $this, $type);
}
function search($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search($VAR, $this, $type);
}
function search_show($VAR)
{
$type = "search";
$this->method["$type"] = split(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
}
?>

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<construct>
<module>voip_vm</module>
<table>voip_vm</table>
<dependancy>voip</dependancy>
<cache>0</cache>
<order_by>id</order_by>
<limit>35</limit>
<index>
<context>context,mailbox</context>
</index>
<field>
<id>
<type>I4</type>
<unique>1</unique>
</id>
<site_id>
<type>I4</type>
</site_id>
<account_id>
<type>I4</type>
<asso_table>account</asso_table>
<asso_field>username</asso_field>
<validate>any</validate>
</account_id>
<context>
<type>C(128)</type>
</context>
<mailbox>
<type>C(128)</type>
<validate>any</validate>
</mailbox>
<password>
<type>C(128)</type>
<validate>any</validate>
</password>
<fullname>
<type>C(128)</type>
<validate>any</validate>
</fullname>
<email>
<type>C(128)</type>
</email>
<pager>
<type>C(128)</type>
</pager>
<options>
<type>C(128)</type>
</options>
</field>
<method>
<add>id,site_id,account_id,context,mailbox,password,fullname,email,pager,options</add>
<update>id,site_id,account_id,context,mailbox,password,fullname,email,pager,options</update>
<delete>id,site_id,account_id,context,mailbox,password,fullname,email,pager,options</delete>
<view>id,site_id,account_id,context,mailbox,password,fullname,email,pager,options</view>
<search>id,site_id,account_id,context,mailbox,password,fullname,email,pager,options</search>
</method>
<trigger>0</trigger>
</construct>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<install>
<module_properties>
<name>voip_vm</name>
<parent>voip</parent>
<notes>This module controls the VoIP voicemail interface</notes>
<menu_display>1</menu_display>
<dependancy>voip</dependancy>
<sub_modules></sub_modules>
</module_properties>
<sql_inserts>
<module_method>
<add>
<name>add</name>
<page>%%:add</page>
<menu_display>1</menu_display>
</add>
<update>
<name>update</name>
</update>
<delete>
<name>delete</name>
</delete>
<view>
<name>view</name>
<page>core:search&amp;module=%%&amp;_escape=1</page>
<menu_display>1</menu_display>
</view>
<search>
<name>search</name>
<page>%%:search_form</page>
<menu_display>1</menu_display>
</search>
<search_form>
<name>search_form</name>
</search_form>
<search_show>
<name>search_show</name>
</search_show>
</module_method>
</sql_inserts>
</install>