2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2019-10-12 23:37:22 +02:00
|
|
|
Copyright (C) 2010 - 2019
|
2012-06-04 16:58:40 +02:00
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2013-01-23 16:56:00 +01:00
|
|
|
//define the menu class
|
2016-04-15 07:23:14 +02:00
|
|
|
if (!class_exists('menu')) {
|
2012-06-04 16:58:40 +02:00
|
|
|
class menu {
|
2016-03-27 05:22:52 +02:00
|
|
|
//define the variables
|
|
|
|
|
public $menu_uuid;
|
|
|
|
|
public $menu_language;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//delete items in the menu that are not protected
|
2016-03-27 05:18:02 +02:00
|
|
|
public function delete() {
|
2015-05-12 05:03:09 +02:00
|
|
|
//remove existing menu languages
|
2013-06-11 21:04:40 +02:00
|
|
|
$sql = "delete from v_menu_languages ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
2017-07-02 00:05:25 +02:00
|
|
|
$sql .= "and menu_item_uuid in ( ";
|
|
|
|
|
$sql .= " select menu_item_uuid ";
|
|
|
|
|
$sql .= " from v_menu_items ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= " where menu_uuid = :menu_uuid ";
|
2017-07-02 00:05:25 +02:00
|
|
|
$sql .= " and ( ";
|
|
|
|
|
$sql .= " menu_item_protected <> 'true' ";
|
|
|
|
|
$sql .= " or menu_item_protected is null ";
|
|
|
|
|
$sql .= " ) ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= ") ";
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->execute($sql, $parameters);
|
|
|
|
|
unset($sql, $parameters);
|
2019-10-12 23:37:22 +02:00
|
|
|
|
2015-05-12 05:03:09 +02:00
|
|
|
//remove existing unprotected menu item groups
|
|
|
|
|
$sql = "delete from v_menu_item_groups ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
2015-05-12 05:03:09 +02:00
|
|
|
$sql .= "and menu_item_uuid in ( ";
|
2015-05-12 08:31:34 +02:00
|
|
|
$sql .= " select menu_item_uuid ";
|
|
|
|
|
$sql .= " from v_menu_items ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= " where menu_uuid = :menu_uuid ";
|
2015-05-12 08:31:34 +02:00
|
|
|
$sql .= " and ( ";
|
|
|
|
|
$sql .= " menu_item_protected <> 'true' ";
|
|
|
|
|
$sql .= " or menu_item_protected is null ";
|
|
|
|
|
$sql .= " ) ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= ") ";
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->execute($sql, $parameters);
|
|
|
|
|
unset($sql, $parameters);
|
2019-10-12 23:37:22 +02:00
|
|
|
|
2015-05-12 05:03:09 +02:00
|
|
|
//remove existing unprotected menu items
|
2012-10-11 17:01:48 +02:00
|
|
|
$sql = "delete from v_menu_items ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
2012-10-11 17:01:48 +02:00
|
|
|
$sql .= "and (menu_item_protected <> 'true' ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "or menu_item_protected is null) ";
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->execute($sql, $parameters);
|
|
|
|
|
unset($sql, $parameters);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//restore the menu
|
2016-03-27 05:18:02 +02:00
|
|
|
public function restore() {
|
2017-07-01 22:13:51 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//get the $apps array from the installed apps from the core and mod directories
|
2015-05-12 20:11:05 +02:00
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php");
|
2014-12-27 18:22:57 +01:00
|
|
|
$x = 0;
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($config_list)) {
|
|
|
|
|
foreach ($config_list as &$config_path) {
|
|
|
|
|
$app_path = dirname($config_path);
|
|
|
|
|
$app_path = preg_replace('/\A.*(\/.*\/.*)\z/', '$1', $app_path);
|
|
|
|
|
$y = 0;
|
|
|
|
|
try {
|
|
|
|
|
//echo "[".$x ."] ".$config_path."\n";
|
|
|
|
|
include($config_path);
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
echo 'exception caught: ' . $e->getMessage() . "\n";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2014-12-27 08:25:11 +01:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-01 18:21:21 +02:00
|
|
|
//get the list of languages
|
|
|
|
|
$language = new text;
|
|
|
|
|
|
2019-10-12 23:37:22 +02:00
|
|
|
//create a uuid array of the original uuid used as the key and new uuid as the value
|
|
|
|
|
if (is_array($apps)) {
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($apps as $row) {
|
|
|
|
|
if (is_array($row['menu'])) {
|
|
|
|
|
foreach ($row['menu'] as $menu) {
|
|
|
|
|
$uuid_array[$menu['uuid']] = uuid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if the item uuid is not currently in the db then add it
|
|
|
|
|
$sql = "select * from v_menu_items ";
|
|
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$parameters['uuid'] = $uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$menu_items = $database->select($sql, $parameters, 'all');
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//use the app array to restore the default menu
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($apps)) {
|
2019-09-03 17:59:37 +02:00
|
|
|
$x = 0;
|
2017-11-17 22:44:31 +01:00
|
|
|
foreach ($apps as $row) {
|
|
|
|
|
if (is_array($row['menu'])) {
|
|
|
|
|
foreach ($row['menu'] as $menu) {
|
|
|
|
|
//set the variables
|
|
|
|
|
if (strlen($menu['title'][$this->menu_language]) > 0) {
|
|
|
|
|
$menu_item_title = $menu['title'][$this->menu_language];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$menu_item_title = $menu['title']['en-us'];
|
|
|
|
|
}
|
2019-10-12 23:37:22 +02:00
|
|
|
$uuid = $menu['uuid'];
|
|
|
|
|
$menu_item_uuid = $uuid_array[$menu['uuid']];
|
|
|
|
|
$menu_item_parent_uuid = $uuid_array[$menu['parent_uuid']];
|
2017-11-17 22:44:31 +01:00
|
|
|
$menu_item_category = $menu['category'];
|
|
|
|
|
$menu_item_icon = $menu['icon'];
|
|
|
|
|
$menu_item_path = $menu['path'];
|
|
|
|
|
$menu_item_order = $menu['order'];
|
|
|
|
|
$menu_item_description = $menu['desc'];
|
|
|
|
|
|
|
|
|
|
//menu found set the default
|
|
|
|
|
$menu_item_exists = true;
|
|
|
|
|
|
|
|
|
|
//if the item uuid is not currently in the db then add it
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql = "select count(*) from v_menu_items ";
|
|
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
2019-10-12 23:37:22 +02:00
|
|
|
$sql .= "and uuid = :uuid ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
2019-10-12 23:37:22 +02:00
|
|
|
$parameters['uuid'] = $uuid;
|
2019-09-03 17:59:37 +02:00
|
|
|
$database = new database;
|
|
|
|
|
$num_rows = $database->select($sql, $parameters, 'column');
|
|
|
|
|
if ($num_rows == 0) {
|
2019-10-12 23:37:22 +02:00
|
|
|
|
2019-09-03 17:59:37 +02:00
|
|
|
//menu found the menu
|
|
|
|
|
$menu_item_exists = false;
|
|
|
|
|
|
2019-10-12 23:37:22 +02:00
|
|
|
//build the menu array
|
|
|
|
|
if ($menu_item_uuid != $menu_item_parent_uuid) {
|
|
|
|
|
$array['menu_items'][$x]['menu_item_uuid'] = $menu_item_uuid;
|
|
|
|
|
$array['menu_items'][$x]['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$array['menu_items'][$x]['uuid'] = $uuid;
|
|
|
|
|
$array['menu_items'][$x]['menu_item_title'] = $menu_item_title;
|
|
|
|
|
$array['menu_items'][$x]['menu_item_link'] = $menu_item_path;
|
|
|
|
|
$array['menu_items'][$x]['menu_item_category'] = $menu_item_category;
|
|
|
|
|
$array['menu_items'][$x]['menu_item_icon'] = $menu_item_icon;
|
|
|
|
|
if (strlen($menu_item_order) > 0) {
|
|
|
|
|
$array['menu_items'][$x]['menu_item_order'] = $menu_item_order;
|
|
|
|
|
}
|
|
|
|
|
if (is_uuid($menu_item_parent_uuid)) {
|
|
|
|
|
$array['menu_items'][$x]['menu_item_parent_uuid'] = $menu_item_parent_uuid;
|
|
|
|
|
}
|
|
|
|
|
$array['menu_items'][$x]['menu_item_description'] = $menu_item_description;
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
unset($sql, $parameters, $num_rows);
|
2017-11-17 22:44:31 +01:00
|
|
|
|
|
|
|
|
//set the menu languages
|
2019-09-03 17:59:37 +02:00
|
|
|
if (!$menu_item_exists && is_array($language->languages)) {
|
2017-11-17 22:44:31 +01:00
|
|
|
foreach ($language->languages as $menu_language) {
|
2019-10-12 23:37:22 +02:00
|
|
|
//set the menu item title
|
|
|
|
|
$menu_item_title = $menu["title"][$menu_language];
|
|
|
|
|
if (strlen($menu_item_title) == 0) {
|
|
|
|
|
$menu_item_title = $menu["title"]['en-us'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 17:59:37 +02:00
|
|
|
//build insert array
|
2019-10-12 23:37:22 +02:00
|
|
|
$array['menu_languages'][$x]['menu_language_uuid'] = uuid();
|
2019-09-03 17:59:37 +02:00
|
|
|
$array['menu_languages'][$x]['menu_item_uuid'] = $menu_item_uuid;
|
|
|
|
|
$array['menu_languages'][$x]['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$array['menu_languages'][$x]['menu_language'] = $menu_language;
|
|
|
|
|
$array['menu_languages'][$x]['menu_item_title'] = $menu_item_title;
|
|
|
|
|
$x++;
|
2013-07-29 20:55:51 +02:00
|
|
|
}
|
2017-07-02 00:05:25 +02:00
|
|
|
}
|
2017-07-01 22:13:51 +02:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-29 20:55:51 +02:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
|
|
|
|
//grant temporary permissions
|
|
|
|
|
$p = new permissions;
|
|
|
|
|
$p->add('menu_item_add', 'temp');
|
|
|
|
|
$p->add('menu_language_add', 'temp');
|
|
|
|
|
//execute insert
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'menu';
|
|
|
|
|
$database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('menu_item_add', 'temp');
|
|
|
|
|
$p->delete('menu_language_add', 'temp');
|
|
|
|
|
}
|
2013-09-27 06:15:43 +02:00
|
|
|
}
|
2013-11-24 01:15:02 +01:00
|
|
|
|
2016-04-03 19:54:09 +02:00
|
|
|
//make sure the default user groups exist
|
|
|
|
|
$group = new groups;
|
|
|
|
|
$group->defaults();
|
|
|
|
|
|
2015-05-12 05:03:09 +02:00
|
|
|
//get default global group_uuids
|
|
|
|
|
$sql = "select group_uuid, group_name from v_groups ";
|
|
|
|
|
$sql .= "where domain_uuid is null ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$database = new database;
|
|
|
|
|
$result = $database->select($sql, null, 'all');
|
|
|
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
2017-11-17 22:44:31 +01:00
|
|
|
foreach ($result as $row) {
|
|
|
|
|
$group_uuids[$row['group_name']] = $row['group_uuid'];
|
|
|
|
|
}
|
2015-05-12 05:03:09 +02:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
unset($sql, $result, $row);
|
2015-05-12 05:03:09 +02:00
|
|
|
|
2013-11-24 01:15:02 +01:00
|
|
|
//if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($apps)) {
|
2019-09-03 17:59:37 +02:00
|
|
|
$x = 0;
|
2017-11-17 22:44:31 +01:00
|
|
|
foreach($apps as $app) {
|
|
|
|
|
if (is_array($apps)) {
|
|
|
|
|
foreach ($app['menu'] as $sub_row) {
|
2019-09-03 17:59:37 +02:00
|
|
|
if (isset($sub_row['groups'])) {
|
|
|
|
|
foreach ($sub_row['groups'] as $group) {
|
|
|
|
|
$sql = "select count(*) from v_menu_item_groups ";
|
|
|
|
|
$sql .= "where menu_item_uuid = :menu_item_uuid ";
|
|
|
|
|
$sql .= "and menu_uuid = :menu_uuid ";
|
|
|
|
|
$sql .= "and group_name = :group_name ";
|
|
|
|
|
$sql .= "and group_uuid = :group_uuid ";
|
2019-10-12 23:37:22 +02:00
|
|
|
$parameters['menu_item_uuid'] = $uuid_array[$sub_row['uuid']];
|
2019-09-03 17:59:37 +02:00
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$parameters['group_name'] = $group;
|
|
|
|
|
$parameters['group_uuid'] = $group_uuids[$group];
|
|
|
|
|
$database = new database;
|
|
|
|
|
$num_rows = $database->select($sql, $parameters, 'column');
|
|
|
|
|
if ($num_rows == 0) {
|
|
|
|
|
//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_uuid'] = $this->menu_uuid;
|
2019-10-12 23:37:22 +02:00
|
|
|
$array['menu_item_groups'][$x]['menu_item_uuid'] = $uuid_array[$sub_row['uuid']];
|
2019-09-03 17:59:37 +02:00
|
|
|
$array['menu_item_groups'][$x]['group_name'] = $group;
|
|
|
|
|
$array['menu_item_groups'][$x]['group_uuid'] = $group_uuids[$group];
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
unset($sql, $parameters, $num_rows);
|
2017-11-17 22:44:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-29 19:22:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-12 23:37:22 +02:00
|
|
|
|
2019-09-03 17:59:37 +02:00
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
|
|
|
|
//grant temporary permissions
|
|
|
|
|
$p = new permissions;
|
|
|
|
|
$p->add('menu_item_group_add', 'temp');
|
|
|
|
|
//execute insert
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'menu';
|
|
|
|
|
$database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('menu_item_group_add', 'temp');
|
|
|
|
|
}
|
2013-07-29 19:22:40 +02:00
|
|
|
}
|
2013-11-24 01:15:02 +01:00
|
|
|
|
2019-09-03 17:59:37 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//create the menu
|
2016-03-27 05:18:02 +02:00
|
|
|
public function build_html($menu_item_level = 0) {
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_html_full = '';
|
|
|
|
|
|
|
|
|
|
$menu_array = $this->menu_array();
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
if (!isset($_SESSION['groups'])) {
|
|
|
|
|
$_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($menu_array)) {
|
|
|
|
|
foreach($menu_array as $menu_field) {
|
|
|
|
|
//set the variables
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_item_link = $menu_field['menu_item_link'];
|
|
|
|
|
$menu_item_category = $menu_field['menu_item_category'];
|
|
|
|
|
$menu_items = $menu_field['menu_items'];
|
2017-11-17 22:44:31 +01:00
|
|
|
|
|
|
|
|
//prepare the protected menus
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_item_title = ($menu_field['menu_item_protected'] == "true") ? $menu_field['menu_item_title'] : $menu_field['menu_language_title'];
|
2017-11-17 22:44:31 +01:00
|
|
|
|
|
|
|
|
//prepare the menu_tags according to the category
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_tags = '';
|
|
|
|
|
switch ($menu_item_category) {
|
|
|
|
|
case "internal":
|
|
|
|
|
$menu_tags = "href='".PROJECT_PATH.$submenu_item_link."'";
|
|
|
|
|
break;
|
|
|
|
|
case "external":
|
|
|
|
|
if (substr($submenu_item_link, 0,1) == "/") {
|
|
|
|
|
$submenu_item_link = PROJECT_PATH.$submenu_item_link;
|
|
|
|
|
}
|
|
|
|
|
$menu_tags = "href='".$submenu_item_link."' target='_blank'";
|
|
|
|
|
break;
|
|
|
|
|
case "email":
|
|
|
|
|
$menu_tags = "href='mailto:".$submenu_item_link."'";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-09 21:30:36 +01:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
if ($menu_item_level == 0) {
|
|
|
|
|
$menu_html = "<ul class='menu_main'>\n";
|
|
|
|
|
$menu_html .= "<li>\n";
|
|
|
|
|
if (!isset($_SESSION["username"])) {
|
|
|
|
|
$_SESSION["username"] = '';
|
|
|
|
|
}
|
|
|
|
|
if (strlen($_SESSION["username"]) == 0) {
|
|
|
|
|
$menu_html .= "<a $menu_tags style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2017-11-17 22:44:31 +01:00
|
|
|
if ($submenu_item_link == "/login.php" || $submenu_item_link == "/users/signup.php") {
|
|
|
|
|
//hide login and sign-up when the user is logged in
|
2015-01-09 21:57:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2017-11-17 22:44:31 +01:00
|
|
|
if (strlen($submenu_item_link) == 0) {
|
|
|
|
|
$menu_html .= "<h2 align='center' style=''>".$menu_item_title."</h2>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$menu_html .= "<a ".$menu_tags." style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
|
|
|
|
|
}
|
2015-01-09 21:57:40 +01:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($menu_field['menu_items']) && count($menu_field['menu_items']) > 0) {
|
|
|
|
|
$menu_html .= $this->build_child_html($menu_item_level, $menu_field['menu_items']);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
if ($menu_item_level == 0) {
|
|
|
|
|
$menu_html .= "</li>\n";
|
|
|
|
|
$menu_html .= "</ul>\n\n";
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
$menu_html_full .= $menu_html;
|
|
|
|
|
} //end for each
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-07-30 19:49:51 +02:00
|
|
|
return $menu_html_full;
|
2019-09-03 17:59:37 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//create the sub menus
|
2016-03-27 05:18:02 +02:00
|
|
|
private function build_child_html($menu_item_level, $submenu_array) {
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
$db = $this->db;
|
|
|
|
|
$menu_item_level = $menu_item_level+1;
|
|
|
|
|
|
|
|
|
|
if (count($_SESSION['groups']) == 0) {
|
|
|
|
|
$_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
if (is_array($submenu_array)) {
|
2012-06-04 16:58:40 +02:00
|
|
|
//child menu found
|
2015-07-30 19:49:51 +02:00
|
|
|
$submenu_html = "<ul class='menu_sub'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-07-30 19:49:51 +02:00
|
|
|
foreach($submenu_array as $submenu_field) {
|
2013-09-27 06:15:43 +02:00
|
|
|
//set the variables
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_item_link = $submenu_field['menu_item_link'];
|
|
|
|
|
$menu_item_category = $submenu_field['menu_item_category'];
|
|
|
|
|
$menu_items = $submenu_field['menu_items'];
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2013-02-09 21:30:36 +01:00
|
|
|
//prepare the protected menus
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_item_title = ($submenu_field['menu_item_protected'] == "true") ? $submenu_field['menu_item_title'] : $submenu_field['menu_language_title'];
|
2013-02-09 21:30:36 +01:00
|
|
|
|
|
|
|
|
//prepare the menu_tags according to the category
|
|
|
|
|
switch ($menu_item_category) {
|
|
|
|
|
case "internal":
|
|
|
|
|
$menu_tags = "href='".PROJECT_PATH.$menu_item_link."'";
|
|
|
|
|
break;
|
|
|
|
|
case "external":
|
|
|
|
|
if (substr($menu_item_link, 0,1) == "/") {
|
2015-07-30 19:49:51 +02:00
|
|
|
$menu_item_link = PROJECT_PATH.$menu_item_link;
|
2013-02-09 21:30:36 +01:00
|
|
|
}
|
|
|
|
|
$menu_tags = "href='".$menu_item_link."' target='_blank'";
|
|
|
|
|
break;
|
|
|
|
|
case "email":
|
|
|
|
|
$menu_tags = "href='mailto:".$menu_item_link."'";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-07-30 19:49:51 +02:00
|
|
|
$submenu_html .= "<li>";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//get sub menu for children
|
2015-07-30 19:49:51 +02:00
|
|
|
if (is_array($menu_items) && count($menu_items) > 0) {
|
|
|
|
|
$str_child_menu = $this->build_child_html($menu_item_level, $menu_items);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen($str_child_menu) > 1) {
|
2015-07-30 19:49:51 +02:00
|
|
|
$submenu_html .= "<a ".$menu_tags.">".$menu_item_title."</a>";
|
|
|
|
|
$submenu_html .= $str_child_menu;
|
2012-06-04 16:58:40 +02:00
|
|
|
unset($str_child_menu);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-07-30 19:49:51 +02:00
|
|
|
$submenu_html .= "<a ".$menu_tags.">".$menu_item_title."</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2015-07-30 19:49:51 +02:00
|
|
|
$submenu_html .= "</li>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2015-07-30 19:49:51 +02:00
|
|
|
unset($submenu_array);
|
|
|
|
|
|
|
|
|
|
$submenu_html .="</ul>\n";
|
|
|
|
|
|
|
|
|
|
return $submenu_html;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
}
|
2015-06-22 19:56:40 +02:00
|
|
|
|
|
|
|
|
//create the menu array
|
2019-09-03 17:59:37 +02:00
|
|
|
public function menu_array($menu_item_level = 0) {
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//if there are no groups then set the public group
|
2017-11-17 22:28:07 +01:00
|
|
|
if (!isset($_SESSION['groups'][0]['group_name'])) {
|
2016-03-26 19:22:15 +01:00
|
|
|
$_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the menu from the database
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, ".
|
|
|
|
|
$sql .= "i.menu_item_title, i.menu_item_protected, i.menu_item_category, ";
|
|
|
|
|
$sql .= "i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
|
|
|
|
|
$sql .= "from v_menu_items as i, v_menu_languages as l ";
|
|
|
|
|
$sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
|
|
|
|
|
$sql .= "and l.menu_language = :menu_language ";
|
|
|
|
|
$sql .= "and l.menu_uuid = :menu_uuid ";
|
|
|
|
|
$sql .= "and i.menu_uuid = :menu_uuid ";
|
|
|
|
|
$sql .= "and i.menu_item_parent_uuid is null ";
|
|
|
|
|
$sql .= "and i.menu_item_uuid in ";
|
|
|
|
|
$sql .= "( ";
|
|
|
|
|
$sql .= "select menu_item_uuid ";
|
|
|
|
|
$sql .= "from v_menu_item_groups ";
|
|
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach($_SESSION['groups'] as $row) {
|
|
|
|
|
$sql_where_or[] = "group_name = :group_name_".$x;
|
|
|
|
|
$parameters['group_name_'.$x] = $row['group_name'];
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
|
2016-03-26 19:22:15 +01:00
|
|
|
$sql .= "and ( ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= implode(' or ', $sql_where_or);
|
2016-03-26 19:22:15 +01:00
|
|
|
$sql .= ") ";
|
|
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "and menu_item_uuid is not null ";
|
|
|
|
|
$sql .= ") ";
|
|
|
|
|
$sql .= "order by i.menu_item_order asc ";
|
|
|
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'];
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$result = $database->select($sql, $parameters, 'all');
|
|
|
|
|
unset($sql, $parameters);
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//save the menu into an array
|
|
|
|
|
$x = 0;
|
2016-03-30 09:15:49 +02:00
|
|
|
$a = Array();
|
2019-09-03 17:59:37 +02:00
|
|
|
if (is_array($result) && @sizeof($result) != 0) {
|
2017-11-17 22:44:31 +01:00
|
|
|
foreach($result as $row) {
|
|
|
|
|
//add the row to the array
|
|
|
|
|
$a[$x] = $row;
|
|
|
|
|
|
|
|
|
|
//add the sub menus to the array
|
|
|
|
|
$menu_item_level = 0;
|
|
|
|
|
if (strlen($row['menu_item_uuid']) > 0) {
|
|
|
|
|
$a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $row['menu_item_uuid']);
|
|
|
|
|
}
|
2016-03-26 19:22:15 +01:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
//increment the row number
|
|
|
|
|
$x++;
|
2019-09-03 17:59:37 +02:00
|
|
|
}
|
2017-11-17 22:44:31 +01:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
unset($result, $row);
|
2016-03-26 19:22:15 +01:00
|
|
|
|
|
|
|
|
//return the array
|
|
|
|
|
return $a;
|
2019-09-03 17:59:37 +02:00
|
|
|
}
|
2016-03-26 19:22:15 +01:00
|
|
|
|
|
|
|
|
//create the sub menus
|
2016-03-27 05:18:02 +02:00
|
|
|
private function menu_child_array($menu_item_level, $menu_item_uuid) {
|
2016-03-26 19:22:15 +01:00
|
|
|
|
|
|
|
|
//set the level
|
2019-09-03 17:59:37 +02:00
|
|
|
$menu_item_level = $menu_item_level + 1;
|
2016-03-26 19:22:15 +01:00
|
|
|
|
2017-11-17 22:44:31 +01:00
|
|
|
//if there are no groups then set the public group
|
|
|
|
|
if (!isset($_SESSION['groups'][0]['group_name'])) {
|
|
|
|
|
$_SESSION['groups'][0]['group_name'] = 'public';
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//get the child menu from the database
|
2016-05-02 22:42:06 +02:00
|
|
|
$sql = "select i.menu_item_link, l.menu_item_title as menu_language_title, i.menu_item_title, i.menu_item_protected, i.menu_item_category, i.menu_item_icon, i.menu_item_uuid, i.menu_item_parent_uuid ";
|
2015-06-22 19:56:40 +02:00
|
|
|
$sql .= "from v_menu_items as i, v_menu_languages as l ";
|
|
|
|
|
$sql .= "where i.menu_item_uuid = l.menu_item_uuid ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "and l.menu_language = :menu_language ";
|
|
|
|
|
$sql .= "and l.menu_uuid = :menu_uuid ";
|
|
|
|
|
$sql .= "and i.menu_uuid = :menu_uuid ";
|
|
|
|
|
$sql .= "and i.menu_item_parent_uuid = :menu_item_parent_uuid ";
|
2015-06-22 19:56:40 +02:00
|
|
|
$sql .= "and i.menu_item_uuid in ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "( ";
|
|
|
|
|
$sql .= "select menu_item_uuid ";
|
|
|
|
|
$sql .= "from v_menu_item_groups ";
|
|
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
2017-11-17 22:44:31 +01:00
|
|
|
$x = 0;
|
|
|
|
|
foreach($_SESSION['groups'] as $row) {
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql_where_or[] = "group_name = :group_name_".$x;
|
|
|
|
|
$parameters['group_name_'.$x] = $row['group_name'];
|
2017-11-17 22:44:31 +01:00
|
|
|
$x++;
|
2015-06-22 19:56:40 +02:00
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) {
|
|
|
|
|
$sql .= "and ( ";
|
|
|
|
|
$sql .= implode(' or ', $sql_where_or);
|
|
|
|
|
$sql .= ") ";
|
|
|
|
|
}
|
2015-06-22 19:56:40 +02:00
|
|
|
$sql .= ") ";
|
2016-03-26 19:22:15 +01:00
|
|
|
$sql .= "order by l.menu_item_title, i.menu_item_order asc ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$parameters['menu_language'] = $_SESSION['domain']['language']['code'];
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$parameters['menu_item_parent_uuid'] = $menu_item_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$sub_result = $database->select($sql, $parameters, 'all');
|
|
|
|
|
unset($sql, $parameters);
|
2016-03-26 19:22:15 +01:00
|
|
|
|
|
|
|
|
//save the child menu into an array
|
2019-09-03 17:59:37 +02:00
|
|
|
$x = 0;
|
|
|
|
|
$a = Array();
|
|
|
|
|
if (is_array($sub_result) && @sizeof($sub_result) != 0) {
|
2016-03-26 19:22:15 +01:00
|
|
|
foreach($sub_result as $row) {
|
|
|
|
|
//set the variables
|
|
|
|
|
$menu_item_link = $row['menu_item_link'];
|
|
|
|
|
$menu_item_category = $row['menu_item_category'];
|
2016-05-02 22:42:06 +02:00
|
|
|
$menu_item_icon = $row['menu_item_icon'];
|
2016-03-26 19:22:15 +01:00
|
|
|
$menu_item_uuid = $row['menu_item_uuid'];
|
|
|
|
|
$menu_item_parent_uuid = $row['menu_item_parent_uuid'];
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//add the row to the array
|
|
|
|
|
$a[$x] = $row;
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//prepare the protected menus
|
|
|
|
|
if ($row['menu_item_protected'] == "true") {
|
|
|
|
|
$a[$x]['menu_item_title'] = $row['menu_item_title'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$a[$x]['menu_item_title'] = $row['menu_language_title'];
|
|
|
|
|
}
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//get sub menu for children
|
|
|
|
|
if (strlen($menu_item_uuid) > 0) {
|
|
|
|
|
$a[$x]['menu_items'] = $this->menu_child_array($menu_item_level, $menu_item_uuid);
|
|
|
|
|
}
|
2015-06-22 19:56:40 +02:00
|
|
|
|
2016-03-26 19:22:15 +01:00
|
|
|
//increment the row
|
|
|
|
|
$x++;
|
2015-06-22 19:56:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
unset($sub_result, $row);
|
|
|
|
|
|
|
|
|
|
//return the array
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
2016-03-27 05:18:02 +02:00
|
|
|
|
|
|
|
|
//add the default menu when no menu exists
|
2016-03-27 05:22:52 +02:00
|
|
|
public function menu_default() {
|
2016-03-27 05:18:02 +02:00
|
|
|
//set the default menu_uuid
|
|
|
|
|
$this->menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
|
|
|
|
|
//check to see if any menu exists
|
2016-04-26 03:19:58 +02:00
|
|
|
$sql = "select count(*) as count from v_menus ";
|
2019-09-03 17:59:37 +02:00
|
|
|
$sql .= "where menu_uuid = :menu_uuid ";
|
|
|
|
|
$parameters['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$num_rows = $database->select($sql, $parameters, 'column');
|
|
|
|
|
if ($num_rows == 0) {
|
|
|
|
|
//built insert array
|
|
|
|
|
$array['menus'][0]['menu_uuid'] = $this->menu_uuid;
|
|
|
|
|
$array['menus'][0]['menu_name'] = 'default';
|
|
|
|
|
$array['menus'][0]['menu_language'] = 'en-us';
|
|
|
|
|
$array['menus'][0]['menu_description'] = 'Default Menu';
|
|
|
|
|
|
|
|
|
|
//grant temporary permissions
|
|
|
|
|
$p = new permissions;
|
|
|
|
|
$p->add('menu_add', 'temp');
|
|
|
|
|
|
|
|
|
|
//execute insert
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'menu';
|
|
|
|
|
$database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
|
|
|
|
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('menu_add', 'temp');
|
2016-03-27 05:18:02 +02:00
|
|
|
|
|
|
|
|
//add the menu items
|
|
|
|
|
$this->restore();
|
|
|
|
|
}
|
2019-09-03 17:59:37 +02:00
|
|
|
unset($sql, $parameters, $result, $row);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2016-04-15 07:23:14 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2017-07-01 22:13:51 +02:00
|
|
|
?>
|