<%@ page import="java.text.DateFormat" %> <%@ page import="java.text.SimpleDateFormat" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.Calendar" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Collections" %> <%@ page import="java.util.Comparator" %> <%@page import="com.insightguru.giraffe.common.constant.UserProfileBitFlags"%> <%@page import="com.insightguru.giraffe.server.domain.FeaturedDriver"%> <%@page import="com.insightguru.giraffe.server.domain.Company"%> <%@page import="com.insightguru.giraffe.server.domain.Identifier"%> <%@page import="com.insightguru.giraffe.server.domain.User"%> <%@page import="com.insightguru.giraffe.server.dao.CompanyDAO"%> <%@page import="com.insightguru.giraffe.server.dao.FeaturedDriverDAO"%> <%@page import="com.insightguru.giraffe.server.dao.IdentifierDAO"%> <%@page import="com.insightguru.giraffe.server.dao.UserDAO"%> <%@page import="com.insightguru.giraffe.server.utils.FeaturedCompanyUtil"%> <%@page import="com.insightguru.giraffe.server.utils.ServletUtil"%> <%@page import="com.insightguru.giraffe.server.controller.LoginController"%> <%@page import="com.insightguru.giraffe.server.service.ClearCacheService"%> <%@page import="com.insightguru.giraffe.server.service.ClearCacheService.CacheType"%> <%@ page import="org.owasp.esapi.ESAPI" %> <%@ page import="org.owasp.esapi.Encoder" %> <%@page import="org.json.JSONObject"%> <%@page import="java.util.ArrayList"%> <%! DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT); %> Add a Featured Driver <%@ include file="components/commonHead.jsp" %>
<% User loggedInUser = UserDAO.getCurrentUser(); if(loggedInUser == null || !UserProfileBitFlags.isAdmin(loggedInUser)) { %>

Admin Access Only

Logout and try again <% } else { %> <% if("submit".equals(request.getParameter("do"))) { boolean editing = request.getParameter("id") != null; FeaturedDriver featuredDriver; if(editing) featuredDriver = FeaturedDriverDAO.getFeaturedDriver(Integer.parseInt(request.getParameter("id"))); else featuredDriver = new FeaturedDriver(); featuredDriver.setDriver(IdentifierDAO.load(request.getParameter("driver"))); featuredDriver.setTitle(request.getParameter("title")); featuredDriver.setSnippet(request.getParameter("snippet")); featuredDriver.setDay(dateFormat.parse(request.getParameter("day"))); FeaturedDriverDAO.saveFeaturedDriver(featuredDriver); ClearCacheService.clear(CacheType.FEATURED_DRIVERS); %>

Featured Driver <%= editing ? "edited" : "added" %>!

<% } %> <% if("delete".equals(request.getParameter("do"))) { FeaturedDriverDAO.deleteFeaturedDriver(Integer.parseInt(request.getParameter("id"))); ClearCacheService.clear(CacheType.FEATURED_DRIVERS); %>

Featured Driver deleted!

<% } %> <% if("add".equals(request.getParameter("do")) || "edit".equals(request.getParameter("do"))) { FeaturedDriver toEdit = null; if("edit".equals(request.getParameter("do"))) toEdit = FeaturedDriverDAO.getFeaturedDriver(Integer.parseInt(request.getParameter("id"))); List companies = CompanyDAO.getCompanies(false); Collections.sort(companies, new Comparator() { public int compare(Company company1, Company company2) { return company1.getSymbol().compareToIgnoreCase(company2.getSymbol()); } }); %>
Date:
Company:
Driver:
Title: "/>
Snippet:
Cancel
<% if(toEdit != null) { %> <% } %>
<%@ include file="/components/commonJS.jsp" %> <% } else {%> Add a new Featured Driver <% final List featuredDrivers; if (request.getParameter("showAll") == null) { Calendar fiveDaysAgo = Calendar.getInstance(); fiveDaysAgo.add(Calendar.DATE, -5); featuredDrivers = FeaturedDriverDAO.getAllFeaturedDriversAfter(fiveDaysAgo.getTime()); %> | Show All

Recent and Future Featured Drivers

<% } else { featuredDrivers = FeaturedDriverDAO.getAllFeaturedDrivers(); %> | Show Recent

All Featured Drivers

<% } %> <% for(FeaturedDriver featuredDriver : featuredDrivers) { %> <% } %>
Date Company Driver Preview
<%= dateFormat.format(featuredDriver.getDay()) %> <%= ESAPI.encoder().encodeForHTML(featuredDriver.getDriver().getCompany().getCompanyName()) %> <%= ESAPI.encoder().encodeForHTML(featuredDriver.getDriver().getShortName()) %>

<%= ESAPI.encoder().encodeForHTML(featuredDriver.getTitle()) %>

<%= FeaturedCompanyUtil.getAugmentedEscapedSnippet(featuredDriver) %>
Edit Delete
<% } %> <% } %>