PROGRAM MenuRoles; {-- *************************************************************************** -- ** Descr. : Extracts and reports all the roles used by menus. -- ** the text outputfile will be a matrix report having all rows -- ** on the horizontal and all menus/menuitems vertically -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 229 and up -- *************************************************************************** -- ** 30/12/01 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} CONST C_REPTITLE = 'Menu Roles Report by FormsAPI Master'; C_REP_MAXITEMLENGHT = 60; //max size reserved for menuitem names C_REP_NOTDISP = '-'; //character in report for item that is not displayed when not in this role C_REP_DISP = '+'; //character in report for item that is in this role C_REP_MENUNOROLSEC = '='; //character in report for menu that has role security disabled C_REP_MENUROLSEC = '*'; //character in report for menu that has role security enabled C_REP_ROLEDISTANCE = 5; //distance between role columns // global variables VAR frm : number; files : TStringList; items : TStringList; filename : varchar2; ps : TParamScreen; pb : TParamBoard; i,j,k : number; out_filename : varchar2; outreportheader : tstringlist; rolecount : number; rolename : varchar2; allroles : tstringlist; maxrolelength : number; repwidth : number; s : varchar2; x : number; dummyline : varchar2; menuitem : number; repchar : char; BEGIN //build a nice parameterscreen ps := TParamScreen.create; pb := ps.AddBoard('Modules',picModules); pb.addparam(parLabel,'MYLABEL','This script will report Menu Roles usage of menu modules.','',''); pb.addparam(parFiles,'MYFILES','Menu Modules','','Menu Modules (*.mmb)|*.mmb'); pb.addparam(parSaveFilename,'MYOUTPUT','Output Filename','c:\rolesreport.txt','Text File (*.txt)|*.txt|All Files (*.*)|*.*'); if ps.ShowParamScreen('Menu Roles Reporter ...') then begin //get the values specified on the parameterscreen out_filename := ps.Paramvalue('MYOUTPUT'); if out_filename ='' then raiseexception('Output filename needs to be specified!'); //get all selected *.mmb files in an array(stringlist) files := tstringlist.create; files.text := ps.ParamValue('MYFILES'); //this variable holds the stringlength of the biggest rolename //we need this one to nicely report the rolenames vertically maxrolelength := 0; //create a list for getting the roles. set the list to ignore duplicates //as we don't want roles multiple times allroles := tstringlist.create; allroles.sorted := true; allroles.duplicates := dupIgnore; //first loop through all meunfiles to get the roles for j := 0 to files.count-1 do begin //get the filename from the array filename := files.strings[j]; logadd('Getting Roles in '+filename); // try to load the menu try frm := Menu_Load(filename); //get the number of roles in this menu module rolecount := generic_getvalue(frm,D2FP_ROLE_COUNT); //get the roles and add them to the roles list. //duplicate roles will be automatically ignored. for i := 1 to rolecount do begin rolename := Menu_GetRole(frm,i); allroles.add(rolename); maxrolelength := max ( length(rolename) , maxrolelength); end; //free the forms module from memory API_DestroyModule(frm); except //output the error if something happened logadd(' =>'+GetError , LogError); end; end; //we report our matrixreport header into a stringlist, makes handling //much easier as we want to display the rolenames vertically and thous //need a way to access line by line outreportheader := tstringlist.create; //get report width repwidth := C_REP_MAXITEMLENGHT + 2 + ((allroles.count-1) * C_REP_ROLEDISTANCE)+2; //get a empty line dummyline := rpad('',repwidth); //report header title s := insertstring(dummyline,C_REPTITLE,(length(dummyline)-length(C_REPTITLE)) div 2); outreportheader.add(substr(s,1,repwidth)); //report report run time s := datetimetostr(sysdate); s := insertstring(dummyline,s,(length(dummyline)-length(s)) div 2); outreportheader.add(substr(s,1,repwidth)); //add some empty lines for displaying the rolenames for i := 1 to maxrolelength do begin outreportheader.add(rpad('',repwidth)); end; //add some textlines at the end of the header outreportheader.add(substr('Menu Modules/Itemnames'+dummyline,1,repwidth)); outreportheader.add(rpad('',repwidth,'-')); //patch the rolenames vertically into the headerlines for i := 0 to allroles.count-1 do begin rolename := allroles.strings[i]; x := length(rolename); for j := 1 to x do begin s := outreportheader.strings[j+maxrolelength-x+2]; s[C_REP_MAXITEMLENGHT + 2 + (i * C_REP_ROLEDISTANCE)] := rolename[j]; outreportheader.strings[j+maxrolelength-x+2] := s; end; end; //save report header savestring(outreportheader.text,out_filename); //free our report header list from memory outreportheader.free; //now loop through all menu files again and report the menuitems and //roles usage this time for j := 0 to files.count-1 do begin //get the filename from the array filename := files.strings[j]; logadd('Getting Roles in ('+to_char(j+1)+'/'+to_char(files.count)+') '+filename); // try to load the form try frm := Menu_Load(filename); //get modulename s := extractfilename(filename)+rpad('',repwidth); if generic_getvalue(frm, D2FP_USE_SECURITY)=false then repchar := C_REP_MENUNOROLSEC else repchar := C_REP_MENUROLSEC; rolecount := generic_getvalue(frm,D2FP_ROLE_COUNT); for i := 1 to rolecount do begin rolename := Menu_GetRole(frm,i); x := allroles.indexof(rolename); s[C_REP_MAXITEMLENGHT + 2 + (x * C_REP_ROLEDISTANCE)] := repchar; end; saveappendstring(substr(s,1,repwidth)+C_CR,out_filename); //loop through all menuitem objects items := API_GetAllItemObjects(frm); for i := 0 to items.count-1 do begin menuitem := items.objects[i]; s := ' '+api_getobjectname(generic_getvalue(menuitem,D2FP_OWNER))+'.'+api_getobjectname(menuitem)+rpad('',repwidth); if generic_getvalue(menuitem, D2FP_DISP_NO_PRIV)=true then repchar := C_REP_DISP else repchar := C_REP_NOTDISP; rolecount := generic_getvalue(menuitem,D2FP_ROLE_COUNT); for k := 1 to rolecount do begin rolename := MenuItem_GetRole(menuitem,k); x := allroles.indexof(rolename); s[C_REP_MAXITEMLENGHT + 2 + (x * C_REP_ROLEDISTANCE)] := repchar; end; s := substr(s,1,repwidth)+C_CR; saveappendstring(s,out_filename); end; //free the items-list from memory items.free; //free the forms module from memory API_DestroyModule(frm); except //output the error if something happened logadd(' =>'+GetError , LogError); end; end; host('notepad '+out_filename,false); end; //free the parameterscreen from memory ps.free; END.