'
' Example script for 2BrightSparks SyncBackPro that stops a profile
' from being run more than once per day. If its a simulated run,
' or a restore, then it can be run regardless.
'
' SBLang=Basic
'
' http://www.2BrightSparks.com/
'

'
' This is a configuration script and runtime script 
'
Function Description(ByRef ScriptType)
  Description = "Run at most once per day"
  ScriptType = SCRIPTTYPE_RUN + SCRIPTTYPE_CONFIG
End Function

'
' We use the LastRunDT value from the profiles settings. It contains
' the last run date and time of the profile. If it has already been
' run today then we stop the profile running, and no log is created.
'
Function RunDisabledCheck(NoLog)
  ' Get the current date now just in case it changes while
  ' the string is being built
  RightNow = Date

  ' Create a string that has the current date in the
  ' format of YYYYMMDD
  NowDate = CStr(Year(RightNow))

  If Month(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Month(RightNow))
  Else
    NowDate = NowDate & CStr(Month(RightNow))
  End If

  If Day(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Day(RightNow))
  Else
    NowDate = NowDate & CStr(Day(RightNow))
  End If

  ' Get the date & time when this profile was
  ' last run. We are only interested in the date.
  LastRun = Left(SBVariables.GetProperty("LastRunDT", "00000000", TRUE), 8)

  ' Check to see if the profile has run
  If not SBRunning.Restore and not SBRunning.Simulated and LastRun = NowDate then
    RunDisabledCheck = "The profile has already been run on " & CStr(RightNow)
    NoLog = TRUE
  Else
    RunDisabledCheck = ""
    NoLog = FALSE
  End If
End Function

'
' Configuration part of the script
'

' Not for group profiles, and only display setup page if the profile
' is using the script.
Function ConfigWantSetupNode(IsGroup)
  ConfigWantSetupNode = not IsGroup and SBProfile.UsesScript
End Function

' Not supported
Sub ConfigFactoryDefaults
End Sub

' Not supported
Function ConfigCanRevert
  ConfigCanRevert = FALSE
End Function

' Always allow the setup page to close
Function ConfigCanClose
  ConfigCanClose = TRUE
End Function

' Setup node caption
Function ConfigNodeCaption
  ConfigNodeCaption = "Once Per Day"
End Function

' Create setup window display
Sub ConfigSetupDisplay
  ' Get the current date now just in case it changes while
  ' the string is being built
  RightNow = Date

  ' Create a string that has the current date in the
  ' format of YYYYMMDD
  NowDate = CStr(Year(RightNow))

  If Month(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Month(RightNow))
  Else
    NowDate = NowDate & CStr(Month(RightNow))
  End If

  If Day(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Day(RightNow))
  Else
    NowDate = NowDate & CStr(Day(RightNow))
  End If

  ' Get the date & time when this profile was
  ' last run. We are only interested in the date.
  LastRun = Left(SBVariables.GetProperty("LastRunDT", "00000000", TRUE), 8)

  ' Check to see if the profile has run
  If LastRun = NowDate then
    SBProfile.AddLabel("The profile has already been run today.", 1)
  Else
    SBProfile.AddLabel("The profile has not been run today.", 1)
  End If
End Sub

' Load settings. Return error message on failure.
Function ConfigLoadSettings
  ConfigLoadSettings = ""
End Function

' Save settings. Return error message on failure.
Function ConfigSaveSettings(Silent)
  ConfigSaveSettings = ""
End Function

' The settings have changed
Sub ConfigUpdateConditionals
End Sub
