From c679165016dde65cf1fdfc3a0cf0ebf3f3cc8514 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sat, 27 May 2023 12:00:02 -0600 Subject: [PATCH] Menu: PHP 8.1 updates --- core/menu/menu_item_edit.php | 106 +++++++----- core/menu/menu_item_list.php | 258 +++++++++++++++-------------- core/menu/menu_reload.php | 128 +++++++------- core/menu/menu_restore_default.php | 10 +- resources/classes/menu.php | 67 ++++---- 5 files changed, 299 insertions(+), 270 deletions(-) diff --git a/core/menu/menu_item_edit.php b/core/menu/menu_item_edit.php index f816d79754..23e0025d5d 100644 --- a/core/menu/menu_item_edit.php +++ b/core/menu/menu_item_edit.php @@ -45,29 +45,50 @@ $language = new text; $text = $language->get(); +//define the variables + $menu_uuid = null; + $menu_item_uuid = null; + $menu_item_title = ''; + $menu_item_link = ''; + $menu_item_category = ''; + $menu_item_icon = ''; + $menu_item_description = ''; + $menu_item_protected = ''; + $menu_item_parent_uuid = null; + $menu_item_order = null; + //get the menu_uuid - $menu_uuid = $_REQUEST["id"]; - $menu_item_uuid = $_REQUEST['menu_item_uuid']; - $group_uuid_name = $_REQUEST['group_uuid_name']; - $menu_item_group_uuid = $_REQUEST['menu_item_group_uuid']; + if (!empty($_REQUEST)) { + $menu_uuid = $_REQUEST["id"]; + $menu_item_uuid = $_REQUEST['menu_item_uuid'] ?? null; + $group_uuid_name = $_REQUEST['group_uuid_name'] ?? null; + $menu_item_group_uuid = $_REQUEST['menu_item_group_uuid'] ?? null; + } + +//set the action + $action = ''; + if (!empty($_REQUEST["a"])) { + $action = $_REQUEST["a"]; + } //delete the group from the menu item - if ($_REQUEST["a"] == "delete" && permission_exists("menu_delete") && is_uuid($menu_item_group_uuid)) { + if ($action == "delete" && permission_exists("menu_delete") && is_uuid($menu_item_group_uuid)) { //delete the group from the users - $array['menu_item_groups'][0]['menu_item_group_uuid'] = $menu_item_group_uuid; - $database = new database; - $database->app_name = 'menu'; - $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; - $database->delete($array); - unset($array); + $array['menu_item_groups'][0]['menu_item_group_uuid'] = $menu_item_group_uuid; + $database = new database; + $database->app_name = 'menu'; + $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; + $database->delete($array); + unset($array); + //redirect the browser - message::add($text['message-delete']); - header("Location: menu_item_edit.php?id=".urlencode($menu_uuid)."&menu_item_uuid=".urlencode($menu_item_uuid)."&menu_uuid=".urlencode($menu_uuid)); - return; + message::add($text['message-delete']); + header("Location: menu_item_edit.php?id=".urlencode($menu_uuid)."&menu_item_uuid=".urlencode($menu_item_uuid)."&menu_uuid=".urlencode($menu_uuid)); + return; } //action add or update - if (is_uuid($_REQUEST["menu_item_uuid"])) { + if (!empty($_REQUEST["menu_item_uuid"]) && is_uuid($_REQUEST["menu_item_uuid"])) { $action = "update"; $menu_item_uuid = $_REQUEST["menu_item_uuid"]; } @@ -76,25 +97,24 @@ } //get the HTTP POST variables and set them as PHP variables - if (count($_POST) > 0) { - $menu_uuid = $_POST["menu_uuid"]; - $menu_item_uuid = $_POST["menu_item_uuid"]; - $menu_item_title = $_POST["menu_item_title"]; - $menu_item_link = $_POST["menu_item_link"]; - $menu_item_category = $_POST["menu_item_category"]; - $menu_item_icon = $_POST["menu_item_icon"]; - $menu_item_description = $_POST["menu_item_description"]; - $menu_item_protected = $_POST["menu_item_protected"]; - //$menu_item_uuid = $_POST["menu_item_uuid"]; - $menu_item_parent_uuid = $_POST["menu_item_parent_uuid"]; - $menu_item_order = $_POST["menu_item_order"]; + if (!empty($_POST)) { + $menu_uuid = $_POST["menu_uuid"] ?? ''; + $menu_item_uuid = $_POST["menu_item_uuid"] ?? ''; + $menu_item_title = $_POST["menu_item_title"] ?? ''; + $menu_item_link = $_POST["menu_item_link"] ?? ''; + $menu_item_category = $_POST["menu_item_category"] ?? ''; + $menu_item_icon = $_POST["menu_item_icon"] ?? ''; + $menu_item_description = $_POST["menu_item_description"] ?? ''; + $menu_item_protected = $_POST["menu_item_protected"] ?? ''; + $menu_item_parent_uuid = $_POST["menu_item_parent_uuid"] ?? null; + $menu_item_order = $_POST["menu_item_order"] ?? ''; } //sanitize the menu link $menu_item_link = preg_replace('#[^a-zA-Z0-9_:\-\.\&\=\?\/]#', '', $menu_item_link); //when a HTTP POST is available then process it - if (count($_POST) > 0 && empty($_POST["persistformvar"])) { + if (!empty($_POST) && empty($_POST["persistformvar"])) { if ($action == "update") { $menu_item_uuid = $_POST["menu_item_uuid"]; @@ -127,7 +147,7 @@ } //add or update the database - if ($_POST["persistformvar"] != "true") { + if (empty($_POST["persistformvar"])) { //get the language from the menu $sql = "select menu_language from v_menus "; $sql .= "where menu_uuid = :menu_uuid "; @@ -213,7 +233,7 @@ unset($parameters); //add a group to the menu - if ($_REQUEST["a"] != "delete" && !empty($group_uuid_name) && permission_exists('menu_add')) { + if (!empty($group_uuid_name) && permission_exists('menu_add')) { $group_data = explode('|', $group_uuid_name); $group_uuid = $group_data[0]; $group_name = $group_data[1]; @@ -234,7 +254,7 @@ } //add the menu item label - if ($_REQUEST["a"] != "delete" && !empty($menu_item_title) && permission_exists('menu_add')) { + if (!empty($menu_item_title) && permission_exists('menu_add')) { $sql = "select count(*) from v_menu_languages "; $sql .= "where menu_item_uuid = :menu_item_uuid "; $sql .= "and menu_language = :menu_language "; @@ -279,7 +299,7 @@ } //redirect the user - if ($_REQUEST['submit'] == $text['button-add']) { + if (!empty($_REQUEST['submit']) && $_REQUEST['submit'] == $text['button-add']) { header("Location: menu_item_edit.php?id=".urlencode($menu_uuid)."&menu_item_uuid=".urlencode($menu_item_uuid)."&menu_uuid=".urlencode($menu_uuid)); } else { @@ -290,7 +310,7 @@ } //pre-populate the form - if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + if (!empty($_GET["menu_item_uuid"]) && empty($_POST["persistformvar"])) { $menu_item_uuid = $_GET["menu_item_uuid"]; $sql = "select * from v_menu_items "; @@ -348,8 +368,8 @@ unset($sql, $parameters); //set the assigned_groups array - if (is_array($menu_item_groups) && sizeof($menu_item_groups) != 0) { - $assigned_groups = array(); + $assigned_groups = array(); + if (!empty($menu_item_groups) && sizeof($menu_item_groups) != 0) { foreach ($menu_item_groups as $field) { if (!empty($field['group_name'])) { if (is_uuid($field['group_uuid'])) { @@ -362,7 +382,7 @@ //get the groups $sql = "select * from v_groups "; $sql .= "where (domain_uuid is null or domain_uuid = :domain_uuid) "; - if (is_array($assigned_groups) && sizeof($assigned_groups) != 0) { + if (!empty($assigned_groups) && is_array($assigned_groups) && sizeof($assigned_groups) != 0) { $sql .= "and group_uuid not in ('".implode("','",$assigned_groups)."') "; } $sql .= "order by domain_uuid desc, group_name asc "; @@ -477,13 +497,13 @@ echo " "; echo " ".$text['label-groups'].""; echo " "; - if (is_array($menu_item_groups) && sizeof($menu_item_groups) != 0) { + if (!empty($menu_item_groups) && sizeof($menu_item_groups) != 0) { echo "\n"; foreach($menu_item_groups as $field) { if (!empty($field['group_name'])) { echo "\n"; echo " \n"; if (permission_exists('group_member_delete') || if_group("superadmin")) { echo "
"; - echo $field['group_name'].(($field['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['group_domain_uuid']]['domain_name'] : null); + echo $field['group_name'].((!empty($field['group_domain_uuid'])) ? "@".$_SESSION['domains'][$field['group_domain_uuid']]['domain_name'] : null); echo " "; @@ -496,13 +516,13 @@ echo "
\n"; echo "
\n"; } - if (is_array($groups)) { + if (!empty($groups)) { echo ""; diff --git a/core/menu/menu_item_list.php b/core/menu/menu_item_list.php index f5b52e842e..fe57e7e243 100644 --- a/core/menu/menu_item_list.php +++ b/core/menu/menu_item_list.php @@ -42,14 +42,14 @@ } //get the http post data - if (is_array($_POST['menu_items'])) { + if (!empty($_POST['menu_items'])) { $action = $_POST['action']; $menu_uuid = $_POST['menu_uuid']; $menu_items = $_POST['menu_items']; } //process the http post data by action - if ($action != '' && is_array($menu_items) && @sizeof($menu_items) != 0) { + if (!empty($action) && !empty($menu_items)) { switch ($action) { case 'toggle': if (permission_exists('menu_item_edit')) { @@ -69,12 +69,21 @@ exit; } -$tmp_menu_item_order = 0; +//get variables used to control the order + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; -function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { - global $menu_uuid, $tmp_menu_item_order, $v_link_label_edit, $v_link_label_delete, $page, $text, $x; +//set from session variables + $list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false'; - //check for sub menus +//set the initial value + $tmp_menu_item_order = 0; + +//add the build db child menu list + function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { + global $menu_uuid, $list_row_edit_button, $tmp_menu_item_order, $v_link_label_edit, $v_link_label_delete, $page, $text, $x; + + //check for sub menus $menu_item_level = $menu_item_level+1; $sql = "select * from v_menu_items "; $sql .= "where menu_uuid = :menu_uuid "; @@ -85,135 +94,132 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { $database = new database; $result2 = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); - - if (is_array($result2) && sizeof($result2) != 0) { + if (!empty($result2) && sizeof($result2) != 0) { foreach ($result2 as $row2) { - //set the db values as php variables - $menu_item_uuid = $row2['menu_item_uuid']; - $menu_item_category = $row2['menu_item_category']; - $menu_item_protected = $row2['menu_item_protected']; - $menu_item_parent_uuid = $row2['menu_item_parent_uuid']; - $menu_item_order = $row2['menu_item_order']; - $menu_item_language = $row2['menu_item_language']; - $menu_item_title = $row2['menu_item_title']; - $menu_item_link = $row2['menu_item_link']; - //get the groups that have been assigned to the menu - $sql = "select "; - $sql .= " g.group_name, g.domain_uuid as group_domain_uuid "; - $sql .= "from "; - $sql .= " v_menu_item_groups as mig, "; - $sql .= " v_groups as g "; - $sql .= "where "; - $sql .= " mig.group_uuid = g.group_uuid "; - $sql .= " and mig.menu_uuid = :menu_uuid "; - $sql .= " and mig.menu_item_uuid = :menu_item_uuid "; - $sql .= "order by "; - $sql .= " g.domain_uuid desc, "; - $sql .= " g.group_name asc "; - $parameters['menu_uuid'] = $menu_uuid; - $parameters['menu_item_uuid'] = $menu_item_uuid; - $database = new database; - $sub_result = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters, $group_list); - if (is_array($sub_result) && sizeof($sub_result) != 0) { - foreach ($sub_result as &$sub_row) { - $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); - } - $group_list = isset($group_list) ? implode(', ', $group_list) : ''; + //set the db values as php variables + $menu_item_uuid = $row2['menu_item_uuid']; + $menu_item_category = $row2['menu_item_category']; + $menu_item_protected = $row2['menu_item_protected']; + $menu_item_parent_uuid = $row2['menu_item_parent_uuid']; + $menu_item_order = $row2['menu_item_order']; + $menu_item_title = $row2['menu_item_title']; + $menu_item_link = $row2['menu_item_link']; + + //get the groups that have been assigned to the menu + $sql = "select "; + $sql .= " g.group_name, g.domain_uuid as group_domain_uuid "; + $sql .= "from "; + $sql .= " v_menu_item_groups as mig, "; + $sql .= " v_groups as g "; + $sql .= "where "; + $sql .= " mig.group_uuid = g.group_uuid "; + $sql .= " and mig.menu_uuid = :menu_uuid "; + $sql .= " and mig.menu_item_uuid = :menu_item_uuid "; + $sql .= "order by "; + $sql .= " g.domain_uuid desc, "; + $sql .= " g.group_name asc "; + $parameters['menu_uuid'] = $menu_uuid; + $parameters['menu_item_uuid'] = $menu_item_uuid; + $database = new database; + $sub_result = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters, $group_list); + + $group_list = ''; + if (!empty($sub_result) && sizeof($sub_result) != 0) { + foreach ($sub_result as &$sub_row) { + $group_array[] = $sub_row["group_name"].((!empty($sub_row['group_domain_uuid'])) ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); } - unset($sql, $sub_result, $sub_row); + $group_list = !empty($group_array) ? implode(', ', $group_array) : ''; + } + unset($sql, $sub_result, $sub_row); + //display the main body of the list - switch ($menu_item_category) { - case "internal": - $menu_item_link = "$menu_item_link"; - break; - case "external": - if (substr($menu_item_link,0,1) == "/") { - $menu_item_link = PROJECT_PATH.$menu_item_link; - } - $menu_item_link = "".$menu_item_link.""; - break; - case "email": - $menu_item_link = "".$menu_item_link.""; - break; - } + switch ($menu_item_category) { + case "internal": + $menu_item_link = "$menu_item_link"; + break; + case "external": + if (substr($menu_item_link,0,1) == "/") { + $menu_item_link = PROJECT_PATH.$menu_item_link; + } + $menu_item_link = "".$menu_item_link.""; + break; + case "email": + $menu_item_link = "".$menu_item_link.""; + break; + } //display the content of the list - if (permission_exists('menu_item_edit')) { - $list_row_url = 'menu_item_edit.php?id='.urlencode($menu_uuid)."&menu_item_uuid=".urlencode($menu_item_uuid)."&menu_item_parent_uuid=".urlencode($row2['menu_item_parent_uuid']); - } - echo "\n"; - if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - } - echo "\n"; - if (permission_exists('menu_item_edit')) { - echo " ".escape($menu_item_title)."\n"; - } - else { - echo " ".escape($menu_item_title); - } - echo "\n"; - echo "".$menu_item_link." \n"; - echo "".$group_list." "; - echo "".$menu_item_category." "; - if (permission_exists('menu_item_edit')) { - echo " \n"; - echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.($menu_item_protected == 'true' ? 'true' : 'false')],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]); - } - else { - echo " \n"; - echo $text['label-'.($menu_item_protected == 'true' ? 'true' : 'false')]; - } + if (permission_exists('menu_item_edit')) { + $list_row_url = 'menu_item_edit.php?id='.urlencode($menu_uuid)."&menu_item_uuid=".urlencode($menu_item_uuid)."&menu_item_parent_uuid=".urlencode($row2['menu_item_parent_uuid']); + } + echo "\n"; + if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; - echo " "; + } + echo "\n"; + if (permission_exists('menu_item_edit')) { + echo " ".escape($menu_item_title)."\n"; + } + else { + echo " ".escape($menu_item_title); + } + echo "\n"; + echo "".$menu_item_link." \n"; + echo "".$group_list." "; + echo "".$menu_item_category." "; + if (permission_exists('menu_item_edit')) { + echo " \n"; + echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.($menu_item_protected == 'true' ? 'true' : 'false')],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]); + } + else { + echo " \n"; + echo $text['label-'.($menu_item_protected == 'true' ? 'true' : 'false')]; + } + echo " \n"; + echo " "; - //echo ""; - //if (permission_exists('menu_edit')) { - // echo " "; - // echo " "; - //} - //echo ""; + //echo ""; + //if (permission_exists('menu_edit')) { + // echo " "; + // echo " "; + //} + //echo ""; - if (permission_exists('menu_item_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { - echo " \n"; - echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); - echo " \n"; - } - echo "\n"; - $x++; + if (permission_exists('menu_item_edit') && $list_row_edit_button == 'true') { + echo " \n"; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo " \n"; + } + echo "\n"; + $x++; //update the menu order - if ($row2['menu_item_order'] != $tmp_menu_item_order) { - $array['menu_items'][0]['menu_item_uuid'] = $row2['menu_item_uuid']; - $array['menu_items'][0]['menu_uuid'] = $menu_uuid; - $array['menu_items'][0]['menu_item_title'] = $row2['menu_item_title']; - $array['menu_items'][0]['menu_item_order'] = $tmp_menu_item_order; - $database = new database; - $database->app_name = 'menu'; - $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; - $database->save($array); - unset($array); - } - $tmp_menu_item_order++; + if ($row2['menu_item_order'] != $tmp_menu_item_order) { + $array['menu_items'][0]['menu_item_uuid'] = $row2['menu_item_uuid']; + $array['menu_items'][0]['menu_uuid'] = $menu_uuid; + $array['menu_items'][0]['menu_item_title'] = $row2['menu_item_title']; + $array['menu_items'][0]['menu_item_order'] = $tmp_menu_item_order; + $database = new database; + $database->app_name = 'menu'; + $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; + $database->save($array); + unset($array); + } + $tmp_menu_item_order++; //check for additional sub menus - if (strlen($menu_item_uuid)> 0) { - build_db_child_menu_list($db, $menu_item_level, $menu_item_uuid); - } - + if (!empty($menu_item_uuid)) { + build_db_child_menu_list($db, $menu_item_level, $menu_item_uuid); + } } unset($result2, $row2); } -} - -//get variables used to control the order - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; + } //get the list $sql = "select * from v_menu_items "; @@ -262,7 +268,7 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { echo " "; if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; } echo " ".$text['label-title'].""; @@ -271,12 +277,12 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { echo " ".$text['label-category'].""; echo " ".$text['label-protected'].""; echo " ".$text['label-menu_order'].""; - if (permission_exists('menu_item_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if (permission_exists('menu_item_edit') && $list_row_edit_button == 'true') { echo "  \n"; } echo "\n"; - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result) && @sizeof($result) != 0) { $x = 0; foreach ($result as $row) { //set the db values as php variables @@ -305,9 +311,9 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { $sub_result = $database->select($sql, $parameters, 'all'); unset($sql, $group_list); - if (is_array($sub_result) && sizeof($sub_result) != 0) { + if (!empty($sub_result) && sizeof($sub_result) != 0) { foreach ($sub_result as &$sub_row) { - $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); + $group_list[] = $sub_row["group_name"].((!empty($sub_row['group_domain_uuid'])) ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); } $group_list = implode(', ', $group_list); } @@ -369,7 +375,7 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { //} //echo ""; - if (permission_exists('menu_item_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if (permission_exists('menu_item_edit') && $list_row_edit_button == 'true') { echo "\n"; echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); echo "\n"; @@ -424,7 +430,7 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid) { echo " }\n"; //update number of menu items - echo " document.getElementById('num_rows').innerHTML = '".($x ?: 0)."';\n"; + echo " document.getElementById('num_rows').innerHTML = '".(!empty($x) ?: 0)."';\n"; echo "\n"; diff --git a/core/menu/menu_reload.php b/core/menu/menu_reload.php index b90bd4ecc9..e9e3882c51 100644 --- a/core/menu/menu_reload.php +++ b/core/menu/menu_reload.php @@ -1,65 +1,65 @@ - - Portions created by the Initial Developer are Copyright (C) 2020 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//set the include path - $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); - set_include_path(parse_ini_file($conf[0])['document.root']); - -//includes files - require_once "resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('menu_add') || permission_exists('menu_edit')) { - //access granted - } - else { - echo "access denied"; - return; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//get the http value and set as a php variable - $menu_uuid = $_REQUEST["menu_uuid"]; - -//unset the sesssion menu array - unset($_SESSION['menu']['array']); - -//get the menu array and save it to the session - $menu = new menu; - $menu->menu_uuid = $_SESSION['domain']['menu']['uuid']; - $_SESSION['menu']['array'] = $menu->menu_array(); - unset($menu); - -//redirect the user - message::add($text['message-reload']); - header("Location: ".PROJECT_PATH."/core/menu/menu_edit.php?id=".urlencode($menu_uuid)); - return; - + + Portions created by the Initial Developer are Copyright (C) 2020 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//set the include path + $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); + set_include_path(parse_ini_file($conf[0])['document.root']); + +//includes files + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('menu_add') || permission_exists('menu_edit')) { + //access granted + } + else { + echo "access denied"; + return; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get the http value and set as a php variable + $menu_uuid = $_REQUEST["menu_uuid"]; + +//unset the sesssion menu array + unset($_SESSION['menu']['array']); + +//get the menu array and save it to the session + $menu = new menu; + $menu->menu_uuid = $_SESSION['domain']['menu']['uuid']; + $_SESSION['menu']['array'] = $menu->menu_array(); + unset($menu); + +//redirect the user + //message::add($text['message-reload']); + header("Location: ".PROJECT_PATH."/core/menu/menu_edit.php?id=".urlencode($menu_uuid)); + return; + ?> \ No newline at end of file diff --git a/core/menu/menu_restore_default.php b/core/menu/menu_restore_default.php index 835c03d401..80bc999cb9 100644 --- a/core/menu/menu_restore_default.php +++ b/core/menu/menu_restore_default.php @@ -25,7 +25,7 @@ */ //check permissions - if (!$included) { + if(!defined('STDIN')) { //set the include path $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); set_include_path(parse_ini_file($conf[0])['document.root']); @@ -47,13 +47,15 @@ $text = $language->get(); //get the http value and set as a php variable - if (!$included) { + if (!empty($_REQUEST["menu_uuid"])) { $menu_uuid = $_REQUEST["menu_uuid"]; + } + if (!empty($_REQUEST["menu_language"])) { $menu_language = $_REQUEST["menu_language"]; } //menu restore default - require_once "resources/classes/menu.php"; + //require_once "resources/classes/menu.php"; $menu = new menu; $menu->menu_uuid = $menu_uuid; $menu->menu_language = $menu_language; @@ -68,7 +70,7 @@ unset($menu); //redirect - if (!$included) { + if(!defined('STDIN')) { //show a message to the user message::add($text['message-restore']); header("Location: ".PROJECT_PATH."/core/menu/menu_edit.php?id=".urlencode($menu_uuid)); diff --git a/resources/classes/menu.php b/resources/classes/menu.php index 4d6df5f038..d147ca3dc2 100644 --- a/resources/classes/menu.php +++ b/resources/classes/menu.php @@ -86,7 +86,7 @@ if (!class_exists('menu')) { //build the delete array $x = 0; foreach ($records as $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { //remove menu languages $array['menu_languages'][$x][$this->name.'_uuid'] = $record['uuid']; @@ -156,7 +156,7 @@ if (!class_exists('menu')) { //build the delete array $x = 0; foreach ($records as $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { //build array $uuids[] = "'".$record['uuid']."'"; //remove menu languages @@ -171,12 +171,12 @@ if (!class_exists('menu')) { } //include child menu items - if (is_array($uuids) && @sizeof($uuids) != 0) { + if (!empty($uuids) && @sizeof($uuids) != 0) { $sql = "select menu_item_uuid as uuid from v_".$this->table." "; $sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") "; $database = new database; - $rows = $database->select($sql, $parameters, 'all'); - if (is_array($rows) && @sizeof($rows) != 0) { + $rows = $database->select($sql, null, 'all'); + if (!empty($rows) && @sizeof($rows) != 0) { foreach ($rows as $row) { //remove menu languages $array['menu_languages'][$x][$this->name.'_uuid'] = $row['uuid']; @@ -240,12 +240,12 @@ if (!class_exists('menu')) { header('Location: '.$this->location); exit; } -https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805e327 + //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['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $uuids[] = "'".$record['uuid']."'"; } } @@ -253,6 +253,7 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 $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; + $parameters = null; $rows = $database->select($sql, $parameters, 'all'); if (is_array($rows) && @sizeof($rows) != 0) { foreach ($rows as $row) { @@ -912,7 +913,7 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 public function menu_horizontal($menu_array) { //determine menu behavior - $menu_style = $_SESSION['theme']['menu_style']['text'] != '' ? $_SESSION['theme']['menu_style']['text'] : 'fixed'; + $menu_style = !empty($_SESSION['theme']['menu_style']['text']) ? $_SESSION['theme']['menu_style']['text'] : 'fixed'; switch ($menu_style) { case 'inline': $menu_type = 'default'; @@ -949,10 +950,10 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 $html .= " ".$menu_brand_text."\n"; break; case 'image_text': - $menu_brand_image = ($_SESSION['theme']['menu_brand_image']['text'] != '') ? escape($_SESSION['theme']['menu_brand_image']['text']) : PROJECT_PATH."/themes/default/images/logo.png"; + $menu_brand_image = (!empty($_SESSION['theme']['menu_brand_image']['text'])) ? escape($_SESSION['theme']['menu_brand_image']['text']) : PROJECT_PATH."/themes/default/images/logo.png"; $html .= " "; $html .= " "; - if ($_SESSION['theme']['menu_brand_image_hover']['text'] != '') { + if (!empty($_SESSION['theme']['menu_brand_image_hover']['text'])) { $html .= ""; } $html .= "\n"; @@ -965,7 +966,7 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 $menu_brand_image = !empty($_SESSION['theme']['menu_brand_image']['text']) ? escape($_SESSION['theme']['menu_brand_image']['text']) : PROJECT_PATH."/themes/default/images/logo.png"; $html .= " "; $html .= " "; - if (isset($_SESSION['theme']['menu_brand_image_hover']['text']) && $_SESSION['theme']['menu_brand_image_hover']['text'] != '') { + if (isset($_SESSION['theme']['menu_brand_image_hover']['text']) && !empty($_SESSION['theme']['menu_brand_image_hover']['text'])) { $html .= ""; } $html .= "\n"; @@ -982,20 +983,20 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 $html .= " \n"; //main menu items - if (is_array($menu_array) && sizeof($menu_array) != 0) { + if (!empty($menu_array)) { foreach ($menu_array as $menu_index_main => $menu_item_main) { $menu_target = ($menu_item_main['menu_item_category'] == 'external') ? '_blank' : ''; - $html .= " "; + $html .= " "; if (is_array($menu_item_main['menu_items']) && sizeof($menu_item_main['menu_items']) != 0 && $_SESSION['theme']['menu_side_item_main_sub_icons']['boolean'] == 'true') { - $html .= " \n"; + $html .= " \n"; } - if ($menu_item_main['menu_item_icon'] != '') { + if (!empty($menu_item_main['menu_item_icon'])) { $html .= ""; } $html .= "".$menu_item_main['menu_language_title'].""; @@ -1143,9 +1144,9 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 //header: left $html .= "
\n"; $html .= button::create(['type'=>'button','id'=>'menu_side_state_hidden_button','title'=>$this->text['theme-label-expand_menu'],'icon'=>'bars','class'=>'default '.($_SESSION['theme']['menu_side_state']['text'] != 'hidden' ? 'hide-sm-up ' : null).'float-left','onclick'=>'menu_side_expand();']); - $body_header_brand_text = $_SESSION['theme']['body_header_brand_text']['text'] != '' ? escape($_SESSION['theme']['body_header_brand_text']['text']) : "FusionPBX"; + $body_header_brand_text = !empty($_SESSION['theme']['body_header_brand_text']['text']) ? escape($_SESSION['theme']['body_header_brand_text']['text']) : "FusionPBX"; if ($_SESSION['theme']['body_header_brand_type']['text'] == 'image' || $_SESSION['theme']['body_header_brand_type']['text'] == 'image_text') { - $body_header_brand_image = $_SESSION['theme']['body_header_brand_image']['text'] != '' ? $_SESSION['theme']['body_header_brand_image']['text'] : PROJECT_PATH."/themes/default/images/logo_side_expanded.png"; + $body_header_brand_image = !empty($_SESSION['theme']['body_header_brand_image']['text']) ? $_SESSION['theme']['body_header_brand_image']['text'] : PROJECT_PATH."/themes/default/images/logo_side_expanded.png"; $html .= "
"; $html .= ""; $html .= "
"; @@ -1161,20 +1162,20 @@ https://www.fusionpbx.com/app/pages/page.php?id=f48cceb2-5e31-47c2-a84a-8f45d805 $html .= " text['theme-label-user']."\">".$_SESSION['username'].""; $html .= "\n"; //domain name/selector (sm+) - if (isset($_SESSION['username']) && $_SESSION['username'] != '' && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $_SESSION['theme']['domain_visible']['text'] == 'true') { + if (!empty($_SESSION['username']) && permission_exists('domain_select') && count($_SESSION['domains']) > 1 && $_SESSION['theme']['domain_visible']['text'] == 'true') { $html .= "\n"; $html .= " ".escape($_SESSION['domain_name']).""; $html .= "\n"; } //logout icon - if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") { + if (!empty($_SESSION['username']) && $_SESSION['theme']['logout_icon_visible']['text'] == "true") { $html .= "text['theme-label-logout']."\" onclick=\"modal_open('modal-logout','btn_logout');\">"; } $html .= "
"; $html .= " \n"; //modal for logout icon (above) - if (isset($_SESSION['username']) && $_SESSION['username'] != '' && $_SESSION['theme']['logout_icon_visible']['text'] == "true") { + if (!empty($_SESSION['username']) && $_SESSION['theme']['logout_icon_visible']['text'] == "true") { $html .= modal::create(['id'=>'modal-logout','type'=>'general','message'=>$this->text['theme-confirm-logout'],'actions'=>button::create(['type'=>'button','label'=>$this->text['theme-label-logout'],'icon'=>'sign-out-alt','id'=>'btn_logout','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>PROJECT_PATH.'/logout.php','onclick'=>"modal_close();"])]); }