diff --git a/app/devices/device_edit.php b/app/devices/device_edit.php index 62dd19ef27..e94ce7fb12 100644 --- a/app/devices/device_edit.php +++ b/app/devices/device_edit.php @@ -44,8 +44,14 @@ $device_firmware_version = ''; $device_template =''; -//include the device class - require_once "app/devices/resources/classes/device.php"; +//get the domain uuid + $domain_uuid = $_SESSION['domain_uuid'] ?? ''; + +//initialize the database object + $database = database::new(); + +//initialize the settigns object + $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]); //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { @@ -56,12 +62,11 @@ $action = "add"; } -//get total device count from the database, check limit, if defined +//get the total device count from the database, check the limit, if defined if ($action == 'add') { if (!empty($_SESSION['limit']['devices']['numeric']) && $_SESSION['limit']['devices']['numeric']) { $sql = "select count(*) from v_devices where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; $total_devices = $database->select($sql, $parameters, 'column'); if ($total_devices >= $_SESSION['limit']['devices']['numeric']) { message::add($text['message-maximum_devices'].' '.$_SESSION['limit']['devices']['numeric'], 'negative'); @@ -101,7 +106,6 @@ $sql = "select device_address from v_devices "; $sql .= "where device_uuid = :device_uuid "; $parameters['device_uuid'] = $device_uuid; - $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $device_address = $row["device_address"]; @@ -224,7 +228,6 @@ $sql .= " and d1.device_uuid <> :device_uuid "; } $parameters['device_address'] = $device_address; - $database = new database; $domain_name = $database->select($sql, $parameters, 'column'); if ($domain_name != '') { $message = $text['message-duplicate'].(if_group("superadmin") && $_SESSION["domain_name"] != $domain_name ? ": ".$domain_name : null); @@ -436,7 +439,6 @@ } //save the device - $database = new database; $database->app_name = 'devices'; $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; $database->save($array); @@ -479,7 +481,7 @@ //write the provision files if (!empty($_SESSION['provision']['path']['text'])) { - $prov = new provision; + $prov = new provision(['settings' => $settings]); $prov->domain_uuid = $domain_uuid; $response = $prov->write(); } @@ -507,7 +509,7 @@ $sql = "select * from v_devices "; $sql .= "where device_uuid = :device_uuid "; $parameters['device_uuid'] = $device_uuid; - $database = new database; + $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $device_address = $row["device_address"]; @@ -556,7 +558,6 @@ $sql .= "and device_uuid = :device_uuid "; $parameters['domain_uuid'] = $domain_uuid; $parameters['device_uuid'] = $device_uuid_alternate; - $database = new database; $device_alternate = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); } @@ -566,7 +567,7 @@ $sql .= "where device_uuid = :device_uuid "; $sql .= "order by cast(line_number as int) asc "; $parameters['device_uuid'] = $device_uuid ?? null; - $database = new database; + $device_lines = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); @@ -606,7 +607,6 @@ $sql .= "else 100 end, "; $sql .= $db_type == "mysql" ? "device_key_id asc " : "cast(device_key_id as numeric) asc "; $parameters['device_uuid'] = $device_uuid ?? null; - $database = new database; $device_keys = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); @@ -638,7 +638,7 @@ $sql .= "from v_device_vendors "; $sql .= "where enabled = 'true' "; $sql .= "order by name asc "; - $database = new database; + $device_vendors = $database->select($sql, null, 'all'); unset($sql); @@ -649,7 +649,6 @@ $sql .= "and v.enabled = 'true' "; $sql .= "and f.enabled = 'true' "; $sql .= "order by v.name asc, f.type asc "; - $database = new database; $vendor_functions = $database->select($sql, null, 'all'); unset($sql); @@ -658,7 +657,6 @@ $sql .= "where device_uuid = :device_uuid "; $sql .= "order by device_setting_subcategory asc "; $parameters['device_uuid'] = $device_uuid ?? null; - $database = new database; $device_settings = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); @@ -686,7 +684,6 @@ $sql .= "and user_enabled = 'true' "; $sql .= "order by username asc "; $parameters['domain_uuid'] = $domain_uuid; - $database = new database; $users = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); @@ -1007,7 +1004,7 @@ } if (permission_exists("device_files")) { //get the template directory - $prov = new provision; + $prov = new provision(['settings' => $settings]); $prov->domain_uuid = $domain_uuid; $template_dir = $prov->template_dir; $files = glob($template_dir.'/'.$device_template.'/*'); @@ -1017,8 +1014,7 @@ echo " \n"; foreach ($files as $file) { //format the device address - $format = new provision(); - $address = $format->format_address($device_address, $device_vendor); + $address = $prov->format_address($device_address, $device_vendor); //render the file name $file_name = str_replace("{\$address}", $address, basename($file)); $file_name = str_replace("{\$mac}", $address, basename($file_name)); @@ -1458,7 +1454,6 @@ $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; $sql .= "order by device_profile_name asc "; $parameters['domain_uuid'] = $domain_uuid; - $database = new database; $device_profiles = $database->select($sql, $parameters, 'all'); if (is_array($device_profiles) && @sizeof($device_profiles) != 0) { echo "
".print_r($table_name, 1)."\n";
- }
- }
- else {
- $table_name = $row['table']['name'];
- }
- if ($table_name !== "v" && isset($row['fields'])) {
- foreach ($row['fields'] as $field) {
- if ($field['name'] == 'domain_uuid' && $table_name != 'v_domains') {
- $sql = "delete from ".$table_name." where domain_uuid = :domain_uuid ";
- $parameters['domain_uuid'] = $id;
- $database = new database;
- $database->app_name = 'domain_settings';
- $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
- $database->execute($sql, $parameters);
- unset($sql, $parameters);
- }
- }
- }
- }
- }
-
- //delete the directories
- if (!empty($domain_name)) {
- //set the needle
- if (count($_SESSION["domains"]) > 1) {
- $v_needle = 'v_'.$domain_name.'_';
- }
- else {
- $v_needle = 'v_';
- }
-
- //delete the dialplan
- @unlink($_SESSION['switch']['dialplan']['dir'].'/'.$domain_name.'.xml');
- if (!empty($_SESSION['switch']['dialplan']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/'.$domain_name);
- }
-
- //delete the dialplan public
- @unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name.'.xml');
- if (!empty($_SESSION['switch']['dialplan']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['dialplan']['dir'].'/public/'.$domain_name);
- }
-
- //delete the extension
- @unlink($_SESSION['switch']['extensions']['dir'].'/'.$domain_name.'.xml');
- if (!empty($_SESSION['switch']['extensions']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['extensions']['dir'].'/'.$domain_name);
- }
-
- //delete fax
- if (!empty($_SESSION['switch']['storage']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['storage']['dir'].'/fax/'.$domain_name);
- }
-
- //delete the gateways
- if (!empty($_SESSION['switch']['sip_profiles']['dir'])) {
- if ($dh = opendir($_SESSION['switch']['sip_profiles']['dir'])) {
- $files = Array();
- while ($file = readdir($dh)) {
- if ($file != "." && $file != ".." && $file[0] != '.') {
- if (is_dir($dir . "/" . $file)) {
- //this is a directory do nothing
- }
- else {
- //check if file extension is xml
- if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
- @unlink($_SESSION['switch']['sip_profiles']['dir']."/".$file);
- }
- }
- }
- }
- closedir($dh);
- }
- }
-
- //delete the ivr menu
- if (!empty($_SESSION['switch']['conf']['dir'])) {
- if ($dh = opendir($_SESSION['switch']['conf']['dir']."/ivr_menus")) {
- $files = Array();
- while ($file = readdir($dh)) {
- if ($file != "." && $file != ".." && $file[0] != '.') {
- if (!empty($dir) && !empty($file) && is_dir($dir."/".$file)) {
- //this is a directory
- }
- else {
- if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') {
- @unlink($_SESSION['switch']['conf']['dir']."/ivr_menus/".$file);
- }
- }
- }
- }
- closedir($dh);
- }
- }
-
- //delete the recordings
- if (!empty($_SESSION['switch']['recordings']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name);
- }
-
- //delete voicemail
- if (!empty($_SESSION['switch']['voicemail']['dir'])) {
- system('rm -rf '.$_SESSION['switch']['voicemail']['dir'].'/'.$domain_name);
- }
- }
-
- //apply settings reminder
- $_SESSION["reload_xml"] = true;
-
- //remove the domain from domains session array
- unset($_SESSION["domains"][$id]);
-
- //add domain uuid to array for deletion below
- $domain_array['domains'][] = ['domain_uuid'=>$id];
- }
- }
-
- //delete the checked rows
- if (is_array($domain_array) && @sizeof($domain_array) != 0) {
- //execute delete
- $database = new database;
- $database->app_name = $this->app_name;
- $database->app_uuid = $this->app_uuid;
- $database->delete($domain_array);
-
- //set message
- message::add($text['message-delete']);
-
- //reload default/domain settings
- $this->set();
- }
- 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 (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
- $uuids[] = "'".$record['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 ?? null, '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 (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
- $uuids[] = "'".$record['uuid']."'";
- }
- }
-
- //create the array from existing data
- if (is_array($uuids) && @sizeof($uuids) != 0) {
- $sql = "select * 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) {
- $x = 0;
- foreach ($rows as $row) {
- //copy data
- $array[$this->table][$x] = $row;
-
- //add copy to the description
- $array[$this->table][$x][$this->name.'_uuid'] = uuid();
- $array[$this->table][$x][$this->name.'_description'] = trim($row[$this->name.'_description']).' ('.$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);
- }
- }
- }
-
- /**
- * add default, domain and user settings to the session array
- */
- public function set() {
-
- //get previous domain settings
- if (isset($_SESSION["previous_domain_uuid"])) {
- $sql = "select * from v_domain_settings ";
- $sql .= "where domain_uuid = :previous_domain_uuid ";
- $sql .= "and domain_setting_enabled = 'true' ";
- $sql .= " order by domain_setting_order asc ";
- $parameters['previous_domain_uuid'] = $_SESSION["previous_domain_uuid"];
- $database = new database;
- $result = $database->select($sql, $parameters, 'all');
- unset($sql, $parameters);
-
- //unset previous domain settings
- foreach ($result as $row) {
- if ($row['domain_setting_category'] != 'user') { //skip off-limit categories
- unset($_SESSION[$row['domain_setting_category']][$row['domain_setting_subcategory']]);
- }
- }
- unset($_SESSION["previous_domain_uuid"]);
- }
-
- //get the default settings
- $sql = "select * from v_default_settings ";
- $sql .= "order by default_setting_order asc ";
- $database = new database;
- $result = $database->select($sql, null, 'all');
- unset($sql, $parameters);
-
- //unset all settings
- foreach ($result as $row) {
- if ($row['default_setting_category'] != 'user') { //skip off-limit categories
- unset($_SESSION[$row['default_setting_category']][$row['default_setting_subcategory']]);
- }
- }
-
- //set the enabled settings as a session
- foreach ($result as $row) {
- if ($row['default_setting_enabled'] == 'true') {
- $name = $row['default_setting_name'];
- $category = $row['default_setting_category'];
- $subcategory = $row['default_setting_subcategory'];
- if (empty($subcategory)) {
- if ($name == "array") {
- $_SESSION[$category][] = $row['default_setting_value'];
- }
- else {
- $_SESSION[$category][$name] = $row['default_setting_value'];
- }
- }
- else {
- 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'];
- }
- }
- }
- }
-
- //get the domains settings
- if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php")) {
- include "app/domains/resources/settings.php";
- }
-
- //get the domains settings
- if (!empty($_SESSION["domain_uuid"]) && is_uuid($_SESSION["domain_uuid"])) {
-
- //get settings from the database
- $sql = "select * from v_domain_settings ";
- $sql .= "where domain_uuid = :domain_uuid ";
- $sql .= "and domain_setting_enabled = 'true' ";
- $sql .= " order by domain_setting_order asc ";
- $parameters['domain_uuid'] = $_SESSION["domain_uuid"];
- $database = new database;
- $result = $database->select($sql, $parameters, 'all');
- unset($sql, $parameters);
-
- //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]);
- }
- }
-
- //set the enabled settings as a session
- foreach ($result as $row) {
- if ($row['domain_setting_enabled'] == 'true') {
- $name = $row['domain_setting_name'];
- $category = $row['domain_setting_category'];
- $subcategory = $row['domain_setting_subcategory'];
- if (empty($subcategory)) {
- //$$category[$name] = $row['domain_setting_value'];
- if ($name == "array") {
- $_SESSION[$category][] = $row['domain_setting_value'];
- }
- else {
- $_SESSION[$category][$name] = $row['domain_setting_value'];
- }
- }
- else {
- //$$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'];
- }
- }
- }
- }
- }
-
- //get the user settings
- if (array_key_exists("domain_uuid",$_SESSION) && array_key_exists("user_uuid",$_SESSION) && is_uuid($_SESSION["domain_uuid"])) {
- $sql = "select * from v_user_settings ";
- $sql .= "where domain_uuid = :domain_uuid ";
- $sql .= "and user_uuid = :user_uuid ";
- $sql .= " order by user_setting_order asc ";
- $parameters['domain_uuid'] = $_SESSION["domain_uuid"];
- $parameters['user_uuid'] = $_SESSION["user_uuid"];
- $database = new database;
- $result = $database->select($sql, $parameters, 'all');
- if (is_array($result)) {
- foreach ($result as $row) {
- if ($row['user_setting_enabled'] == 'true') {
- $name = $row['user_setting_name'];
- $category = $row['user_setting_category'];
- $subcategory = $row['user_setting_subcategory'];
- if (!empty($row['user_setting_value'])) {
- if (empty($subcategory)) {
- //$$category[$name] = $row['domain_setting_value'];
- if ($name == "array") {
- $_SESSION[$category][] = $row['user_setting_value'];
- }
- else {
- $_SESSION[$category][$name] = $row['user_setting_value'];
- }
- }
- else {
- //$$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'];
- }
- }
- }
- }
- }
- }
- }
-
- //set the values from the session variables
- if (!empty($_SESSION['domain']['time_zone']['name'])) {
- //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
- if (!empty($_SESSION["domain_name"])) {
- $_SESSION["context"] = $_SESSION["domain_name"];
- }
- }
-
- /**
- * upgrade application defaults
- */
- public function upgrade() {
-
- //add multi-lingual support
- $language = new text;
- $text = $language->get(null, 'core/upgrade');
-
- //includes files
- require dirname(__DIR__, 2) . "/resources/require.php";
-
- //add missing default settings
- $this->settings();
-
- //get the variables
- $config = new config;
- $config_path = $config->config_file;
-
- //get the list of installed apps from the core and app directories (note: GLOB_BRACE doesn't work on some systems)
- $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);
- $x=0;
- foreach ($config_list as &$config_path) {
- $app_path = dirname($config_path);
- $app_path = preg_replace('/\A.*(\/.*\/.*)\z/', '$1', $app_path);
- include($config_path);
- $x++;
- }
-
- //get the domains
- $sql = "select * from v_domains ";
- $database = new database;
- $domains = $database->select($sql, null, 'all');
- unset($sql);
-
- //loop through all domains
- $domains_processed = 1;
- foreach ($domains as $domain) {
- //get the values from database and set them as php variables
- $domain_uuid = $domain["domain_uuid"];
- $domain_name = $domain["domain_name"];
-
- //get the context
- $context = $domain_name;
-
- //get the email queue settings
- $setting = new settings(["domain_uuid" => $domain_uuid]);
-
- //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");
- foreach ($default_list as &$default_path) {
- //echo $default_path."
\n";
- include($default_path);
- }
-
- //track of the number of domains processed
- $domains_processed++;
- }
-
- //output result
- if (defined('STDIN')) {
- if ($domains_processed > 1) {
- echo $text['message-upgrade_apps']."\n";
- }
- }
-
- } //end upgrade method
-
- /**
- * add missing default settings
- * update the uuid for older default settings that were added before the uuids was predefined.
- */
- public function settings() {
-
- //includes files
- require dirname(__DIR__, 2) . "/resources/require.php";
-
- //get an array of the default settings UUIDs
- $sql = "select * from v_default_settings ";
- $database = new database;
- $result = $database->select($sql, null, 'all');
- foreach($result as $row) {
- $setting[$row['default_setting_uuid']] = 1;
- }
- unset($sql);
-
- //get the list of default settings
- $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 (isset($app['default_settings']) && is_array($app['default_settings'])) {
- foreach ($app['default_settings'] as $row) {
- if (!isset($setting[$row['default_setting_uuid']])) {
- $array['default_settings'][$x] = $row;
- $array['default_settings'][$x]['app_uuid'] = $app['uuid'];
- $x++;
- }
- }
- }
- }
-
- //add the missing default settings
- if (isset($array) && is_array($array) && count($array) > 0) {
- //grant temporary permissions
- $p = new permissions;
- $p->add('default_setting_add', 'temp');
-
- //execute insert
- $database = new database;
- $database->app_name = 'default_settings';
- $database->app_uuid = '2c2453c0-1bea-4475-9f44-4d969650de09';
- $database->save($array, false);
- unset($array);
-
- //revoke temporary permissions
- $p->delete('default_setting_add', 'temp');
- }
-
- } //end settings method
-
- /**
- * get a domain list
- */
- public function all() {
- //get the domains from the database
- $database = new database;
- if ($database->table_exists('v_domains')) {
- $sql = "select * from v_domains order by domain_name asc;";
- $database = new database;
- $result = $database->select($sql, null, 'all');
- foreach($result as $row) {
- $domain_names[] = $row['domain_name'];
- }
- unset($prep_statement);
- }
-
- //build the domains array in the correct order
- if (is_array($domain_names)) {
- foreach ($domain_names as $dn) {
- foreach ($result as $row) {
- if ($row['domain_name'] == $dn) {
- $domains[] = $row;
- }
- }
- }
- unset($result);
- }
-
- //return the domains array
- return $domains;
- }
-
- /**
- * get a domain list
- */
- public function session() {
- //get the list of domains
- $domains = $this->all();
-
- //get the domain
- $domain_array = explode(":", $_SERVER["HTTP_HOST"] ?? '');
-
- //set domain_name and domain_uuid and update domains array with domain_uuid as the key
- if (!empty($domains) && is_array($domains)) {
- foreach($domains as $row) {
- if (!isset($_SESSION['username'])) {
- if (!empty($domains) && count($domains) == 1) {
- $domain_uuid = $row["domain_uuid"];
- $domain_name = $row['domain_name'];
- $_SESSION["domain_uuid"] = $row["domain_uuid"];
- $_SESSION["domain_name"] = $row['domain_name'];
- }
- else {
- if ($row['domain_name'] == $domain_array[0] || $row['domain_name'] == 'www.'.$domain_array[0]) {
- $_SESSION["domain_uuid"] = $row["domain_uuid"];
- $_SESSION["domain_name"] = $row["domain_name"];
- }
- }
- }
- $_SESSION['domains'][$row['domain_uuid']] = $row;
- }
- unset($domains, $prep_statement);
- }
- }
-
- }
-}
-
-?>