Add sofia global settings

This commit is contained in:
markjcrane 2021-09-04 22:31:07 -06:00
parent d92797f82a
commit 11fd9ed86b
8 changed files with 1520 additions and 310 deletions

View File

@ -1,310 +1,316 @@
-- xml_handler.lua -- xml_handler.lua
-- Part of FusionPBX -- Part of FusionPBX
-- Copyright (C) 2013 - 2018 Mark J Crane <markjcrane@fusionpbx.com> -- Copyright (C) 2013 - 2018 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved. -- All rights reserved.
-- --
-- Redistribution and use in source and binary forms, with or without -- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met: -- modification, are permitted provided that the following conditions are met:
-- --
-- 1. Redistributions of source code must retain the above copyright notice, -- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer. -- this list of conditions and the following disclaimer.
-- --
-- 2. Redistributions in binary form must reproduce the above copyright -- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the -- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution. -- documentation and/or other materials provided with the distribution.
-- --
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE. -- POSSIBILITY OF SUCH DAMAGE.
--get the cache --get the cache
local cache = require "resources.functions.cache" local cache = require "resources.functions.cache"
local hostname = trim(api:execute("switchname", "")) local hostname = trim(api:execute("switchname", ""))
local sofia_cache_key = "configuration:sofia.conf:" .. hostname local sofia_cache_key = "configuration:sofia.conf:" .. hostname
XML_STRING, err = cache.get(sofia_cache_key) XML_STRING, err = cache.get(sofia_cache_key)
--set the cache --set the cache
if not XML_STRING then if not XML_STRING then
--log cache error --log cache error
if (debug["cache"]) then if (debug["cache"]) then
freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be get from the cache: " .. tostring(err) .. "\n"); freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be get from the cache: " .. tostring(err) .. "\n");
end end
--set a default value --set a default value
if (expire["sofia"] == nil) then if (expire["sofia"] == nil) then
expire["sofia"]= "3600"; expire["sofia"]= "3600";
end end
--connect to the database --connect to the database
local Database = require "resources.functions.database"; local Database = require "resources.functions.database";
dbh = Database.new('system'); dbh = Database.new('system');
--include json library --include json library
local json local json
if (debug["sql"]) then if (debug["sql"]) then
json = require "resources.functions.lunajson" json = require "resources.functions.lunajson"
end end
--exits the script if we didn't connect properly --exits the script if we didn't connect properly
assert(dbh:connected()); assert(dbh:connected());
--get the variables --get the variables
vars = trim(api:execute("global_getvar", "")); vars = trim(api:execute("global_getvar", ""));
--start the xml array --start the xml array
local xml = {} local xml = {}
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]); table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
table.insert(xml, [[<document type="freeswitch/xml">]]); table.insert(xml, [[<document type="freeswitch/xml">]]);
table.insert(xml, [[ <section name="configuration">]]); table.insert(xml, [[ <section name="configuration">]]);
table.insert(xml, [[ <configuration name="sofia.conf" description="sofia Endpoint">]]); table.insert(xml, [[ <configuration name="sofia.conf" description="sofia Endpoint">]]);
table.insert(xml, [[ <global_settings>]]);
table.insert(xml, [[ <param name="log-level" value="0"/>]]); --gt the global settings
--table.insert(xml, [[ <param name="auto-restart" value="false"/>]]); sql = "select * from v_sofia_global_settings ";
table.insert(xml, [[ <param name="debug-presence" value="0"/>]]); sql = sql .. "where global_setting_enabled = 'true' ";
--table.insert(xml, [[ <param name="capture-server" value="udp:homer.domain.com:5060"/>]]); sql = sql .. "order by global_setting_name asc ";
table.insert(xml, [[ </global_settings>]]); local params = {};
table.insert(xml, [[ <profiles>]]); x = 0;
table.insert(xml, [[ <global_settings>]]);
--set defaults dbh:query(sql, params, function(row)
previous_sip_profile_name = ""; table.insert(xml, [[ <param name="]]..row.global_setting_name..[[" value="]]..row.global_setting_value..[["/>]]);
profile_tag_status = "closed"; end)
table.insert(xml, [[ </global_settings>]]);
--run the query
sql = "select p.sip_profile_uuid, p.sip_profile_name, p.sip_profile_description, s.sip_profile_setting_name, s.sip_profile_setting_value "; --set defaults
sql = sql .. "from v_sip_profiles as p, v_sip_profile_settings as s "; previous_sip_profile_name = "";
sql = sql .. "where s.sip_profile_setting_enabled = 'true' "; profile_tag_status = "closed";
sql = sql .. "and p.sip_profile_enabled = 'true' ";
sql = sql .. "and (p.sip_profile_hostname = :hostname or p.sip_profile_hostname is null or p.sip_profile_hostname = '') "; --run the query
sql = sql .. "and p.sip_profile_uuid = s.sip_profile_uuid "; sql = "select p.sip_profile_uuid, p.sip_profile_name, p.sip_profile_description, s.sip_profile_setting_name, s.sip_profile_setting_value ";
sql = sql .. "order by p.sip_profile_name asc "; sql = sql .. "from v_sip_profiles as p, v_sip_profile_settings as s ";
local params = {hostname = hostname}; sql = sql .. "where s.sip_profile_setting_enabled = 'true' ";
if (debug["sql"]) then sql = sql .. "and p.sip_profile_enabled = 'true' ";
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n"); sql = sql .. "and (p.sip_profile_hostname = :hostname or p.sip_profile_hostname is null or p.sip_profile_hostname = '') ";
end sql = sql .. "and p.sip_profile_uuid = s.sip_profile_uuid ";
x = 0; sql = sql .. "order by p.sip_profile_name asc ";
dbh:query(sql, params, function(row) local params = {hostname = hostname};
--set as variables if (debug["sql"]) then
sip_profile_uuid = row.sip_profile_uuid; freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
sip_profile_name = row.sip_profile_name; end
--sip_profile_description = row.sip_profile_description; x = 0;
sip_profile_setting_name = row.sip_profile_setting_name; table.insert(xml, [[ <profiles>]]);
sip_profile_setting_value = row.sip_profile_setting_value; dbh:query(sql, params, function(row)
--set as variables
--open xml tag sip_profile_uuid = row.sip_profile_uuid;
if (sip_profile_name ~= previous_sip_profile_name) then sip_profile_name = row.sip_profile_name;
if (x > 1) then --sip_profile_description = row.sip_profile_description;
table.insert(xml, [[ </settings>]]); sip_profile_setting_name = row.sip_profile_setting_name;
table.insert(xml, [[ </profile>]]); sip_profile_setting_value = row.sip_profile_setting_value;
end
table.insert(xml, [[ <profile name="]]..sip_profile_name..[[">]]); --open xml tag
table.insert(xml, [[ <aliases>]]); if (sip_profile_name ~= previous_sip_profile_name) then
table.insert(xml, [[ </aliases>]]); if (x > 1) then
table.insert(xml, [[ <gateways>]]); table.insert(xml, [[ </settings>]]);
--table.insert(xml, [[ <X-PRE-PROCESS cmd="include" data="]]..sip_profile_name..[[/*.xml"/>]]); table.insert(xml, [[ </profile>]]);
end
--get the gateways table.insert(xml, [[ <profile name="]]..sip_profile_name..[[">]]);
sql = "select * from v_gateways "; table.insert(xml, [[ <aliases>]]);
sql = sql .. "where profile = :profile "; table.insert(xml, [[ </aliases>]]);
sql = sql .. "and enabled = 'true' "; table.insert(xml, [[ <gateways>]]);
sql = sql .. "and (hostname = :hostname or hostname is null or hostname = '') "; --table.insert(xml, [[ <X-PRE-PROCESS cmd="include" data="]]..sip_profile_name..[[/*.xml"/>]]);
local params = {profile = sip_profile_name, hostname = hostname};
if (debug["sql"]) then --get the gateways
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n"); sql = "select * from v_gateways ";
end sql = sql .. "where profile = :profile ";
x = 0; sql = sql .. "and enabled = 'true' ";
dbh:query(sql, params, function(field) sql = sql .. "and (hostname = :hostname or hostname is null or hostname = '') ";
table.insert(xml, [[ <gateway name="]] .. string.lower(field.gateway_uuid) .. [[">]]); local params = {profile = sip_profile_name, hostname = hostname};
if (debug["sql"]) then
if (string.len(field.username) > 0) then freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
table.insert(xml, [[ <param name="username" value="]] .. field.username .. [["/>]]); end
end x = 0;
if (string.len(field.distinct_to) > 0) then dbh:query(sql, params, function(field)
table.insert(xml, [[ <param name="distinct-to" value="]] .. field.distinct_to .. [["/>]]); table.insert(xml, [[ <gateway name="]] .. string.lower(field.gateway_uuid) .. [[">]]);
end
if (string.len(field.auth_username) > 0) then if (string.len(field.username) > 0) then
table.insert(xml, [[ <param name="auth-username" value="]] .. field.auth_username .. [["/>]]); table.insert(xml, [[ <param name="username" value="]] .. field.username .. [["/>]]);
end end
if (string.len(field.password) > 0) then if (string.len(field.distinct_to) > 0) then
table.insert(xml, [[ <param name="password" value="]] .. field.password .. [["/>]]); table.insert(xml, [[ <param name="distinct-to" value="]] .. field.distinct_to .. [["/>]]);
end end
if (string.len(field.realm) > 0) then if (string.len(field.auth_username) > 0) then
table.insert(xml, [[ <param name="realm" value="]] .. field.realm .. [["/>]]); table.insert(xml, [[ <param name="auth-username" value="]] .. field.auth_username .. [["/>]]);
end end
if (string.len(field.from_user) > 0) then if (string.len(field.password) > 0) then
table.insert(xml, [[ <param name="from-user" value="]] .. field.from_user .. [["/>]]); table.insert(xml, [[ <param name="password" value="]] .. field.password .. [["/>]]);
end end
if (string.len(field.from_domain) > 0) then if (string.len(field.realm) > 0) then
table.insert(xml, [[ <param name="from-domain" value="]] .. field.from_domain .. [["/>]]); table.insert(xml, [[ <param name="realm" value="]] .. field.realm .. [["/>]]);
end end
if (string.len(field.proxy) > 0) then if (string.len(field.from_user) > 0) then
table.insert(xml, [[ <param name="proxy" value="]] .. field.proxy .. [["/>]]); table.insert(xml, [[ <param name="from-user" value="]] .. field.from_user .. [["/>]]);
end end
if (string.len(field.register_proxy) > 0) then if (string.len(field.from_domain) > 0) then
table.insert(xml, [[ <param name="register-proxy" value="]] .. field.register_proxy .. [["/>]]); table.insert(xml, [[ <param name="from-domain" value="]] .. field.from_domain .. [["/>]]);
end end
if (string.len(field.outbound_proxy) > 0) then if (string.len(field.proxy) > 0) then
table.insert(xml, [[ <param name="outbound-proxy" value="]] .. field.outbound_proxy .. [["/>]]); table.insert(xml, [[ <param name="proxy" value="]] .. field.proxy .. [["/>]]);
end end
if (string.len(field.expire_seconds) > 0) then if (string.len(field.register_proxy) > 0) then
table.insert(xml, [[ <param name="expire-seconds" value="]] .. field.expire_seconds .. [["/>]]); table.insert(xml, [[ <param name="register-proxy" value="]] .. field.register_proxy .. [["/>]]);
end end
if (string.len(field.register) > 0) then if (string.len(field.outbound_proxy) > 0) then
table.insert(xml, [[ <param name="register" value="]] .. field.register .. [["/>]]); table.insert(xml, [[ <param name="outbound-proxy" value="]] .. field.outbound_proxy .. [["/>]]);
end end
if (string.len(field.expire_seconds) > 0) then
if (field.register_transport) then table.insert(xml, [[ <param name="expire-seconds" value="]] .. field.expire_seconds .. [["/>]]);
if (field.register_transport == "udp") then end
table.insert(xml, [[ <param name="register-transport" value="udp"/>]]); if (string.len(field.register) > 0) then
elseif (field.register_transport == "tcp") then table.insert(xml, [[ <param name="register" value="]] .. field.register .. [["/>]]);
table.insert(xml, [[ <param name="register-transport" value="tcp"/>]]); end
elseif (field.register_transport == "tls") then
table.insert(xml, [[ <param name="register-transport" value="tls"/>]]); if (field.register_transport) then
table.insert(xml, [[ <param name="contact-params" value="transport=tls"/>]]); if (field.register_transport == "udp") then
else table.insert(xml, [[ <param name="register-transport" value="udp"/>]]);
table.insert(xml, [[ <param name="register-transport" value="udp"/>]]); elseif (field.register_transport == "tcp") then
end table.insert(xml, [[ <param name="register-transport" value="tcp"/>]]);
end elseif (field.register_transport == "tls") then
table.insert(xml, [[ <param name="register-transport" value="tls"/>]]);
if (string.len(field.retry_seconds) > 0) then table.insert(xml, [[ <param name="contact-params" value="transport=tls"/>]]);
table.insert(xml, [[ <param name="retry-seconds" value="]] .. field.retry_seconds .. [["/>]]); else
end table.insert(xml, [[ <param name="register-transport" value="udp"/>]]);
if (string.len(field.extension) > 0) then end
table.insert(xml, [[ <param name="extension" value="]] .. field.extension .. [["/>]]); end
end
if (string.len(field.ping) > 0) then if (string.len(field.retry_seconds) > 0) then
table.insert(xml, [[ <param name="ping" value="]] .. field.ping .. [["/>]]); table.insert(xml, [[ <param name="retry-seconds" value="]] .. field.retry_seconds .. [["/>]]);
end end
if (string.len(field.ping_min) > 0) then if (string.len(field.extension) > 0) then
table.insert(xml, [[ <param name="ping-min" value="]] .. field.ping_min .. [["/>]]); table.insert(xml, [[ <param name="extension" value="]] .. field.extension .. [["/>]]);
end end
if (string.len(field.ping_max) > 0) then if (string.len(field.ping) > 0) then
table.insert(xml, [[ <param name="ping-max" value="]] .. field.ping_max .. [["/>]]); table.insert(xml, [[ <param name="ping" value="]] .. field.ping .. [["/>]]);
end end
if (string.len(field.context) > 0) then if (string.len(field.ping_min) > 0) then
table.insert(xml, [[ <param name="context" value="]] .. field.context .. [["/>]]); table.insert(xml, [[ <param name="ping-min" value="]] .. field.ping_min .. [["/>]]);
end end
if (string.len(field.caller_id_in_from) > 0) then if (string.len(field.ping_max) > 0) then
table.insert(xml, [[ <param name="caller-id-in-from" value="]] .. field.caller_id_in_from .. [["/>]]); table.insert(xml, [[ <param name="ping-max" value="]] .. field.ping_max .. [["/>]]);
end end
if (string.len(field.supress_cng) > 0) then if (string.len(field.context) > 0) then
table.insert(xml, [[ <param name="supress-cng" value="]] .. field.supress_cng .. [["/>]]); table.insert(xml, [[ <param name="context" value="]] .. field.context .. [["/>]]);
end end
if (string.len(field.extension_in_contact) > 0) then if (string.len(field.caller_id_in_from) > 0) then
table.insert(xml, [[ <param name="extension-in-contact" value="]] .. field.extension_in_contact .. [["/>]]); table.insert(xml, [[ <param name="caller-id-in-from" value="]] .. field.caller_id_in_from .. [["/>]]);
end end
table.insert(xml, [[ <variables>]]); if (string.len(field.supress_cng) > 0) then
if (string.len(field.sip_cid_type) > 0) then table.insert(xml, [[ <param name="supress-cng" value="]] .. field.supress_cng .. [["/>]]);
table.insert(xml, [[ <variable name="sip_cid_type" value="]] .. field.sip_cid_type .. [["/>]]); end
end if (string.len(field.extension_in_contact) > 0) then
table.insert(xml, [[ </variables>]]); table.insert(xml, [[ <param name="extension-in-contact" value="]] .. field.extension_in_contact .. [["/>]]);
table.insert(xml, [[ </gateway>]]); end
end) table.insert(xml, [[ <variables>]]);
if (string.len(field.sip_cid_type) > 0) then
table.insert(xml, [[ </gateways>]]); table.insert(xml, [[ <variable name="sip_cid_type" value="]] .. field.sip_cid_type .. [["/>]]);
table.insert(xml, [[ <domains>]]); end
table.insert(xml, [[ </variables>]]);
--add sip profile domain: name, alias, and parse table.insert(xml, [[ </gateway>]]);
table.insert(xml, [[ <!-- indicator to parse the directory for domains with parse="true" to get gateways-->]]); end)
table.insert(xml, [[ <!--<domain name="$${domain}" parse="true"/>-->]]);
table.insert(xml, [[ <!-- indicator to parse the directory for domains with parse="true" to get gateways and alias every domain to this profile -->]]); table.insert(xml, [[ </gateways>]]);
table.insert(xml, [[ <!--<domain name="all" alias="true" parse="true"/>-->]]); table.insert(xml, [[ <domains>]]);
sql = "SELECT sip_profile_domain_name, sip_profile_domain_alias, sip_profile_domain_parse FROM v_sip_profile_domains ";
sql = sql .. "WHERE sip_profile_uuid = :sip_profile_uuid"; --add sip profile domain: name, alias, and parse
local params = {sip_profile_uuid = sip_profile_uuid}; table.insert(xml, [[ <!-- indicator to parse the directory for domains with parse="true" to get gateways-->]]);
if (debug["sql"]) then table.insert(xml, [[ <!--<domain name="$${domain}" parse="true"/>-->]]);
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; sip_profile_uuid:" .. sip_profile_uuid .. "\n"); table.insert(xml, [[ <!-- indicator to parse the directory for domains with parse="true" to get gateways and alias every domain to this profile -->]]);
end table.insert(xml, [[ <!--<domain name="all" alias="true" parse="true"/>-->]]);
dbh:query(sql, params, function(row) sql = "SELECT sip_profile_domain_name, sip_profile_domain_alias, sip_profile_domain_parse FROM v_sip_profile_domains ";
name = row.sip_profile_domain_name; sql = sql .. "WHERE sip_profile_uuid = :sip_profile_uuid";
alias = row.sip_profile_domain_alias; local params = {sip_profile_uuid = sip_profile_uuid};
parse = row.sip_profile_domain_parse; if (debug["sql"]) then
if (name == nil or name == '') then name = 'false'; end freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "; sip_profile_uuid:" .. sip_profile_uuid .. "\n");
if (alias == nil or alias == '') then alias = 'false'; end end
if (parse == nil or parse == '') then parse = 'false'; end dbh:query(sql, params, function(row)
table.insert(xml, [[ <domain name="]] .. name .. [[" alias="]] .. alias .. [[" parse="]] .. parse .. [["/>]]); name = row.sip_profile_domain_name;
end); alias = row.sip_profile_domain_alias;
parse = row.sip_profile_domain_parse;
table.insert(xml, [[ </domains>]]); if (name == nil or name == '') then name = 'false'; end
table.insert(xml, [[ <settings>]]); if (alias == nil or alias == '') then alias = 'false'; end
profile_tag_status = "open"; if (parse == nil or parse == '') then parse = 'false'; end
end table.insert(xml, [[ <domain name="]] .. name .. [[" alias="]] .. alias .. [[" parse="]] .. parse .. [["/>]]);
end);
--loop through the var array
for line in (vars.."\n"):gmatch"(.-)\n" do table.insert(xml, [[ </domains>]]);
if (line) then table.insert(xml, [[ <settings>]]);
pos = string.find(line, "=", 0, true); profile_tag_status = "open";
--name = string.sub( line, 0, pos-1); end
--value = string.sub( line, pos+1);
sip_profile_setting_value = sip_profile_setting_value:gsub("%$%${"..string.sub( line, 0, pos-1).."}", string.sub( line, pos+1)); --loop through the var array
end for line in (vars.."\n"):gmatch"(.-)\n" do
end if (line) then
pos = string.find(line, "=", 0, true);
--remove $ and replace with "" --name = string.sub( line, 0, pos-1);
--if (sip_profile_setting_value) then --value = string.sub( line, pos+1);
-- sip_profile_setting_value = sip_profile_setting_value:gsub("%$", ""); sip_profile_setting_value = sip_profile_setting_value:gsub("%$%${"..string.sub( line, 0, pos-1).."}", string.sub( line, pos+1));
--end end
end
--set the parameters
if (sip_profile_setting_name) then --remove $ and replace with ""
table.insert(xml, [[ <param name="]]..sip_profile_setting_name..[[" value="]]..sip_profile_setting_value..[["/>]]); --if (sip_profile_setting_value) then
end -- sip_profile_setting_value = sip_profile_setting_value:gsub("%$", "");
--end
--set the previous value
previous_sip_profile_name = sip_profile_name; --set the parameters
if (sip_profile_setting_name) then
--increment the value of x table.insert(xml, [[ <param name="]]..sip_profile_setting_name..[[" value="]]..sip_profile_setting_value..[["/>]]);
x = x + 1; end
end)
--set the previous value
--close the extension tag if it was left open previous_sip_profile_name = sip_profile_name;
if (profile_tag_status == "open") then
table.insert(xml, [[ </settings>]]); --increment the value of x
table.insert(xml, [[ </profile>]]); x = x + 1;
profile_tag_status = "close"; end)
end
table.insert(xml, [[ </profiles>]]); --close the extension tag if it was left open
table.insert(xml, [[ </configuration>]]); if (profile_tag_status == "open") then
table.insert(xml, [[ </section>]]); table.insert(xml, [[ </settings>]]);
table.insert(xml, [[</document>]]); table.insert(xml, [[ </profile>]]);
XML_STRING = table.concat(xml, "\n"); profile_tag_status = "close";
if (debug["xml_string"]) then end
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n"); table.insert(xml, [[ </profiles>]]);
end table.insert(xml, [[ </configuration>]]);
table.insert(xml, [[ </section>]]);
--close the database connection table.insert(xml, [[</document>]]);
dbh:release(); XML_STRING = table.concat(xml, "\n");
if (debug["xml_string"]) then
--set the cache freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: " .. XML_STRING .. "\n");
local ok, err = cache.set(sofia_cache_key, XML_STRING, expire["sofia"]) end
if debug["cache"] then
if ok then --close the database connection
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " stored in the cache\n"); dbh:release();
else
freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be stored in the cache: " .. tostring(err) .. "\n"); --set the cache
end local ok, err = cache.set(sofia_cache_key, XML_STRING, expire["sofia"])
end if debug["cache"] then
if ok then
--send to the console freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " stored in the cache\n");
if (debug["cache"]) then else
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: database\n"); freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be stored in the cache: " .. tostring(err) .. "\n");
end end
else end
--send to the console
if (debug["cache"]) then --send to the console
freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: cache\n"); if (debug["cache"]) then
end freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: database\n");
end --if XML_STRING end
else
--send the xml to the console --send to the console
if (debug["xml_string"]) then if (debug["cache"]) then
local file = assert(io.open(temp_dir .. "/sofia.conf.xml", "w")); freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: cache\n");
file:write(XML_STRING); end
file:close(); end --if XML_STRING
end
--send the xml to the console
if (debug["xml_string"]) then
local file = assert(io.open(temp_dir .. "/sofia.conf.xml", "w"));
file:write(XML_STRING);
file:close();
end

View File

@ -0,0 +1,67 @@
<?php
//application details
$apps[$x]['name'] = 'sofia_global_settings';
$apps[$x]['uuid'] = '240c25a3-a2cf-44ea-a300-0626eca5b945';
$apps[$x]['category'] = '';
$apps[$x]['subcategory'] = '';
$apps[$x]['version'] = '';
$apps[$x]['license'] = 'Mozilla Public License 1.1';
$apps[$x]['url'] = 'http://www.fusionpbx.com';
$apps[$x]['description']['en-us'] = '';
//permission details
$y = 0;
$apps[$x]['permissions'][$y]['name'] = 'sofia_global_setting_view';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
//$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'sofia_global_setting_add';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
//$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'sofia_global_setting_edit';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
//$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'sofia_global_setting_delete';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
//$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'sofia_global_setting_all';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
//sofia_global_settings
$y = 0;
$apps[$x]['db'][$y]['table']['name'] = 'v_sofia_global_settings';
$apps[$x]['db'][$y]['table']['parent'] = '';
$z = 0;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'sofia_global_setting_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'global_setting_name';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['search_by'] = '';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the global setting name.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'global_setting_value';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['search_by'] = '';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the global setting value.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'global_setting_enabled';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'boolean';
$apps[$x]['db'][$y]['fields'][$z]['toggle'] = ['true','false'];
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the global setting enabled.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'global_setting_description';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['search_by'] = '';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the global setting description.';
$z++;
?>

View File

@ -0,0 +1,46 @@
<?php
if ($domains_processed == 1) {
//build array
$x = 0;
$array['sofia_global_settings'][$x]['sofia_global_setting_uuid'] = '9a0e83b3-e71c-4a9a-9f1c-680d32f756f8';
$array['sofia_global_settings'][$x]['global_setting_name'] = 'log-level';
$array['sofia_global_settings'][$x]['global_setting_value'] = '0';
$array['sofia_global_settings'][$x]['global_setting_enabled'] = 'true';
$array['sofia_global_settings'][$x]['global_setting_description'] = '';
$x++;
$array['sofia_global_settings'][$x]['sofia_global_setting_uuid'] = 'c2aa551a-b6d2-49a6-b633-21b5b1ddd5df';
$array['sofia_global_settings'][$x]['global_setting_name'] = 'auto-restart';
$array['sofia_global_settings'][$x]['global_setting_value'] = 'true';
$array['sofia_global_settings'][$x]['global_setting_enabled'] = 'true';
$array['sofia_global_settings'][$x]['global_setting_description'] = '';
$x++;
$array['sofia_global_settings'][$x]['sofia_global_setting_uuid'] = 'a9901c0c-efd8-4e66-9648-239566af576e';
$array['sofia_global_settings'][$x]['global_setting_name'] = 'debug-presence';
$array['sofia_global_settings'][$x]['global_setting_value'] = '0';
$array['sofia_global_settings'][$x]['global_setting_enabled'] = 'true';
$array['sofia_global_settings'][$x]['global_setting_description'] = '';
$x++;
$array['sofia_global_settings'][$x]['sofia_global_setting_uuid'] = '31054912-3b07-422d-a109-b995fd8d67f7';
$array['sofia_global_settings'][$x]['global_setting_name'] = 'capture-server';
$array['sofia_global_settings'][$x]['global_setting_value'] = 'udp:127.0.0.1:9060';
$array['sofia_global_settings'][$x]['global_setting_enabled'] = 'false';
$array['sofia_global_settings'][$x]['global_setting_description'] = '';
//grant temporary permissions
$p = new permissions;
$p->add('sofia_global_setting_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'sofia_global_settings';
$database->app_uuid = '240c25a3-a2cf-44ea-a300-0626eca5b945';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('sofia_global_setting_add', 'temp');
}
?>

View File

@ -0,0 +1,224 @@
<?php
//Sofia Global Settings
$text['title-sofia_global_settings']['en-us'] = 'Sofia Global Settings';
$text['title-sofia_global_settings']['ar-eg'] = '';
$text['title-sofia_global_settings']['de-at'] = '';
$text['title-sofia_global_settings']['de-ch'] = '';
$text['title-sofia_global_settings']['de-de'] = '';
$text['title-sofia_global_settings']['es-cl'] = '';
$text['title-sofia_global_settings']['es-mx'] = '';
$text['title-sofia_global_settings']['fr-ca'] = '';
$text['title-sofia_global_settings']['fr-fr'] = '';
$text['title-sofia_global_settings']['he-il'] = '';
$text['title-sofia_global_settings']['it-it'] = '';
$text['title-sofia_global_settings']['nl-nl'] = '';
$text['title-sofia_global_settings']['pl-pl'] = '';
$text['title-sofia_global_settings']['pt-br'] = '';
$text['title-sofia_global_settings']['pt-pt'] = '';
$text['title-sofia_global_settings']['ro-ro'] = '';
$text['title-sofia_global_settings']['ru-ru'] = '';
$text['title-sofia_global_settings']['sv-se'] = '';
$text['title-sofia_global_settings']['uk-ua'] = '';
$text['title-sofia_global_setting']['en-us'] = 'Sofia Global Setting';
$text['title-sofia_global_setting']['ar-eg'] = '';
$text['title-sofia_global_setting']['de-at'] = '';
$text['title-sofia_global_setting']['de-ch'] = '';
$text['title-sofia_global_setting']['de-de'] = '';
$text['title-sofia_global_setting']['es-cl'] = '';
$text['title-sofia_global_setting']['es-mx'] = '';
$text['title-sofia_global_setting']['fr-ca'] = '';
$text['title-sofia_global_setting']['fr-fr'] = '';
$text['title-sofia_global_setting']['he-il'] = '';
$text['title-sofia_global_setting']['it-it'] = '';
$text['title-sofia_global_setting']['nl-nl'] = '';
$text['title-sofia_global_setting']['pl-pl'] = '';
$text['title-sofia_global_setting']['pt-br'] = '';
$text['title-sofia_global_setting']['pt-pt'] = '';
$text['title-sofia_global_setting']['ro-ro'] = '';
$text['title-sofia_global_setting']['ru-ru'] = '';
$text['title-sofia_global_setting']['sv-se'] = '';
$text['title-sofia_global_setting']['uk-ua'] = '';
$text['title_description-sofia_global_settings']['en-us'] = 'Used to define sofia global settings.';
$text['title_description-sofia_global_settings']['ar-eg'] = '';
$text['title_description-sofia_global_settings']['de-at'] = '';
$text['title_description-sofia_global_settings']['de-ch'] = '';
$text['title_description-sofia_global_settings']['de-de'] = '';
$text['title_description-sofia_global_settings']['es-cl'] = '';
$text['title_description-sofia_global_settings']['es-mx'] = '';
$text['title_description-sofia_global_settings']['fr-ca'] = '';
$text['title_description-sofia_global_settings']['fr-fr'] = '';
$text['title_description-sofia_global_settings']['he-il'] = '';
$text['title_description-sofia_global_settings']['it-it'] = '';
$text['title_description-sofia_global_settings']['nl-nl'] = '';
$text['title_description-sofia_global_settings']['pl-pl'] = '';
$text['title_description-sofia_global_settings']['pt-br'] = '';
$text['title_description-sofia_global_settings']['pt-pt'] = '';
$text['title_description-sofia_global_settings']['ro-ro'] = '';
$text['title_description-sofia_global_settings']['ru-ru'] = '';
$text['title_description-sofia_global_settings']['sv-se'] = '';
$text['title_description-sofia_global_settings']['uk-ua'] = '';
$text['label-global_setting_name']['en-us'] = 'Name';
$text['label-global_setting_name']['ar-eg'] = '';
$text['label-global_setting_name']['de-at'] = '';
$text['label-global_setting_name']['de-ch'] = '';
$text['label-global_setting_name']['de-de'] = '';
$text['label-global_setting_name']['es-cl'] = '';
$text['label-global_setting_name']['es-mx'] = '';
$text['label-global_setting_name']['fr-ca'] = '';
$text['label-global_setting_name']['fr-fr'] = '';
$text['label-global_setting_name']['he-il'] = '';
$text['label-global_setting_name']['it-it'] = '';
$text['label-global_setting_name']['nl-nl'] = '';
$text['label-global_setting_name']['pl-pl'] = '';
$text['label-global_setting_name']['pt-br'] = '';
$text['label-global_setting_name']['pt-pt'] = '';
$text['label-global_setting_name']['ro-ro'] = '';
$text['label-global_setting_name']['ru-ru'] = '';
$text['label-global_setting_name']['sv-se'] = '';
$text['label-global_setting_name']['uk-ua'] = '';
$text['description-global_setting_name']['en-us'] = 'Enter the global setting name.';
$text['description-global_setting_name']['ar-eg'] = '';
$text['description-global_setting_name']['de-at'] = '';
$text['description-global_setting_name']['de-ch'] = '';
$text['description-global_setting_name']['de-de'] = '';
$text['description-global_setting_name']['es-cl'] = '';
$text['description-global_setting_name']['es-mx'] = '';
$text['description-global_setting_name']['fr-ca'] = '';
$text['description-global_setting_name']['fr-fr'] = '';
$text['description-global_setting_name']['he-il'] = '';
$text['description-global_setting_name']['it-it'] = '';
$text['description-global_setting_name']['nl-nl'] = '';
$text['description-global_setting_name']['pl-pl'] = '';
$text['description-global_setting_name']['pt-br'] = '';
$text['description-global_setting_name']['pt-pt'] = '';
$text['description-global_setting_name']['ro-ro'] = '';
$text['description-global_setting_name']['ru-ru'] = '';
$text['description-global_setting_name']['sv-se'] = '';
$text['description-global_setting_name']['uk-ua'] = '';
$text['label-global_setting_value']['en-us'] = 'Value';
$text['label-global_setting_value']['ar-eg'] = '';
$text['label-global_setting_value']['de-at'] = '';
$text['label-global_setting_value']['de-ch'] = '';
$text['label-global_setting_value']['de-de'] = '';
$text['label-global_setting_value']['es-cl'] = '';
$text['label-global_setting_value']['es-mx'] = '';
$text['label-global_setting_value']['fr-ca'] = '';
$text['label-global_setting_value']['fr-fr'] = '';
$text['label-global_setting_value']['he-il'] = '';
$text['label-global_setting_value']['it-it'] = '';
$text['label-global_setting_value']['nl-nl'] = '';
$text['label-global_setting_value']['pl-pl'] = '';
$text['label-global_setting_value']['pt-br'] = '';
$text['label-global_setting_value']['pt-pt'] = '';
$text['label-global_setting_value']['ro-ro'] = '';
$text['label-global_setting_value']['ru-ru'] = '';
$text['label-global_setting_value']['sv-se'] = '';
$text['label-global_setting_value']['uk-ua'] = '';
$text['description-global_setting_value']['en-us'] = 'Enter the global setting value.';
$text['description-global_setting_value']['ar-eg'] = '';
$text['description-global_setting_value']['de-at'] = '';
$text['description-global_setting_value']['de-ch'] = '';
$text['description-global_setting_value']['de-de'] = '';
$text['description-global_setting_value']['es-cl'] = '';
$text['description-global_setting_value']['es-mx'] = '';
$text['description-global_setting_value']['fr-ca'] = '';
$text['description-global_setting_value']['fr-fr'] = '';
$text['description-global_setting_value']['he-il'] = '';
$text['description-global_setting_value']['it-it'] = '';
$text['description-global_setting_value']['nl-nl'] = '';
$text['description-global_setting_value']['pl-pl'] = '';
$text['description-global_setting_value']['pt-br'] = '';
$text['description-global_setting_value']['pt-pt'] = '';
$text['description-global_setting_value']['ro-ro'] = '';
$text['description-global_setting_value']['ru-ru'] = '';
$text['description-global_setting_value']['sv-se'] = '';
$text['description-global_setting_value']['uk-ua'] = '';
$text['label-global_setting_enabled']['en-us'] = 'Enabled';
$text['label-global_setting_enabled']['ar-eg'] = '';
$text['label-global_setting_enabled']['de-at'] = '';
$text['label-global_setting_enabled']['de-ch'] = '';
$text['label-global_setting_enabled']['de-de'] = '';
$text['label-global_setting_enabled']['es-cl'] = '';
$text['label-global_setting_enabled']['es-mx'] = '';
$text['label-global_setting_enabled']['fr-ca'] = '';
$text['label-global_setting_enabled']['fr-fr'] = '';
$text['label-global_setting_enabled']['he-il'] = '';
$text['label-global_setting_enabled']['it-it'] = '';
$text['label-global_setting_enabled']['nl-nl'] = '';
$text['label-global_setting_enabled']['pl-pl'] = '';
$text['label-global_setting_enabled']['pt-br'] = '';
$text['label-global_setting_enabled']['pt-pt'] = '';
$text['label-global_setting_enabled']['ro-ro'] = '';
$text['label-global_setting_enabled']['ru-ru'] = '';
$text['label-global_setting_enabled']['sv-se'] = '';
$text['label-global_setting_enabled']['uk-ua'] = '';
$text['description-global_setting_enabled']['en-us'] = 'Enter the global setting enabled.';
$text['description-global_setting_enabled']['ar-eg'] = '';
$text['description-global_setting_enabled']['de-at'] = '';
$text['description-global_setting_enabled']['de-ch'] = '';
$text['description-global_setting_enabled']['de-de'] = '';
$text['description-global_setting_enabled']['es-cl'] = '';
$text['description-global_setting_enabled']['es-mx'] = '';
$text['description-global_setting_enabled']['fr-ca'] = '';
$text['description-global_setting_enabled']['fr-fr'] = '';
$text['description-global_setting_enabled']['he-il'] = '';
$text['description-global_setting_enabled']['it-it'] = '';
$text['description-global_setting_enabled']['nl-nl'] = '';
$text['description-global_setting_enabled']['pl-pl'] = '';
$text['description-global_setting_enabled']['pt-br'] = '';
$text['description-global_setting_enabled']['pt-pt'] = '';
$text['description-global_setting_enabled']['ro-ro'] = '';
$text['description-global_setting_enabled']['ru-ru'] = '';
$text['description-global_setting_enabled']['sv-se'] = '';
$text['description-global_setting_enabled']['uk-ua'] = '';
$text['label-global_setting_description']['en-us'] = 'Description';
$text['label-global_setting_description']['ar-eg'] = '';
$text['label-global_setting_description']['de-at'] = '';
$text['label-global_setting_description']['de-ch'] = '';
$text['label-global_setting_description']['de-de'] = '';
$text['label-global_setting_description']['es-cl'] = '';
$text['label-global_setting_description']['es-mx'] = '';
$text['label-global_setting_description']['fr-ca'] = '';
$text['label-global_setting_description']['fr-fr'] = '';
$text['label-global_setting_description']['he-il'] = '';
$text['label-global_setting_description']['it-it'] = '';
$text['label-global_setting_description']['nl-nl'] = '';
$text['label-global_setting_description']['pl-pl'] = '';
$text['label-global_setting_description']['pt-br'] = '';
$text['label-global_setting_description']['pt-pt'] = '';
$text['label-global_setting_description']['ro-ro'] = '';
$text['label-global_setting_description']['ru-ru'] = '';
$text['label-global_setting_description']['sv-se'] = '';
$text['label-global_setting_description']['uk-ua'] = '';
$text['description-global_setting_description']['en-us'] = 'Enter the global setting description.';
$text['description-global_setting_description']['ar-eg'] = '';
$text['description-global_setting_description']['de-at'] = '';
$text['description-global_setting_description']['de-ch'] = '';
$text['description-global_setting_description']['de-de'] = '';
$text['description-global_setting_description']['es-cl'] = '';
$text['description-global_setting_description']['es-mx'] = '';
$text['description-global_setting_description']['fr-ca'] = '';
$text['description-global_setting_description']['fr-fr'] = '';
$text['description-global_setting_description']['he-il'] = '';
$text['description-global_setting_description']['it-it'] = '';
$text['description-global_setting_description']['nl-nl'] = '';
$text['description-global_setting_description']['pl-pl'] = '';
$text['description-global_setting_description']['pt-br'] = '';
$text['description-global_setting_description']['pt-pt'] = '';
$text['description-global_setting_description']['ro-ro'] = '';
$text['description-global_setting_description']['ru-ru'] = '';
$text['description-global_setting_description']['sv-se'] = '';
$text['description-global_setting_description']['uk-ua'] = '';
?>

View File

@ -0,0 +1,261 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2019 - 2021
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
/**
* sofia_global_settings class
*
* @method null delete
* @method null toggle
* @method null copy
*/
if (!class_exists('sofia_global_settings')) {
class sofia_global_settings {
/**
* declare the variables
*/
private $app_name;
private $app_uuid;
private $name;
private $table;
private $toggle_field;
private $toggle_values;
private $description_field;
private $location;
/**
* called when the object is created
*/
public function __construct() {
//assign the variables
$this->app_name = 'sofia_global_settings';
$this->app_uuid = '240c25a3-a2cf-44ea-a300-0626eca5b945';
$this->name = 'sofia_global_setting';
$this->table = 'sofia_global_settings';
$this->toggle_field = 'global_setting_enabled';
$this->toggle_values = ['true','false'];
$this->description_field = 'global_setting_description';
$this->location = 'sofia_global_settings.php';
}
/**
* called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* delete rows from the database
*/
public function delete($records) {
if (permission_exists($this->name.'_delete')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
$x = 0;
foreach ($records as $record) {
//add to the array
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x]['sofia_global_setting_uuid'] = $record['sofia_global_setting_uuid'];
}
//increment the id
$x++;
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
}
/**
* toggle a field between two values
*/
public function toggle($records) {
if (permission_exists($this->name.'_edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $record) {
if ($record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
$uuids[] = "'".$record['sofia_global_setting_uuid']."'";
}
}
if (is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($states as $uuid => $state) {
//create the array
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
//increment the id
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
}
/**
* copy rows from the database
*/
public function copy($records) {
if (permission_exists($this->name.'_add')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//copy the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get checked records
foreach($records as $record) {
if ($record['checked'] == 'true' && is_uuid(sofia_global_setting_uuid')) {
$uuids[] = "'".$record['sofia_global_setting_uuid']."'";
}
}
//create the array from existing data
if (is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select * from v_".$this->table." ";
$sql .= "where sofia_global_setting_uuid in (".implode(', ', $uuids).") ";
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
$x = 0;
foreach ($rows as $row) {
//copy data
$array[$this->table][$x] = $row;
//add copy to the description
$array[$this->table][$x][sofia_global_setting.'_uuid'] = uuid();
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]).' ('.$text['label-copy'].')';
//increment the id
$x++;
}
}
unset($sql, $parameters, $rows, $row);
}
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-copy']);
}
unset($records);
}
}
}
}
}
?>

View File

@ -0,0 +1,90 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
// make sure the PATH_SEPARATOR is defined
umask(2);
if (!defined("PATH_SEPARATOR")) {
if (strpos($_ENV["OS"], "Win") !== false) {
define("PATH_SEPARATOR", ";");
} else {
define("PATH_SEPARATOR", ":");
}
}
if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html';
// make sure the document_root is set
$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]);
if(PHP_SAPI == 'cli'){
chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME));
$script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]);
$dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME));
if (file_exists('/project_root.php')) {
$path = '/';
} else {
$i = 1;
$path = '';
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
}
$_SERVER["DOCUMENT_ROOT"] = $path;
}else{
$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
}
$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
// try to detect if a project path is being used
if (!defined('PROJECT_PATH')) {
if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) {
define('PROJECT_PATH', '/fusionpbx');
} elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) {
define('PROJECT_PATH', '');
} else {
$dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)));
$i = 1;
$path = $_SERVER["DOCUMENT_ROOT"];
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
if(!file_exists($path. '/project_root.php')){
die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance");
}
$project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
define('PROJECT_PATH', $project_path);
}
$_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH);
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]);
}
?>

View File

@ -0,0 +1,267 @@
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('sofia_global_setting_add') || permission_exists('sofia_global_setting_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//action add or update
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$sofia_global_setting_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (is_array($_POST)) {
$global_setting_name = $_POST["global_setting_name"];
$global_setting_value = $_POST["global_setting_value"];
$global_setting_enabled = $_POST["global_setting_enabled"];
$global_setting_description = $_POST["global_setting_description"];
}
//process the user data and save it to the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: sofia_global_settings.php');
exit;
}
//process the http post data by submitted action
if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
//prepare the array(s)
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('sofia_global_setting_add')) {
$obj = new database;
$obj->copy($array);
}
break;
case 'delete':
if (permission_exists('sofia_global_setting_delete')) {
$obj = new database;
$obj->delete($array);
}
break;
case 'toggle':
if (permission_exists('sofia_global_setting_update')) {
$obj = new database;
$obj->toggle($array);
}
break;
}
//redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
header('Location: sofia_global_setting_edit.php?id='.$id);
exit;
}
}
//check for all required data
$msg = '';
if (strlen($global_setting_name) == 0) { $msg .= $text['message-required']." ".$text['label-global_setting_name']."<br>\n"; }
if (strlen($global_setting_value) == 0) { $msg .= $text['message-required']." ".$text['label-global_setting_value']."<br>\n"; }
if (strlen($global_setting_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-global_setting_enabled']."<br>\n"; }
//if (strlen($global_setting_description) == 0) { $msg .= $text['message-required']." ".$text['label-global_setting_description']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add the sofia_global_setting_uuid
if (!is_uuid($_POST["sofia_global_setting_uuid"])) {
$sofia_global_setting_uuid = uuid();
}
//prepare the array
$array['sofia_global_settings'][0]['sofia_global_setting_uuid'] = $sofia_global_setting_uuid;
$array['sofia_global_settings'][0]['global_setting_name'] = $global_setting_name;
$array['sofia_global_settings'][0]['global_setting_value'] = $global_setting_value;
$array['sofia_global_settings'][0]['global_setting_enabled'] = $global_setting_enabled;
$array['sofia_global_settings'][0]['global_setting_description'] = $global_setting_description;
//save the data
$database = new database;
$database->app_name = 'sofia_global_settings';
$database->app_uuid = '240c25a3-a2cf-44ea-a300-0626eca5b945';
$database->save($array);
//redirect the user
if (isset($action)) {
if ($action == "add") {
$_SESSION["message"] = $text['message-add'];
}
if ($action == "update") {
$_SESSION["message"] = $text['message-update'];
}
//header('Location: sofia_global_settings.php');
header('Location: sofia_global_setting_edit.php?id='.urlencode($sofia_global_setting_uuid));
return;
}
}
//pre-populate the form
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
$sql = "select ";
$sql .= " sofia_global_setting_uuid, ";
$sql .= " global_setting_name, ";
$sql .= " global_setting_value, ";
$sql .= " cast(global_setting_enabled as text), ";
$sql .= " global_setting_description ";
$sql .= "from v_sofia_global_settings ";
$sql .= "where sofia_global_setting_uuid = :sofia_global_setting_uuid ";
$parameters['sofia_global_setting_uuid'] = $sofia_global_setting_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$global_setting_name = $row["global_setting_name"];
$global_setting_value = $row["global_setting_value"];
$global_setting_enabled = $row["global_setting_enabled"];
$global_setting_description = $row["global_setting_description"];
}
unset($sql, $parameters, $row);
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//show the header
$document['title'] = $text['title-sofia_global_setting'];
require_once "resources/header.php";
//show the content
echo "<form name='frm' id='frm' method='post' action=''>\n";
echo "<input class='formfld' type='hidden' name='sofia_global_setting_uuid' value='".escape($sofia_global_setting_uuid)."'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-sofia_global_setting']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'sofia_global_settings.php']);
if ($action == 'update') {
if (permission_exists('_add')) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
}
if (permission_exists('_delete')) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
}
}
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['title_description-sofia_global_settings']."\n";
echo "<br /><br />\n";
if ($action == 'update') {
if (permission_exists('sofia_global_setting_add')) {
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]);
}
if (permission_exists('sofia_global_setting_delete')) {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
}
}
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-global_setting_name']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='global_setting_name' maxlength='255' value='".escape($global_setting_name)."'>\n";
echo "<br />\n";
echo $text['description-global_setting_name']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-global_setting_value']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='global_setting_value' maxlength='255' value='".escape($global_setting_value)."'>\n";
echo "<br />\n";
echo $text['description-global_setting_value']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-global_setting_enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='global_setting_enabled'>\n";
echo " <option value=''></option>\n";
if ($global_setting_enabled == "true") {
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
}
else {
echo " <option value='true'>".$text['label-true']."</option>\n";
}
if ($global_setting_enabled == "false") {
echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
}
else {
echo " <option value='false'>".$text['label-false']."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-global_setting_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-global_setting_description']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='global_setting_description' maxlength='255' value='".escape($global_setting_description)."'>\n";
echo "<br />\n";
echo $text['description-global_setting_description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "<br /><br />";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>";
//include the footer
require_once "resources/footer.php";
?>

View File

@ -0,0 +1,249 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2018 - 2021
the Initial Developer. All Rights Reserved.
*/
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('sofia_global_setting_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the http post data
if (is_array($_POST['sofia_global_settings'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$sofia_global_settings = $_POST['sofia_global_settings'];
}
//process the http post data by action
if ($action != '' && is_array($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) {
switch ($action) {
case 'copy':
if (permission_exists('sofia_global_setting_add')) {
$obj = new sofia_global_settings;
$obj->copy($sofia_global_settings);
}
break;
case 'toggle':
if (permission_exists('sofia_global_setting_edit')) {
$obj = new sofia_global_settings;
$obj->toggle($sofia_global_settings);
}
break;
case 'delete':
if (permission_exists('sofia_global_setting_delete')) {
$obj = new sofia_global_settings;
$obj->delete($sofia_global_settings);
}
break;
}
//redirect the user
header('Location: sofia_global_settings.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
//get order and order by
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//add the search
if (isset($_GET["search"])) {
$search = strtolower($_GET["search"]);
}
//get the count
$sql = "select count(sofia_global_setting_uuid) ";
$sql .= "from v_sofia_global_settings ";
if (isset($search)) {
$sql .= "where (";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = $search ? "&search=".$search : null;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list
$sql = "select ";
$sql .= "sofia_global_setting_uuid, ";
$sql .= "global_setting_name, ";
$sql .= "global_setting_value, ";
$sql .= "cast(global_setting_enabled as text), ";
$sql .= "global_setting_description ";
$sql .= "from v_sofia_global_settings ";
if (isset($_GET["search"])) {
$sql .= "where (";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
$sql .= order_by($order_by, $order, 'global_setting_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$sofia_global_settings = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//additional includes
$document['title'] = $text['title-sofia_global_settings'];
require_once "resources/header.php";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-sofia_global_settings']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
if (permission_exists('sofia_global_setting_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'sofia_global_setting_edit.php']);
}
if (permission_exists('sofia_global_setting_add') && $sofia_global_settings) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
}
if (permission_exists('sofia_global_setting_edit') && $sofia_global_settings) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
}
if (permission_exists('sofia_global_setting_delete') && $sofia_global_settings) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'sofia_global_settings.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('sofia_global_setting_add') && $sofia_global_settings) {
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
}
if (permission_exists('sofia_global_setting_edit') && $sofia_global_settings) {
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
}
if (permission_exists('sofia_global_setting_delete') && $sofia_global_settings) {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
}
echo $text['title_description-sofia_global_settings']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('sofia_global_setting_add') || permission_exists('sofia_global_setting_edit') || permission_exists('sofia_global_setting_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($sofia_global_settings ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo th_order_by('global_setting_name', $text['label-global_setting_name'], $order_by, $order);
echo th_order_by('global_setting_value', $text['label-global_setting_value'], $order_by, $order);
echo th_order_by('global_setting_enabled', $text['label-global_setting_enabled'], $order_by, $order, null, "class='center'");
echo " <th class='hide-sm-dn'>".$text['label-global_setting_description']."</th>\n";
if (permission_exists('sofia_global_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
if (is_array($sofia_global_settings) && @sizeof($sofia_global_settings) != 0) {
$x = 0;
foreach ($sofia_global_settings as $row) {
if (permission_exists('sofia_global_setting_edit')) {
$list_row_url = "sofia_global_setting_edit.php?id=".urlencode($row['sofia_global_setting_uuid']);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('sofia_global_setting_add') || permission_exists('sofia_global_setting_edit') || permission_exists('sofia_global_setting_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='sofia_global_settings[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='sofia_global_settings[$x][sofia_global_setting_uuid]' value='".escape($row['sofia_global_setting_uuid'])."' />\n";
echo " </td>\n";
}
echo " <td>\n";
if (permission_exists('sofia_global_setting_edit')) {
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['global_setting_name'])."</a>\n";
}
else {
echo " ".escape($row['global_setting_name']);
}
echo " </td>\n";
echo " <td>".escape($row['global_setting_value'])."</td>\n";
if (permission_exists('sofia_global_setting_edit')) {
echo " <td class='no-link center'>\n";
echo " <input type='hidden' name='number_translations[$x][global_setting_enabled]' value='".escape($row['global_setting_enabled'])."' />\n";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['global_setting_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
else {
echo " <td class='center'>\n";
echo $text['label-'.$row['global_setting_enabled']];
}
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['global_setting_description'])."</td>\n";
if (permission_exists('sofia_global_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>\n";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";
$x++;
}
unset($sofia_global_settings);
}
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//include the footer
require_once "resources/footer.php";
?>