memset(class_names, 0, sizeof(char*)*1000);

//            @co_lcall('"sys"','"meta_class"',"getFullPathByClassName",par_area=>'"sys"',par_class=>'"meta_class"',par_id=>-1,callback=>'""',class_name=>for_class);
@co_lcall('"sys"','"meta_class"',"getFullInheritancePath",par_id=>-1,par_area=>for_area,par_class=>for_class);
__GET_RETURNED_STRING(path)

__SEND_MESG_DEBUG("obtained path: %s",path)

/* WARNING: MODIFIES READ ReturnValue ! */
cou_split(path,class_names,"|",1000);

i=0;
while(class_names[i+1])
{
//                cur_menu_name = ap_psprintf(p, "%s#%s@%s", menu_name, type, class_names[i]);
//                __SEND_MESG_DEBUG(cur_menu_name)
//                @co_getProp('"sys"','"menu"',
// not very intelligent but works
@co_lcall('"sys"','"menu"',"getByNameAndClass",par_id=>-1,menu_name=>"ap_psprintf(p,\"%s#%s\",menu_name,type)",for_area_class=>"class_names[i]");
__GET_RETURNED_INTEGER(id_menu)

//                @co_getPropByName('"sys"', '"menu"', cur_menu_name, '"id"');
if(id_menu)
{
__SEND_MESG_DEBUG("got menu_id=%d",id_menu)
__SEND_MESG_DEBUG("for_class=%s",for_area)
__SEND_MESG_DEBUG("got menu_id=%s",for_class)

if(strlen(SQLString)>0) __APPEND_TO_QUERY(" UNION \n");

__APPEND_TO_QUERY(
" SELECT DISTINCT m.* "
" FROM co_sys_menu m "
" WHERE m.id_parent = %d AND "
" CASE WHEN sec_type=1 THEN co_%s_%s_check_acl_class(id_permission, %d) "
" ELSE co_%s_%s_check_acl(%d, id_permission, %d) END = 1",
id_menu,
for_area, for_class, cnx->id_role,
for_area, for_class, for_id, cnx->id_role
)
}// if
else
{
__SEND_MESG_DEBUG("no id for given class")
}

i++;
} // while
//__ASSERT(strlen(SQLString)>0, "Menu not found")
if (strlen(SQLString)>0) // something was found - we have query
{
__SEND_MESG_DEBUG("menu found\n%s",SQLString)
__APPEND_TO_QUERY(" ORDER BY menu_position ")
__GET_RESULT_AND_CREATE_JS
}