<!--#include file="CNCASPPageManager_PagesApproveDecline.inc" -->

<%
' ************************************************************************
' File:		/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/
'				TaskAssistant/ApprovalAssistant/PagesApproveDecline/
'				PagesApproveDecline.asp
'
' Author:	Microsoft Corporation.
' Purpose:	This ASP page is invoked from the Approval Assistant page when
'			a user has selected a set of one or more pages for approval
'			and initiates the operation.
'
' Query String Parameters:
'
'	[API-Generated-Query-Params]:
'		This set of query string parameters is forwarded by the calling
'		page. These parameters are not used explicitly here but are
'		forwarded back to the calling page after the approve or decline
'		operation has been performed.
'
' Expected Form Data:
'
'	IDS_FORM_ELEMENT_SELECTFORAPPROVEDECLINE
'		This form element lists what postings have been selected for the
'		approve or decline operation. The operation is performed by
'		iterating through the list and calling upon the ROM to do the
'		action for each posting.
'
'	IDS_FORM_ELEMENT_APPROVEORDECLINE
'		This form element indicates whether the operation to be performed
'		is an approval or a decline operation.
'
'	IDS_FORM_ELEMENT_PREFIX & <GUID>
'		The value of this form element indicates the name of the posting
'		that is to be operated upon.
'
'**************************************************************************

' we can only run in unpublished mode
if (AutoSession.IsModeUnpublished = false) AND (AutoSession.IsModeUpdate = false) then
	Response.End
end if

' ---- Initialize the ASPPageManager
Dim g_pASPPageManager
Set g_pASPPageManager = New CNCASPPageManager_PagesApproveDecline
Call g_pASPPageManager.InitManager()

Dim pASPUtils
Set pASPUtils = g_pASPPageManager.ASPUtils
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta name="Author" content="Microsoft Corporation.">
<meta name="Description" content="Display the resources delete error report">
<meta name="robots" content="NOINDEX,NOFOLLOW">
<meta http-equiv="Content-Type" content="text/html;charset=<%= g_pASPPageManager.Charset %>">

<title><%= IDS_UI_BROWSER_TITLE %></title>

<% Call EmbedWBCHeadSection %>

</head>

<body <%= IDS_BODYSETTING %> class="<%= IDS_CSS_APPROVALASSISTANT_NORMALTEXT0 %>">

<!--
	WARNING:
	========
	For the following HTML that has <td><img src=...></td>,
	do NOT break them into separate lines as it will alter
	the layout of the rendered page
-->


<table height="90%" width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr valign="top">
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="0">

				<!-- Show the top title -->
				<tr class="<%= IDS_CSS_APPROVALASSISTANT_BACKGROUND1 %>">
					<td align=right><img border=0 src="<%= IDS_PATH_IMAGE_LOGO %>"></td>
					<td width=100% valign="middle"  class="<%= IDS_CSS_APPROVALASSISTANT_HEADERTEXT %>"><%= IDS_UI_APPROVALASSISTANT_ACTION_TITLE & g_pASPPageManager.ActionPresentTense %></td>
					<td><img src="<%= IDS_TRANSPARENT_GIF %>" width="<%= C_INT_MAIN_MARGIN %>" height="<%= C_INT_HEADER_HEIGHT %>" border="0"></td>
				</tr>

				<!-- Show the breadcrumb trail -->
				<tr class="<%= IDS_CSS_APPROVALASSISTANT_BACKGROUND2 %>">
					<td><img src="<%= IDS_TRANSPARENT_GIF %>" width="<%= C_INT_MAIN_MARGIN %>" height="<%= C_INT_SUBHEAD_HEIGHT %>" border="0"></td>
					<td class="<%= IDS_CSS_APPROVALASSISTANT_SUBHEADTEXT %>">
						<a href="<%= g_pASPpageManager.URLRefreshPagesAfterAction %>"><%= IDS_UI_APPROVALASSISTANT_DESC %></a> >
						<%= g_pASPPageManager.ActionPresentTense & IDS_UI_APPROVALASSISTANT_ACTION_DESC %>
					</td>
					<td><img src="<%= IDS_TRANSPARENT_GIF %>" width="<%= C_INT_MAIN_MARGIN %>" height="<%= C_INT_SUBHEAD_HEIGHT %>" border="0"></td>
				</tr>

				<!-- Insert a spacer image -->
				<tr>
					<td colspan=3><img src="<%=IDS_TRANSPARENT_GIF%>" width="15" height="<%= C_INT_MAIN_SPACING %>" border="0"></td>
				</tr>

				<!-- Set the margin width for the rest of the page -->
				<tr>
					<td rowspan="999"><img src="<%=IDS_TRANSPARENT_GIF%>" width="<%= C_INT_MAIN_MARGIN %>" height="1" border="0"></td>
					<td><img src="<%=IDS_TRANSPARENT_GIF%>"	width="100%" height="1" border="0"></td>
					<td rowspan="999"><img src="<%=IDS_TRANSPARENT_GIF%>" width="<%= C_INT_MAIN_MARGIN %>" height="1" border="0"></td>
				</tr>

				<!-- Show area displaying information about whose pages are displayed  -->
				<tr>
					<td class="<%= IDS_CSS_APPROVALASSISTANT_BACKGROUND1 %>">
						<table width="100%" border="0" cellspacing="<%= C_INT_THICK_BORDER %>" cellpadding="5">
							<tr class="<%= IDS_CSS_APPROVALASSISTANT_BACKGROUND3 %>">
								<td>
									<span class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>"><%= IDS_UI_LABEL_PAGESWAITINGFOR %></span>&nbsp;&nbsp;
									<span class="<%= IDS_CSS_APPROVALASSISTANT_NORMALTEXT1 %>"><% Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode( g_pASPPageManager.UserShortname ), g_pASPPageManager.CodePage ) %></span>
								</td>
							</tr>
						</table>
					</td>
				</tr>

				<!-- Insert a spacer image -->
				<tr>
					<td colspan=3><img src="<%=IDS_TRANSPARENT_GIF%>"
						width="15" height="<%= C_INT_MAIN_SPACING %>" border="0"></td>
				</tr>


				<!-- Show the Content area -->
				<tr>
					<td valign="top">
						<table width="100%" border="0" cellspacing="<%= C_INT_THICK_BORDER %>" cellpadding="5" >
							<tr>
								<td valign="top" >
									<table width="100%" border="0" cellspacing="0" cellpadding="5" >

				<%
									' this section of ASP code is responsible for performing
									' the requested operation on the posting (approve or decline)
									' and summarizing error information as required.

									' temporary pointer to the current posting being approved/
									' declined
									Dim pPosting

									' GUID of the posting that is currently being approved/
									' declined
									Dim strPostingGUID

									' the number of postings that were successful and failures
									' for approve/decline operation
									Dim nSuccess
									Dim nFail

									' a string representing the details of any error cases
									' that have occurred. The reason is the reason for the failure
									' as reported by the ROM.
									Dim strFailureDetails
									Dim strFailureReason

									nSuccess = 0
									nFail = 0

									' loop over all of the postings to be approved/declined. Check
									' each one for errors and attempt the approve operation, dumping
									' out error messages as required. Note that the value of each
									' of the form elements representing postings to be approved/
									' declined is the GUID of the posting.
									For Each strPostingGUID In g_pASPPageManager.FormReader.Form( IDS_FORM_ELEMENT_SELECTFORAPPROVEDECLINE )

										AutoSession.ClearLastError()
										strFailureDetails = ""
										strFailureReason = ""

										' try to retrieve the posting object
										Set pPosting = AutoSession.Searches.GetByGUID( strPostingGUID )

										If ( pPosting Is Nothing ) Then

											' cannot even retrieve posting based on the GUID. Track
											' the details of the failure as well as the count of
											' failures to this point
											nFail = nFail + 1
											strFailureDetails = "'" & Server.HTMLEncode( g_pASPPageManager.FormReader.Form(IDS_FORM_ELEMENT_PREFIX & strPostingGUID) ) & "' " & _
																g_pASPPageManager.ActionPresentTense & IDS_UI_ERROR_APPROVALASSISTANT_ACTIONFAILED
											strFailureReason = "'" & IDS_UI_ERROR_APPROVALASSISTANT_POSTINGNOTFOUND & "'"

										ElseIf ( g_pASPPageManager.HasNoRightsToApprove( pPosting ) ) Then

											' the page could not be approved because the user is
											' lacking rights to approve the operation
											nFail = nFail + 1
											strFailureDetails = "'" & Server.HTMLEncode( g_pASPPageManager.FormReader.Form(IDS_FORM_ELEMENT_PREFIX & strPostingGUID) ) & "'" & _
																g_pASPPageManager.ActionPresentTense & IDS_UI_ERROR_APPROVALASSISTANT_ACTIONFAILED
											strFailureReason = "'" & IDS_UI_ERROR_APPROVALASSISTANT_NORIGHTS & "'"

										Else

											' the initial checks passed, so try and approve or
											' decline the posting (based on the action parameter
											' passed in the form)
											Call g_pASPPageManager.PerformPostingActionSafe( pPosting )

											If AutoSession.LastError.ID <> 0 Then

												' the approve/decline of the posting failed, so flag
												' the error
												nFail = nFail + 1
												strFailureDetails = "'" & Server.HTMLEncode( g_pASPPageManager.FormReader.Form(IDS_FORM_ELEMENT_PREFIX & strPostingGUID) ) & "'" & g_pASPPageManager.ActionPresentTense & _
																	IDS_UI_ERROR_APPROVALASSISTANT_ACTIONFAILED
												strFailureReason = "'" & AutoSession.LastError.Description & "'"

											Else

												Call AutoSession.CommitAll()

												Call g_pASPPageManager.RegisterApprovedPosting( pPosting )
												nSuccess = nSuccess + 1

											End If  'if no error when approve happened

										End If  'else user can approve

										' if an error occurred, display the string to the user
										If ( strFailureDetails <> "" ) Then
					%>
											<!-- Show delete failure one at a time -->
											<tr valign="top">
												<td class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>"><%= strFailureDetails %></td>
												<td class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>"><%= strFailureReason %>
											</tr>
					<%
										End If  'if error occurred

									Next  'loop over all postings to be approved/declined

									' if everything went well, redirect back to previous ASP page
									If ( nFail = 0 ) Then

										Response.Clear
										Response.Redirect( g_pASPPageManager.URLRefreshPagesAfterAction )

									End If  'if no errors
					%>
									</table>
								</td>
							</tr>

							<!-- Insert a spacer image -->
							<tr>
								<td colspan=3><img src="<%=IDS_TRANSPARENT_GIF%>" width="15" height="<%= C_INT_MAIN_SPACING %>" border="0"></td>
							</tr>

							<!-- Show the separator for the Summary section -->
							<tr valign="middle">
								<td colspan="2">
									<table width=100% border=0 cellspacing=0 cellpadding=0>
										<tr class="<%= IDS_CSS_APPROVALASSISTANT_BACKGROUND2 %>">
											<td width="*"><hr></td>
											<td width="250" align="Center" valign="top" class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>">
												<nobr> <%= IDS_UI_LABEL_ACTIONSUMMARY & g_pASPPageManager.ActionPastTense %> </nobr>
											</td>
											<td width="*"><hr></td>
										</tr>
									</table>
								</td>
							</tr>

							<!-- Render delete resource summary -->
							<tr valign="top">
								<td class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>"><nobr><%= IDS_UI_LABEL_ACTIONSUMMARY_SUCCESS & g_pASPPageManager.ActionPastTense %> </nobr></td>
								<td class="<%= IDS_CSS_APPROVALASSISTANT_NORMALTEXT1 %>"><%= nSuccess %></td>
							</tr>
							<tr valign="top">
								<td class="<%= IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 %>"><nobr><%= IDS_UI_LABEL_ACTIONSUMMARY_FAILURE & g_pASPPageManager.ActionPastTense %> </nobr></td>
								<td class="<%= IDS_CSS_APPROVALASSISTANT_NORMALTEXT1 %>"><%= nFail %></td>
							</tr>

							<tr>
								<td colspan="2">&nbsp;</td>
							</tr>


						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>