'#Reference {A3B5C45B-F842-44fc-A5E5-50CED69BA86E}#2.0#0#C:\Program Files\Mindjet\MindManager 6\Mm5WebExport.dll#Mm5webexport 2.0 Type Library
'#Uses "GlobalUtilities.mmbas"

Option Explicit

Sub Main

    Dim addin As Mm5WebExportAddIn
    Dim webex As WebExport
    Dim aPage As Mm5WebExportLib.Page

    Set addin = WebExportHelper.WebExportAddIn
    Set webex = addin.ActiveWebExport

    Dim count As Long
    Dim i As Long
    Dim template As String
    Dim topicString As String
    Dim bodyString As String
    Dim TheUnit As Long
    Dim DoExport As Boolean
    Dim boxCounterTaskPlanning As Integer

    Dim oneIconsCollection As Icons
    Dim oneIcon As Icon
    Dim oneTopic As Topic
    Dim oneTask As Task

    On Error GoTo ReportError
    
    webex.Trace("Entering BoxTask.mmbas",2)

    template = webex.ReadFile("BoxTask.htm")

    Set oneTopic = webex.ActiveTopic
    Set oneTask = oneTopic.Task

    If    webex.GetParameter("Strings.Show.TaskPlanning") = False _
       Or DoExportTaskSection(oneTask) = False Then

       ' Don't export task info section
       bodyString = ""

    Else

       ' Determine duration unit
       TheUnit = oneTask.DurationUnit

       Select Case TheUnit
            Case 1
                webex.SetParameter("CustomParameter.DurationUnit", webex.GetParameter ("Strings.Hidden.TaskDurationUnitHours"))
                webex.SetParameter("CustomParameter.Duration", oneTask.GetDuration(mmDurationUnitHour))
            Case 2
                webex.SetParameter("CustomParameter.DurationUnit", webex.GetParameter ("Strings.Hidden.TaskDurationUnitDays"))
                webex.SetParameter("CustomParameter.Duration", oneTask.GetDuration(mmDurationUnitDay))
            Case 3
                webex.SetParameter("CustomParameter.DurationUnit", webex.GetParameter ("Strings.Hidden.TaskDurationUnitWeeks"))
                webex.SetParameter("CustomParameter.Duration", oneTask.GetDuration(mmDurationUnitWeek))
            Case 4
                webex.SetParameter("CustomParameter.DurationUnit", webex.GetParameter ("Strings.Hidden.TaskDurationUnitMonths"))
                webex.SetParameter("CustomParameter.Duration", oneTask.GetDuration(mmDurationUnitMonth))
            Case Else
                webex.SetParameter("CustomParameter.DurationUnit", "")
                webex.SetParameter("CustomParameter.Duration", webex.GetParameter ("Strings.Hidden.TaskNoDuration"))
        End Select

        ' Get parameters for HTML template processing
        If oneTask.Priority > 0 Then
            webex.SetParameter("CustomParameter.Priority", oneTask.Priority)
        Else
            webex.SetParameter("CustomParameter.Priority", webex.GetParameter("Strings.Hidden.TaskNoPriority"))
        End If
        If oneTask.StartDate <> 0 Then ' Skip value if set to default
            webex.SetParameter("CustomParameter.StartDate", DateValue(CStr(oneTask.StartDate)))
        Else
            webex.SetParameter("CustomParameter.StartDate", webex.GetParameter ("Strings.Hidden.TaskNoStartDate"))
        End If
        If oneTask.DueDate <> 0 Then ' Skip value if set to default
            webex.SetParameter("CustomParameter.DueDate", DateValue(CStr(oneTask.DueDate)))
        Else
            webex.SetParameter("CustomParameter.DueDate", webex.GetParameter ("Strings.Hidden.TaskNoDueDate"))
        End If
        If oneTask.Complete > 0 Then
            webex.SetParameter("CustomParameter.Completed", oneTask.Complete)
        Else
            webex.SetParameter("CustomParameter.Completed", "0")
        End If

        webex.SetParameter("CustomParameter.Resource", oneTask.Resources)

        ' Read our template
        topicString = template

        ' Process all commands and parameters
        ProcessString webex, topicString

        ' Our merged string to write back
        bodyString = topicString

        ' Increment box counter number
        boxCounterTaskPlanning = webex.GetParameter("CustomParameter.BoxCounterTaskPlanning")
        boxCounterTaskPlanning = boxCounterTaskPlanning + 1
        webex.SetParameter("CustomParameter.BoxCounterTaskPlanning", boxCounterTaskPlanning)

    End If

    ' Write out the result
    webex.PushString(bodyString)

    webex.Trace("Exiting Page_box_taskplanning.mmbas",2)

    Exit Sub
 
ReportError:
    ProcessError(webex)
    Exit Sub
 
End Sub

Function DoExportTaskSection (oneTask As Task)

    DoExportTaskSection  = False

    ' Allow task to have priority and percentage complete info
    ' defined without exporting the task planning section

    'If oneTask.Priority <> "" Then
    '   Exit Function
    'End If
    'If oneTask.Complete <> "" Then
    '   DoExportTaskSection = True
    'End If
    If oneTask.DurationInHours <> 0 Then
        DoExportTaskSection = True
    End If
    If oneTask.Resources <> "" Then
        DoExportTaskSection = True
    End If
    If oneTask.DueDate <> 0 Then
        DoExportTaskSection = True
    End If
    If oneTask.StartDate <> 0 Then
        DoExportTaskSection = True
    End If

End Function
