2012-10-11 02:08:51 +02:00
|
|
|
<?php
|
2012-10-11 08:36:24 +02:00
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
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/
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
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.
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
The Original Code is FusionPBX
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2016-09-11 01:33:47 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2016
|
2012-10-11 08:36:24 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
sreis
|
|
|
|
|
*/
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2016-04-15 07:23:14 +02:00
|
|
|
if (!class_exists('domains')) {
|
2012-10-11 08:36:24 +02:00
|
|
|
class domains {
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2016-04-15 06:10:47 +02:00
|
|
|
//define variables
|
|
|
|
|
public $db;
|
2017-06-08 17:39:50 +02:00
|
|
|
public $display_type;
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2016-04-15 06:10:47 +02:00
|
|
|
//class constructor
|
|
|
|
|
public function __construct() {
|
2016-09-11 01:33:47 +02:00
|
|
|
|
2016-04-15 06:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function set() {
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2016-09-11 01:33:47 +02:00
|
|
|
//connect to the database if not connected
|
|
|
|
|
if (!$this->db) {
|
|
|
|
|
require_once "resources/classes/database.php";
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->connect();
|
|
|
|
|
$this->db = $database->db;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 03:32:36 +02:00
|
|
|
//set the PDO error mode
|
2016-04-15 06:10:47 +02:00
|
|
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
2014-07-25 03:32:36 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
//get the default settings
|
|
|
|
|
$sql = "select * from v_default_settings ";
|
2014-07-25 03:32:36 +02:00
|
|
|
try {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql . " order by default_setting_order asc ");
|
2014-07-25 03:32:36 +02:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
}
|
|
|
|
|
catch(PDOException $e) {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql);
|
2014-07-25 03:32:36 +02:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
}
|
2012-10-11 08:36:24 +02:00
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
2015-05-12 20:11:05 +02:00
|
|
|
//unset all settings
|
2014-08-09 18:05:03 +02:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
unset($_SESSION[$row['default_setting_category']]);
|
|
|
|
|
}
|
2015-05-12 20:11:05 +02:00
|
|
|
//set the enabled settings as a session
|
2012-10-11 08:36:24 +02:00
|
|
|
foreach ($result as $row) {
|
2015-05-01 14:14:52 +02:00
|
|
|
if ($row['default_setting_enabled'] == 'true') {
|
|
|
|
|
$name = $row['default_setting_name'];
|
|
|
|
|
$category = $row['default_setting_category'];
|
|
|
|
|
$subcategory = $row['default_setting_subcategory'];
|
|
|
|
|
if (strlen($subcategory) == 0) {
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
2012-12-14 23:58:20 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2015-05-01 14:14:52 +02:00
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][$subcategory][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$subcategory]['uuid'] = $row['default_setting_uuid'];
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
2012-12-14 23:58:20 +01:00
|
|
|
}
|
2012-10-11 08:36:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the domains settings
|
2014-07-25 11:08:51 +02:00
|
|
|
if (strlen($_SESSION["domain_uuid"]) > 0) {
|
|
|
|
|
$sql = "select * from v_domain_settings ";
|
|
|
|
|
$sql .= "where domain_uuid = '" . $_SESSION["domain_uuid"] . "' ";
|
|
|
|
|
$sql .= "and domain_setting_enabled = 'true' ";
|
|
|
|
|
try {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql . " order by domain_setting_order asc ");
|
2014-07-25 11:08:51 +02:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
}
|
|
|
|
|
catch(PDOException $e) {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql);
|
2014-07-25 11:08:51 +02:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
}
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
2014-08-09 18:32:52 +02:00
|
|
|
//unset the arrays that domains are overriding
|
|
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
|
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
unset($_SESSION[$category][$subcategory]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-12 20:11:05 +02:00
|
|
|
//set the enabled settings as a session
|
2014-07-25 11:08:51 +02:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
|
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
|
|
|
|
if (strlen($subcategory) == 0) {
|
|
|
|
|
//$$category[$name] = $row['domain_setting_value'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][] = $row['domain_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$name] = $row['domain_setting_value'];
|
|
|
|
|
}
|
2015-05-01 14:14:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2014-07-25 11:08:51 +02:00
|
|
|
//$$category[$subcategory][$name] = $row['domain_setting_value'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][$subcategory][] = $row['domain_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
|
|
|
|
|
}
|
2012-12-14 23:58:20 +01:00
|
|
|
}
|
2012-10-11 08:36:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the user settings
|
2016-04-26 03:19:58 +02:00
|
|
|
if (array_key_exists("domain_uuid",$_SESSION) and array_key_exists("user_uuid",$_SESSION) and strlen($_SESSION["domain_uuid"]) > 0 && strlen($_SESSION["user_uuid"]) > 0) {
|
2014-05-13 01:30:26 +02:00
|
|
|
$sql = "select * from v_user_settings ";
|
|
|
|
|
$sql .= "where domain_uuid = '" . $_SESSION["domain_uuid"] . "' ";
|
|
|
|
|
$sql .= "and user_uuid = '" . $_SESSION["user_uuid"] . "' ";
|
2014-07-25 03:32:36 +02:00
|
|
|
try {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql . " order by user_setting_order asc ");
|
2014-07-25 03:32:36 +02:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
}
|
|
|
|
|
catch(PDOException $e) {
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql);
|
2014-05-13 01:30:26 +02:00
|
|
|
$prep_statement->execute();
|
2014-07-25 03:32:36 +02:00
|
|
|
}
|
|
|
|
|
if ($prep_statement) {
|
2014-05-13 01:30:26 +02:00
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach ($result as $row) {
|
2015-05-01 14:14:52 +02:00
|
|
|
if ($row['user_setting_enabled'] == 'true') {
|
|
|
|
|
$name = $row['user_setting_name'];
|
|
|
|
|
$category = $row['user_setting_category'];
|
|
|
|
|
$subcategory = $row['user_setting_subcategory'];
|
|
|
|
|
if (strlen($row['user_setting_value']) > 0) {
|
|
|
|
|
if (strlen($subcategory) == 0) {
|
|
|
|
|
//$$category[$name] = $row['domain_setting_value'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][] = $row['user_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$name] = $row['user_setting_value'];
|
|
|
|
|
}
|
2014-06-10 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2015-05-01 14:14:52 +02:00
|
|
|
//$$category[$subcategory][$name] = $row['domain_setting_value'];
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][$subcategory][] = $row['user_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['user_setting_value'];
|
|
|
|
|
}
|
2014-06-10 22:04:14 +02:00
|
|
|
}
|
2014-05-13 01:30:26 +02:00
|
|
|
}
|
2012-12-14 23:58:20 +01:00
|
|
|
}
|
2012-10-11 08:36:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 03:32:36 +02:00
|
|
|
//set the PDO error mode
|
2016-04-15 06:10:47 +02:00
|
|
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, '');
|
2014-07-25 03:32:36 +02:00
|
|
|
|
2012-10-11 08:36:24 +02:00
|
|
|
//set the values from the session variables
|
|
|
|
|
if (strlen($_SESSION['domain']['time_zone']['name']) > 0) {
|
|
|
|
|
//server time zone
|
|
|
|
|
$_SESSION['time_zone']['system'] = date_default_timezone_get();
|
|
|
|
|
//domain time zone set in system settings
|
|
|
|
|
$_SESSION['time_zone']['domain'] = $_SESSION['domain']['time_zone']['name'];
|
|
|
|
|
//set the domain time zone as the default time zone
|
|
|
|
|
date_default_timezone_set($_SESSION['domain']['time_zone']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set the context
|
2015-03-10 11:47:25 +01:00
|
|
|
$_SESSION["context"] = $_SESSION["domain_name"];
|
2012-10-11 08:36:24 +02:00
|
|
|
|
|
|
|
|
}
|
2014-07-15 07:46:15 +02:00
|
|
|
|
|
|
|
|
public function upgrade() {
|
|
|
|
|
|
2016-09-11 01:33:47 +02:00
|
|
|
//connect to the database if not connected
|
|
|
|
|
if (!$this->db) {
|
|
|
|
|
require_once "resources/classes/database.php";
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->connect();
|
|
|
|
|
$this->db = $database->db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the variables
|
2015-11-28 03:59:50 +01:00
|
|
|
$config = new config;
|
|
|
|
|
$config_exists = $config->exists();
|
|
|
|
|
$config_path = $config->find();
|
|
|
|
|
$config->get();
|
|
|
|
|
$db_type = $config->db_type;
|
|
|
|
|
$db_name = $config->db_name;
|
|
|
|
|
$db_username = $config->db_username;
|
|
|
|
|
$db_password = $config->db_password;
|
|
|
|
|
$db_host = $config->db_host;
|
|
|
|
|
$db_path = $config->db_path;
|
|
|
|
|
$db_port = $config->db_port;
|
2014-07-15 19:49:28 +02:00
|
|
|
|
|
|
|
|
//get the PROJECT PATH
|
|
|
|
|
include "root.php";
|
2014-07-15 07:46:15 +02:00
|
|
|
|
2017-01-14 22:33:05 +01:00
|
|
|
//check for default settings
|
|
|
|
|
$this->settings();
|
|
|
|
|
|
2015-05-12 20:11:05 +02:00
|
|
|
//get the list of installed apps from the core and app directories (note: GLOB_BRACE doesn't work on some systems)
|
2015-05-13 06:37:36 +02:00
|
|
|
$config_list_1 = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
|
|
|
|
|
$config_list_2 = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php");
|
|
|
|
|
$config_list = array_merge((array)$config_list_1, (array)$config_list_2);
|
|
|
|
|
unset($config_list_1,$config_list_2);
|
2016-04-15 06:34:10 +02:00
|
|
|
$db = $this->db;
|
2014-07-15 07:46:15 +02:00
|
|
|
$x=0;
|
|
|
|
|
foreach ($config_list as &$config_path) {
|
|
|
|
|
include($config_path);
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 08:47:49 +02:00
|
|
|
//get the domains
|
2014-07-15 07:46:15 +02:00
|
|
|
$sql = "select * from v_domains ";
|
2016-04-15 06:10:47 +02:00
|
|
|
$prep_statement = $this->db->prepare($sql);
|
2014-07-15 07:46:15 +02:00
|
|
|
$prep_statement->execute();
|
2016-04-15 08:47:49 +02:00
|
|
|
$domains = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
unset($prep_statement);
|
|
|
|
|
|
|
|
|
|
//get the domain_settings
|
|
|
|
|
$sql = "select * from v_domain_settings ";
|
|
|
|
|
$sql .= "where domain_setting_enabled = 'true' ";
|
|
|
|
|
$prep_statement = $this->db->prepare($sql);
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$domain_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
unset($prep_statement);
|
|
|
|
|
|
|
|
|
|
//get the default settings
|
|
|
|
|
$sql = "select * from v_default_settings ";
|
|
|
|
|
$sql .= "where default_setting_enabled = 'true' ";
|
|
|
|
|
$prep_statement = $this->db->prepare($sql);
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$database_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
unset($prep_statement);
|
|
|
|
|
|
2017-01-14 21:15:03 +01:00
|
|
|
|
2016-04-15 08:47:49 +02:00
|
|
|
//get the domain_uuid
|
|
|
|
|
foreach($domains as $row) {
|
|
|
|
|
if (count($domains) == 1) {
|
2014-07-15 07:46:15 +02:00
|
|
|
$_SESSION["domain_uuid"] = $row["domain_uuid"];
|
|
|
|
|
$_SESSION["domain_name"] = $row['domain_name'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-06-01 06:54:21 +02:00
|
|
|
if (lower_case($row['domain_name']) == lower_case($domain_array[0]) || lower_case($row['domain_name']) == lower_case('www.'.$domain_array[0])) {
|
2014-07-15 07:46:15 +02:00
|
|
|
$_SESSION["domain_uuid"] = $row["domain_uuid"];
|
|
|
|
|
$_SESSION["domain_name"] = $row['domain_name'];
|
|
|
|
|
}
|
|
|
|
|
$_SESSION['domains'][$row['domain_uuid']]['domain_uuid'] = $row['domain_uuid'];
|
|
|
|
|
$_SESSION['domains'][$row['domain_uuid']]['domain_name'] = $row['domain_name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//loop through all domains
|
2016-04-15 08:47:49 +02:00
|
|
|
$domain_count = count($domains);
|
2014-07-15 07:46:15 +02:00
|
|
|
$domains_processed = 1;
|
2016-04-15 08:47:49 +02:00
|
|
|
foreach ($domains as &$row) {
|
2014-07-15 07:46:15 +02:00
|
|
|
//get the values from database and set them as php variables
|
|
|
|
|
$domain_uuid = $row["domain_uuid"];
|
|
|
|
|
$domain_name = $row["domain_name"];
|
|
|
|
|
|
|
|
|
|
//get the context
|
2015-03-10 11:47:25 +01:00
|
|
|
$context = $domain_name;
|
2014-07-15 07:46:15 +02:00
|
|
|
|
|
|
|
|
//show the domain when display_type is set to text
|
|
|
|
|
if ($display_type == "text") {
|
|
|
|
|
echo "\n";
|
|
|
|
|
echo $domain_name;
|
|
|
|
|
echo "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the default settings - this needs to be done to reset the session values back to the defaults for each domain in the loop
|
2016-04-15 08:47:49 +02:00
|
|
|
foreach($database_default_settings as $row) {
|
2014-07-15 07:46:15 +02:00
|
|
|
$name = $row['default_setting_name'];
|
|
|
|
|
$category = $row['default_setting_category'];
|
|
|
|
|
$subcategory = $row['default_setting_subcategory'];
|
|
|
|
|
if (strlen($subcategory) == 0) {
|
|
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
2015-05-01 14:14:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2014-07-15 07:46:15 +02:00
|
|
|
if ($name == "array") {
|
|
|
|
|
$_SESSION[$category][$subcategory][] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_SESSION[$category][$subcategory]['uuid'] = $row['default_setting_uuid'];
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 08:47:49 +02:00
|
|
|
//get the domains settings for the current domain
|
|
|
|
|
foreach($domain_settings as $row) {
|
|
|
|
|
if ($row['domain_uuid'] == $domain_uuid) {
|
|
|
|
|
$name = $row['domain_setting_name'];
|
|
|
|
|
$category = $row['domain_setting_category'];
|
|
|
|
|
$subcategory = $row['domain_setting_subcategory'];
|
|
|
|
|
if (strlen($subcategory) == 0) {
|
|
|
|
|
//$$category[$name] = $row['domain_setting_value'];
|
|
|
|
|
$_SESSION[$category][$name] = $row['domain_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//$$category[$subcategory][$name] = $row['domain_setting_value'];
|
|
|
|
|
$_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
|
|
|
|
|
}
|
2014-07-15 07:46:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
|
|
|
|
|
$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
|
2017-06-08 17:39:50 +02:00
|
|
|
$display_type = $this->display_type;
|
2014-07-15 07:46:15 +02:00
|
|
|
foreach ($default_list as &$default_path) {
|
|
|
|
|
include($default_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//track of the number of domains processed
|
|
|
|
|
$domains_processed++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//synchronize the dialplan
|
|
|
|
|
if (function_exists('save_dialplan_xml')) {
|
|
|
|
|
save_dialplan_xml();
|
|
|
|
|
}
|
2016-03-24 22:02:04 +01:00
|
|
|
|
2015-12-02 17:07:23 +01:00
|
|
|
//update config.lua
|
2016-03-27 08:33:19 +02:00
|
|
|
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/scripts/resources/classes/scripts.php')) {
|
|
|
|
|
$obj = new scripts;
|
|
|
|
|
$obj->write_config();
|
|
|
|
|
}
|
2014-07-15 07:46:15 +02:00
|
|
|
|
|
|
|
|
//clear the session variables
|
|
|
|
|
unset($_SESSION['domain']);
|
|
|
|
|
unset($_SESSION['switch']);
|
|
|
|
|
|
2017-01-14 21:15:03 +01:00
|
|
|
} //end upgrade method
|
|
|
|
|
|
|
|
|
|
public function settings() {
|
|
|
|
|
|
|
|
|
|
//connect to the database if not connected
|
|
|
|
|
if (!$this->db) {
|
|
|
|
|
require_once "resources/classes/database.php";
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->connect();
|
|
|
|
|
$this->db = $database->db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the list of installed apps from the core and mod directories
|
|
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
|
|
|
|
$x=0;
|
|
|
|
|
foreach ($config_list as $config_path) {
|
|
|
|
|
include($config_path);
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($apps as $app) {
|
|
|
|
|
if (is_array($app['default_settings'])) {
|
|
|
|
|
foreach ($app['default_settings'] as $setting) {
|
|
|
|
|
$array[$x] = ($setting);
|
|
|
|
|
$array[$x]['app_uuid'] = $app['uuid'];
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get an array of the default settings
|
|
|
|
|
$sql = "select * from v_default_settings ";
|
2017-01-15 02:15:34 +01:00
|
|
|
$sql .= "order by default_setting_category asc, default_setting_subcategory asc";
|
2017-01-14 21:15:03 +01:00
|
|
|
$prep_statement = $this->db->prepare($sql);
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
unset ($prep_statement, $sql);
|
|
|
|
|
|
2017-01-15 02:15:34 +01:00
|
|
|
//named array
|
|
|
|
|
foreach ($default_settings as $row) {
|
|
|
|
|
$default_settings[$row['default_setting_category']][$row['default_setting_subcategory']][$row['default_setting_name']]['uuid'] = $row['default_setting_uuid'];
|
|
|
|
|
$default_settings[$row['default_setting_category']][$row['default_setting_subcategory']][$row['default_setting_name']]['value'] = $row['default_setting_value'];
|
|
|
|
|
$default_settings[$row['default_setting_category']][$row['default_setting_subcategory']][$row['default_setting_name']]['app_uuid'] = $row['app_uuid'];
|
|
|
|
|
//echo "[".$row['default_setting_category']."][".$row['default_setting_subcategory']."][".$row['default_setting_name']."] = ".$row['default_setting_value']."\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update matching settings with the correct default_setting_uuid and app_uuid and if they exist remove them from the array
|
2017-01-14 21:15:03 +01:00
|
|
|
$x = 0;
|
2017-01-15 02:15:34 +01:00
|
|
|
foreach ($array as $row) {
|
|
|
|
|
$category = $row['default_setting_category'];
|
|
|
|
|
$subcategory = $row['default_setting_subcategory'];
|
|
|
|
|
$name = $row['default_setting_name'];
|
|
|
|
|
|
|
|
|
|
if (isset($default_settings[$category][$subcategory][$name]['value'])) {
|
|
|
|
|
//set the variables
|
|
|
|
|
$default_setting_uuid = $default_settings[$category][$subcategory][$name]['uuid'];
|
|
|
|
|
$app_uuid = $default_settings[$category][$subcategory][$name]['app_uuid'];
|
|
|
|
|
//update matching settings
|
|
|
|
|
if ($app_uuid == null) {
|
|
|
|
|
$sql = "update v_default_settings set ";
|
|
|
|
|
if ($default_setting_uuid != $row['default_setting_uuid']) {
|
|
|
|
|
$sql .= "default_setting_uuid = '".$row['default_setting_uuid']."', ";
|
2017-01-14 21:15:03 +01:00
|
|
|
}
|
2017-01-15 02:15:34 +01:00
|
|
|
$sql .= "app_uuid = '".$row['app_uuid']."' ";
|
|
|
|
|
$sql .= "where default_setting_uuid = '".$row['default_setting_uuid']."';";
|
2017-01-15 02:17:21 +01:00
|
|
|
//echo $category." ".$subcategory." ".$name." ".$app_uuid."\n";
|
|
|
|
|
//echo $sql."\n";
|
2017-01-15 02:15:34 +01:00
|
|
|
$this->db->exec(check_sql($sql));
|
|
|
|
|
//echo "\n";
|
|
|
|
|
}
|
2017-01-14 21:15:03 +01:00
|
|
|
|
2017-01-15 02:15:34 +01:00
|
|
|
//remove settings from the array that were found
|
|
|
|
|
unset($array[$x]);
|
2017-01-14 21:15:03 +01:00
|
|
|
}
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
unset($default_settings);
|
|
|
|
|
|
|
|
|
|
//get the missing count
|
2017-01-15 02:15:34 +01:00
|
|
|
$array_count = count($array);
|
2017-01-14 21:15:03 +01:00
|
|
|
|
|
|
|
|
//add the missing default settings
|
2017-01-15 02:15:34 +01:00
|
|
|
if (is_array($array) && count($array) > 0) {
|
2017-01-14 21:15:03 +01:00
|
|
|
foreach ($array as $row) {
|
2017-01-17 21:37:26 +01:00
|
|
|
$sql = "insert into v_default_settings (";
|
|
|
|
|
$sql .= "default_setting_uuid, ";
|
|
|
|
|
$sql .= "default_setting_category, ";
|
|
|
|
|
$sql .= "default_setting_subcategory, ";
|
|
|
|
|
$sql .= "default_setting_name, ";
|
|
|
|
|
$sql .= "default_setting_value, ";
|
|
|
|
|
$sql .= "default_setting_enabled, ";
|
|
|
|
|
$sql .= "default_setting_description ";
|
|
|
|
|
$sql .= ") values \n";
|
2017-01-14 21:15:03 +01:00
|
|
|
$sql .= "(";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_uuid'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_category'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_subcategory'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_name'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_value'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_enabled'])."', ";
|
|
|
|
|
$sql .= "'".check_str($row['default_setting_description'])."' ";
|
2017-01-17 21:37:26 +01:00
|
|
|
$sql .= ");";
|
|
|
|
|
//echo $sql."\n";
|
|
|
|
|
$this->db->exec(check_sql($sql));
|
|
|
|
|
unset($array);
|
2017-01-14 21:15:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //end settings method
|
2012-10-11 08:36:24 +02:00
|
|
|
}
|
2016-04-15 07:23:14 +02:00
|
|
|
}
|
2012-10-11 02:08:51 +02:00
|
|
|
|
2016-09-11 01:33:47 +02:00
|
|
|
?>
|