<!--#include file="../../owFunctions/I_GeneralFunctions.asp"-->
<!--#include file="../header.asp"-->
<%
	'************************************************************************************
	'*																					*
	'*	MODIFICATION TO THIS SCRIPT OR ANY FILES INCLUDED WITH 							*
	'*		ONEWORLDSTORE IS DONE AT YOUR OWN RISK!										*
	'*	Product  : OneWorldStore														*
	'*	Version  : 9.0000																*
	'*	Modified : June 2004															*
	'*	Copyright:	Copyright (C) 2004 OneWorldStore.Com								*
	'*				Registration Number: 1024507										*
	'*				http://strategis.ic.gc.ca/											*
	'*																					*
	'************************************************************************************
	
	sAction				= Trim(Request("sAction"))
	bResetDBLoc			= False
	sURL				= "owListOptions.asp"
	sTarget				= "owMain"
	sSort				= Trim(Request("sSort"))
	sSearch				= Trim(Request("sSearch"))
	sSearchText			= Trim(Request("sSearchText"))
	
	If ( sAction = "Delete" ) Then
		For Each sCheckbox In Request.Form
			If ( InStr(sCheckbox, "sDelete") > 0 ) Then
				sTemp = Replace(sCheckbox, "sDelete", "")
				sSuccess = DeleteOption(sTemp)
			End If
		Next
		bResetDBLoc = True
	End If
	
	If ( sSearchText <> "" ) Then
		sTempSearch = " AND optionDescrip LIKE '" & sSearchText & "%'"
	Else
		sTempSearch = ""
	End If

	sSQLText 	= "SELECT O.idOption, O.optionDescrip, OG.OptionGroupDesc FROM Options O, OptionsGroups OG, Options_OptionsGroups OOG WHERE O.idOption = OOG.idOption AND OOG.idOptionGroup = OG.idOptionGroup" & sTempSearch & " UNION SELECT idOption, optionDescrip, '' FROM Options WHERE idOption NOT IN (SELECT DISTINCT idOption FROM Options_OptionsGroups)" & sTempSearch
	sSQLCount	= "SELECT count(*) + (SELECT count(*) FROM Options WHERE idOption NOT IN (SELECT DISTINCT idOption FROM Options_OptionsGroups)" & sTempSearch & ")  FROM Options O, OptionsGroups OG, Options_OptionsGroups OOG WHERE O.idOption = OOG.idOption AND OOG.idOptionGroup = OG.idOptionGroup" & sTempSearch
	
	If ( sSort <> "" ) Then
		sSQLText = sSQLText & " ORDER BY " & sSort
	Else
		sSQLText = sSQLText & " ORDER BY OG.OptionGroupDesc, O.optionDescrip"
	End If

	iBeginPagination = SetupPagination( sSQLCount, bResetTtlNumItems, bResetDBLoc )
	Call PaginationQuery( sSQLText, rsStoreData, iBeginPagination )
	%>
	<script language = "javascript">
		parent.owBodyFooter.location="owBodyFooter.asp?sPage=ListOptions&sAction=<%=sAction%>&sSearchText=<%=sSearchText%>&sSort=<%=sSort%>&sSearch=<%=sSearch%>&iOWNumPerPage=<%=iOWNumPerPage%>&iTtlNumItems=<%=iTtlNumItems%>&iDBLoc=<%=iDBLoc%>"
	</script>
	<%
	
	If ( sSuccess <> "" ) Or ( rsStoreData.EOF ) Then
		If ( sSuccess <> "" ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sPage=ListOptions&sMessage=<%=Server.URLEncode(sSuccess)%>"
			</script>
			<%
		End If
		If ( rsStoreData.EOF ) Then
			%>
			<script language = "javascript">
				parent.owBodyTopNav.location="owBodyTopNav.asp?sPage=ListOptions&sMessage=<%=Server.URLEncode(LANG_DT( "OPTIONS_NONEFOUND", "** No Options found **" ))%>"
			</script>
			<%
		End If
	Else
		' just refresh the top bar to remove any "Save" buttons or old messages
		%>
		<script language = "javascript">
			parent.owBodyTopNav.location="owBodyTopNav.asp?sPage=ListOptions"
		</script>
		<%
	End If
	sQueryString = "sSearchText=" & Server.URLEncode(sSearchText) & "&sSearch=" & Server.URLEncode(Trim(sSearch)) & "&sSort="
	%>
	<script language = "javascript">
		
		function ColumnOn(sStyle)
		{
			sStyle.background	= "#F5C058";
		}
		function ColumnOff(sStyle)
		{
			sStyle.background	= "#C3DAF9";
		}
		
		function ColumnDataOn(sStyle)
		{
			sStyle.background	= "#EAF1F9";
		}
		function ColumnDataOff(sStyle)
		{
			sStyle.background	= "#FFFFFF";
		}
		
	</script>
	<body bgcolor="C3DAF9" text="#000000" topmargin="0" leftmargin="0">
		<table width=100% border="0" cellpadding="2" cellspacing="0" style="font-size: 11px" bgcolor=FFFFFF>
		<form action='owListOptions.asp' method='post' name='OptionsList'>
			<input type='hidden' name='sAction' value=''>
			<input type='hidden' name='sSort' value=''>
			<tr> 
				<td class="ColumnHead" align="center"><%=LANG_DT( "SELECT", "Select" )%></td>
				<td onClick="location.href='owListOptions.asp?<%=sQueryString%>O.optionDescrip'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead"><%=LANG_DT( "OPTION_NAMELIST", "Option Name" )%></td>
				<td onClick="location.href='owListOptions.asp?<%=sQueryString%>O.Type'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead"><%=LANG_DT( "OPTION_TYPE", "Option Type" )%></td>
				<td onClick="location.href='owListOptions.asp?<%=sQueryString%>OG.OptionGroupDesc'" onMouseOver="ColumnOn(this.style);" onMouseOut="ColumnOff(this.style);" class="ColumnHead"><%=LANG_DT( "OPTION_GROUPNAME", "Option Group Name" )%></td>
			</tr>
			<%
			sSQLCount = 0
			While ( ( NOT rsStoreData.EOF ) And ( sSQLCount < iOWNumPerPage ) )
				OptionGroupDesc = Trim(rsStoreData("OptionGroupDesc"))
				optionDescrip	= Trim(rsStoreData("optionDescrip"))
				idOption		= Trim(rsStoreData("idOption"))
				If ( OptionGroupDesc = "" ) Then
					OptionGroupDesc = "&lt;Not Assigned Yet&gt;"
				End If
				sQueryString2 = sQueryString & sSort & "&idOption=" & idOption
				%>
				<tr onMouseOver="ColumnDataOn(this.style);" onMouseOut="ColumnDataOff(this.style);"> 
					<td width=5% class='ColumnData' align="center"><input size="1" type="checkbox" style="font-size: 6px;" name="sDelete<%=idOption%>" value="Y"></td>
					<td width=35% onclick="location.href='owModifyOptionsForm.asp?<%=sQueryString2%>'" class='ColumnData'><%=optionDescrip%>&nbsp;</td>
					<td width=35% onclick="location.href='owModifyOptionsForm.asp?<%=sQueryString2%>'" class='ColumnData'>
						<%
						Select Case sType
							Case "Radio"
								Response.Write LANG_DT( "OPTION_RADIO", "Radio Buttons" )
							Case "Checkbox"
								Response.Write LANG_DT( "OPTION_CHECKBOX", "Checkboxes" )
							Case "Dropdown"
								Response.Write LANG_DT( "OPTION_DROPDOWN", "Dropdown List" )
							Case "Text"
								Response.Write LANG_DT( "OPTION_TEXT", "Text Field" )
							Case "Memo"
								Response.Write LANG_DT( "OPTION_MEMO", "Memo Field" )
							Case "File"
								Response.Write LANG_DT( "OPTION_FILE", "File Upload" )
							Case "Multipick"
								Response.Write LANG_DT( "OPTION_MULTIPICK", "Multipick Pick List" )
						End Select
						%>
						&nbsp;
					</td>
					<td onclick="location.href='owModifyOptionsForm.asp?<%=sQueryString2%>'" class='ColumnData'><%=OptionGroupDesc%>&nbsp;</td>
				</tr>
				<%
				sSQLCount = sSQLCount + 1
				rsStoreData.moveNext
			Wend
			Call DB_closeRecordset(rsStoreData)
			%>
    		</form>
  		</table>
	<!--#include file="../footer.asp"-->
	<%
	'************************************************************************************


	'************************************************************************************
	'*																					*
	'*																					*
	'*																					*
	'************************************************************************************
	Function DeleteOption(sIDOption)

		If ( NOT bOWBackOfficeDemoMode ) Then	' just do a cursory check in case hackers try to replicate the forms on their computers (return no error)
			' remove from the group assignment table
			Call DB_updateDatabase("DELETE FROM Options_OptionsGroups WHERE idOption = " & sIDOption)
			
			' remove the option
			Call DB_updateDatabase("DELETE FROM Options WHERE idOption = " & sIDOption)
			
			DeleteOption = LANG_DT( "OPTION_DELOK", "** Deletion Successful **" )
		End If
	
	End Function
	'************************************************************************************
	%>