|
@@ -49,14 +49,27 @@ if (!class_exists('menu')) {
|
|
public $menu_language;
|
|
public $menu_language;
|
|
public $text;
|
|
public $text;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Set in the constructor. Must be a database object and cannot be null.
|
|
|
|
+ * @var database Database Object
|
|
|
|
+ */
|
|
|
|
+ private $database;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* called when the object is created
|
|
* called when the object is created
|
|
*/
|
|
*/
|
|
- public function __construct() {
|
|
|
|
|
|
+ public function __construct($setting_array = []) {
|
|
//assign the variables
|
|
//assign the variables
|
|
- $this->app_name = 'menus';
|
|
|
|
- $this->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
- $this->location = 'menus.php';
|
|
|
|
|
|
+ $this->app_name = 'menus';
|
|
|
|
+ $this->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
+ $this->location = 'menus.php';
|
|
|
|
+
|
|
|
|
+ //open a database connection
|
|
|
|
+ if (empty($setting_array['database'])) {
|
|
|
|
+ $this->database = database::new();
|
|
|
|
+ } else {
|
|
|
|
+ $this->database = $setting_array['database'];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -113,10 +126,9 @@ if (!class_exists('menu')) {
|
|
$p->add('menu_language_delete', 'temp');
|
|
$p->add('menu_language_delete', 'temp');
|
|
|
|
|
|
//execute delete
|
|
//execute delete
|
|
- $database = new database;
|
|
|
|
- $database->app_name = $this->app_name;
|
|
|
|
- $database->app_uuid = $this->app_uuid;
|
|
|
|
- $database->delete($array);
|
|
|
|
|
|
+ $this->database->app_name = $this->app_name;
|
|
|
|
+ $this->database->app_uuid = $this->app_uuid;
|
|
|
|
+ $this->database->delete($array);
|
|
unset($array);
|
|
unset($array);
|
|
|
|
|
|
//revoke temporary permissions
|
|
//revoke temporary permissions
|
|
@@ -174,8 +186,7 @@ if (!class_exists('menu')) {
|
|
if (!empty($uuids) && @sizeof($uuids) != 0) {
|
|
if (!empty($uuids) && @sizeof($uuids) != 0) {
|
|
$sql = "select menu_item_uuid as uuid from v_".$this->table." ";
|
|
$sql = "select menu_item_uuid as uuid from v_".$this->table." ";
|
|
$sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") ";
|
|
$sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") ";
|
|
- $database = new database;
|
|
|
|
- $rows = $database->select($sql, null, 'all');
|
|
|
|
|
|
+ $rows = $this->database->select($sql, null, 'all');
|
|
if (!empty($rows) && @sizeof($rows) != 0) {
|
|
if (!empty($rows) && @sizeof($rows) != 0) {
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
//remove menu languages
|
|
//remove menu languages
|
|
@@ -199,10 +210,9 @@ if (!class_exists('menu')) {
|
|
$p->add('menu_item_group_delete', 'temp');
|
|
$p->add('menu_item_group_delete', 'temp');
|
|
|
|
|
|
//execute delete
|
|
//execute delete
|
|
- $database = new database;
|
|
|
|
- $database->app_name = $this->app_name;
|
|
|
|
- $database->app_uuid = $this->app_uuid;
|
|
|
|
- $database->delete($array);
|
|
|
|
|
|
+ $this->database->app_name = $this->app_name;
|
|
|
|
+ $this->database->app_uuid = $this->app_uuid;
|
|
|
|
+ $this->database->delete($array);
|
|
unset($array);
|
|
unset($array);
|
|
|
|
|
|
//revoke temporary permissions
|
|
//revoke temporary permissions
|
|
@@ -252,9 +262,8 @@ if (!class_exists('menu')) {
|
|
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
|
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
|
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
|
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
|
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
|
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
|
- $database = new database;
|
|
|
|
$parameters = null;
|
|
$parameters = null;
|
|
- $rows = $database->select($sql, $parameters, 'all');
|
|
|
|
|
|
+ $rows = $this->database->select($sql, $parameters, 'all');
|
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
$states[$row['uuid']] = $row['toggle'] == '' ? $this->toggle_values[1] : $row['toggle'];
|
|
$states[$row['uuid']] = $row['toggle'] == '' ? $this->toggle_values[1] : $row['toggle'];
|
|
@@ -279,10 +288,9 @@ if (!class_exists('menu')) {
|
|
//save the changes
|
|
//save the changes
|
|
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
|
|
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
|
|
//save the array
|
|
//save the array
|
|
- $database = new database;
|
|
|
|
- $database->app_name = $this->app_name;
|
|
|
|
- $database->app_uuid = $this->app_uuid;
|
|
|
|
- $database->save($array);
|
|
|
|
|
|
+ $this->database->app_name = $this->app_name;
|
|
|
|
+ $this->database->app_uuid = $this->app_uuid;
|
|
|
|
+ $this->database->save($array);
|
|
unset($array);
|
|
unset($array);
|
|
|
|
|
|
//set message
|
|
//set message
|
|
@@ -310,8 +318,7 @@ if (!class_exists('menu')) {
|
|
$sql .= " ) ";
|
|
$sql .= " ) ";
|
|
$sql .= ") ";
|
|
$sql .= ") ";
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $database->execute($sql, $parameters);
|
|
|
|
|
|
+ $this->database->execute($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
|
|
|
|
//remove existing unprotected menu item groups
|
|
//remove existing unprotected menu item groups
|
|
@@ -327,8 +334,7 @@ if (!class_exists('menu')) {
|
|
$sql .= " ) ";
|
|
$sql .= " ) ";
|
|
$sql .= ") ";
|
|
$sql .= ") ";
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $database->execute($sql, $parameters);
|
|
|
|
|
|
+ $this->database->execute($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
|
|
|
|
//remove existing unprotected menu items
|
|
//remove existing unprotected menu items
|
|
@@ -339,8 +345,7 @@ if (!class_exists('menu')) {
|
|
$sql .= " or menu_item_protected is null ";
|
|
$sql .= " or menu_item_protected is null ";
|
|
$sql .= ") ";
|
|
$sql .= ") ";
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $database->execute($sql, $parameters);
|
|
|
|
|
|
+ $this->database->execute($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -388,8 +393,7 @@ if (!class_exists('menu')) {
|
|
$sql = "select * from v_menu_items ";
|
|
$sql = "select * from v_menu_items ";
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $menu_items = $database->select($sql, $parameters, 'all');
|
|
|
|
|
|
+ $menu_items = $this->database->select($sql, $parameters, 'all');
|
|
|
|
|
|
//use the app array to restore the default menu
|
|
//use the app array to restore the default menu
|
|
if (is_array($apps)) {
|
|
if (is_array($apps)) {
|
|
@@ -493,10 +497,9 @@ if (!class_exists('menu')) {
|
|
$p->add('menu_item_add', 'temp');
|
|
$p->add('menu_item_add', 'temp');
|
|
$p->add('menu_language_add', 'temp');
|
|
$p->add('menu_language_add', 'temp');
|
|
//execute insert
|
|
//execute insert
|
|
- $database = new database;
|
|
|
|
- $database->app_name = 'menu';
|
|
|
|
- $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
- $database->save($array);
|
|
|
|
|
|
+ $this->database->app_name = 'menu';
|
|
|
|
+ $this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
+ $this->database->save($array);
|
|
unset($array);
|
|
unset($array);
|
|
//revoke temporary permissions
|
|
//revoke temporary permissions
|
|
$p->delete('menu_item_add', 'temp');
|
|
$p->delete('menu_item_add', 'temp');
|
|
@@ -511,8 +514,7 @@ if (!class_exists('menu')) {
|
|
//get default global group_uuids
|
|
//get default global group_uuids
|
|
$sql = "select group_uuid, group_name from v_groups ";
|
|
$sql = "select group_uuid, group_name from v_groups ";
|
|
$sql .= "where domain_uuid is null ";
|
|
$sql .= "where domain_uuid is null ";
|
|
- $database = new database;
|
|
|
|
- $result = $database->select($sql, null, 'all');
|
|
|
|
|
|
+ $result = $this->database->select($sql, null, 'all');
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
|
foreach ($result as $row) {
|
|
foreach ($result as $row) {
|
|
$group_uuids[$row['group_name']] = $row['group_uuid'];
|
|
$group_uuids[$row['group_name']] = $row['group_uuid'];
|
|
@@ -537,8 +539,7 @@ if (!class_exists('menu')) {
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['group_name'] = $group;
|
|
$parameters['group_name'] = $group;
|
|
$parameters['group_uuid'] = $group_uuids[$group] ?? null;
|
|
$parameters['group_uuid'] = $group_uuids[$group] ?? null;
|
|
- $database = new database;
|
|
|
|
- $num_rows = $database->select($sql, $parameters, 'column');
|
|
|
|
|
|
+ $num_rows = $this->database->select($sql, $parameters, 'column');
|
|
if ($num_rows == 0) {
|
|
if ($num_rows == 0) {
|
|
//no menu item groups found, build insert array for defaults
|
|
//no menu item groups found, build insert array for defaults
|
|
$array['menu_item_groups'][$x]['menu_item_group_uuid'] = uuid();
|
|
$array['menu_item_groups'][$x]['menu_item_group_uuid'] = uuid();
|
|
@@ -560,10 +561,9 @@ if (!class_exists('menu')) {
|
|
$p = new permissions;
|
|
$p = new permissions;
|
|
$p->add('menu_item_group_add', 'temp');
|
|
$p->add('menu_item_group_add', 'temp');
|
|
//execute insert
|
|
//execute insert
|
|
- $database = new database;
|
|
|
|
- $database->app_name = 'menu';
|
|
|
|
- $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
- $database->save($array);
|
|
|
|
|
|
+ $this->database->app_name = 'menu';
|
|
|
|
+ $this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
+ $this->database->save($array);
|
|
unset($array);
|
|
unset($array);
|
|
//revoke temporary permissions
|
|
//revoke temporary permissions
|
|
$p->delete('menu_item_group_add', 'temp');
|
|
$p->delete('menu_item_group_add', 'temp');
|
|
@@ -758,8 +758,7 @@ if (!class_exists('menu')) {
|
|
$sql .= "order by i.menu_item_order asc ";
|
|
$sql .= "order by i.menu_item_order asc ";
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'] ?? null;
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'] ?? null;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $result = $database->select($sql, $parameters, 'all');
|
|
|
|
|
|
+ $result = $this->database->select($sql, $parameters, 'all');
|
|
unset($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
|
|
|
|
//save the menu into an array
|
|
//save the menu into an array
|
|
@@ -828,8 +827,7 @@ if (!class_exists('menu')) {
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'];
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'];
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_item_parent_uuid'] = $menu_item_uuid;
|
|
$parameters['menu_item_parent_uuid'] = $menu_item_uuid;
|
|
- $database = new database;
|
|
|
|
- $sub_result = $database->select($sql, $parameters, 'all');
|
|
|
|
|
|
+ $sub_result = $this->database->select($sql, $parameters, 'all');
|
|
unset($sql, $parameters);
|
|
unset($sql, $parameters);
|
|
|
|
|
|
//save the child menu into an array
|
|
//save the child menu into an array
|
|
@@ -880,8 +878,7 @@ if (!class_exists('menu')) {
|
|
$sql = "select count(*) as count from v_menus ";
|
|
$sql = "select count(*) as count from v_menus ";
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
- $database = new database;
|
|
|
|
- $num_rows = $database->select($sql, $parameters, 'column');
|
|
|
|
|
|
+ $num_rows = $this->database->select($sql, $parameters, 'column');
|
|
if ($num_rows == 0) {
|
|
if ($num_rows == 0) {
|
|
//built insert array
|
|
//built insert array
|
|
$array['menus'][0]['menu_uuid'] = $this->menu_uuid;
|
|
$array['menus'][0]['menu_uuid'] = $this->menu_uuid;
|
|
@@ -894,10 +891,9 @@ if (!class_exists('menu')) {
|
|
$p->add('menu_add', 'temp');
|
|
$p->add('menu_add', 'temp');
|
|
|
|
|
|
//execute insert
|
|
//execute insert
|
|
- $database = new database;
|
|
|
|
- $database->app_name = 'menu';
|
|
|
|
- $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
- $database->save($array);
|
|
|
|
|
|
+ $this->database->app_name = 'menu';
|
|
|
|
+ $this->database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
+ $this->database->save($array);
|
|
unset($array);
|
|
unset($array);
|
|
|
|
|
|
//revoke temporary permissions
|
|
//revoke temporary permissions
|