[SOLVED]Dynamically generated menus

Hi there,

I have some nifty onLoad code in a Menu application that generates the menu from a MySQL Query, namely:


sc_appmenu_reset(menu);
sc_appmenu_create(menu);
sc_lookup(menulevel1, "SELECT menu_id, menu_description, application, parameters, icon, target FROM ss_menu WHERE activeflag_id='1' AND parent_id='0' ORDER BY sequence ASC;");
if(!empty({menulevel1})) {
	foreach({menulevel1} as $a_1menu) {
		if($a_1menu[3] != NULL) { $id_params=$a_1menu[3]; } else { $id_params=''; }
		sc_appmenu_add_item('menu', 'item_' . $a_1menu[0], '', $a_1menu[1], $a_1menu[2], $id_params, $a_1menu[4], '', $a_1menu[5]);
		sc_lookup(menulevel2, "SELECT menu_id, menu_description, application, parameters, icon, target FROM ss_menu WHERE activeflag_id='1' AND parent_id='" . $a_1menu[0] . "' ORDER BY sequence ASC;");
		if(!empty({menulevel2})) {
			foreach({menulevel2} as $a_2menu) {
				if($a_2menu[3] != NULL) { $id_params=$a_2menu[3]; } else { $id_params=''; }
				sc_appmenu_add_item('menu', 'item_' . $a_2menu[0], 'item_' . $a_1menu[0], $a_2menu[1], $a_2menu[2], $id_params, $a_2menu[4], '', $a_2menu[5]);
				sc_lookup(menulevel3, "SELECT menu_id, menu_description, application, parameters, icon, target FROM ss_menu WHERE activeflag_id='1' AND parent_id='" . $a_2menu[0] . "' ORDER BY sequence ASC;");
				if(!empty({menulevel3})) {
					foreach({menulevel3} as $a_3menu) {
						if($a_3menu[3] != NULL) { $id_params=$a_3menu[3]; } else { $id_params=''; }
						sc_appmenu_add_item('menu', 'item_' . $a_3menu[0], 'item_' . $a_2menu[0], $a_3menu[1], $a_3menu[2], $id_params, $a_3menu[4], '', $a_3menu[5]);
						sc_lookup(menulevel4, "SELECT menu_id, menu_description, application, parameters, icon, target FROM ss_menu WHERE activeflag_id='1' AND parent_id='" . $a_3menu[0] . "' ORDER BY sequence ASC;");
						if(!empty({menulevel4})) {
							foreach({menulevel4} as $a_4menu) {
								if($a_4menu[3] != NULL) { $id_params=$a_4menu[3]; } else { $id_params=''; }
								sc_appmenu_add_item('menu', 'item_' . $a_4menu[0], 'item_' . $a_3menu[0], $a_4menu[1], $a_4menu[2], $id_params, $a_4menu[4], '', $a_4menu[5]);
							}
						}
					}
				}
			}
		}
	}	
}

When Generated and Run, this code generates the following syntax error in the browser:

Parse error: syntax error, unexpected '"*scout"' (T_CONSTANT_ENCAPSED_STRING) in /opt/NetMake/v8/wwwroot/scriptcase/app/ServiceUnity/menu/index.php on line 882

If I log in to my server via SSH, open the above referenced PHP script with VIM, and go to line 882, I see the following (bad) code:

scriptcase']['sc_def_menu']["menu"]['item_' . $a_1menu[0]]['parm']           = $id_params . "*scin""*scout" . "nm_run_menu*scin1*scout";

It looks like this could be as simple as a period [.] missing from the space between “scin” and “*scout”

Can someone fix this bug and push it out in an update, please?

For any who search and find this post, the fix for this is generally simple… exclude the parameters option from your sc_appmenu_add_item() statement. But it defeats the purpose of the parameters option if it doesn’t work. :slight_smile:

Thanks!

Hello,

Issue reported to our bugs team.

regards,
Bernhard Bernsmann

Is there any solution?

Hello.
This problem does not this is a bug.

The macro sc_appmenu_add_item not pass parameters through variables.
As shown in the code: sc_appmenu add_item (‘menu’, ‘item_’ $ a_1menu [0], ‘’, $ a_1menu [1], $ a_1menu [2], $ id_params, $ a_1menu [4] ‘’. $ a_1menu [5]);
Parameters: $id_params

The macro should be used as follows:
Parameters - String with parameters to pass to the menu item application.
Ex .: param1 = value; param2 = value

More information: http://www.scriptcase.net/docs/en_us/v8/scriptcase-macros/scriptcase-macros#sc_appmenu_add_item

I went down the rabbit hole on this and believe I found a solution.
The string required for parameters in the function call to sc_appmenu_add_item is
parm=value

The SC code generator splits this string on the “=” so in the generated code you end up with
parm*scinvalue*scoutnm_run_menu*sc1*scount

So in the above example if you do this:

list($parm, $value) = explode('=', $id_params);
sc_appmenu_add_item('menu', 'item_' . $a_4menu[0], 'item_' . $a_3menu[0], $a_4menu[1], $a_4menu[2], $parm=$value, $a_4menu[4], '', $a_4menu[5]);

it should work for one parameter. If you need more than one I’m guess you’ll be able to test thru that and figure out what it wants.

Now if only SC would enhance this macro to accept all the menu attributes (e.g. fontawesome icons, active/inactive/hover colors, and the inherit style on tab)