Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (revision 27f58d007df3a168dc37fef184f15d6d65039e5f)
@@ -0,0 +1,178 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+package org.lamsfoundation.lams.web;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.lamsfoundation.lams.lesson.Lesson;
+import org.lamsfoundation.lams.usermanagement.Organisation;
+import org.lamsfoundation.lams.usermanagement.OrganisationState;
+import org.lamsfoundation.lams.usermanagement.OrganisationType;
+import org.lamsfoundation.lams.usermanagement.Role;
+import org.lamsfoundation.lams.usermanagement.UserOrganisation;
+import org.lamsfoundation.lams.usermanagement.UserOrganisationRole;
+import org.lamsfoundation.lams.usermanagement.service.UserManagementService;
+import org.lamsfoundation.lams.web.util.HttpSessionManager;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * @version
+ *
+ *
+ * View Source
+ *
+ *
+ * @author Fei Yang
+ *
+ * Created at 16:59:28 on 13/06/2006
+ */
+/**
+ * struts doclet
+ *
+ * @struts.action path="/index" validate="false"
+ *
+ * @struts.action-forward name="index" path="/indexContent.jsp"
+ */
+public class IndexAction extends Action {
+ private static Logger log = Logger.getLogger(IndexAction.class);
+
+ private static WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(HttpSessionManager.getInstance().getServletContext());
+
+ private static UserManagementService service = (UserManagementService) ctx.getBean("userManagementServiceTarget");
+
+ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ log.debug("User:"+request.getRemoteUser());
+ List headerLinks = new ArrayList();
+ headerLinks.add(new IndexLinkBean("My Profile", "profile.do?username=" + request.getRemoteUser()));
+ if (request.isUserInRole(Role.SYSADMIN)) {
+ log.debug("user is sysadmin");
+ headerLinks.add(new IndexLinkBean("System Administration", "admin/sysadminstart.do"));
+ headerLinks.add(new IndexLinkBean("Course Management", "admin/orgmanage.do?org=" + service.getRootOrganisation().getOrganisationId()));
+ }
+ if (request.isUserInRole(Role.AUTHOR)) {
+ log.debug("user is author");
+ headerLinks.add(new IndexLinkBean("Author", "home.do?method=author"));
+ }
+ log.debug("set headerLinks in request");
+ request.setAttribute("headerLinks", headerLinks);
+
+ List orgBeans = new ArrayList();
+ if (request.isUserInRole(Role.SYSADMIN)) {
+ List roles = new ArrayList();
+ List organisations = service.getOrganisationsByTypeAndStatus(OrganisationType.COURSE_TYPE, OrganisationState.ACTIVE);
+ log.debug("we got "+organisations.size()+" organisations whose type is "+OrganisationType.COURSE_DESCRIPTION+" and whose state is "+OrganisationState.ACTIVE);
+ roles.add(Role.ROLE_SYSADMIN);
+ for (Organisation org:organisations) {
+ orgBeans.add(createOrgBean(org, roles, request.getRemoteUser(),true));
+ }
+ } else {
+ List userOrganisations = service.getUserOrganisationsForUserByTypeAndStatus(request.getRemoteUser(),OrganisationType.COURSE_TYPE,OrganisationState.ACTIVE);
+ log.debug("we got "+userOrganisations.size()+" organisations whose type is "+OrganisationType.COURSE_DESCRIPTION+" and whose state is "+OrganisationState.ACTIVE);
+ for (UserOrganisation userOrganisation: userOrganisations) {
+ List roles = new ArrayList();
+ for(Object userOrganisationRole:userOrganisation.getUserOrganisationRoles()){
+ roles.add(((UserOrganisationRole)userOrganisationRole).getRole().getRoleId());
+ }
+ orgBeans.add(createOrgBean(userOrganisation.getOrganisation(),roles,request.getRemoteUser(),false));
+ }
+ }
+ log.debug("set orgBeans in request");
+ request.setAttribute("orgBeans",orgBeans);
+ return mapping.findForward("index");
+ }
+
+ private IndexOrgBean createOrgBean(Organisation org, List roles, String username, boolean isSysAdmin) {
+ log.debug("creating orgBean for org:"+org.getName());
+ IndexOrgBean orgBean = new IndexOrgBean(org.getName(), org.getOrganisationType().getOrganisationTypeId());
+ List links = new ArrayList();
+ if(isSysAdmin){
+ if (orgBean.getType().equals(OrganisationType.COURSE_TYPE)) {
+ links.add(new IndexLinkBean("Manage Classes", "admin/orgmanage.do?org=" + org.getOrganisationId()));
+ }
+ }
+ if (contains(roles, Role.ROLE_COURSE_ADMIN) || contains(roles, Role.ROLE_COURSE_MANAGER)) {
+ if (orgBean.getType().equals(OrganisationType.COURSE_TYPE)) {
+ if(!isSysAdmin){
+ links.add(new IndexLinkBean("Manage Classes", "admin/orgmanage.do?org=" + org.getOrganisationId()));
+ }
+ links.add(new IndexLinkBean("Add Lesson", "home.do?method=addLesson&courseID=" + org.getOrganisationId()));
+ }else{//CLASS_TYPE
+ links.add(new IndexLinkBean("Add Lesson","home.do?method=addLesson&courseID="+org.getParentOrganisation().getOrganisationId()+"&classID="+org.getOrganisationId()));
+ }
+ }
+ orgBean.setLinks(links);
+
+ List lessonBeans = new ArrayList();
+ Set lessons = org.getLessons();
+ for(Lesson lesson:lessons) {
+ List lessonLinks = new ArrayList();
+ if(contains(roles,Role.ROLE_COURSE_MANAGER)||contains(roles,Role.ROLE_STAFF)){
+ lessonLinks.add(new IndexLinkBean("Monitor", "home.do/method=monitorLesson&lessonID=" + lesson.getLessonId()));
+ }else if(contains(roles,Role.ROLE_LEARNER)){
+ lessonLinks.add(new IndexLinkBean("Participate","home.do?method=learner&lessonID="+lesson.getLessonId()));
+ }
+ IndexLessonBean lessonBean = new IndexLessonBean(lesson.getLessonName(), lessonLinks);
+ lessonBeans.add(lessonBean);
+ }
+ orgBean.setLessons(lessonBeans);
+
+ if(orgBean.getType().equals(OrganisationType.COURSE_TYPE)){
+ Set children = org.getChildOrganisations();
+ List childOrgBeans = new ArrayList();
+ for(Organisation organisation:children){
+ if(organisation.getOrganisationState().getOrganisationStateId().equals(OrganisationState.ACTIVE)){
+ List classRoles = new ArrayList();
+ List userOrganisationRoles = service.getUserOrganisationRoles(organisation.getOrganisationId(),username);
+ for(UserOrganisationRole userOrganisationRole:userOrganisationRoles){
+ classRoles.add(userOrganisationRole.getRole().getRoleId());
+ }
+ childOrgBeans.add(createOrgBean(organisation,classRoles,username,isSysAdmin));
+ }
+ }
+ orgBean.setChildIndexOrgBeans(childOrgBeans);
+ }
+ return orgBean;
+ }
+
+ private boolean contains(List roles, Integer roleId) {
+ log.debug("roleId:"+roleId);
+ for (int i = 0; i < roles.size(); i++) {
+ log.debug(roles.get(i));
+ if (roleId.equals(roles.get(i)))
+ return true;
+ }
+ return false;
+ }
+
+}
Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexLessonBean.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/IndexLessonBean.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/IndexLessonBean.java (revision 27f58d007df3a168dc37fef184f15d6d65039e5f)
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+package org.lamsfoundation.lams.web;
+
+import java.util.List;
+
+/**
+ * @version
+ *
+ *
+ * View Source
+ *
+ *
+ * @author Fei Yang
+ *
+ * Created at 10:13:43 on 14/06/2006
+ */
+public class IndexLessonBean {
+ private String name;
+ private List links;
+
+ public IndexLessonBean(String name, List links) {
+ this.name = name;
+ this.links = links;
+ }
+ /**
+ * @return Returns the links.
+ */
+ public List getLinks() {
+ return links;
+ }
+ /**
+ * @param links The links to set.
+ */
+ public void setLinks(List links) {
+ this.links = links;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexLinkBean.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/IndexLinkBean.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/IndexLinkBean.java (revision 27f58d007df3a168dc37fef184f15d6d65039e5f)
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+package org.lamsfoundation.lams.web;
+
+/**
+ * @version
+ *
+ *
+ * View Source
+ *
+ *
+ * @author Fei Yang
+ *
+ * Created at 10:12:09 on 14/06/2006
+ */
+public class IndexLinkBean {
+
+ private String name;
+ private String url;
+
+ public IndexLinkBean(String name, String url) {
+ this.name = name;
+ this.url = url;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ /**
+ * @return Returns the url.
+ */
+ public String getUrl() {
+ return url;
+ }
+ /**
+ * @param url The url to set.
+ */
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+}
Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexOrgBean.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/IndexOrgBean.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/IndexOrgBean.java (revision 27f58d007df3a168dc37fef184f15d6d65039e5f)
@@ -0,0 +1,116 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+package org.lamsfoundation.lams.web;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @version
+ *
+ *
+ * View Source
+ *
+ *
+ * @author Fei Yang
+ *
+ * Created at 10:01:23 on 14/06/2006
+ */
+public class IndexOrgBean {
+
+ private String name;
+ private Integer type;
+ private List links;
+ private List lessons;
+ private List childIndexOrgBeans;
+
+
+ public IndexOrgBean(String name, Integer type) {
+ this.name = name;
+ this.type = type;
+ this.links = new ArrayList();
+ this.lessons = new ArrayList();
+ this.childIndexOrgBeans = new ArrayList();
+ }
+ /**
+ * @return Returns the childIndexOrgBeans.
+ */
+ public List getChildIndexOrgBeans() {
+ return childIndexOrgBeans;
+ }
+ /**
+ * @param childIndexOrgBeans The childIndexOrgBeans to set.
+ */
+ public void setChildIndexOrgBeans(List childIndexOrgBeans) {
+ this.childIndexOrgBeans = childIndexOrgBeans;
+ }
+ /**
+ * @return Returns the lessons.
+ */
+ public List getLessons() {
+ return lessons;
+ }
+ /**
+ * @param lessons The lessons to set.
+ */
+ public void setLessons(List lessons) {
+ this.lessons = lessons;
+ }
+ /**
+ * @return Returns the links.
+ */
+ public List getLinks() {
+ return links;
+ }
+ /**
+ * @param links The links to set.
+ */
+ public void setLinks(List links) {
+ this.links = links;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public Integer getType() {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(Integer type) {
+ this.type = type;
+ }
+
+}