PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/www/assets/php/_core/calendar.php

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