PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/application/views/milestone/calendar.php

https://gitlab.com/x33n/ProjectPier-Core
PHP | 178 lines | 161 code | 7 blank | 10 comment | 39 complexity | 1d02c0548ebf092bf5f9597e13b1ec37 MD5 | raw file
  1. <?php
  2. set_page_title(lang('milestones'));
  3. project_tabbed_navigation('milestones');
  4. project_crumbs(array(
  5. array(lang('milestones'), get_url('milestone', 'index')),
  6. array(lang('view calendar'))
  7. ));
  8. if (ProjectMilestone::canAdd(logged_user(), active_project())) {
  9. add_page_action(lang('add milestone'), get_url('milestone', 'add'));
  10. } // if
  11. add_stylesheet_to_page('project/calendar.css');
  12. $view_image = $view_type=="list" ? "icons/list_on.png" : "icons/list_off.png";
  13. add_view_option(lang('list'), get_image_url( $view_image ), get_url('milestone', 'index', array("view" => "list") ));
  14. $view_image = $view_type=="card" ? "icons/excerpt_on.png" : "icons/excerpt_off.png";
  15. add_view_option(lang('card'), get_image_url( $view_image ), get_url('milestone', 'index', array("view" => "details") ) );
  16. add_view_option(lang('calendar'), get_image_url( "icons/calendar_off.png" ), get_url('milestone', 'calendar'));
  17. ?>
  18. <div class="calendar">
  19. <h2><?php echo clean(lang(sprintf('month %u', $month))); ?> <?php echo $year; ?></h2>
  20. <?php
  21. $calendar = array();
  22. if (is_array($milestones) && count($milestones)) {
  23. foreach ($milestones as $milestone) {
  24. $due = $milestone->getDueDate();
  25. if ($due->getYear() != $year or $due->getMonth() != $month) {
  26. continue;
  27. }
  28. $calendar[$due->getDay()][] = $milestone;
  29. }
  30. } // if
  31. trace(__FILE__,'task lists:begin');
  32. if (is_array($task_lists) && count($task_lists)) {
  33. foreach ($task_lists as $task_list) {
  34. $due = $task_list->getDueDate();
  35. if ($due->getYear() != $year or $due->getMonth() != $month) {
  36. continue;
  37. }
  38. $calendar[$due->getDay()][] = $task_list;
  39. $tasks = $task_list->getTasks();
  40. if (is_array($tasks)) {
  41. foreach($tasks as $task) {
  42. $due = $task_list->getDueDate();
  43. if (is_null($due)) continue;
  44. if ($due->getYear() != $year or $due->getMonth() != $month) {
  45. continue;
  46. }
  47. $calendar[$due->getDay()][] = $task;
  48. }
  49. }
  50. }
  51. } // if
  52. trace(__FILE__,'task lists: end');
  53. $thisMonth = gmmktime(0, 0, 0, $month, 2, $year, 0);
  54. //echo date('Y m d H i s', $thisMonth);
  55. $prevMonth = strtotime('-1 month', $thisMonth);
  56. $nextMonth = strtotime('+1 month', $thisMonth);
  57. $daysInMonth = gmdate('t', $thisMonth);
  58. $firstDayOfWeek = config_option('calendar_first_day_of_week', 1);
  59. $daysInWeek = 7; // in case you live on another planet...
  60. $lastDayOfWeek = 8;
  61. $firstDayOfMonth = gmdate('w', $thisMonth); // Sunday = 0, Monday = 1, ... Saturday = 6
  62. if ($firstDayOfMonth == 0) {
  63. $firstDayOfMonth = 7; // Monday = 1, ... Saturday = 6, Sunday = 7
  64. }
  65. ?>
  66. <table width="100%">
  67. <tr valign="top">
  68. <?php
  69. for ($dow = 1; $dow < 8; $dow++) {
  70. if ($dow > 5) {
  71. $dow_class = "weekend";
  72. } else {
  73. $dow_class = "weekday";
  74. }
  75. ?>
  76. <th class="<?php echo $dow_class; ?>"><?php echo clean(lang(sprintf('weekday short %u', $dow ))); ?></th>
  77. <?php
  78. } // for
  79. ?>
  80. </tr>
  81. <tr valign="top">
  82. <?php
  83. /*
  84. * Skip days from previous month.
  85. */
  86. for ($dow = 1; $dow < $firstDayOfMonth; $dow++) {
  87. if ($dow % $daysInWeek > 5) {
  88. $dow_class = "weekend";
  89. } else {
  90. $dow_class = "weekday";
  91. }
  92. ?>
  93. <td class="<?php echo $dow_class; ?>">&nbsp;</td>
  94. <?php
  95. } // for
  96. /*
  97. * Render the month's calendar.
  98. */
  99. $dow = $firstDayOfMonth;
  100. for ($dom = 1; $dom <= $daysInMonth;) {
  101. for (; ($dow < $lastDayOfWeek) && ($dom <= $daysInMonth); $dow++, $dom++) {
  102. if ($dow > 5) {
  103. $dow_class = "weekend";
  104. } else {
  105. $dow_class = "weekday";
  106. }
  107. ?>
  108. <td class="<?php echo $dow_class; ?>">
  109. <div class="date"><?php echo $dom; ?></div>
  110. <?php
  111. if (isset($calendar[$dom])
  112. && is_array($calendar[$dom])
  113. && count($calendar[$dom])) {
  114. ?>
  115. <ul class="entries">
  116. <?php
  117. foreach ($calendar[$dom] as $obj) {
  118. if (use_permitted(logged_user(), active_project(), 'tasks')) {
  119. printf('<li class="%s"><a href="%s">%s</a></li>'."\n",
  120. strtr(lc($obj->getObjectTypeName()), ' ', '_'),
  121. $obj->getViewUrl(),
  122. clean($obj->getObjectName())
  123. );
  124. } else {
  125. printf('<li class="%s">%s</li>'."\n",
  126. strtr(lc($obj->getObjectTypeName()), ' ', '_'),
  127. clean($obj->getObjectName())
  128. );
  129. }
  130. }
  131. ?>
  132. <ul>
  133. <?php
  134. } // if
  135. ?>
  136. </td>
  137. <?php
  138. } // for
  139. ?>
  140. </tr>
  141. <?php if ($dom <= $daysInMonth) { ?>
  142. <tr valign="top">
  143. <?php
  144. $dow = 1;
  145. } // if
  146. } // for
  147. /*
  148. * Skip days from next month.
  149. */
  150. if ($dow < $lastDayOfWeek) {
  151. for (; $dow < $lastDayOfWeek; $dow++) {
  152. if ($dow % $daysInWeek > 5) {
  153. $dow_class = "weekend";
  154. } else {
  155. $dow_class = "weekday";
  156. }
  157. ?>
  158. <td class="<?php echo $dow_class; ?>">&nbsp;</td>
  159. <?php
  160. } // for
  161. ?>
  162. </tr>
  163. <?php
  164. } // if
  165. ?>
  166. </table>
  167. <div class="month-nav">
  168. <div class="prev-month"><a href="<?php echo get_url('milestone', 'calendar', gmdate('Ym', $prevMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $prevMonth)))); ?> <?php echo gmdate('Y', $prevMonth); ?></a></div>
  169. <div class="next-month"><a href="<?php echo get_url('milestone', 'calendar', gmdate('Ym', $nextMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $nextMonth)))); ?> <?php echo gmdate('Y', $nextMonth); ?></a></div>
  170. </div>
  171. </div>