<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.csc.library.utilities.*,com.csc.library.database.*,com.csc.library.session.*" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%
String uri=request.getQueryString();
%>
<%
com.csc.library.utilities.UProfile uprofile = null;
if(session != null ) {
	uprofile = (com.csc.library.utilities.UProfile)session.getAttribute("userprofile");
}

if( uprofile == null ){
	response.sendRedirect("AUTHORIZEERROR.jsp?"+uri);
	return;
}
				    DataSet  ds =null;
					String url="";
					boolean myforward=false;
					String[] arrstr=uri.split("&\\w+=");
					//out.println("<br>1= " +arrstr[0]);
					//out.println("<br>2= " +arrstr[1]);
					//out.println("<br>3= " +arrstr[2]);										
					if(arrstr.length==3){
							try {
								 String dbtype = new InitialEnvironment(uprofile.getDbName()).getValue("datasource-dbtype");
								String filter=" WF_ID='"+arrstr[1]+"' and WF_SEQ_NO='"+arrstr[2]+"' and ACTOR_ID='"+(String)uprofile.get("employeeid")+"'";  
								String sql= "select ap.WF_ID,ap.WF_VER,ap.WF_SEQ_NO,ap.STEP_ID,ap.STEP_SEQ_NO,ap.ACTOR_ID,ap.ACTOR_SEQ_NO,ap.SENDER_ID,ap.DOC_NO,ap.ACTOR_URL,ai.START_TIME,ai.COMPLETION_TIME,ai.STATUS, "+
													 " case when ai.status='1'  then ap.ACTOR_URL+'&__singlereadonly=true&__readonly=false' else ap.ACTOR_URL+'&__singledisabled=true&__readonly=true' end as ACTOR_URL2 "+
													 " from (select * from ACTOR_PARAMETER where "+filter+") ap "+
													 " inner join (select * from ACTOR_INCIDENT where "+filter+") ai "+
													 " on ap.WF_ID=ai.WF_ID and ap.WF_VER=ai.WF_VER and ap.WF_SEQ_NO=ai.WF_SEQ_NO and ap.ACTOR_ID=ai.ACTOR_ID and ap.STEP_ID=ai.STEP_ID and ap.STEP_SEQ_NO=ai.STEP_SEQ_NO and ap.ACTOR_SEQ_NO=ai.ACTOR_SEQ_NO "+
													 " order by ai.COMPLETION_TIME ";
									if(dbtype.equalsIgnoreCase("ORACLE")){	
											sql="select ap.WF_ID,ap.WF_VER,ap.WF_SEQ_NO,ap.STEP_ID,ap.STEP_SEQ_NO,ap.ACTOR_ID,ap.ACTOR_SEQ_NO,ap.SENDER_ID,ap.DOC_NO,ap.ACTOR_URL,ai.START_TIME,ai.COMPLETION_TIME,ai.STATUS, "+
													" case when ai.status='1'  then ap.ACTOR_URL||'&'||'__singlereadonly=true'||'&'||'__readonly=false' else ap.ACTOR_URL||'&'||'__singledisabled=true'||'&'||'__readonly=true' end as ACTOR_URL2 "+
													" from (select * from ACTOR_PARAMETER where "+filter+") ap "+
													" inner join (select * from ACTOR_INCIDENT where  "+filter+") ai "+
													" on ap.WF_ID=ai.WF_ID and ap.WF_VER=ai.WF_VER and ap.WF_SEQ_NO=ai.WF_SEQ_NO and ap.ACTOR_ID=ai.ACTOR_ID and ap.STEP_ID=ai.STEP_ID and ap.STEP_SEQ_NO=ai.STEP_SEQ_NO and ap.ACTOR_SEQ_NO=ai.ACTOR_SEQ_NO " +
													" order by ai.COMPLETION_TIME ";										 
									}
													 
								ds=new DataSet(sql,uprofile.getDbName(), "actor_incident");
								ds.setFetchAll(false);
								ds.initConnection(uprofile);
								while(ds.next()){
								   url=ds.getString("actor_url2");
								}
							} catch (Exception e) {            
									myforward=false;    	
							}finally{
								if(ds!=null){
										ds.closeConnection();
								}
							}
			
							if(url.length()>0){					
								response.sendRedirect(url.substring(1));
							}else{
								response.sendRedirect("./MYNOTE/INBOX.jsp");
							}
					}else if(arrstr.length==4){
						response.sendRedirect(arrstr[3]+".jsp");
					}else{
						response.sendRedirect("./MYNOTE/INBOX.jsp");
					}
%>