-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarNavigator.php
161 lines (139 loc) · 6.1 KB
/
CalendarNavigator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
//CalendarNavigator Class @0-3FBC5CCD
class clsCalendarNavigator {
public $ComponentType = "CalendarNavigator";
public $CalendarNavigatorName;
public $TargetName;
public $CalendarType;
public $Visible;
public $CCSEvents;
public $CCSEventResult;
public $Parent;
public $YearsRange;
public $CurrentProcessingDate;
public $NextProcessingDate;
public $PrevProcessingDate;
public $CurrentDate;
public $Attributes;
function clsCalendarNavigator($ComponentName, $CalendarNavigatorName, $CalendarType, $YearsRange = 10, & $Parent){
$this->TargetName = $ComponentName;
$this->CalendarNavigatorName = $CalendarNavigatorName;
$this->CalendarType = $CalendarType;
$this->YearsRange = $YearsRange;
$this->Visible = true;
$this->CCSEvents = array();
$this->Parent = & $Parent;
$this->Attributes = new clsAttributes($this->CalendarNavigatorName . ":");
}
function CreateURL($QueryString) {
global $CCSUseAmp;
global $FileName;
$datestr = CCFormatDate($this->CurrentProcessingDate, array("yyyy","-", "mm"));
$Return = $FileName . "?" . CCAddParam($QueryString, $this->TargetName . "Date", $datestr);
if ($CCSUseAmp) {
$Return = str_replace("&", "&", $Return);
}
return $Return;
}
function ShowBlock($QueryString, $name="", $to = "", $accumulate = true) {
global $Tpl;
$Tpl->SetVar("URL", $this->CreateURL($QueryString));
$Tpl->SetVar("CalendarName", $this->TargetName);
$Tpl->SetVar("Year", CCFormatDate($this->CurrentProcessingDate, array("yyyy")));
if (strpos($name, "CalendarNavigator") !== false || strpos($name, "Month") !== false || strpos($name, "Quarter") !== false) {
$Tpl->SetVar("Quarter", CCFormatDate($this->CurrentProcessingDate, array("q")));
$Tpl->SetVar("Month", CCFormatDate($this->CurrentProcessingDate, array("m")));
$Tpl->SetVar("MonthFullName", CCFormatDate($this->CurrentProcessingDate, array("mmmm")));
$Tpl->SetVar("MonthShortName", CCFormatDate($this->CurrentProcessingDate, array("mmm")));
}
if ($to)
$Tpl->ParseTo($name, $accumulate, $to);
else
$Tpl->Parse($name, $accumulate);
}
function Show() {
global $CCSUseAmp;
global $Tpl;
global $FileName;
$this->EventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
if(!$this->Visible) { return; }
$RemoveFromUrl = array(
$this->TargetName . "Year",
$this->TargetName . "Month",
$this->TargetName . "Date",
);
$QueryString = CCGetQueryString("QueryString", $RemoveFromUrl);
$ParentPath = $Tpl->block_path;
$CalendarNavigatorBlock = "CalendarNavigator " . $this->CalendarNavigatorName;
$Tpl->block_path = $ParentPath . "/" . $CalendarNavigatorBlock;
$Tpl->SetBlockVar("", "");
$Tpl->SetBlockVar("Years", "");
$Tpl->SetBlockVar("Months", "");
$Tpl->SetBlockVar("Quarters", "");
$this->Attributes->Show();
$Blocks = array("Months", "Quarters", "Years");
foreach ($Blocks as $Block) {
if ($Tpl->BlockExists($Block)) {
if ($Block == "Years") {
$this->CurrentProcessingDate = CCDateAdd($this->CurrentDate, "-" . $this->YearsRange . "years");
$LastDate = CCDateAdd($this->CurrentDate, "+" . $this->YearsRange . "years");
$add = "1year";
$name = "Year";
} elseif ($Block == "Quarters" && $this->CalendarType == "Quarter") {
$this->CurrentProcessingDate = CCParseDate(CCFormatDate($this->CurrentDate, array("yyyy","-01-01 00:00:00")), array("yyyy","-","mm","-","dd"," ","HH",":","nn",":","ss"));
$LastDate = CCDateAdd($this->CurrentProcessingDate, "+1year -1sec");
$add = "3month";
$name = "Quarter";
} elseif ($this->CalendarType != 12) {
$this->CurrentProcessingDate = CCParseDate(CCFormatDate($this->CurrentDate, array("yyyy","-01-01 00:00:00")), array("yyyy","-","mm","-","dd"," ","HH",":","nn",":","ss"));
$LastDate = CCDateAdd($this->CurrentProcessingDate, "+1year -1sec");
$add="1month";
$name = "Month";
} else {
continue;
}
while (CCCompareValues($this->CurrentProcessingDate, $LastDate, ccsDate) <= 0) {
$NextDate = CCDateAdd($this->CurrentProcessingDate, $add);
if (($Block == "Years" && $this->CurrentProcessingDate[ccsYear] == $this->CurrentDate[ccsYear]) ||
($Block == "Months" && $this->CurrentProcessingDate[ccsMonth] == $this->CurrentDate[ccsMonth]) ||
($Block == "Quarters" && ceil($this->CurrentProcessingDate[ccsMonth] / 3 + 0.1) == ceil($this->CurrentDate[ccsMonth] / 3))) {
$this->ShowBlock($QueryString, $Block . "/Current_" . $name, $Block . "/Regular_" . $name);
} else {
$this->ShowBlock($QueryString, $Block . "/Regular_" . $name);
}
$this->CurrentProcessingDate = $NextDate;
}
$this->ShowBlock($QueryString, $Block);
}
}
if ($Tpl->BlockExists("Prev_Year")) {
$this->CurrentProcessingDate = CCDateAdd($this->CurrentDate, "-1year");
$this->ShowBlock($QueryString, "Prev_Year", "", false);
}
if ($Tpl->BlockExists("Next_Year")) {
$this->CurrentProcessingDate = CCDateAdd($this->CurrentDate, "+1year");
$this->ShowBlock($QueryString, "Next_Year", "", false);
}
if ($this->CalendarType != 12) {
if ($Tpl->BlockExists("Prev")){
$this->CurrentProcessingDate = $this->PrevProcessingDate;
$this->ShowBlock($QueryString, "Prev", "", false);
}
if ($Tpl->BlockExists("Next")){
$this->CurrentProcessingDate = $this->NextProcessingDate;
$this->ShowBlock($QueryString, "Next", "", false);
}
}
$Tpl->block_path = $ParentPath;
$ActionStr = $FileName . "?" . CCAddParam($QueryString, "ccsForm", $this->TargetName);
if ($CCSUseAmp) {
$ActionStr = str_replace('&', '&', $ActionStr);
}
$Tpl->SetVar("Action", $ActionStr);
$Tpl->SetVar("CalendarName", $this->TargetName);
$this->CurrentProcessingDate = $this->CurrentDate;
$this->ShowBlock($QueryString, $CalendarNavigatorBlock, "", false);
}
}
//End CalendarNavigator Class
?>