home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / CHIPCD_3_98.iso / software / testsoft / exchange / webdata / usa / lib / pageutil.inc < prev    next >
Text File  |  1997-08-25  |  12KB  |  434 lines

  1. <%
  2. '!--Microsoft Outlook Web Access-->
  3. '!--pageutil.inc - functions that help with page processing -->
  4. '!--Copyright (c) Microsoft Corporation 1993-1997. All rights reserved.-->
  5.  
  6.  
  7. Sub DeleteItem(obj)
  8.     Dim objMoveObj
  9.     Dim bIsAuthenticated
  10.     Dim strDeletedItemsID
  11.     Dim strPublicStoreID
  12.     
  13.     If (Not obj Is Nothing) Then
  14.  
  15.         bIsAuthenticated = Session(bstrAuthenticated)
  16.  
  17.         'Check to make sure user is authenticated. If not authenticated then delete the object.
  18.         If bIsAuthenticated then
  19.             'Get the deleted items entry id from the session.
  20.             strDeletedItemsID = Session(bstrDeletedItemsID)
  21.             strPublicStoreID = Session(bstrPublicStoreEntryID)
  22.             
  23.             'If the object is not in the public store or in the Deleted items folder then 
  24.             'the object is moved to the deleted items folder.
  25.             If obj.StoreID <> strPublicStoreID and obj.FolderID <> strDeletedItemsID then
  26.                 Set objMoveObj = obj.MoveTo(strDeletedItemsID)
  27.                 If (Err.Number <> 0) Or (objMoveObj Is Nothing) Then
  28.                     ReportError1 L_errFailDeleteMessage_ErrorMessage
  29.     
  30.                 Else
  31.                     Set objMoveObj = Nothing
  32.                 End If
  33.             Else
  34.                 'The object is deleted if it is already in the deleted items folder
  35.                 obj.Delete
  36.                 If (Err.Number <> 0) Then
  37.                     ReportError1 L_errFailDeleteMessage_ErrorMessage
  38.                 End If
  39.             End If
  40.         Else
  41.             obj.Delete
  42.             If (Err.Number <> 0) Then
  43.                 ReportError1 L_errFailDeleteMessage_ErrorMessage
  44.             End If
  45.         End If
  46.  
  47.     End If
  48.     
  49.     Set obj = Nothing
  50. End Sub
  51.  
  52. '=======================
  53. ' DeleteItemByID
  54. '
  55. ' szObj - EntryID for Object
  56. ' bIsFolder - Default is false.  If it is a folder then pass in True.
  57. ' Deletes items in private or public store. Items are actually moved to deleted items
  58. ' folder if they are in the private store.
  59. ' Dependencies: The session objects must be instantiated before calling this sub.
  60. '=======================
  61.  
  62. Sub DeleteItemByID(szObj, bIsFolder)
  63.     Dim obj
  64.     
  65.     If bIsFolder then
  66.         Set obj = OpenFolder(szObj)
  67.     Else
  68.         Set obj = OpenMessage(szObj)
  69.     End If
  70.  
  71.     If (obj Is Nothing) Then
  72.         ReportError1 L_errFailDeleteAccess_ErrorMessage
  73.     Else
  74.         DeleteItem obj
  75.     End If
  76.  
  77. End Sub
  78.  
  79. '=======================
  80. ' DeleteItems
  81. '
  82. ' Delete list of items
  83. '=======================
  84.  
  85. Public Sub DeleteItems
  86.  
  87.     For Each szElement In Request.Form
  88.         If IsNumeric(szElement) Then
  89.             szEntryID = Request.Form(szElement)
  90.  
  91.             Set objMessage = OpenMessage(szEntryID)
  92.         If (objMessage Is Nothing) Then
  93.                 ReportError1 L_errFailDeleteAccess_ErrorMessage
  94.             Else
  95.                 DeleteItem objMessage
  96.                 Set objMessage = Nothing
  97.             End If
  98.         End If
  99.     Next
  100.  
  101. End Sub
  102.  
  103. '=======================
  104. ' CheckIndex
  105. '
  106. ' Check index returned and assign to session
  107. '=======================
  108.  
  109. Public Sub CheckIndex
  110.  
  111.     strIndex = Request.QueryString("index")
  112.     If Len(strIndex) > 0 Then
  113.         iIndex = CInt(strIndex)
  114.         Session(CURRENT_INDEX) = iIndex
  115.     End If
  116.  
  117. End Sub
  118.  
  119. '=======================
  120. ' CheckPage
  121. '
  122. ' Check state returned and assign to session
  123. '=======================
  124.  
  125. Public Sub CheckPage(objRenderer)
  126.     On Error Resume Next
  127.  
  128.     If (Not objRenderer Is Nothing) Then
  129.  
  130.         iCurrentView = CInt(Request.QueryString("view"))
  131.         If iCurrentView > 0 Then
  132.             ' set up the view
  133.             objRenderer.CurrentView = iCurrentView
  134.  
  135.             ' set up page count
  136.             Set objMessages = Session(CURRENT_CONTENTS)
  137.             cMessages = objMessages.Count
  138.             If cMessages < 1 Then
  139.                 cPages = 1
  140.             Else
  141.                 cRows = Session(CURRENT_ROWS)
  142.                 cPages = (cMessages - 1) \ cRows
  143.                 cPages = cPages + 1
  144.             End If
  145.  
  146.             Session(CURRENT_COUNT) = cMessages
  147.             Session(CURRENT_INDEX) = 1
  148.             Session(CURRENT_PAGES) = cPages
  149.             Session(CURRENT_VIEW) = iCurrentView
  150.         End If
  151.  
  152.         iPage = CInt(Request.QueryString("page"))
  153.         If iPage > 0 Then
  154.             cPages = Session(CURRENT_PAGES)
  155.             If iPage > cPages Then
  156.                 Session(CURRENT_PAGE) = cPages
  157.             Else
  158.                 Session(CURRENT_PAGE) = iPage
  159.             End If
  160.         End If
  161.     End If 'objRender <> nothing
  162. End Sub
  163.  
  164. '=======================
  165. ' InitPage
  166. '
  167. ' Initialise page state - parses URL
  168. '=======================
  169. Public Sub InitPage(nType)
  170.     On Error Resume Next
  171.  
  172.     If Not Session(bstrAuthenticated) Then 
  173.         nType = PUBLIC_ANONYMOUS
  174.     End If
  175.  
  176.     ' set up the folder object
  177.     szObj = Request.QueryString("obj")
  178.     If nType = PRIVATE_AUTHENTICATED Then
  179.         OpenPrivateStore
  180.  
  181.         If szObj = "" Then
  182.             Set objFolder = objOMSession.Inbox
  183.             If (objFolder Is Nothing) Then
  184.                 ReportError1 L_errFailedToGetInbox_ErrorMessage
  185.             End If
  186.  
  187.             szObj = objFolder.ID
  188.         Else    
  189.             Set objFolder = OpenFolder(szObj)
  190.         End If
  191.         
  192.         If (objFolder Is Nothing) Then
  193.             ReportError1 L_errFailedToGetInbox_ErrorMessage
  194.         End If
  195.  
  196.     ElseIf nType = PUBLIC_AUTHENTICATED Then
  197.         OpenPublicStore
  198.  
  199.         If szObj = "" Then
  200.             szObj = Session(bstrPublicStoreRootID)
  201.         End If
  202.         Set objFolder = OpenFolder(szObj)
  203.  
  204.         If (objFolder Is Nothing) Then
  205.             ReportError1 L_errFailGetPubFolder_ErrorMessage
  206.         End If
  207.  
  208.     ElseIf nType = PUBLIC_ANONYMOUS Then
  209.         OpenPublicStore
  210.         
  211.         If szObj = "" Then
  212.             Set objFolder = Nothing
  213.         Else
  214.             Set objFolder = OpenFolder(szObj)
  215.         End If
  216.  
  217.     End If
  218.  
  219.     'set up the messages renderer
  220.     If nType = PUBLIC_ANONYMOUS And objFolder Is Nothing Then
  221.         ' We're rendering the hierarchy for the anonymous root.
  222.  
  223.         ' set up the hierarchy renderer
  224.         Set objHRenderer = GetPublicHierarchyRenderer(fNew)
  225.  
  226.         ' This is not a real folder, but a list of folder IDs defined
  227.         ' by the administrator and stored with our DS config information.
  228.         Set objApplication = Application( bstrRenderApp )
  229.         aPubFolders = objApplication.ConfigParameter("Published Public Folders")
  230.  
  231.         If Not IsEmpty(aPubFolders) Then
  232.             i = UBound(aPubFolders)
  233.             If i >= LBound(aPubFolders) Then
  234.                 ReDim Preserve aPubFolders(i+2)
  235.  
  236.                 ' To the list of folders, add two things:
  237.                 '    ...a name for the pseudo-folder we're making up
  238.                 aPubFolders(i+1) = L_PublicFolders_Text
  239.  
  240.                 '    ...and a store interface so the renderer can get stuff from the folders
  241.                 Set aPubFolders(i+2) = Session(bstrObjPublicStore)
  242.  
  243.                 ' Now give it to the renderer
  244.                 Err.Clear
  245.                 objHRenderer.DataSource = aPubFolders
  246.                 If (Err.Number <> 0) Then
  247.                     ReportError1 L_errFailGetAnonPubFolders_ErrorMessage
  248.                 End If
  249.             End If
  250.         End If
  251.  
  252.  
  253.         Set Session(CURRENT_FOLDER) = Nothing
  254.         Set Session(CURRENT_CONTENTS) = Nothing
  255.         Set Session(CURRENT_HIERARCHY) = Nothing
  256.         SetPageDefaults
  257.     Else
  258.         Set objCRenderer = GetMessagesRenderer(fNew)
  259.         Set objCur = objCRenderer.DataSource
  260.         If objCur Is Nothing Then
  261.             Err.Clear
  262.  
  263.             Set objMessages = objFolder.Messages
  264.  
  265.             ' Traps the case where the folder is there but either not yet
  266.             ' replicated or the folders server is down.
  267.             If objMessages Is Nothing Then
  268.                 Exit Sub 'let caller handle err.number
  269.             Else
  270.                 objCRenderer.DataSource = objMessages
  271.                 ApplyCheckBoxColumn(objCRenderer)
  272.             End If
  273.         Else
  274.             If Not objFolder.IsSameAs(objCur.Parent) Then
  275.                 Err.Clear
  276.  
  277.                 Set objMessages = objFolder.Messages
  278.  
  279.                 ' Traps the case where the folder is there but either not yet
  280.                 ' replicated or the folders server is down.
  281.                 If objMessages Is Nothing Then 
  282.                     Exit Sub 'let caller handle err.number
  283.                 Else
  284.                     objCRenderer.DataSource = objMessages
  285.                     ApplyCheckBoxColumn(objCRenderer)
  286.                 End If
  287.             Else
  288.                 Set objMessages = objCur
  289.             End If
  290.         End If
  291.  
  292.         If (Err.Number <> 0) Then
  293.             ReportError1 L_errInternalErrorRendObj_ErrorMessage
  294.         End If
  295.  
  296.         ' set up the view
  297.         iCurrentView = CInt(Request.QueryString("view"))
  298.         If iCurrentView > 0 Then
  299.             objCRenderer.CurrentView = iCurrentView
  300.         Else
  301.             iCurrentView = objCRenderer.CurrentView.Index
  302.         End If
  303.  
  304.         ' set up the rows per page
  305.         cRows = CInt(Request.QueryString("rows"))
  306.         If cRows < 1 Then
  307.             cRows = iDefaultNumRows
  308.         End If
  309.         objCRenderer.RowsPerPage = cRows
  310.  
  311.         ' set up page count
  312.         If objMessages Is Nothing Then
  313.             cMessages = 0
  314.         Else
  315.             cMessages = objMessages.Count
  316.         End If
  317.         
  318.         If cMessages < 1 Then
  319.             cPages = 1
  320.         Else
  321.             cPages = (cMessages - 1) \ cRows
  322.             cPages = cPages + 1
  323.         End If
  324.  
  325.         ' set up the hierarchy renderer
  326.         If nType > PRIVATE_AUTHENTICATED Then
  327.             Set objHRenderer = GetPublicHierarchyRenderer(fNew)
  328.         Else
  329.             Set objHRenderer = GetPrivateHierarchyRenderer(fNew)
  330.         End If
  331.  
  332.         Set objCur = objHRenderer.DataSource
  333.         If objCur Is Nothing Then
  334.             Err.Clear
  335.             Set objFolders = objFolder.Folders
  336.             objHRenderer.DataSource = objFolders
  337.         Else
  338.             If Not objFolder.IsSameAs(objCur.Parent) Then
  339.                 Err.Clear
  340.                 Set objFolders = objFolder.Folders
  341.                 objHRenderer.DataSource = objFolders
  342.             Else
  343.                 Set objFolders = objCur
  344.             End If
  345.         End If
  346.         If (Err.Number <> 0) Then
  347.             ReportError1 L_errInternalErrorDataSrc_ErrorMessage
  348.         End If
  349.  
  350.         iPage = CInt(Request.QueryString("page"))
  351.         If iPage < 1 Then
  352.             iPage = 1
  353.         End If
  354.  
  355.         Set Session(CURRENT_FOLDER) = objFolder
  356.         Set Session(CURRENT_CONTENTS) = objMessages
  357.         Set Session(CURRENT_HIERARCHY) = objFolders
  358.         Session(CURRENT_INDEX) = 1
  359.         Session(CURRENT_COUNT) = cMessages
  360.         Session(CURRENT_PAGES) = cPages
  361.         Session(CURRENT_ROWS) = cRows
  362.         Session(CURRENT_VIEW) = iCurrentView
  363.         Session(CURRENT_PAGE) = iPage
  364.     End If
  365. End Sub
  366.  
  367. '=======================
  368. ' IsSpecialFolder
  369. '
  370. ' checks for special folders
  371. '=======================
  372. Public Function IsSpecialFolder(szObj)
  373.     IsSpecialFolder = False
  374.  
  375.     Set objStore = Session(bstrObjPrivateStore)
  376.     If Not objStore Is Nothing Then
  377.         If (szObj = objOMSession.Inbox.ID) Or _
  378.             (szObj = objStore.Fields.Item(ActMsgPR_IPM_OUTBOX_ENTRYID).Value) Or _
  379.             (szObj = objStore.Fields.Item(ActMsgPR_IPM_WASTEBASKET_ENTRYID).Value) Or _
  380.             (szObj = objStore.Fields.Item(ActMsgPR_IPM_SENTMAIL_ENTRYID).Value) Or _
  381.             (szObj = objStore.Fields.Item(ActMsgPR_IPM_SUBTREE_ENTRYID).Value) Then
  382.             IsSpecialFolder = True
  383.          End If
  384.     End If
  385. End Function
  386.  
  387. '=======================
  388. ' FolderAction
  389. '
  390. ' Execute requested folder action
  391. ' Returns TRUE if action was delete
  392. '=======================
  393. Public Function FolderAction(objFolder)
  394.     On Error Resume Next
  395.  
  396.     FolderAction = 0
  397.  
  398.     ' deal with any special actions
  399.     Action = Request.QueryString("action")
  400.     If (Err.Number <> 0) Then
  401.         ReportErrorLoad L_errGeneralErr_ErrorMessage, bstrVirtRoot + "/root.asp?obj=" + objFolder.ID
  402.     End If
  403.  
  404.     If Action="newFolder" Then
  405.         Set objFolders = Session(CURRENT_HIERARCHY)
  406.         Set objNewFolder = objFolders.Add(Request.QueryString("folderName"))
  407.         FolderAction = Err.Number 'let the caller handle this
  408.   
  409.     ElseIf Action="deleteFolder" Then
  410.         OpenAllStores        
  411.         If IsSpecialFolder(objFolder.ID) Then 
  412.             ReportErrorLoad L_errFailDeleteFolder_ErrorMessage, bstrVirtRoot + "/root.asp?obj=" + objFolder.ID
  413.         End If
  414.  
  415.         DeleteItem objFolder
  416.         If (Err.Number <> 0) Then
  417.             ReportErrorLoad L_errFailDeleteFolder_ErrorMessage, bstrVirtRoot + "/root.asp?obj=" + objFolder.ID
  418.         End If
  419.         
  420.         FolderAction = -1
  421.     End If
  422. End Function
  423.  
  424. Public Sub EmptyDeletedItemsFldr 
  425.         If (Session(bstrAuthenticated)) Then
  426.             objOMSession.getDefaultFolder(ActMsgDefaultFolderDeletedItems).Messages.Delete
  427.             objOMSession.getDefaultFolder(ActMsgDefaultFolderDeletedItems).Folders.Delete
  428.         Else
  429.             ReportError1 L_errFailDeleteMessage_ErrorMessage
  430.         End If
  431. End Sub
  432.  
  433.  
  434. %>