<%
//Name of the form submission button
final String SUBMIT_NAME = "requestsubmission";
final String SUBMIT_VALUE = "SUBSCRIBE";
final String CLEAR_FORM_NAME = "clearform";
final String CLEAR_FORM_VALUE = "Clear Form";
// HTTP header with the URL from where the user navigated to the feedback page
final String REFERER = "Referer";
// Type of request expected for form submission
final String POST_REQUEST = "POST";
// Address to which user input is sent
final String TO_ADDRESS = "ocw-emma@mit.edu"; //Yvonne's e-mail id
// Address from which user input is shown as orignating from
final String SOURCE_ADDRESS = "ocw-mail@MIT.EDU";
// Form fields to be filled in by the user
final String FROM_ADDRESS = "fromemail";
final String FIRST_NAME = "firstname";
final String LAST_NAME = "lastname";
final String EDUCATIONAL_ROLE = "educationalRole";
final String GEOGRAPHIC_REGION = "geographicRegion";
final String GEOGRAPHIC_REGION_ID = "geo";
final String EMAIL_PREFERENCE = "preference";
// URL to which the form will be posted
final String ACTION_URL = "/OcwWeb/jsp/subscribe.jsp";
%>
<%
// Indicates if the Form field values are sent via POST by the user
boolean requestSubmitted = false;
// URL from which the user navigated to the feedback page
String referer = null;
// List of errors in the Form submitted by the user
ArrayList errorList = null;
// Form field values
String fromAddress = "";
String firstName = "";
String lastName = "";
String educationalRole = "";
String geographicRegion = "";
String preference = "";
String str = "";
// Request method - GET or POST
String requestMethod = request.getMethod();
String selected_value = "";
String[] array_countries = {"United States", "United Kingdom", "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo (Brazzaville)", "Congo (Kinshasa)", "Cook Islands", "Costa Rica", "Côte d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equitorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Holy See", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia, The Former Yugoslavia Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Federal States of", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"};
String country = "";
// Accept only submissions made via post (i.e., from the subscribe page itself)
if (requestMethod.equals(POST_REQUEST))
{
requestSubmitted = true;
referer = request.getParameter(REFERER);
}
else
{
referer = request.getHeader(REFERER);
if (referer == null || referer.equals(ACTION_URL))
{
referer = "/OcwWeb/index.htm";
}
}
%>
<% if (requestSubmitted) {
// Get the values input by the user
fromAddress = request.getParameter(FROM_ADDRESS);
firstName = request.getParameter(FIRST_NAME);
lastName = request.getParameter(LAST_NAME);
educationalRole = request.getParameter(EDUCATIONAL_ROLE);
geographicRegion = request.getParameter(GEOGRAPHIC_REGION);
preference = request.getParameter(EMAIL_PREFERENCE);
if (firstName == null || firstName.trim().equals("")){
firstName = "";
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("The First Name field is blank.");
}
if (lastName == null || lastName.trim().equals("")){
lastName = "";
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("The Last Name field is blank.");
}
if (fromAddress == null || fromAddress.trim().equals("")){
fromAddress = "";
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("The Email Address field is blank.");
}
else{
int atIndex = 0;
int dotIndex = 0;
// Ensure that the e-mail address is of the correct format. The following
// check is performed.
// 1. There is exactly one '@' character in the address and that is neither
// the first nor the last character
// 2. There is at least one '.' character in the address after the '@' character
// and that is not the last character
if (((atIndex = fromAddress.indexOf("@")) < 1) ||
((dotIndex = fromAddress.indexOf(".", atIndex)) == -1) ||
(atIndex != fromAddress.lastIndexOf("@")) ||
(fromAddress.lastIndexOf(".") == fromAddress.length()))
{
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("The format of the e-mail address is invalid.");
}
}
if ("".equals(educationalRole) || educationalRole.equals("No Selection")){
if (errorList == null) {
errorList = new ArrayList();
}
errorList.add("The Educational Role field is blank.");
}
if ("".equals(geographicRegion) || geographicRegion.equals("No Selection")){
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("The Geographic Region field is blank.");
}
if ("".equals(preference) || preference == null){
preference = "";
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("No option is selected in E-mail Preference field.");
}
// The following statements determine the course to which the URL from which
// the user navigated from belongs to
//String absPath = OcwSiteInfo.getAbsolutePath(referer);
boolean sent = false;
String course = "";
if (referer != null)
{
course = referer.replace('/', File.separatorChar);
}
// Send the message only if no error is encountered and the information
// is complete
if (errorList == null)
{
try {
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
catch (Exception e) {
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("We are sorry for the inconvenience, but we are experiencing technical difficulty. Please try again later.");
}
// URL of CGI-Bin script.
url = new URL ("https://app.e2ma.net/app/view:RemoteSignup");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream());
String content = "&username=mitocw&password=remote&signup_post=22089&emma_account_id=12960&group[5420816]=1" +
"&emma_member_name_first=" + URLEncoder.encode (firstName) +
"&emma_member_name_last=" + URLEncoder.encode (lastName) +
"&emma_member_email=" + URLEncoder.encode (fromAddress) +
"&emma_member_wildcard_6741=" + URLEncoder.encode (educationalRole) +
"&emma_member_country=" + URLEncoder.encode (geographicRegion) +
"&emma_member_plaintext_preferred=" + URLEncoder.encode (preference);
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
str = input.readLine();
input.close ();
sent = true;
}
catch (Throwable e)
{
if (errorList == null){
errorList = new ArrayList();
}
errorList.add("We are sorry for the inconvenience, but we are experiencing technical difficulty. Please try again later.");
}
}
%>
<% if (errorList == null) {
String message="";
if ("1".equals(str))
{
message = message + "Your subscription request has been submitted. Thanks!
A confirmation email is on its way to your email.
Note: To ensure proper delivery of our emails, please take a moment now and add us - ocw-mail@MIT.EDU - to your address book, trusted sender list, or company white list.";
}
else if ("2".equals(str) || "3".equals(str))
{
message = message + "Thank you for subscribing, but our records show you are currently a subscriber. If you need assistance, please contact us at ocw@mit.edu.";
}
else if ("-1".equals(str) || "-2".equals(str) || "-3".equals(str))
{
message = message + "Thank you for your interest. We are sorry for the inconvenience, but we are experiencing technical difficulty. Please try again later.";
// Subject of the e-mail that will be sent
String subject = "Error with the newsletter subscription form";
// The following statements construct the message to be sent
StringBuffer mailmessage = new StringBuffer(256);
mailmessage.append("Name: ").append(firstName).append(" ").append(lastName);
mailmessage.append("\n\nE-mail: ").append(fromAddress);
mailmessage.append("\n\nEducational Role: ").append(educationalRole);
mailmessage.append("\n\nGeographic Region: ").append(geographicRegion);
mailmessage.append("\n\nE-mail Preference: ").append(preference).append("\n\n");
mailmessage.append("An error has occurred with the newsletter subscription form. Please contact Emma/MIT Support.\n");
String toAddresses[] = new String[1];
toAddresses[0] = TO_ADDRESS;
String fromAddresses[] = new String [1];
fromAddresses[0] = fromAddress;
// Send the message only if no error is encountered and the information is complete
if (errorList == null)
{
try
{
//OcwNotifier.sendMessage(SOURCE_ADDRESS, toAddresses, null, null, subject, mailmessage.toString());
sent = true;
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
else if ("-3".equals(str))
{
message = message + "Failed to update Member";
}
else
{
message = message + "No action";
}%>
Subscribe
<%if ("1".equals(str) || "2".equals(str) || "3".equals(str)){%>
<%=message%>
<%}
else {%>
<%=message%>
<%}%>
<%}%>
<%}%>
<%
// Display the form if the request is not of type POST or
// the information posted had errors or was incomplete or
// the form was refreshed
if ((errorList != null) || (!requestSubmitted)) {
if(!"".equals((String)request.getParameter("txt_subscribe")) && (String)request.getParameter("txt_subscribe") != null){
fromAddress = (String) request.getParameter("txt_subscribe");
}
%>
Subscribe
Subscribe to the free monthly "MIT OpenCourseWare Update" e-newsletter. You'll receive notification of new courses and other OCW news.
All fields are required.
<% if (errorList != null){
//Display all the errors that were encountered
for (int i = 0; i < errorList.size(); i++){%>
<%=((String)errorList.get(i))%>
<%}%>
<%}%>
<%}%>
Current newsletter
Our current newsletter is available now.
Read more