Announcement

Collapse
No announcement yet.

Dynamic Menu with Auto Delete of Menu Items

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic Menu with Auto Delete of Menu Items

    Hi,

    I created a dynamic menu based on my database pursuant to the Scriptcase tutorial. Here's my working code located in AppInit and OnLoad events:

    ************************************************** *******

    //======================Preparation

    sc_reset_menu_disable();

    sc_reset_menu_delete();

    sc_appmenu_reset('main_menu');

    //======================Dynamic Menu Creation

    sc_appmenu_create('main_menu');

    sc_lookup(dsmenu,"
    SELECT
    id,
    parent_item,
    label,
    application,
    parameters,
    icon,
    hint,
    target
    FROM
    main_menu
    ORDER BY
    parent_item ASC,
    node_order ASC,
    label ASC");

    foreach({dsmenu} as $arr_menu)
    {

    $item_id = $arr_menu[0];

    $menu_item_id = 'item_'.$arr_menu[0];

    if($arr_menu[1] == 0)
    {
    $parent_item = "";
    }
    else
    {
    $parent_item = 'item_'.$arr_menu[1];
    }

    sc_appmenu_add_item('main_menu',
    $menu_item_id,
    $parent_item,
    $arr_menu[2],
    $arr_menu[3],
    "",
    $arr_menu[5],
    $arr_menu[6],
    $arr_menu[7]);
    }

    //====================== Delete menu items not accessible to the user_group

    sc_select(rs, "
    SELECT id
    FROM main_menu
    WHERE id != '0' AND id != 1 AND application IN (SELECT app_name FROM groups_apps WHERE group_id = '".[glo_group_id]."' AND priv_access IS NULL) AND id NOT IN (SELECT parent_item FROM main_menu WHERE parent_item != '')
    ");

    while(!$rs->EOF)
    {
    $del_item = 'item_'.$rs->fields[0];
    sc_appmenu_remove_item ('main_menu', $del_item);

    $rs->MoveNext();
    }
    $rs->Close();

    ************************************************** *******

    I need to have it automatically delete/remove menu items that fall under the following criteria:
    1) Auto delete menu items that the user group has no access in the linked applications per Scriptcase Security Module generated tables (do not forget to enable security module in "My Scriptcase" option);
    2) Auto delete menu items (node) that has no active/existing submenu items -- when all submenu items were already automatically deleted per criteria #1;
    3) Auto delete menu items (which are not node) that has no linked application.

    Any help would be greatly appreciated. I've been trying to solve this for weeks now and it's badly needed. Thanks in advance!


    --Mister Grey

    PS. I only studied programming via online tutorials so please bear with me.

  • #2
    Originally posted by mistergrey View Post
    //====================== Delete menu items not accessible to the user_group

    sc_select(rs, "
    SELECT id
    FROM main_menu
    WHERE id != '0' AND id != 1 AND application IN (SELECT app_name FROM groups_apps WHERE group_id = '".[glo_group_id]."' AND priv_access IS NULL) AND id NOT IN (SELECT parent_item FROM main_menu WHERE parent_item != '')
    ");

    while(!$rs->EOF)
    {
    $del_item = 'item_'.$rs->fields[0];
    sc_appmenu_remove_item ('main_menu', $del_item);

    $rs->MoveNext();
    }
    $rs->Close();

    ************************************************** *******

    I need to have it automatically delete/remove menu items that fall under the following criteria:
    1) Auto delete menu items that the user group has no access in the linked applications per Scriptcase Security Module generated tables (do not forget to enable security module in "My Scriptcase" option);
    Does this piece of code not address your first question?

    Comment


    • #3
      Hi,

      Thanks for replying to this thread.

      Yes, that code you quoted addressed my first criteria..

      I was able to achieve what I needed by changing my approach.. Instead of deleting unnecessary menu items, do not create or add them in the first place. Just create the menu items needed.. I did this this way:

      1) Create menu items with linked applications in accordance with the authorization table created by the security module.
      2) Then create nodes (could be an empty menu item which is a parent of the menu item that is linked to an application)..
      3) And create parent nodes.. Continue creating parent nodes if you have multi level menu..
      4) Run the code in the appinit event and have a menu item (preferably HOME) that will call the menu application if you want to immediately update the menu.

      That's it! A totally and literally dynamic menu!

      Comment

      Working...
      X