<%

'foo! 
    
Dim SQL1, SQL2, SQL3, SQL4
Dim Conn, RS, RS2, RS3, RS4

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("conn_string")

Set RS = Server.CreateObject("ADODB.RecordSet")
SQL1 = "Select * from States where country_id = '2'"
RS.Open SQL1, Conn
	
'SQL2 = "Select * from Entity E inner join (Group_Entity_Map GEM inner join (Att_Group_Map AGM Inner Join Attribute_Type A on AGM.ATT_ID = A.ATT_ID) on GEM.Group_ID = AGM.Group_ID)	on E.Entity_ID = GEM.Entity_ID Where E.Entity_ID = '" & Request.QueryString("Entity_ID") & "'"
'Set RS2=Conn.Execute(SQL2)

If (Mid(UCase(Request.ServerVariables("CONTENT_TYPE")),1, 19) = "MULTIPART/FORM-DATA") Then

  Dim Xfer
  Set Xfer = Server.CreateObject("aspSmartUpload.SmartUpload")
  Xfer.Upload

  If Not Xfer.Form("Name") = "" Or Not XFer.Form("State") = "" Then
    
	If (UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST") Then

		If Xfer.Files.count <> 0 Then

			Dim DestDir, OrigDir
			Dim Realm_ID, Image_URL, FStatus
			Dim Orig_Image_ID, Orig_Image_URL
			Dim Image_Height, Image_Width
			Dim Image_ID, Image_Type_ID	
			Dim Arr_Image_Type_ID 
			Dim IM_Corrupt, IM_Format, IM_Height, IM_Width, IM_BC, IM_BGC
			Dim TempArr
			Dim TempStr
		
			OrigDir = "D:\Images\Originals" 	'Path to save original images to.
			Orig_Type_ID = "31"					'Type ID for the Original
			Orig_Image_URL = ""					'URL For the Original

			DestDir = "D:\Images" 				' Path to save image id based images to.
			Image_URL = ""						' URL for the new Image.. filename will be appended.
			Xfer.AllowedFilesList = "jpg,gif"	' Allowed File Types...

			Dim item
			Dim value
			Dim file
			Dim intCount

			Dim FName, FSize, FExt, FCap, FDesc, FNewName

			If Not Image_URL = "" And Right(Image_URL,1) <> "/" Then Image_URL = Image_URL & "/"
			If Not Orig_Image_URL = "" And Right(Orig_Image_URL,1) <> "/" Then Orig_Image_URL = Orig_Image_URL & "/"						
			If Not DestDir = "" And Right(DestDir,1) <> "\" Then DestDir = DestDir & "\"
			If Not OrigDir = "" And Right(OrigDir,1) <> "\" Then OrigDir = OrigDir & "\"
	
			For each file In Xfer.Files
	
				FName = file.FileName
			
				If FName <> "" Then
	
					FSize = file.Size
					FExt = file.FileExt
					FCap = Xfer.Form(File.Name & "caption")
					FDesc = Xfer.Form(File.Name & "description")
					FAlt = Xfer.Form(File.Name & "alt")
					Arr_Image_Type_ID = Split(Xfer.Form(file.Name & "types"), ",")
				
					OrigFile = Session("Admin_Group_ID") & "-" & FName  'Replace(Replace(Replace(FormatDateTime(Now), "/", "-"), " ", "-"), ":","-")
					intCount = file.SaveAs(OrigDir & OrigFile)
					
					Set Executor = Server.CreateObject("ASPExec.Execute")
					Executor.Application = "cmd /c ""c:\im\identify.exe -verbose " & OrigDir & OrigFile & """"
					strResult = Executor.ExecuteDosApp
					ParseResult = Split(Replace(strResult,Chr(10),""),Chr(13))

					For i = 0 to Ubound(ParseResult)
						ParseIt = Trim(ParseResult(i))

						If UCase(Mid(ParseIt, 1, 9)) = "IDENTIFY:" Then
							TempArr = Split(ParseIt, ":")
							TempStr = TempArr(1)
							If Trim(UCase(TempStr)) = "MISSING AN IMAGE FILE NAME." Then
								IM_Corrupt=True
							End If
						ElseIf UCase(Mid(ParseIt, 1, 9)) = "GEOMETRY:" Then
							TempArr = Split(ParseIt, ":")
							TempStr = TempArr(1)
							TempArr = Split(TempStr, "x")
							IM_Width=TempArr(0)
							IM_Height=TempArr(1)
						ElseIf UCase(Mid(ParseIt, 1, 17)) = "BACKGROUND COLOR:" Then
							TempArr = Split(ParseIt, ":")
							IM_BGC = Trim(TempArr(1))
						ElseIf UCase(Mid(ParseIt, 1, 13)) = "BORDER COLOR:" Then
							TempArr = Split(ParseIt, ":")
							IM_BC = Trim(TempArr(1))
						End If
					Next
				
					If IM_Corrupt = True Then
						Response.Write "<h2><font color=""#D30000"">You have uploaded a corrupt image.<br>Please check the image and retry.</font></h2>"
						Response.End
					End If
	
					SQL3 = "Add_Image @Image_URL = '" & Orig_Image_URL & "', @Image_File = '" & OrigFile & "', @Image_Ext = '" & FExt 
					SQL3 = SQL3 & "', @Image_Width = '" & IM_Width & "', @Image_Height = '" & IM_Height & "', @Image_BorderColor = '" & IM_BC
					SQL3 = SQL3 & "', @Image_BGColor = '" & IM_BGC & "', @Image_Caption = '" & FCap & "', @Image_Desc = '" & FDesc 
					SQL3 = SQL3 & "', @Image_Alt = '" & FAlt & "', @Image_Size = '" & FSize & "', @Image_Type_ID = '" & Orig_Type_ID & "'"
		
					Set RS3 = Conn.Execute(SQL3)
					Orig_Image_ID = RS3("Image_ID")
	
					For i = 0 to UBound(Arr_Image_Type_ID)
	
						Image_Type_ID = Arr_Image_Type_ID(i)
						
						SQL3 = "Select * From Image_Type Where Image_Type_ID='" & Image_Type_ID & "'"
						Set RS3 = Conn.Execute(SQL3)
						Image_Height = RS3("Height")
						Image_Width = RS3("Width")
	
						SQL3 = "Add_Image_Group @Group_ID='" & Session("Admin_Group_ID") & "', @Image_URL = '" & Image_URL & "', @Image_File = '" & OrigFile & "', @Image_Ext = '" & FExt 
						SQL3 = SQL3 & "', @Image_Width = '" & Image_Width & "', @Image_Height = '" & Image_Height & "', @Image_BorderColor = '" & IM_BC
						SQL3 = SQL3 & "', @Image_BGColor = '" & IM_BGC & "', @Image_Caption = '" & FCap & "', @Image_Desc = '" & FDesc 
						SQL3 = SQL3 & "', @Image_Alt = '" & FAlt & "', @Image_Size = '" & FSize & "', @Image_Type_ID = '" & Image_Type_ID & "', @Status = '" & Xfer.Form(file.Name & "status") & "'" 
	
						Set RS3 = Conn.Execute(SQL3)
						Image_ID = RS3.Fields("Image_ID")
			
						NewFile = Image_ID & "." & FExt
	
						Executor.Application = "cmd /c ""c:\im\copyresize.bat " & OrigDir & OrigFile & "  " & DestDir & NewFile & " """ & Trim(Image_Width) & "x" & Trim(Image_Height) & ">"""""
						strResult = Executor.ExecuteDosApp
						ParseResult = Split(Replace(strResult,Chr(10),""),Chr(13))
	
						New_Width = "0"
						New_Height = "0"
	
						For j = 0 to Ubound(ParseResult)
							ParseIt = Trim(ParseResult(j))

							If InStr(1, ParseIt, ":h") Then
								TempArr = Split(ParseIt, ":h")
								New_Width = Mid(TempArr(0), 2, Len(TempArr(0)) -1)
								New_Height = TempArr(1)
							End If
						Next
				
						'Update Image Width and Height with the New Width and Height.. assume the image was resized..
						Conn.Execute("Update [Image] Set [Image_Width] = '" & New_Width & "', [Image_Height] = '" & New_Height & "' Where [Image_ID]='" & Image_ID & "'")
	
						'Loop through Realms....
						For Each Value in Xfer.Form("Realm")
							Conn.Execute("Add_Realm_Image_Map @Image_ID='" & Image_ID & "', @Realm_ID='" & Value & "', @Status='" & Xfer.Form("realmstatus" & Value) & "'")
						Next
	
					Next			
	
					Set Executor = Nothing			
					Set RS3 = Nothing
					FormAdd = FormAdd + 1
			
				End If
			Next
	
			If Err Then
				Response.Write("<b>There was an error: </b>" & Err.description & "<br><br>")
			Else

				'Cary's godly code can go here. 
				SQL4 = "Add_Destination_Map_Entry @Map_Name='" & Xfer.Form("Name") & "', @Map_State='" & Xfer.Form("State") & "', @Map_Image_ID='" & Image_ID & "'"
				Set RS4 = Conn.Execute(SQL4)
				Set RS4 = Nothing

				If Xfer.Form("cont") = "1" Then 
					Set Xfer = Nothing	
					If Session("default_page") = "" Then Session("default_page") = "default.asp"
					Response.Redirect Session("default_page")

				ElseIf Xfer.Form("cont") = "2" Then 
					Set Xfer = Nothing	
					Response.Redirect "destination-page-content-create.asp"
				End If
			End If
		End If
	End If
End If
End If
%>


<html>
<STYLE>
BODY {SCROLLBAR-FACE-COLOR: #5e5ebe; SCROLLBAR-HIGHLIGHT-COLOR: #5e5ebe; SCROLLBAR-SHADOW-COLOR: #5e5ebe; SCROLLBAR-3DLIGHT-COLOR: #5e5ebe; SCROLLBAR-ARROW-COLOR:  #6666CC; SCROLLBAR-TRACK-COLOR: #E3E3E3; SCROLLBAR-DARKSHADOW-COLOR: #666666; }
</STYLE>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function Sub_Form(cont) {
  form1.cont.value=cont
  form1.submit();
}

//-->
</script>
<link rel="stylesheet" href="../Style-sheets/headline.css" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/icon-return-to-main-2.gif','images/icon-submit-changes-2.gif','images/icon-continue-wizard-2.gif')">
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="page" value="30">
<input type="hidden" name="cont" value="">
  <table width="525" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr bgcolor="#FFFFFF"> 
    <td width="467">&nbsp;</td>
    <td align="right" width="58">&nbsp;</td>
  </tr>
  <tr bgcolor="#5e5ebe"> 
      <td width="467" align="center" class="headline-ffffff">Destination Map Page 
        Creation</td>
    <td bgcolor="#5e5ebe" align="right" width="58"><a href="javascript:;" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','images/icon-return-to-main-2.gif',1)" onClick="MM_goToURL('this','default.asp');return document.MM_returnValue"><img src="images/icon-return-to-main.gif" width="75" height="17" usemap="#returntomain" border="0" name="Image1"></a></td>
  </tr>
  <tr> 
    <td width="467">&nbsp;</td>
    <td width="58">&nbsp;</td>
  </tr>
</table>
  <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr> 
      <td width="162">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">Name:</td>
      <td width="228"> 
        <input type="text" name="Name">
      </td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">State:</td>
      <td width="228"> 
        <select name="State">
        <OPTION value="" selected>Select</OPTION>
        <% Do While Not RS.EOF%>
        <OPTION value="<%=RS("State_Abbr")%>"><%=RS("State_Abbr")%></OPTION>
        <%RS.MoveNext()
        Loop%>
        </select>
      </td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">Map Image:</td>
      <td width="228"> 
        <input type="file" name="file">
      </td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">Image Caption:</td>
      <td width="228"> 
        <input type="text" name="filecaption">
      </td>
      <td width="110">&nbsp;</td>
    </tr>

    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">Image Description:</td>
      <td width="228"> 
        <input type="text" name="filedescription">
      </td>
      <td width="110">&nbsp;</td>
    </tr>

    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold">Image Alt Tag:</td>
      <td width="228"> 
        <input type="alt" name="filealt">
      </td>
      <td width="110">&nbsp;</td>
    </tr>


    <tr> 
      <td width="162" class="manage-menu-bold">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162" class="manage-menu-bold" height="22">Active Realms:</td>
      <td width="228" height="22"> 
        <select name="Realm" size="3" multiple>
          <option value="1">Vacation in Florida</option>
          <option value="2">Campground Network</option>
          <option value="3">Western RV News</option>
          <option value="4">Mexico Rving</option>
        </select>
      </td>
      <td width="110" height="22">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
    <tr> 
      <td width="162">&nbsp;</td>
      <td width="228">&nbsp;</td>
      <td width="110">&nbsp;</td>
    </tr>
  </table>
<table width="525" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="#5e5ebe"> 
    <td align="right" width="49%" height="18"><a href="javascript:Sub_Form('1');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submitchanges','','images/icon-submit-changes-2.gif',1)"><img src="images/icon-submit-changes.gif" width="200" height="15" name="submitchanges" border="0"></a></td>
      <td width="51%" height="18"><a href="javascript:Sub_Form('2');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','images/icon-continue-wizard-2.gif',1)"><img src="images/icon-continue-wizard.gif" width="150" height="15" usemap="#continue" border="0" name="Image2"></a></td>
  </tr>
  <tr> 
    <td width="49%">&nbsp;</td>
    <td width="51%">&nbsp;</td>
  </tr>
</table></form>
</body>
</html>
