Add. user parameters to build query for mod_directory. (#2091)

This commit is contained in:
Alexey Melnichuk 2016-11-18 20:37:16 +03:00 committed by FusionPBX
parent 5e4a9eec11
commit c36cbe2771
1 changed files with 11 additions and 3 deletions

View File

@ -1,8 +1,15 @@
--connect to the database
local Database = require "resources.functions.database"
local log = require "resources.functions.log"["directory_dir"]
local dbh = Database.new('system')
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
--build the xml
local xml = {}
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]])
@ -14,13 +21,14 @@
sql = sql .. "where d.domain_uuid = e.domain_uuid and "
sql = sql .. "(e.directory_visible = 'true' or e.directory_exten_visible='true') "
if domain_name then
sql = sql .. "and d.domain_name = '"..domain_name.."' "
sql = sql .. "and d.domain_name = :domain_name"
else
sql = sql .. "order by d.domain_name"
end
local sql_params = {domain_name = domain_name}
if debug['sql'] then
log.noticef("SQL - %s", sql)
log.noticef("SQL: %s; params: %s", sql, json.encode(sql_params))
end
-- export this params
@ -37,7 +45,7 @@
local prev_domain_name
dbh:query(sql, function(row)
dbh:query(sql, sql_params, function(row)
if prev_domain_name ~= row.domain_name then
if prev_domain_name then
table.insert(xml, [[ </users>]])