HTMLMenu.java 0100660 0100306 0000144 00000070714 07477076171 013047 0 ustar mmhilleb users
/*****************************************************************************
* MODULE DESCRIPTION
******************************************************************************
*
* NAME: HTMLMenu
* LANGUAGE: JavaBean
* DATE: 8.6.2001
* AUTHOR: Heikki Uuksulainen, Jyväskylän yliopisto
*
******************************************************************************
* COPYRIGHT (C) KORPPI-PROJEKTIRYHMÄ
* Limited rights granted. Please refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
* 8.6.2001
* - First version
* 2.5.2002 Minna Hillebrand
* - Added KOPPELO navigation
* 6.5.2002 Marko Ylitalo
* - Corrected KOPPELO-navingation
* 17.5.2002 Marko Ylitalo
* - Some visual fixing. Removed assignments etc.
*
*****************************************************************************/
package kotkabeans;
import java.util.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.IOException;
import java.sql.*;
import java.io.*;
/**
* This class creates the "leftbar" of the pages.
*/
public class HTMLMenu {
// Attributes
/**
* base address where to look for pages.
*/
protected String baseAddress;
protected static String PATH_TO_TEACHER_COURSE = "/kotka/course/teacher/";
protected static String PATH_TO_STUDENT_COURSE = "/kotka/course/student/";
protected static String PATH_TO_PERSON = "/kotka/person/";
protected static String PATH_TO_KOLIBRI = "/kotka/kolibri/";
protected static String PATH_TO_PORTAL = "/kotka/portal/";
protected static String PATH_TO_KOPPELO = "/kotka/koppelo/";
protected static String COURSE_MODULE_NAME = "Opiskelusi";
protected static String CALENDAR_MODULE_NAME = "Kalenteri";
protected static String PERSON_MODULE_NAME = "Henkilötiedot";
protected static String COURSE_MODULE_NAME_FOR_TEACHING = "Opetuksesi";
protected static String ASS_MODULE_NAME = "Opinnäytteesi";
protected static String ASS_SUPERVISOR_MODULE_NAME = "Ohjauksesi";
protected static String ASS_NAME = "Aiheet ja haku";
/**
* Arraylist contains items that are "under" this menu.
*/
private ArrayList items = new ArrayList(3);
/**
* Database connection
*/
DB db = new DB();
// Access Methods
/**
* Simple access method
*/
public void setDB(DB db){
this.db = db;
}
/**
* Simple access method.
* @return baseAddress
*/
public String getBaseAddress() {
return baseAddress;
}
/**
* Simple access method.
* @param newAddress new base address to set.
*/
public void setBaseAddress(String newAddress) {
baseAddress = newAddress;
}
/**
* Prints given string s to given output.
*/
public void print(String s, JspWriter out) {
try {
out.write(s);
out.newLine();
} catch (IOException e) {}
}
/**
* This method adds item to menu.
*
* @param name Items name.
* @param address Items address.
* @param ilevel Items level.
* @param link Is item link or not.
* @param p String array containing parameters that this item is interested in.
* @return Added item
*/
public HTMLMenuItem addItem(String name, String baseAdd, String address, int ilevel, boolean link, String[] p) {
HTMLMenuItem item = new HTMLMenuItem();
item.setName(name);
item.setAddress(address);
item.setLevel(ilevel);
item.setLink(link);
item.setParams(p);
item.setBaseAddress(baseAdd);
items.add(item);
System.out.println("Lisätty: " + name);
return item;
}
/**
* This method creates students "tree".
*
* @param user User that we are dealing with.
* @return 1
*/
private int createStudentTree(User user, int level) throws Exception {
HTMLMenuItem Item1, Item2, Item3, Item4;
ResultSet rs, rs2, rs3;
int languageID = user.getLanguageID();
int personID = user.getPersonID();
String baseAdd = PATH_TO_STUDENT_COURSE;
String name = COURSE_MODULE_NAME;
String usergroup ="1";
if(level > 1) { usergroup = "1"; }
String addressToCourseInfo = "courseInfo.jsp";
int courseRight = 1;
boolean wasConnected = false;
ArrayList courseList = new ArrayList(20);
ArrayList groupList = new ArrayList(20);
EventGroup eg = new EventGroup();
if(!db.isConnected()) db.connect();
else wasConnected = true;
rs = db.executeQuery("SELECT code, courseinstance.courseinstanceid, usergroupid FROM course, courseinstance, courseparticipant WHERE course.courseid=courseinstance.courseid AND "+
" courseinstance.courseinstanceid=courseparticipant.courseinstanceid AND courseparticipant.personid="+personID+" AND courseparticipant.deleted='f' AND "+
" courseparticipant.usergroupid IN ("+usergroup+") AND courseinstance.deleted='f' ORDER BY code;");
Item1 = addItem(name,baseAdd, "opisKurssit.jsp",0,true, null);
//create subtree for "Kurssit"
while(rs.next()) {
CourseInstance c = new CourseInstance();
c.setCode(rs.getString("code"));
c.setCourseInstanceID(rs.getInt("courseinstanceid"));
courseList.add(c);
}
CourseInstance c = new CourseInstance();
for(int i=0;i 1) {
// if(level > 2) {
Item3 = Item2.addItem(user.T("Ajat ja paikat"),baseAdd, "ope_lisaa_kurssi.jsp?course="+courseID,3,true, new String[] {"course"});
for(i=0;i 2) {
// Item3 = Item2.addItem(user.T("Opintosuoritukset"),baseAdd, "ope_opintosuoritukset.jsp?course="+courseID,3,true, new String[] {"course"});
}
Item3 = Item2.addItem(user.T("Kurssikuvaus"),baseAdd, "showDescriptions.jsp?course="+courseID,3,true, new String[] {"course"});
}
return Item1;
}
/**
* This method teachers "tree".
*
* @param user User that we are dealing with.
* @return 1
*/
private int createTeacherTree(User user, int level) throws Exception {
HTMLMenuItem Item1, Item2, Item3, Item4;
ResultSet rs, rs2, rs3, rs4;
int languageID = user.getLanguageID();
int personID = user.getPersonID();
String[] grouptype = new String[4];
String[] groupname = new String[4];
String groupTypes = "1,2,4,9";
int i = -1, grouptypelkm = 0;
String baseAdd = PATH_TO_TEACHER_COURSE;
int usergroup = 1;
boolean wasConnected = false;
if(!db.isConnected()) db.connect();
else wasConnected = true;
rs4 = db.executeQuery("SELECT grouptypeid, name FROM grouptypetranslation "+
"WHERE languageid = "+languageID+" AND grouptype.deleted = FALSE AND grouptypetranslation.grouptypeid=grouptype.grouptypeid "+
"AND grouptype.grouptypeid IN ("+groupTypes+");");
while(rs4.next()) {
i++;
if(i 2) {
rs = db.executeQuery("SELECT code, courseinstanceid FROM course, courseinstance WHERE course.courseid=courseinstance.courseid AND "+
" courseinstance.deleted='f';");
}
else {
rs = db.executeQuery("SELECT code, courseinstance.courseinstanceid, usergroupid FROM course, courseinstance, courseparticipant WHERE course.courseid=courseinstance.courseid AND "+
" courseinstance.courseinstanceid=courseparticipant.courseinstanceid AND courseparticipant.personid="+personID+" AND "+
" courseparticipant.usergroupid IN (2,3) AND courseparticipant.deleted='f' AND courseinstance.deleted='f' ORDER BY code;");
}
//create subtree for "Kurssit", active courses
Item2 = Item1.addItem("Aktiiviset",baseAdd, "ope_aloitus_uusi.jsp?active=true",1,true, new String[] {"active"});
while(rs.next()) {
if(level > 2) usergroup = 6;
else usergroup = rs.getInt("usergroupid");
Item2 = teacherSubTree(rs.getString("courseinstanceid"),rs.getString("code"),Item2,grouptype,groupname,usergroup);
}
/*************************** hidden courses ********************************************************/
if(level > 2) {
rs = db.executeQuery("SELECT code, courseinstance.courseinstanceid FROM course, courseinstance WHERE course.courseid=courseinstance.courseid AND "+
" courseinstance.deleted='t';");
}
else {
rs = db.executeQuery("SELECT code, courseinstance.courseinstanceid, usergroupid FROM course, courseinstance, courseparticipant WHERE course.courseid=courseinstance.courseid AND "+
" courseinstance.courseinstanceid=courseparticipant.courseinstanceid AND courseparticipant.personid="+personID+" AND "+
" courseparticipant.usergroupid IN (2,3) AND courseparticipant.deleted='f' AND courseinstance.deleted='t' ORDER BY code;");
}
//create subtree for "kurssit", hidden courses
Item2 = Item1.addItem("Piilotetut",baseAdd, "ope_aloitus_uusi.jsp?active=false",1,true, new String[] {"active"});
while(rs.next()) {
if(level > 2) usergroup = 6;
else usergroup = rs.getInt("usergroupid");
Item2 = teacherSubTree(rs.getString("courseinstanceid"),rs.getString("code"),Item2,grouptype,groupname,usergroup);
}
/***********************************************************************************************************/
if(!wasConnected) db.disconnect();
if(level > 1) {
Item2 = Item1.addItem("Lisää kurssi",baseAdd, "addCourseInstance.jsp",1,true,null);
Item2 = Item1.addItem("Kurssikuvaukset",baseAdd, "showDescriptions.jsp?course=0",1,true, new String[] {"course"});
Item2 = Item1.addItem("Tentit",baseAdd, "ope_tentit.jsp",1,true, null);
}
return 1;
}
/****************** KOPPELO *************************************************************/
/**
* This method creates teachers assignment "tree".
*
* @param user User that we are dealing with.
* @return 1
*/
private int createSupervisorAssignmentTree(User user, int level) throws Exception {
HTMLMenuItem Item1= new HTMLMenuItem();
HTMLMenuItem Item2= new HTMLMenuItem();
// HTMLMenuItem Item3= new HTMLMenuItem();
// int f= 0;
int asstypeID = -1;
ResultSet rs /*,rs2*/ ;
int languageID = user.getLanguageID();
int personID = user.getPersonID();
// KoppeloVector assignments = new KoppeloVector();
String baseAdd = PATH_TO_KOPPELO;
String name = ASS_SUPERVISOR_MODULE_NAME;
boolean wasConnected = false;
if(!db.isConnected()) db.connect();
else wasConnected = true;
//create subtree for "Ohjauksesi"
rs = db.executeQuery("SELECT distinct assignmenttype.typeid as ID, asstypetranslation.name as name "+
" FROM assignmentrelatedperson "+
" WHERE assignmentrelatedperson.deleted = false "+
" AND assignmentrelatedperson.personid = "+personID+
" AND assignmentrelatedperson.roleid > 1 "+
" AND assignmentrelatedperson.assignmentid = assignment.assignmentid "+
" AND assignment.assignmenttypeid = assignmenttype.typeid "+
" AND assignmenttype.typeid = asstypetranslation.typeid "+
" AND asstypetranslation.languageid = "+languageID+ " ;");
/* rs2 = db.executeQuery(" Select distinct assignment.assignmentid as assID, "+
" assdetailtranslation.name as name, "+
" assignment.assignmenttypeid as typeID "+
" from assignment "+
" where assdetailtranslation.languageid = "+ languageID +
" and asstypetranslation.languageid = "+ languageID +
" and assignmentrelatedperson.personid = "+ personID+
" and assignmentrelatedperson.deleted = false "+
" and assignmentrelatedperson.roleid > 1"+
" and assignmentrelatedperson.assignmentid = assignment.assignmentid "+
" and assignment.assignmentid = assignmentreldetail.assignmentid "+
" and assignmentdetail.detailid = assignmentreldetail.detailid "+
" and assignmentdetail.typeid = 8"+
" and assdetailtranslation.detailid = assignmentreldetail.detailid "+
" and assignment.phaseid = assphasetranslation.phaseid "+
" and assignment.phaseid <> 4 "+
" and assignment.phaseid <> 5 "+
" and assignment.assignmenttypeid = asstypetranslation.typeid "+
" and assignment.deleted = false; ");
while(rs2.next()) {
assignments.addItem(rs2.getString("name"), rs2.getInt("assID"), rs2.getInt("typeID"));
}
*/
Item1=addItem(name,baseAdd, "index.jsp?teacher=true",0,true, new String[] {"teacher"});
Item2=Item1.addItem("Aihe-ehdotukset", baseAdd, "propositions.jsp", 1, true, null );
while(rs.next()) {
/*
if (f == 0) {
Item1=addItem(name,baseAdd, "index.jsp?teacher=true",0,true, new String[] {"teacher"});
Item2=Item1.addItem("Aihe-ehdotukset", baseAdd, "propositions.jsp", 1, true, null );
f=1;
}
*/
asstypeID = rs.getInt("ID");
Item2 = Item1.addItem(rs.getString("name")+"t", baseAdd, "searchResult.jsp?personid="+personID+"&typeid="+asstypeID+"&phaseid=5", 1, true,
new String[] {"personid","typeid", "phaseid"});
/*
for(int i=0;i 4 "+
" and assignment.phaseid <> 5 "+
" and assignment.assignmenttypeid = asstypetranslation.typeid "+
" and assignment.deleted = false; ");
while(rs2.next()) {
assignments.addItem(rs2.getString("name"), rs2.getInt("assID"), rs2.getInt("typeID"));
}
*/
Item1=addItem(name,baseAdd, "index.jsp?student=bad",0,true, new String[] {"student"});
while(rs.next()) {
asstypeID = rs.getInt("ID");
Item2 = Item1.addItem(rs.getString("name")+"t", baseAdd, "searchResult.jsp?personid="+personID+"&typeid="+asstypeID+"&phaseid=-1", 1, true,
new String[] {"personid","typeid", "phaseid"});
/*
for(int i=0;i 1) {
Item1.addItem("Aihe-ehdotukset", baseAdd, "propositions.jsp", 1, true, null );
Item1.addItem("Opinnäytteen kiinnittäminen",baseAdd, "available.jsp", 1, true, null );
}
return 1;
}
/*****************************************************************************************************/
/**
* This method is called from outside and it decides if user is student or teacher.
*
* @param user User that we are dealing with.
* @return 1
if everything went fine, otherwise-1
*/
public int createTree(User user) throws Exception {
UseModule usemodule = new UseModule();
int personID = user.getPersonID();
// int level = usemodule.rightLevel(personID);
int level = user.getAccessRightLevelID();
int anyCourseLevel = usemodule.maxCourseRight(personID);
items.clear();
HTMLMenuItem Item1 = new HTMLMenuItem(), Item2 = new HTMLMenuItem(), Item3 = new HTMLMenuItem(), Item4 = new HTMLMenuItem();
/***************************** Calendar-module **************************************************************/
// Item1 = addItem("Portaali", "/kotka/portal/", "showMain.jsp", 0,true, null);
Item1 = addItem(user.T("Kalenteri"),PATH_TO_KOLIBRI,"week.jsp",0,true,null);
Item2 = Item1.addItem(user.T("Päivä"),PATH_TO_KOLIBRI,"day.jsp",1,true,null);
// Item2 = Item1.addItem(user.T("Viikko"),PATH_TO_KOLIBRI,"week.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Kuukausi"),PATH_TO_KOLIBRI,"month.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Vuosi"),PATH_TO_KOLIBRI,"year.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Ryhmän luonti"),PATH_TO_KOLIBRI,"group.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Ryhmän tapahtumat"),PATH_TO_KOLIBRI,"groupWeek.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Lisää tapahtuma"),PATH_TO_KOLIBRI,"addAppointment.jsp",1,true,null);
/****************************** Person-module ********************************************************************/
Item1 = addItem("Henkilötiedot", PATH_TO_PERSON, "showMain.jsp", 0,true,null);
if(level > 2) {
// Item2 = Item1.addItem(user.T("Muut henkilöt"),PATH_TO_PERSON,"showMain.jsp?others=true",1,true,new String[] {"others"});
Item2 = Item1.addItem(user.T("Lisää henkilö"),PATH_TO_PERSON,"showAddPerson.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Poista henkilö"),PATH_TO_PERSON,"showRemovePersons.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Henkilötiedot"),PATH_TO_PERSON,"showPersonDetails.jsp",1,true,null);
Item2 = Item1.addItem(user.T("Muuta tietoja"),PATH_TO_PERSON,"showChangePersonDetails.jsp",1,true,null);
Item3 = Item2.addItem(user.T("Yleiset"), PATH_TO_PERSON, "showChangeDetails.jsp?person=", 2, true,new String[] {"person"});
Item3 = Item2.addItem(user.T("Parametrit"), PATH_TO_PERSON, "showAddPersonParameters.jsp?person=", 2, true,new String[] {"person"});
Item3 = Item2.addItem(user.T("Osoitteet"), PATH_TO_PERSON, "showAddPersonAddresses.jsp?person=", 2, true,new String[] {"person"});
Item3 = Item2.addItem(user.T("Oppiarvot"), PATH_TO_PERSON, "showAddPersonDegrees.jsp?person=", 2, true,new String[] {"person"});
Item3 = Item2.addItem(user.T("Tittelit"), PATH_TO_PERSON, "showAddPersonPrefixes.jsp?person=", 2, true,new String[] {"person"});
}
else {
// the next by pjk
// Item2 = Item1.addItem(user.T("Muuta tietojasi"), PATH_TO_PERSON,"forwardChangeOwnDetails.jsp", 1,true,null);
Item2 = Item1.addItem(user.T("Muuta tietojasi"), PATH_TO_PERSON,"showChangeDetails.jsp", 1,true,null);
Item3 = Item2.addItem(user.T("Yleiset"), PATH_TO_PERSON, "showChangeDetails.jsp", 2, true,null);
Item3 = Item2.addItem(user.T("Parametrit"), PATH_TO_PERSON, "showAddPersonParameters.jsp", 2, true,null);
Item3 = Item2.addItem(user.T("Osoitteet"), PATH_TO_PERSON, "showAddPersonAddresses.jsp", 2, true,null);
}
/***************************** Teachers Course-module ***************************************************************/
if(level > 1 || anyCourseLevel > 1) {
try {
createTeacherTree(user, level);
} catch (Exception e) { return -1; }
}
/****************************** Students course-module ********************************************************************/
try {
createStudentTree(user, level);
} catch (Exception e) { System.out.println("Opiskelijan puussa virhe!!!!!!!!");return -1; }
/****************************** KOPPELO-module ********************************************************************/
if (level > 1) {
try {
createSupervisorAssignmentTree(user, level);
} catch (Exception e) { System.out.println("Ohjaajan opinnäytepuussa virhe!!!!!!!!"); return -1; }
}
try {
createStudentAssignmentTree(user, level);
} catch (Exception e) { System.out.println("Opiskelijan opinnäytepuussa virhe!!!!!!!!"); return -1; }
try {
createAssignmentTree(user, level);
} catch (Exception e) { System.out.println("Yhteisessä opinnäytepuussa virhe!!!!!!!!"); return -1; }
return 1;
}
/*****************************************************************************************************************************/
/**
* Prints out html-code to page.
*
* @param request Current http-request.
* @param out Output where to print.
*/
public void getHTML(HttpServletRequest request,JspWriter out) throws Exception {
int i = 0;
HTMLMenuItem item = new HTMLMenuItem();
while(i