1: <?php
2: function CastToInt($strNumber) {
3: settype($strNumber, "int");
4: return $strNumber;
5: }
6:
7: if ((!array_key_exists("intTimestamp", $_GET)) || (!$_GET["intTimestamp"])) {
8: $intTimestamp = time();
9: } else
10: $intTimestamp = $_GET["intTimestamp"];
11:
12: $strFormId = htmlentities($_GET["strFormId"]);
13: $strId = htmlentities($_GET["strId"]);
14:
15: $intSelectedMonth = CastToInt(date("n", $intTimestamp));
16: $intSelectedDay = CastToInt(date("j", $intTimestamp));
17: $intSelectedYear = CastToInt(date("Y", $intTimestamp));
18: $intTimestamp = mktime(0,0,0, $intSelectedMonth, $intSelectedDay, $intSelectedYear);
19: $dttToday = mktime(0,0,0, date("n"), date("j"), date("Y"));
20:
21: $intMonthStartsOn = CastToInt(date("w", mktime(0,0,0, $intSelectedMonth, 1, $intSelectedYear)));
22: $intMonthDays = CastToInt(date("t", $intTimestamp));
23: $intPreviousMonthDays = CastToInt(date("t", mktime(0,0,0, $intSelectedMonth - 1, 1, $intSelectedYear)));
24:
25: $strQueryArgs = sprintf("&strFormId=%s&strId=%s", $strFormId, $strId);
26: $strChangeCommand = sprintf('window.opener.document.forms["%s"].elements["%s"].value = "%s"; ',
27: $strFormId,
28: $strId,
29: date("M j Y", $intTimestamp));
30: $strChangeCommand .= sprintf('window.opener.document.forms["%s"].elements["%s_intTimestamp"].value = "%s"; ',
31: $strFormId,
32: $strId,
33: $intTimestamp);
34: $strChangeCommand .= sprintf('if (window.opener.document.forms["%s"].elements["%s"].onchange) window.opener.document.forms["%s"].elements["%s"].onchange();',
35: $strFormId,
36: $strId,
37: $strFormId,
38: $strId);
39: ?>
40: <html>
41: <head>
42: <title>Calendar</title>
43: <script type="text/javascript">
44: function selectDate(intTimestamp) {
45: document.location = "calendar.php?intTimestamp=" + intTimestamp + "<?php print($strQueryArgs); ?>";
46: }
47:
48: function cancel() {
49: window.close();
50: }
51:
52: function done() {
53: <?php print($strChangeCommand); ?>
54: window.close();
55: }
56: </script>
57: <style>
58: .main {
59: font-family: verdana, arial, helvetica, sans-serif;
60: font-size: 9px;
61: text-align: center;
62: color:
63: }
64:
65: A {
66: text-decoration: none;
67: }
68:
69: .dropdown {
70: background-color:
71: font-family: arial, helvetica, sans-serif;
72: font-size: 8pt;
73: }
74:
75: .button {
76: font-family: verdana, arial, helvetica, sans-serif;
77: font-size: 7.5pt;
78: font-weight: bold;
79: color:
80: background-color:
81: text-align: center;
82: vertical-align: middle;
83: height: 18px;
84: border: thin solid
85: }
86:
87: .offMonth {
88: color:
89: background-color:
90: }
91:
92: .onMonth {
93: color:
94: background-color:
95: }
96:
97: .onMonthWeekend {
98: color:
99: background-color:
100: }
101:
102: .selected {
103: color:
104: background-color:
105: }
106:
107: .today {
108: color:
109: background-color:
110: }
111: </style>
112: </head>
113: <body><form method="get" name="myForm"><center>
114: <select name="dttMonth" class="dropdown" onchange="selectDate(document.myForm.dttMonth.options[document.myForm.dttMonth.selectedIndex].value)">
115: <?php
116: for ($intMonth = 1; $intMonth <= 12; $intMonth++) {
117: $intTimestampLabel = mktime(0,0,0, $intMonth, 1, $intSelectedYear);
118: $strLabel = date("F", $intTimestampLabel);
119: $strSelected = ($intMonth == $intSelectedMonth) ? "selected" : "";
120: printf('<option value="%s" %s>%s</option>', $intTimestampLabel, $strSelected, $strLabel);
121: }
122: ?>
123: </select>
124: <select name="dttYear" class="dropdown" onchange="selectDate(document.myForm.dttYear.options[document.myForm.dttYear.selectedIndex].value)">
125: <?php
126: for ($intYear = 1970; $intYear <= 2020; $intYear++) {
127: $intTimestampLabel = mktime(0,0,0, $intSelectedMonth, 1, $intYear);
128: $strLabel = date("Y", $intTimestampLabel);
129: $strSelected = ($intYear == $intSelectedYear) ? 'selected="selected"' : '';
130: printf('<option value="%s" %s>%s</option>', $intTimestampLabel, $strSelected, $strLabel);
131: }
132: ?>
133: </select>
134: <table cellspacing="2" cellpadding="2" border="0" class="main">
135: <tr>
136: <td>Su</td>
137: <td>Mo</td>
138: <td>Tu</td>
139: <td>We</td>
140: <td>Th</td>
141: <td>Fr</td>
142: <td>Sa</td>
143: </tr>
144: <?php
145: $intDaysBack = ($intMonthStartsOn == 0) ? 7 : $intMonthStartsOn;
146: $intIndex = 1 - $intDaysBack;
147: $intRowCount = 0;
148:
149: while ($intRowCount < 6) {
150: print('<tr>');
151: for ($intDayOfWeek = 0; $intDayOfWeek <= 6; $intDayOfWeek++) {
152: if ($intIndex < 1) {
153: $intLabel = $intPreviousMonthDays + $intIndex;
154: $intTimestampLabel = mktime(0,0,0, $intSelectedMonth - 1, $intLabel, $intSelectedYear);
155: $strCssclass = "offMonth";
156: } else if ($intIndex > $intMonthDays) {
157: $intLabel = $intIndex - $intMonthDays;
158: $intTimestampLabel = mktime(0,0,0, $intSelectedMonth + 1, $intLabel, $intSelectedYear);
159: $strCssclass = "offMonth";
160: } else {
161: $intLabel = $intIndex;
162: $intTimestampLabel = mktime(0,0,0, $intSelectedMonth, $intLabel, $intSelectedYear);
163: $strCssclass = "onMonth";
164: if ((date("w", $intTimestampLabel) == 0) || (date("w", $intTimestampLabel) == 6))
165: $strCssclass = "onMonthWeekend";
166: else
167: $strCssclass = "onMonth";
168: }
169:
170: if ($intTimestampLabel == $intTimestamp)
171: $strCssclass = "selected";
172: else if ($intTimestampLabel == $dttToday)
173: $strCssclass = "today";
174:
175: printf('<td class="%s"><a class="%s" href="#" onclick="selectDate(%s)">%s</a></td>', $strCssclass, $strCssclass, $intTimestampLabel, $intLabel);
176: $intIndex++;
177: }
178: print('</tr>');
179: $intRowCount++;
180: }
181: ?>
182: <tr>
183: <td colspan="7">Selected Day: <?php print(date("n/j/Y", $intTimestamp)); ?><br /> </td>
184: </tr>
185: </table>
186: <input type="button" class="button" name="Done" value="DONE" onclick="done()" />
187: <input type="button" class="button" name="Cancel" value="CANCEL" onclick="cancel()" />
188: </center></form></body></html>