Dyanmic Interface Menu for WebDB - Information July 25, 2003 Yousef Rabah The menu is made out of CSS (Cascading Style Sheets) and PHP code. Here are the list of files associated with menu: 1. utility.pm in new/perl/ 2. utility.pl in new/perl/ 3. testmenu in new/php/ and its just a regular NOT Dynamic yet almost same basic code for dynamic menu used. (Its use is for reference) 4. header.php in new/php/ 5. common.inc in new/php/ (main file) 6. courceSearchDisplay.inc in new/php/ -- The main file here is common.inc. Before I start going through the code, let me expalin what, how and why each of the other files have been used. Meaning that I will go through them first and after i'm done with that I will go through the main file common.inc -- First let me begin with what was added to UTILITY.PM file. For this file There were 6 fuctions that were added. The following are functions that were added and some information about them: ------------- utility.pm ------------- 1. getServices($). This function will basically take the pidm as input and it will return services accessible by the pidm. (Everything involves the pidm here b/c it depends on the pidm of which services were getting. It matters b/c if a person is logged in or not. Also the a unique pidm is given to each student, faculty or staff member of this commmunity that with this pidm. Basically the pidm is like your name.) 2. getServiceUser($). As the getServices it will have the pidm as input. This function has a SQL statment that selects from dk_service, dk_service_access_user. Here we're selecting the service_code, exec_script and service_name, if they are avaliable and service level is 1. Level 1 meaning the parent (parent here refers to 1st row were getting, as an example, my file, Course Inforamtion, campus info .. etc). With this function then is that were pushing in array variable @result the $serviceCode|$serviceName|$execScript, then fux. returns @result. 3. getChildServices($$). This is similar to getServices but the difference is that its getting 2 inputs, the $pidm and $parent. 4. getChildServicesUser($$). Its getting 2 inputs, the $pidm and $parent. Very similar to getServiceUser yet its different. Whats similar is that were selecting service_code, service_name, exec_script. Were also selecting from group_members and access user as well. Here selecting where group_code = '$parent', when also the access user service is avaliabel (i.e Y) and service codes from group_members and access user are equal and when service level is equal to 2. Here the level is 2 we are getting the children. As in getServiceUser, we are still pushing into an array variable $serviceCode|$serviceName|$execScript. 6. getServiceCode($). This is only getting one input wich is the pidm. The purpose of this service code is for the naming of the style sheet that will talk about later in the common.inc file. What getservicecode does is selects ONLY the service code from dk_Service where service is avalible and the level is 1. Here the only thing we want to name for now is the parent, b/c with the parent we will be able to call the children. (i.e when the user clicks on the a prent link, like Person Information, the child were getting is going to be Major/Minor. Now this function is only used for giving names only. So the result is only $serviceCode in a variable. ------------- utility.pl ------------- -- Here we are just seeing if there are 3 things if they are an entry point, meaning if the function's entry point is equal to getServices then @result will get the run of the function based on the parameter put on the command line (or host if in Database) and then for each to print the result. The similar if statment is done for getChildServices and getServiceCode. The main purpose for all this is mainly when we use exec in common.inc or another file we can get information we need. Also we can check and see if the sql statment we did in the funcitons in the utility.pm file was valid and is getting the correct information we requested it to get. -------------- testmenu.php -------------- -- This is an HTML file mainly that has CSS in it. Where this code is not Dynamic but will give you an overview of what we used in common.inc that we turned this code to be dynamic. Its actually the code I used in my website. -- There is also a css.css file in new/php/ that also has the functionality that makes testmenu.php function the way it should. In common.inc, instead of having a whole separate file something.css , we had a function called CSS_menu() which I will explain under common.inc -------------- header.php -------------- -- Here what we added is basically to PRINT THE MENU in the head section of the WebDB site. printMenu I will write about more when I write about the common.inc file additions. -- Now comes common.inc. And Here I will try to be as much specific/clear about explenation of the code. --------------- common.inc --------------- -- First of all, in the HTMLLheader() function. What I added was another input to be in the function to be like this. HTMLheader($title, $doRefresh, $SRVCode). As you can tell, the $SRVCODE is another name for Service Code. Now in this function on line 434, were put printMenu in either case if person is basically loggout out or not. B/c both ways were going to print the menu, but depending if the person is logged in you would get more links (a user would be getting his/her own personal files). printMenu will be exaplained later on. -- function getServiceCode($pidm). What this basically does is use exec to get getServiceCode from utility.pl and put result in $result, then what we do is get the info, then what return is array_values($serviceCode). Which array_values is a built in PHP function that put in array values. So for this functions thats what we are returning. This will be used in the CSS_menu, which im going to explain next. -- function CSS_menu($pidm). The first thing is running the getServiceCode($pidm) function, which is returning array_values($serviceCode). In this function Im embedding style of CSS. The first thing is defining the menu to what basic functionalities we want it to have. Now I have it based on the themes, but I didnt work more to getting the values b/c themes will be different. What I focused on though is getting a Dynamic Naming System avaliable for printMenu to use for example. -- Inside of the style sheet CSS, I have put PHP code in it. This was to name the functionalities based on the ServiceCode. What it basically does is for $i < count($serviceCode), it has a counter $i++ and what it does is prints body.$serviceCode[$i], then prints #menu li#nav_$i, then prints a {background .... Basically the same for the rest. This can be changed easlity to fit with the themes. -- For the first one, basically for the parent, it changes its color for the actual link that was click, so it would look different than the others. -- Using the dynamic naming, we then print the children based on what background, color,... etc we want. Could be changed later, as we see fit. -- function printMenu($pidm, $SRVCode) Has input from $pidm, $SRVCODE. Here is what it will be doing. The first thing the function does is run CSS_menu($pidm), then set $SRVCODE = getServiceCode($pidm). These 2 are there to get CSS_menu naming/style inside the printMenu. We also have the $SRVCode for naming the parent links. So now, what we do is using exec function to execute getServiceds from ../perl/utility.pl and putting it in $result. The using function explode, we take out the | and put result in $statusData. IF the $status[0] = "Success", why b/c it should be the first thing, then we print then we make a list. So here all what happened is were calling class of variable that is in $SRVCode of sub whatever number (1 would be first thing on parent menu , which if your NOT logged in would be CRSRCH, which is the $servicCode). So we then start the listing of the menu, we start with id='menu'. This menu name was got from CSS_menu which we got by defiing it to what values we want (later fittting with themes). Then so we know that after the success, the rest should be Service Code, Service Name and Exec Script, so this is what happens: Now this is for the parent menu list: So we have a for loop which will be while $i <=StatusData[1], $i++, then we use explode function and put result in $serviceData. Then $serviceCode[$i-1] would get $serviceData[0]. $serviceName would get $serviceData[1], then $execScript would get $serviceData[2]. Here then we have another variable called it $y. We set it to get $i-1. This is for printing the list, which is done like this: print ("
  • here the nav_ represents the value in the CSS menu, then we have $y so that it would be a counter of how many navigations/services we had. then it continues with $serviceName"); Here then we print the link name and actual name of the service. This is in the loop so it goes on for all services we're getting. Now for each parent we are ceating a sub-menu , and then printing it out. This is what happens now: We have the same for loop but with a different result we are getting. So we call a variable $parent_code which gets $serviceCode[$j-1], b/c this is needed for calling getChildServices.pl. The what we do is use again the exec built in function and the src is ../perl/utility.pl which we use $pidm and $parent with whatever values they have to execute function getChildServices correctly and result is put in $childResult. So it gets the children belonging to the parent code passed. -- It continues to process the result. So the same thing as with the parent, data is put into $statusChildData, when success, then for loop where for once of each sub menu, print the list of submeny basically like this: . The represnts the end of the list "