Fix multiple PHP warnings

This commit is contained in:
markjcrane
2025-11-01 19:58:21 -06:00
parent a675660473
commit bf5bb4f642
41 changed files with 539 additions and 442 deletions

View File

@@ -33,20 +33,39 @@
class authentication {
/**
* Define variables and their scope
* Declare Public variables
*
* @var mixed
*/
private $database;
public $domain_uuid;
public $user_uuid;
public $domain_name;
public $username;
public $password;
public $key;
/**
* Declare Private variables
*
* @var mixed
*/
private $database;
private $settings;
/**
* Called when the object is created
*/
public function __construct(array $setting_array = []) {
$this->database = $setting_array['database'] ?? database::new();
//set the config object
$config = $setting_array['config'] ?? config::load();
//set the database connection
$this->database = $setting_array['database'] ?? database::new(['config' => $config]);
//set the settings object
$this->settings = $setting_array['settings'];
//intialize the object
$this->user_uuid = null;
}
@@ -68,7 +87,7 @@ class authentication {
}
//create a settings object to pass to plugins
$settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid]);
$this->settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid]);
//start the session if its not started
if (session_status() === PHP_SESSION_NONE) {
@@ -114,7 +133,7 @@ class authentication {
$object->password = $this->password;
}
//initialize the plugin send the authentication object and settings
$array = $object->$name($this, $settings);
$array = $object->$name($this, $this->settings);
//build a result array
if (!empty($array) && is_array($array)) {
@@ -187,11 +206,11 @@ class authentication {
//user is authorized - get user settings, check user cidr
if ($authorized) {
//get the cidr restrictions from global, domain, and user default settings
$settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
$cidr_list = $settings->get('domain', 'cidr', []);
$this->settings = new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
$cidr_list = $this->settings->get('domain', 'cidr', []);
if (check_cidr($cidr_list, $_SERVER['REMOTE_ADDR'])) {
//user passed the cidr check
self::create_user_session($result, $settings);
self::create_user_session($result, $this->settings);
} else {
//user failed the cidr check - no longer authorized
$authorized = false;
@@ -456,12 +475,10 @@ class authentication {
}
//set a default value for unqiue
if (empty($_SESSION["users"]["unique"]["text"])) {
$_SESSION["users"]["unique"]["text"] = 'false';
}
$_SESSION["users"]["unique"]["text"] = $this->settings->get('users', 'unique', '');
//get the domain name from the username
if (!empty($_SESSION['username']) && $_SESSION["users"]["unique"]["text"] != "global") {
if (!empty($_SESSION['username']) && $this->settings->get('users', 'unique', '') != "global") {
$username_array = explode("@", $_SESSION['username']);
if (count($username_array) > 1) {
//get the domain name

View File

@@ -57,6 +57,9 @@ class plugin_database {
//pre-process some settings
$theme_favicon = $settings->get('theme', 'favicon', PROJECT_PATH.'/themes/default/favicon.ico');
$theme_logo = $settings->get('theme', 'logo', PROJECT_PATH.'/themes/default/images/logo_login.png');
$theme_login_type = $settings->get('theme', 'login_brand_type', '');
$theme_login_image = $settings->get('theme', 'login_brand_image', '');
$theme_login_text = $settings->get('theme', 'login_brand_text', '');
$theme_login_logo_width = $settings->get('theme', 'login_logo_width', 'auto; max-width: 300px');
$theme_login_logo_height = $settings->get('theme', 'login_logo_height', 'auto; max-height: 300px');
$theme_message_delay = 1000 * (float)$settings->get('theme', 'message_delay', 3000);
@@ -67,6 +70,12 @@ class plugin_database {
$login_destination = $settings->get('login', 'destination');
$users_unique = $settings->get('users', 'unique', '');
//set the default login type and image
if (empty($theme_login_type)) {
$theme_login_type = 'image';
$theme_login_image = $theme_logo;
}
//determine whether to show the forgot password for resetting the password
$login_password_reset_enabled = false;
if (!empty($settings->get('login', 'password_reset_key'))) {

View File

@@ -41,6 +41,13 @@ class plugin_email {
public $contact_uuid;
public $debug;
/**
* Declare Private variables
*
* @var mixed
*/
private $database;
/**
* Called when the object is created
*/
@@ -60,6 +67,9 @@ class plugin_email {
//pre-process some settings
$theme_favicon = $settings->get('theme', 'favicon', PROJECT_PATH.'/themes/default/favicon.ico');
$theme_logo = $settings->get('theme', 'logo', PROJECT_PATH.'/themes/default/images/logo_login.png');
$theme_login_type = $settings->get('theme', 'login_brand_type', '');
$theme_login_image = $settings->get('theme', 'login_brand_image', '');
$theme_login_text = $settings->get('theme', 'login_brand_text', '');
$theme_login_logo_width = $settings->get('theme', 'login_logo_width', 'auto; max-width: 300px');
$theme_login_logo_height = $settings->get('theme', 'login_logo_height', 'auto; max-height: 300px');
$theme_message_delay = 1000 * (float)$settings->get('theme', 'message_delay', 3000);
@@ -69,7 +79,7 @@ class plugin_email {
//$login_domain_name = $settings->get('login', 'domain_name');
$login_destination = $settings->get('login', 'destination');
$users_unique = $settings->get('users', 'unique', '');
//get the domain
$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
$domain_name = $domain_array[0];

View File

@@ -8,15 +8,25 @@
class plugin_ldap {
/**
* Declare public variables
* Declare Public variables
*
* @var mixed
*/
public $debug;
public $domain_name;
public $domain_uuid;
public $username;
public $password;
public $user_uuid;
public $contact_uuid;
/**
* Declare Private variables
*
* @var mixed
*/
private $database;
/**
* Called when the object is created
*/
@@ -37,13 +47,14 @@ class plugin_ldap {
if ($_REQUEST["username"]) {
//pre-process some settings
$settings['theme']['favicon'] = !empty($_SESSION['theme']['favicon']['text']) ? $_SESSION['theme']['favicon']['text'] : PROJECT_PATH.'/themes/default/favicon.ico';
$settings['login']['destination'] = !empty($_SESSION['login']['destination']['text']) ? $_SESSION['login']['destination']['text'] : '';
$settings['users']['unique'] = !empty($_SESSION['users']['unique']['text']) ? $_SESSION['users']['unique']['text'] : '';
$settings['theme']['logo'] = !empty($_SESSION['theme']['logo']['text']) ? $_SESSION['theme']['logo']['text'] : PROJECT_PATH.'/themes/default/images/logo_login.png';
$settings['theme']['login_logo_width'] = !empty($_SESSION['theme']['login_logo_width']['text']) ? $_SESSION['theme']['login_logo_width']['text'] : 'auto; max-width: 300px';
$settings['theme']['login_logo_height'] = !empty($_SESSION['theme']['login_logo_height']['text']) ? $_SESSION['theme']['login_logo_height']['text'] : 'auto; max-height: 300px';
$settings['theme']['background_video'] = isset($_SESSION['theme']['background_video'][0]) ? $_SESSION['theme']['background_video'][0] : null;
$theme_favicon = $settings->get('theme', 'favicon', PROJECT_PATH.'/themes/default/favicon.ico');
$theme_logo = $settings->get('theme', 'logo', PROJECT_PATH.'/themes/default/images/logo_login.png');
$login_destination = $settings->get('login', 'destination');
$theme_login_logo_width = $settings->get('theme', 'login_logo_width', 'auto; max-width: 300px');
$theme_login_logo_height = $settings->get('theme', 'login_logo_height', 'auto; max-height: 300px');
$background_videos = $settings->get('theme', 'background_video', null);
$theme_background_video = (isset($background_videos) && is_array($background_videos)) ? $background_videos[0] : null;
$users_unique = $settings->get('users', 'unique', '');
//get the domain
$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
@@ -72,12 +83,12 @@ class plugin_ldap {
//assign default values to the template
$view->assign("project_path", PROJECT_PATH);
$view->assign("login_destination_url", $settings['login']['destination']);
$view->assign("favicon", $settings['theme']['favicon']);
$view->assign("login_logo_width", $settings['theme']['login_logo_width']);
$view->assign("login_logo_height", $settings['theme']['login_logo_height']);
$view->assign("login_logo_source", $settings['theme']['logo']);
$view->assign("background_video", $settings['theme']['background_video']);
$view->assign("login_destination_url", $login_destination);
$view->assign("favicon", $theme_favicon);
$view->assign("login_logo_width", $theme_login_logo_width);
$view->assign("login_logo_height", $theme_login_logo_height);
$view->assign("login_logo_source", $theme_logo);
$view->assign("background_video", $theme_background_video);
//add the token name and hash to the view
//$view->assign("token_name", $token['name']);
@@ -90,16 +101,16 @@ class plugin_ldap {
}
//use ldap to validate the user credentials
if (isset($_SESSION["ldap"]["certpath"])) {
$s = "LDAPTLS_CERT=" . $_SESSION["ldap"]["certpath"]["text"];
if (!empty($settings->get('ldap', 'certpath', ''))) {
$s = "LDAPTLS_CERT=" . $settings->get('ldap', 'certpath', '');
putenv($s);
}
if (isset($_SESSION["ldap"]["certkey"])) {
$s = "LDAPTLS_KEY=" . $_SESSION["ldap"]["certkey"]["text"];
if (!empty($settings->get('ldap', 'certkey', ''))) {
$s = "LDAPTLS_KEY=" . $settings->get('ldap', 'certkey', '');
putenv($s);
}
$host = $_SESSION["ldap"]["server_host"]["text"];
$port = $_SESSION["ldap"]["server_port"]["numeric"];
$host = $settings->get('ldap', 'server_host', '');
$port = $settings->get('ldap', 'server_port', '');
$connect = ldap_connect($host, $port)
or die("Could not connect to the LDAP server.");
//ldap_set_option($connect, LDAP_OPT_NETWORK_TIMEOUT, 10);
@@ -110,13 +121,13 @@ class plugin_ldap {
$user_authorized = false;
//provide backwards compatability
if (!empty($_SESSION["ldap"]["user_dn"]["text"])) {
$_SESSION["ldap"]["user_dn"][] = $_SESSION["ldap"]["user_dn"]["text"];
if (!empty($settings->get('ldap', 'user_dn', ''))) {
$ldap_user_dn[] = $settings->get('ldap', 'user_dn', '');
}
//check all user_dn in the array
foreach ($_SESSION["ldap"]["user_dn"] as $user_dn) {
$bind_dn = $_SESSION["ldap"]["user_attribute"]["text"]."=".$this->username.",".$user_dn;
foreach ($ldap_user_dn as $user_dn) {
$bind_dn = $settings->get('ldap', 'user_attribute', '')."=".$this->username.",".$user_dn;
$bind_pw = $this->password;
//Note: As of 4/16, the call below will fail randomly. PHP debug reports ldap_bind
//called below with all arguments '*uninitialized*'. However, the debugger
@@ -135,7 +146,7 @@ class plugin_ldap {
if ($user_authorized) {
$sql = "select * from v_users ";
$sql .= "where username = :username ";
if ($settings['users']['unique'] != "global") {
if (!empty($users_unique) && $users_unique != "global") {
//unique username per domain (not globally unique across system - example: email address)
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $this->domain_uuid;
@@ -144,10 +155,14 @@ class plugin_ldap {
$parameters['username'] = $this->username;
$row = $this->database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
if ($settings['users']['unique'] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
//get the domain uuid
if (!empty($users_unique) && $users_unique == "global" && $row["domain_uuid"] != $this->domain_uuid) {
//set the domain uuid
$this->domain_uuid = $row["domain_uuid"];
$this->domain_name = $_SESSION['domains'][$this->domain_uuid]['domain_name'];
//set the domain name
$sql .= "select domain_name from v_domains where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $this->domain_uuid;
$this->domain_name = $this->database->select($sql, $parameters, 'column');
//set the domain session variables
$_SESSION["domain_uuid"] = $this->domain_uuid;
@@ -176,7 +191,7 @@ class plugin_ldap {
$array['users'][0]['username'] = strtolower($this->username);
$array['users'][0]['password'] = md5($salt.$password);
$array['users'][0]['salt'] = $salt;
$array['users'][0]['add_date'] = now();
$array['users'][0]['add_date'] = 'now()';
$array['users'][0]['add_user'] = strtolower($this->username);
$array['users'][0]['user_enabled'] = true;

View File

@@ -32,15 +32,25 @@
class plugin_totp {
/**
* Define variables and their scope
* Declare Public variables
*
* @var mixed
*/
public $debug;
public $domain_name;
public $domain_uuid;
public $username;
public $password;
public $user_uuid;
public $user_email;
public $contact_uuid;
/**
* Declare Private variables
*
* @var mixed
*/
private $database;
private $user_totp_secret;
/**
@@ -62,6 +72,9 @@ class plugin_totp {
//pre-process some settings
$theme_favicon = $settings->get('theme', 'favicon', PROJECT_PATH.'/themes/default/favicon.ico');
$theme_logo = $settings->get('theme', 'logo', PROJECT_PATH.'/themes/default/images/logo_login.png');
$theme_login_type = $settings->get('theme', 'login_brand_type', '');
$theme_login_image = $settings->get('theme', 'login_brand_image', '');
$theme_login_text = $settings->get('theme', 'login_brand_text', '');
$theme_login_logo_width = $settings->get('theme', 'login_logo_width', 'auto; max-width: 300px');
$theme_login_logo_height = $settings->get('theme', 'login_logo_height', 'auto; max-height: 300px');
$theme_message_delay = 1000 * (float)$settings->get('theme', 'message_delay', 3000);
@@ -71,7 +84,7 @@ class plugin_totp {
//$login_domain_name = $settings->get('login', 'domain_name');
$login_destination = $settings->get('login', 'destination');
$users_unique = $settings->get('users', 'unique', '');
//get the username
if (isset($_SESSION["username"])) {
$this->username = $_SESSION["username"];

View File

@@ -57,6 +57,7 @@
private $permission_prefix;
private $list_page;
private $tables;
private $table;
private $uuid_prefix;
/**

View File

@@ -328,47 +328,49 @@
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
if (permission_exists($this->name.'_delete')) {
//permission not found return false
if (!permission_exists($this->name.'_delete')) {
return false;
}
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($this->text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
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 (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
$array[$this->table][$x]['dashboard_widget_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['dashboard_widget_uuid'] = $record['dashboard_widget_uuid'];
}
//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 (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
$array[$this->table][$x]['dashboard_widget_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['dashboard_widget_uuid'] = $record['dashboard_widget_uuid'];
}
//increment the id
$x++;
}
//increment the id
$x++;
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$this->database->delete($array);
unset($array);
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$this->database->delete($array);
unset($array);
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
public function toggle_widgets($records) {
@@ -377,64 +379,66 @@
$this->table = 'dashboard_widgets';
$this->toggle_field = 'widget_enabled';
if (permission_exists($this->name.'_edit')) {
//permission not found return false
if (!permission_exists($this->name.'_edit')) {
return false;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($this->text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
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 (isset($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $record) {
if (isset($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
$uuids[] = "'".$record['dashboard_widget_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).") ";
$rows = $this->database->select($sql, $parameters ?? null, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
}
}
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).") ";
$rows = $this->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);
}
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];
//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++;
}
//increment the id
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$this->database->save($array);
unset($array);
$this->database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
public function assign_widgets($records, $dashboard_uuid, $group_uuid) {
@@ -442,76 +446,78 @@
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
if (permission_exists($this->name.'_add')) {
//permission not found return false
if (!permission_exists($this->name.'_add')) {
return false;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$group = $this->database->select($sql, $parameters, 'row');
}
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//assign dashboard widget groups
$array[$this->name.'_groups'][$x][$this->name.'_group_uuid'] = uuid();
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
unset($records);
//exlude exist rows
if (!empty($array) && @sizeof($array) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid, ";
$sql .= "group_uuid from v_".$this->name."_groups ";
$dashboard_widget_groups = $this->database->select($sql, null, 'all');
$array[$this->name.'_groups'] = array_filter($array[$this->name.'_groups'], function($ar) use ($dashboard_widget_groups) {
foreach ($dashboard_widget_groups as $existing_array_item) {
if ($ar['dashboard_uuid'] == $existing_array_item['dashboard_uuid'] && $ar[$this->name.'_uuid'] == $existing_array_item[$this->name.'_uuid'] && $ar['group_uuid'] == $existing_array_item['group_uuid']) {
return false;
}
}
return true;
});
unset($dashboard_widget_groups);
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$group = $this->database->select($sql, $parameters, 'row');
}
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//execute save
$this->database->save($array);
unset($array);
//set message
message::add($text['message-add']);
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//assign dashboard widget groups
$array[$this->name.'_groups'][$x][$this->name.'_group_uuid'] = uuid();
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
unset($records);
//exlude exist rows
if (!empty($array) && @sizeof($array) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid, ";
$sql .= "group_uuid from v_".$this->name."_groups ";
$dashboard_widget_groups = $this->database->select($sql, null, 'all');
$array[$this->name.'_groups'] = array_filter($array[$this->name.'_groups'], function($ar) use ($dashboard_widget_groups) {
foreach ($dashboard_widget_groups as $existing_array_item) {
if ($ar['dashboard_uuid'] == $existing_array_item['dashboard_uuid'] && $ar[$this->name.'_uuid'] == $existing_array_item[$this->name.'_uuid'] && $ar['group_uuid'] == $existing_array_item['group_uuid']) {
return false;
}
}
return true;
});
unset($dashboard_widget_groups);
}
}
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//execute save
$this->database->save($array);
unset($array);
//set message
message::add($text['message-add']);
}
}
}
public function unassign_widgets($records, $dashboard_uuid, $group_uuid) {
@@ -519,85 +525,87 @@
$this->name = 'dashboard_widget';
$this->table = 'dashboard_widgets';
if (permission_exists($this->name.'_add')) {
//permission not found return now
if (!permission_exists($this->name.'_add')) {
return false;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//validate the token
$token = new token;
if (!$token->validate('/core/dashboard/dashboard_widget_list.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
exit;
}
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//assign multiple records
if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) {
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$group = $this->database->select($sql, $parameters, 'row');
//define the group_name and group_uuid
if (!empty($records) && @sizeof($records) != 0) {
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$group = $this->database->select($sql, $parameters, 'row');
}
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
//assign dashboard widget groups
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
//build the delete array
$x = 0;
foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['dashboard_widget_uuid'])) {
//build array
$uuids[] = "'".$record['dashboard_widget_uuid']."'";
unset($records);
//include child dashboard widgets and their dasboard_uuid too
if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid from v_".$this->table." ";
$sql .= "where ".$this->name."_parent_uuid in (".implode(', ', $uuids).") ";
$rows = $this->database->select($sql, null, 'all');
if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
//assign dashboard widget groups
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $dashboard_uuid;
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $record['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $row['dashboard_uuid'];
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $row['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
$x++;
}
}
}
unset($records);
unset($uuids);
//include child dashboard widgets and their dasboard_uuid too
if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select dashboard_uuid, ".$this->name."_uuid from v_".$this->table." ";
$sql .= "where ".$this->name."_parent_uuid in (".implode(', ', $uuids).") ";
$rows = $this->database->select($sql, null, 'all');
if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
//assign dashboard widget groups
$array[$this->name.'_groups'][$x]['dashboard_uuid'] = $row['dashboard_uuid'];
$array[$this->name.'_groups'][$x][$this->name.'_uuid'] = $row['dashboard_widget_uuid'];
$array[$this->name.'_groups'][$x]['group_uuid'] = $group['group_uuid'];
//increment
$x++;
}
}
}
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('dashboard_widget_group_delete', 'temp');
unset($uuids);
//execute delete
$this->database->delete($array);
unset($array);
//add the checked rows from group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('dashboard_widget_group_delete', 'temp');
//revoke temporary permissions
$p->delete('dashboard_widget_group_delete', 'temp');
//execute delete
$this->database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('dashboard_widget_group_delete', 'temp');
//set message
message::add($text['message-delete']);
}
}
}
//set message
message::add($text['message-delete']);
}
}
}
}

View File

@@ -59,6 +59,7 @@
/**
* declare private variables
*/
private $domain_uuid;
private $permission_prefix;
private $list_page;
private $table;
@@ -211,7 +212,7 @@
$token = new token;
if (!$token->validate('/core/domain_settings/domain_settings.php')) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->location);
header('Location: '.$this->list_page);
exit;
}

View File

@@ -38,6 +38,7 @@
*/
private $database;
private $database_group_permissions;
/**
* called when the object is created