[Global]
#eParCtlEx_SeverityCritical	= 1
#eParCtlEx_SeverityWarning	= 2
#eParCtlEx_SeverityInfo		= 3

#eParCtlEx_AccessBlocked    = 1
#eParCtlEx_AccessAllowed    = 2
#eParCtlEx_AccessTerminated = 3
#eParCtlEx_AccessNone       = 4

#eParCtlEx_DirectionInbound  = 1
#eParCtlEx_DirectionOutbound = 2

#eParCtlEx_IM_ReasonNone                      = 0
#eParCtlEx_IM_ReasonContactInWhiteList        = 1
#eParCtlEx_IM_ReasonContactInBlackList        = 2
#eParCtlEx_IM_ReasonUnknownContactAllowed     = 3
#eParCtlEx_IM_ReasonUnknownContactSuppressed  = 4
#eParCtlEx_IM_ReasonPersonalInfoSending       = 5

#eIMProtocolHTTP   = 1
#eIMProtocolSMTP   = 2
#eIMProtocolICQ    = 3
#eIMProtocolMSN    = 4
#eIMProtocolP2P    = 5
#eIMProtocolJBR    = 6
#eIMProtocolIRC    = 7
#eIMProtocolMMP    = 8
#eIMProtocolYahoo  = 9
#eIMProtocolGG     = 10

$ParCtlEx_IM_IsPersInfo_Icon = "ParCtlExAll16,17"
$ParCtlEx_IM_IsKeywords_Icon = "ParCtlExAll16,18"

#eParCtlEx_CC_WorkAllowed            = 0
#eParCtlEx_CC_TimeLimitIsOver        = 1
#eParCtlEx_CC_ScheduleTimeIsViolated = 2
#eParCtlEx_CC_ControlIsTurnedOff     = 3
#eParCtlEx_CC_ControlIsTurnedOn      = 4

#eParCtlEx_AU_ReasonAppInWhiteList        = 1
#eParCtlEx_AU_ReasonAppInBlackList        = 2
#eParCtlEx_AU_ReasonUnknownApp            = 3
#eParCtlEx_AU_ReasonDayLimitExhausted     = 4
#eParCtlEx_AU_ReasonTimePeriodRestriction = 5
#eParCtlEx_AU_ReasonControlTurnedOn       = 6
#eParCtlEx_AU_ReasonControlTurnedOff      = 7

#eParCtlEx_IU_ReasonAllowed					= 1
#eParCtlEx_IU_ReasonTimeLimit				= 2
#eParCtlEx_IU_ReasonTimeSpace				= 3
#eParCtlEx_IU_ReasonNotControlled			= 4
#eParCtlEx_IU_ReasonShutdown				= 5

#eParCtlEx_IWC_ReasonUndefined      = 0
#eParCtlEx_IWC_ReasonWhiteList	    = 1
#eParCtlEx_IWC_ReasonBlackList	    = 2
#eParCtlEx_IWC_ReasonUncontrolled	= 3
#eParCtlEx_IWC_ReasonCategoryDeny	= 4
#eParCtlEx_IWC_ReasonCategoryAllow  = 5

#eParCtlEx_IWC_CategoryPorno        = 0x0001
#eParCtlEx_IWC_CategorySoftware	    = 0x0002
#eParCtlEx_IWC_CategoryDrugs		= 0x0004
#eParCtlEx_IWC_CategoryViolence	    = 0x0008
#eParCtlEx_IWC_CategoryUncens		= 0x0010
#eParCtlEx_IWC_CategoryWeapons	    = 0x0020
#eParCtlEx_IWC_CategoryGambling	    = 0x0040
#eParCtlEx_IWC_CategoryChat		    = 0x0080
#eParCtlEx_IWC_CategoryWebMail	    = 0x0100
#eParCtlEx_IWC_CategoryShops		= 0x0200
#eParCtlEx_IWC_CategorySocialNets	= 0x0400
#eParCtlEx_IWC_CategoryProxy		= 0x1000
#eParCtlEx_IWC_CategoryCreditCards  = 0x2000
#eParCtlEx_IWC_CategoryCasualGames  = 0x4000

#eParCtlEx_FDC_ReasonDenyByFileType	= 1

#eParCtlEx_SN_ReasonNone                      = 0
#eParCtlEx_SN_ReasonContactInWhiteList        = 1
#eParCtlEx_SN_ReasonContactInBlackList        = 2
#eParCtlEx_SN_ReasonUnknownContactAllowed     = 3
#eParCtlEx_SN_ReasonUnknownContactSuppressed  = 4
#eParCtlEx_SN_ReasonPersonalInfoSending       = 5

$ParCtl_IsCurUserEnabled = (users.find("UserId == " + toExpr(CurrentUserSID)).settings.Enabled)

[f_OpenWindowChecked]
section,id,page
ret = if(ctl.root.ctlFind(section),window(section+page),if(checkPassword(id),window(section+page)))

[s_ParCtlEx_SeverityIcon]
#eParCtlEx_SeverityCritical	= s_Ico(#ICO_CRIT_14)
#eParCtlEx_SeverityWarning	= s_Ico(#ICO_WARN_14)
def = s_Ico(#ICO_INFO_14)

[f_ParCtlEx_Events_PeriodFilter]
p_PeriodBegin, p_PeriodEnd
ret = if(p_PeriodBegin, "DateTime >= " + p_PeriodBegin + " && DateTime < " + p_PeriodEnd)

[f_ParCtlEx_EventsTimeRange_PeriodFilter]
p_PeriodBegin, p_PeriodEnd
ret = if(p_PeriodBegin, "(StopTime == 0xFFFFFFFF && DateTime < " + p_PeriodEnd + ") || (min(StopTime, " + p_PeriodEnd + ") - max(DateTime, " + p_PeriodBegin + ") >= 0)")

[s_ParCtlEx_Events_SeverityFilter]
Critical = "Severity <= " + #eParCtlEx_SeverityCritical
Warning  = "Severity <= " + #eParCtlEx_SeverityWarning
def      = ""

[s_ParCtlUserReport_SeverityFilter_Icon]
Critical = "ParCtlExAll16,9"
Warning	 = "ParCtlExAll16,8"
def      = "ParCtlExAll16,6"

[s_ParCtlEx_ComponentEnabled_Icon]
1   = "BulletOn"
def = "BulletOff"

[f_ParCtlEx_GetUserAvatar]
p_UserId
ret = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.strAvatarId

[f_ParCtlEx_IsUserAliasDuplicate]
p_UserId, p_Alias
ret = ParCtl.users.find("settings.strAlias=="+toExpr(p_Alias)+" && UserId!="+toExpr(p_UserId))

[s_ParCtlEx_UserAvatarId2Image]
Mother      = "ParCtlEx_Avatars,1"
SonMajor    = "ParCtlEx_Avatars,2"
DotherMajor = "ParCtlEx_Avatars,3"
SonMinor    = "ParCtlEx_Avatars,4"
DotherMinor = "ParCtlEx_Avatars,5"
def         = "ParCtlEx_Avatars,0"

[f_ParCtlEx_GetTimeUsage]
p_StopTime, p_DateTime
ret = var tmStop; tmStop = (p_StopTime != 0xFFFFFFFF ? p_StopTime : utctime()); if(tmStop >= p_DateTime, tmStop - p_DateTime, 0)

[f_ParCtlEx_Events_PeriodFilter]
p_TimeBegin, p_TimeEnd, p_IsTimeRange
ret = if(p_IsTimeRange, "", "")

[f_ParCtlEx_GetStatRangePeriod]
p_PeriodType
ret = s_ParCtlEx_ConvertRangePeriod( p_PeriodType )

[s_ParCtlEx_ConvertRangePeriod]
#ePeriodYear      = #eStatPeriodMonth
#ePeriodMonth     = #eStatPeriodDay
#ePeriodWeek      = #eStatPeriodDay
#ePeriodDay       = #eStatPeriodHour
def               = #eStatPeriodMonth

;[f_ParCtlEx_GetStatRangePeriod]
;p_TimeBegin, p_TimeEnd, &p_nChartPeriod
;ret = var tmDiff; var nPeriodDescritization; \
;	tmDiff = p_TimeEnd - p_TimeBegin; \
;	if(tmDiff <= 60*60*24, \
;		(p_nChartPeriod = "Day"; nPeriodDescritization = #eStatPeriodHour), \
;		if(tmDiff <= 60*60*24*7, \
;			(p_nChartPeriod = "Week"; nPeriodDescritization = #eStatPeriodDay), \
;			if(tmDiff <= 60*60*24*31, \
;				(p_nChartPeriod = "Month"; nPeriodDescritization = #eStatPeriodDay), \
;				(p_nChartPeriod = "Year"; nPeriodDescritization = #eStatPeriodMonth) \
;			) \
;		) \
;	); \
;	nPeriodDescritization

;------------- ParCtlUserReport.MessagingIM -----------------

[s_ParCtlUserReport_IM_ContactId_Icon]
#eParCtlEx_IM_ReasonContactInWhiteList = "ParCtlExAll16,14"
#eParCtlEx_IM_ReasonContactInBlackList = "ParCtlExAll16,16"
def                                    = "ParCtlExAll16,15"

[f_ParCtlEx_GetIMContactGroup]
p_UserId, p_ContactId
ret = var pSett; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.IMControl; if(pSett.WhiteList.find("Id == " + toExpr(p_ContactId)), #eParCtlEx_IM_ReasonContactInWhiteList, if(pSett.BlackList.find("Id == " + toExpr(p_ContactId)), #eParCtlEx_IM_ReasonContactInBlackList, 0))

[f_ParCtlEx_SetIMContactGroup]
p_UserId, p_ContactId, p_GroupId
ret = if(s_ParCtlEx_SetIMContactGroup(p_GroupId, p_ContactId, ParCtl.users.ser().findSettingsUserAccount(p_UserId, true).settings.IMControl), ParCtl.name.ser().setProfileSettingsDirty())

[s_ParCtlEx_SetIMContactGroup]
#eParCtlEx_IM_ReasonContactInWhiteList = @2.BlackList.find("Id == " + toExpr(@1), #vRemove); @2.WhiteList.find("Id == " + toExpr(@1), #vAdd, "Id = " + toExpr(@1) + "; AddTime = utctime()")
#eParCtlEx_IM_ReasonContactInBlackList = @2.WhiteList.find("Id == " + toExpr(@1), #vRemove); @2.BlackList.find("Id == " + toExpr(@1), #vAdd, "Id = " + toExpr(@1) + "; AddTime = utctime()")
def                                    = @2.WhiteList.find("Id == " + toExpr(@1), #vRemove); @2.BlackList.find("Id == " + toExpr(@1), #vRemove)

[f_ParCtlEx_GetIMContactName]
p_UserId, p_ContactId
ret = var strAlias; strAlias = f_ParCtlEx_GetIMContactAlias_(p_UserId, p_ContactId); strAlias ? strAlias : p_ContactId

[f_ParCtlEx_GetIMContactAlias_]
p_UserId, p_ContactId
ret = var pSett; var pListItem; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.IMControl.Contacts; if(pListItem = pSett.find("Id == " + toExpr(p_ContactId)), pListItem.Name, NULL)

[f_ParCtlEx_MessagingIM_Stat_TopN_PercentSum]
p_contacts, p_num, p_count
ret = var nSum; \
	if(p_num >= 1, nSum = nSum + p_contacts.at(0).MsgCount*100/p_count); \
	if(p_num >= 2, nSum = nSum + p_contacts.at(1).MsgCount*100/p_count); \
	if(p_num >= 3, nSum = nSum + p_contacts.at(2).MsgCount*100/p_count); \
	if(p_num >= 4, nSum = nSum + p_contacts.at(3).MsgCount*100/p_count); \
	nSum
	
[f_ParCtlEx_MessagingIM_Stat_TopN_Percent]
p_count, p_contacts, p_num
ret = if(p_contacts.size() > p_num, p_contacts.at(p_num - 1).MsgCount*100/p_count, 100 - f_ParCtlEx_MessagingIM_Stat_TopN_PercentSum(p_contacts, p_num - 1, p_count))

;------------------- ParCtlRepSettMainWindow.SNControl ----------;

[f_ParCtlEx_GetSNContactName]
p_ContactId, p_ContactAlias
ret = var tmpAlias; tmpAlias = SNControl.Contacts.find("Id=="+toExpr(p_ContactId)).Name; if(tmpAlias, tmpAlias, if (p_ContactAlias, p_ContactAlias, p_ContactId) )

;------------------- ParCtlUserReport.ApplicationUsage ----------

[f_ParCtlEx_GetAUAppGroup]
p_UserId, p_AppID
ret = var pSett; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.AppControl; if(pSett.WhiteList.find("AppID == " + toExpr(p_AppID)), #eParCtlEx_AU_ReasonAppInWhiteList, if(pSett.BlackList.find("AppID == " + toExpr(p_AppID)), #eParCtlEx_AU_ReasonAppInBlackList, 0))

[f_ParCtlEx_SetAUAppGroup]
p_UserId, p_AppID, p_GroupId
ret = if(s_ParCtlEx_SetAUAppGroup(p_GroupId, p_AppID, ParCtl.users.ser().findSettingsUserAccount(p_UserId, true).settings.AppControl), ParCtl.name.ser().setProfileSettingsDirty())

[s_ParCtlEx_SetAUAppGroup]
#eParCtlEx_AU_ReasonAppInWhiteList = var AppName; AppName = @2.BlackList.find("AppID == " + @1).AppAlias; \
	if(!dialog("AppControl_EditWhite", p_new(true), p_data(@2.WhiteList.find("AppID == " + @1, #vAdd, "AppID = " + @1 + "; AppHash = filehash(f_AppInfo(" + @1 + ").sImagePath); AppAlias = " + toExpr(AppName) + "; AddTime = utctime()"))), \
		@2.WhiteList.find("AppID == " + @1, #vRemove), 	(@2.BlackList.find("AppID == " + @1, #vRemove); true))
#eParCtlEx_AU_ReasonAppInBlackList = var AppName; AppName = @2.WhiteList.find("AppID == " + @1).AppAlias; \
	if(AppName, (@2.BlackList.find("AppID == " + @1, #vAdd, "AppID = " + @1 + "; AppHash = filehash(f_AppInfo(" + @1 + ").sImagePath); AppAlias = " + toExpr(AppName) + "; AddTime = utctime()"); @2.WhiteList.find("AppID == " + @1, #vRemove); true), \
		if(!dialog("AppControl_EditBlack", p_new(true), p_data(@2.BlackList.find("AppID == " + @1, #vAdd, "AppID = " + @1 + "; AppHash = filehash(f_AppInfo(" + @1 + ").sImagePath); AddTime = utctime()"))), @2.BlackList.find("AppID == " + @1, #vRemove), \
			(@2.WhiteList.find("AppID == " + @1, #vRemove); true)))
def                                = @2.WhiteList.find("AppID == " + @1, #vRemove); @2.BlackList.find("AppID == " + @1, #vRemove)

[f_ParCtlEx_GetAUAppName]
p_UserId, p_AppID
ret = var strAlias; strAlias = f_ParCtlEx_GetAUAppAlias_(p_UserId, p_AppID); strAlias ? strAlias : s_AppName(p_AppID)

[f_ParCtlEx_GetAUAppAlias_]
p_UserId, p_AppID
ret = var pSett; var pWListItem; var pBListItem; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.AppControl; if(pWListItem = pSett.WhiteList.find("AppID == " + toExpr(p_AppID)), pWListItem.AppAlias, if(pBListItem = pSett.BlackList.find("AppID == " + toExpr(p_AppID)), pBListItem.AppAlias, NULL))

;------------- ParCtlUserReport.InternetWebContent -----------------

[f_ParCtlEx_IWC_Category_Mask]
p_CategoryMask, p_Capitalize, p_Str__
ret = \
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryPorno,       p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategorySoftware,    p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryDrugs,       p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryViolence,    p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryUncens,      p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryWeapons,     p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryGambling,    p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryChat,        p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryWebMail,     p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryShops,       p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategorySocialNets,  p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryProxy,       p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryCreditCards, p_Capitalize,	p_Str__);\
	f_ParCtlEx_IWC_Category(p_CategoryMask, #eParCtlEx_IWC_CategoryCasualGames, p_Capitalize,	p_Str__);\
	p_Str__

[f_ParCtlEx_IWC_Category]
p_CategoryMask, p_CategoryId, p_Capitalize, &p_Str
ret = p_Str = p_Str + if(p_CategoryMask & p_CategoryId, if(p_Str, ", ") + capitalize(s_ParCtlEx_IWC_Category(p_CategoryId), p_Capitalize && !p_Str)); NULL

[f_ParCtlEx_GetIWCDomainGroup]
p_UserId, p_Domain
ret = var pSett; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.WebControl; if(pSett.WhiteList.find("Name == " + toExpr(p_Domain)), #eParCtlEx_IWC_ReasonWhiteList, if(pSett.BlackList.find("Name == " + toExpr(p_Domain)), #eParCtlEx_IWC_ReasonBlackList, 0))

[f_ParCtlEx_SetIWCDomainGroup]
p_UserId, p_Domain, p_GroupId
ret = if(s_ParCtlEx_SetIWCDomainGroup(p_GroupId, p_Domain, ParCtl.users.ser().findSettingsUserAccount(p_UserId, true).settings.WebControl), ParCtl.name.ser().setProfileSettingsDirty())

[s_ParCtlEx_SetIWCDomainGroup]
#eParCtlEx_IWC_ReasonWhiteList = @2.BlackList.find("Name == " + toExpr(@1), #vRemove); @2.WhiteList.find("Name == " + toExpr(@1), #vAdd, "Name = " + toExpr(@1) + "; Timestamp = utctime()")
#eParCtlEx_IWC_ReasonBlackList = @2.WhiteList.find("Name == " + toExpr(@1), #vRemove); @2.BlackList.find("Name == " + toExpr(@1), #vAdd, "Name = " + toExpr(@1) + "; Timestamp = utctime()")
def                            = @2.WhiteList.find("Name == " + toExpr(@1), #vRemove); @2.BlackList.find("Name == " + toExpr(@1), #vRemove)

[s_ParCtlEx_IWC_Category]
#eParCtlEx_IWC_CategoryPorno        = $ParCtlCategoryPorno
#eParCtlEx_IWC_CategorySoftware	    = $ParCtlCategorySoftware
#eParCtlEx_IWC_CategoryDrugs		= $ParCtlCategoryDrugs
#eParCtlEx_IWC_CategoryViolence	    = $ParCtlCategoryViolence
#eParCtlEx_IWC_CategoryUncens		= $ParCtlCategoryUncens
#eParCtlEx_IWC_CategoryWeapons	    = $ParCtlCategoryWeapons
#eParCtlEx_IWC_CategoryGambling	    = $ParCtlCategoryGambling
#eParCtlEx_IWC_CategoryChat		    = $ParCtlCategoryChat
#eParCtlEx_IWC_CategoryWebMail	    = $ParCtlCategoryWebMail
#eParCtlEx_IWC_CategoryShops		= $ParCtlCategoryShops
#eParCtlEx_IWC_CategorySocialNets	= $ParCtlCategorySocialNets
#eParCtlEx_IWC_CategoryProxy		= $ParCtlCategoryProxy
#eParCtlEx_IWC_CategoryCreditCards  = $ParCtlCategoryCreditCards
#eParCtlEx_IWC_CategoryCasualGames  = $ParCtlCategoryCasualGames

;------------- ParCtlUserReport.InternetDownload -----------------

[f_ParCtlEx_GetFDCCategoryGroup]
p_UserId, p_Category
ret = var pSett; pSett = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.FileDownloadControl.Items.find("Name == " + toExpr(p_Category)); if(pSett, pSett.Enabled ? #eParCtlEx_AccessBlocked : #eParCtlEx_AccessAllowed, 0)

[f_ParCtlEx_SetFDCCategoryGroup]
p_UserId, p_Category, p_GroupId
ret = ParCtl.users.ser().findSettingsUserAccount(p_UserId).settings.FileDownloadControl.Items.find("Name=="+toExpr(p_Category)).Enabled=(p_GroupId==#eParCtlEx_AccessBlocked?true:false);ParCtl.name.ser().setProfileSettingsDirty()

[s_ImGroupIcon]
#eParCtlEx_IM_ReasonContactInWhiteList = "ParCtlExAll16,14"
#eParCtlEx_IM_ReasonContactInBlackList = "ParCtlExAll16,16"
def = "ParCtlExAll16,15"

;---------------------------

[f_Check_ParctlFirstStartDialog]
ret = if(!productData("DisableParctlNoPasswordDialog") && (!AskForParCtl || !EnablePswrdProtect),dialog("ParctlFirstStartDialog"))

[f_ParCtl_ShowWindow]
p_Tab, p_UserId, p_windowDlg
ret = f_ParCtl_ShowWindowEx(p_Tab, p_UserId, users.find("UserId == " + toExpr(p_UserId)), p_windowDlg)

[f_ParCtl_ShowWindowEx]
p_Tab, p_UserId, p_Data, p_windowDlg
ret = if(checkPassword(#pwdc_OpenParctl), (f_Check_ParctlFirstStartDialog(); window("ParCtlRepSettMainWindow:" + p_Tab, p_modal(p_windowDlg), p_singleton(true), p_data(p_Data), p_User(p_UserId) )))

[f_ParCtl_LastViolationDate]
p_LastViolationDate
ret = (dategroup(p_LastViolationDate) == 0 || dategroup(p_LastViolationDate) == -1) ? s_date(dategroup(p_LastViolationDate)) + ", " + time_tz(p_LastViolationDate) : datetime(p_LastViolationDate)
