Add the menu_default method to app_defaults.php.

This commit is contained in:
markjcrane
2016-03-26 22:59:00 -06:00
parent c0b93e849c
commit fa2b753e62
2 changed files with 8 additions and 155 deletions

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -26,161 +26,14 @@
//if there are no items in the menu then add the default menu
if ($domains_processed == 1) {
$sql = "SELECT count(*) as count FROM v_menus ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement);
if ($sub_result['count'] > 0) {
if ($display_type == "text") {
echo " Menu: no change\n";
}
}
else {
//create the uuid
$menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
//set the defaults
$menu_name = 'default';
$menu_language = 'en';
$menu_description = '';
//add the menu
$sql = "insert into v_menus ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_name, ";
$sql .= "menu_language, ";
$sql .= "menu_description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$menu_uuid."', ";
$sql .= "'$menu_name', ";
$sql .= "'$menu_language', ";
$sql .= "'$menu_description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//add the menu items
require_once "resources/classes/menu.php";
$menu = new menu;
$menu->db = $db;
$menu->menu_uuid = $menu_uuid;
$menu->restore();
unset($menu);
if ($display_type == "text") {
echo " Menu: added\n";
}
}
unset($prep_statement, $sub_result);
}
//if there are no groups listed in v_menu_item_groups then add the default groups
if ($domains_processed == 1) {
$sql = "SELECT * FROM v_menus ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
$db->beginTransaction();
foreach($result as $field) {
//get the menu_uuid
$menu_uuid = $field['menu_uuid'];
//check each menu to see if there are items in the menu assigned to it
$sql = "select count(*) as count from v_menu_item_groups ";
$sql .= "where menu_uuid = '$menu_uuid' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement);
if ($sub_result['count'] == 0) {
//no menu item groups found add the defaults
foreach($apps as $app) {
foreach ($app['menu'] as $sub_row) {
foreach ($sub_row['groups'] as $group) {
//add the record
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$menu_uuid', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec($sql);
unset($sql);
}
}
}
}
}
$db->commit();
unset($prep_statement);
}
require_once "resources/classes/menu.php";
$o = new menu;
$o->db = $db;
$o->menu_default();
unset($menu);
//if menu item group uuid is missing, generate and populate
if ($domains_processed == 1) {
$sql = "select menu_uuid, menu_item_uuid, group_name ";
$sql .= "from v_menu_item_groups where menu_item_group_uuid is null";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
unset($prep_statement);
if ($result_count > 0) {
$db->beginTransaction();
foreach($result as $field) {
$menu_item_group_uuid = uuid();
$sql = "update v_menu_item_groups ";
$sql .= "set menu_item_group_uuid = '".$menu_item_group_uuid."' ";
$sql .= "where ";
$sql .= "menu_uuid = '".$field['menu_uuid']."' ";
$sql .= "and menu_item_uuid = '".$field['menu_item_uuid']."' ";
$sql .= "and group_name = '".$field['group_name']."' ";
$sql .= "and menu_item_group_uuid is null ";
$count = $db->exec(check_sql($sql));
unset($sql);
}
$db->commit();
}
}
//if group uuids are missing, populate with global group uuids
if ($domains_processed == 1) {
$sql = "select menu_item_group_uuid, group_name ";
$sql .= "from v_menu_item_groups where group_uuid is null";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
unset($prep_statement);
if ($result_count > 0) {
foreach($result as $field) {
//note menu item group uuid
$menu_item_group_uuid = $field['menu_item_group_uuid'];
$group_name = $field['group_name'];
//get global group uuid
$sql = "select group_uuid from v_groups ";
$sql .= "where domain_uuid is null ";
$sql .= "and group_name = '".$group_name."' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
$sub_result_count = count($sub_result);
unset ($prep_statement);
//set group uuid
if ($sub_result_count > 0) {
$sql = "update v_menu_item_groups ";
$sql .= "set group_uuid = '".$sub_result['group_uuid']."' ";
$sql .= "where menu_item_group_uuid = '".$menu_item_group_uuid."' ";
$count = $db->exec(check_sql($sql));
unset($sql);
}
} //foreach
} //if
} //if
?>