Add. Use params in is_local/index.lua (#2122)

* Add. Use params in is_local/index.lua

* Fix. syntax error in params table.
This commit is contained in:
Alexey Melnichuk 2016-11-22 00:04:21 +03:00 committed by FusionPBX
parent 1da4785b41
commit fd2a383394
1 changed files with 19 additions and 8 deletions

View File

@ -29,8 +29,13 @@
outbound_caller_id_number = session:getVariable("outbound_caller_id_number");
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
local Database = require "resources.functions.database";
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--prepare the api object
api = freeswitch.API();
@ -43,13 +48,18 @@
--get the destination number
if (cache == "-ERR NOT FOUND") then
sql = "SELECT destination_number, destination_context "
local dbh = Database.new('system');
local sql = "SELECT destination_number, destination_context "
sql = sql .. "FROM v_destinations "
sql = sql .. "WHERE destination_number = '"..destination_number.."' "
sql = sql .. "WHERE destination_number = :destination_number "
sql = sql .. "AND destination_type = 'inbound' "
sql = sql .. "AND destination_enabled = 'true' "
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
assert(dbh:query(sql, function(row)
local params = {destination_number = destination_number};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "SQL:" .. sql .. "; params: " .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
--set the outbound caller id
if (outbound_caller_id_name ~= nil) then
@ -77,7 +87,8 @@
--transfer the call
session:transfer(row.destination_number, "XML", row.destination_context);
end));
end);
else
--add the function
require "resources.functions.explode";
@ -111,4 +122,4 @@
--transfer the call
session:transfer(var["destination_number"], "XML", var["destination_context"]);
end
end