<?php
add_stylesheet_to_page('project/calendar.css');
?>
<div class="calendar" >
<h2><?php echo clean(lang(sprintf('month %u', $month))); ?> <?php echo $year; ?></h2>
<?php
//for milestone
$calendar = array();
if (is_array($milestones) && count($milestones)) {
foreach ($milestones as $milestone) {
$due = $milestone->getDueDate();
if ($due->getYear() != $year or $due->getMonth() != $month) {
continue;
}
$calendar[$due->getDay()][] = $milestone;
}
} // if
//for meeting
$calendar2 = array();
if (is_array($meetings) && count($meetings)) {
foreach ($meetings as $meeting) {
$due = $meeting->getScheduledOn();
if ($due->getYear() != $year or $due->getMonth() != $month) {
continue;
}
$calendar2[$due->getDay()][] = $meeting;
}
} // if
//for task
$calendar3 = array(); //ending task
$calendar4 = array(); //starting task
if (is_array($tasks) && count($tasks)) {
foreach ($tasks as $task) {
$start = $task->getStartDate();
$due = $task->getEndDate();
if ($due->getYear() != $year or $due->getMonth() != $month) { //or
continue;
}
if ($start->getYear() != $year or $start->getMonth() != $month) {
continue;
}
$calendar3[$due->getDay()][] = $task;
$calendar4[$start->getDay()][] = $task;
}
} // if
$thisMonth = gmmktime(0, 0, 0, $month, 1, $year);
$prevMonth = strtotime('-1 month', $thisMonth);
$nextMonth = strtotime('+1 month', $thisMonth);
$daysInMonth = gmdate('d', strtotime('+1 month -1 day', $thisMonth));
$firstDayOfWeek = 1; // configurable?
$daysInWeek = 7;
$lastDayOfWeek = $firstDayOfWeek + $daysInWeek;
$firstDayOfMonth = (gmdate('w', $thisMonth))-1;
?>
<table width="100%">
<tr valign="top">
<?php
for ($dow = $firstDayOfWeek; $dow < $lastDayOfWeek; $dow++) {
if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
$dow_class = "weekend";
} else {
$dow_class = "weekday";
}
?>
<th class="<?php echo $dow_class; ?>"><?php echo clean(lang(sprintf('dow %u', $dow > $daysInWeek ? $dow - $daysInWeek : $dow))); ?></th>
<?php
} // for
?>
</tr>
<tr valign="top">
<?php
/*
* Skip days from previous month.
*/
for ($dow = $firstDayOfWeek; $dow <= $firstDayOfMonth; $dow++) {
if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
$dow_class = "weekend";
} else {
$dow_class = "weekday";
}
?>
<td class="<?php echo $dow_class; ?>"></td>
<?php
} // for
/*
* Render the month's calendar.
*/
for ($dom = 1; $dom <= $daysInMonth; ) {
for (; ($dow < $lastDayOfWeek) && ($dom <= $daysInMonth); $dow++,$dom++) {
if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
$dow_class = "weekend";
} else {
$dow_class = "weekday";
}
?>
<td class="<?php echo $dow_class; ?>" onMouseover="showdiv('date_value[<?php echo $dom ?>]')" onMouseout="hidediv('date_value[<?php echo $dom ?>]')" style="vertical-align:text-top;">
<div class="date">
<div id="date_value[<?php echo $dom ?>]" style="float:left; visibility:hidden"> <a href="<?php echo active_project()->getMilestonesUrl() ?>"><img src="<?php echo icon_url('mi.gif') ?>" title="New Milestone"/></a> <a href="<?php echo active_project()->getTasksUrl() ?>"><img src="<?php echo icon_url('td.gif') ?>" title="New Task"/></a> <a href="<?php echo active_project()->getMeetingsUrl() ?>"><img src="<?php echo icon_url('me.gif') ?>" title="New Meeting" /></a></div>
<?php if ($dom == date('d') && $month == date('m') && $year == date('Y')) { ?>
<span class="date_today" style="font-size:14px; color:#0000FF; background-color:#FFFFCC;"><?php echo $dom; ?></span><br />
<?php } else { ?> <span style="font-size:12px; color: #000000"> <?php echo $dom; ?> </span> <?php } ?><br />
<br />
<?php
//display scheduled milestone per month
if (isset($calendar[$dom]) && is_array($calendar[$dom])
&& count($calendar[$dom])) {
?>
<?php foreach ($calendar[$dom] as $m) { ?>
<?php printf('<img src="'.icon_url('milestone.png').'"><a href="%s">%s</a>'."\n",
get_url("milestone", "view", $m->getId()),
clean($m->getName())); ?>
<br />
<?php } //for
} // if ?>
<?php
//display scheduled ending date of task per month
if (isset($calendar3[$dom]) && is_array($calendar3[$dom])
&& count($calendar3[$dom])) {
?>
<?php
foreach ($calendar3[$dom] as $t) {
$task_start_date = $t->getStartDate()->getDay();
$task_end_date = $t->getEndDate()->getDay();
if(($task_start_date <= $dom) || ($task_end_date == $dom)) {?>
<?php printf('<img src="'.icon_url('task.png').'"><a href="%s">%s</a>'."\n",
get_url("task", "task_list", $t->getId()),
clean($t->getText()));
} //if?>
<br />
<?php $task_start_date = $task_start_date + 1;
$task_end_date = $task_end_date + 1;
} //for
} // if ?>
<?php
//display scheduled starting date of task per month
/*if (isset($calendar4[$dom]) && is_array($calendar4[$dom])
&& count($calendar4[$dom])) {
?>
<?php foreach ($calendar4[$dom] as $ta) {
// if ($due->getDay() == $dom) {
//if(($t->getEndDate()->getDay() == $dom) || (($dom >= $t->getStartDate()->getDay()) && ($dom <= $t->getEndDate()->getDay()))) {?>
<?php printf('<img src="'.icon_url('task.png').'"><a href="%s">%s</a>'."\n",
get_url("task", "task_list", $ta->getId()),
clean($ta->getText()));
//} //if?>
<br />
<?php } //for
} // if */?>
<?php
//display scheduled meeting per month
if (isset($calendar2[$dom]) && is_array($calendar2[$dom])
&& count($calendar2[$dom])) {
?>
<?php foreach ($calendar2[$dom] as $me) { ?>
<?php printf('<img src="'.icon_url('meeting.png').'"><a href="%s">%s</a>'."\n",
get_url("meeting", "view", $me->getId()),
clean($me->getDescription())); ?>
<br />
<?php } //for
} // if ?>
<?php
} // for
?> </td>
<?php if ($dom <= $daysInMonth) { ?>
</tr>
<tr valign="top">
<?php
$dow = $firstDayOfWeek;
} // if
} // for
/*
* Skip days from next month.
*/
if ($dow < $lastDayOfWeek) {
for (; $dow < $lastDayOfWeek; $dow++) {
if (in_array($dow > $daysInWeek ? $dow - $daysInWeek : $dow, array(1, 7))) {
$dow_class = "weekend";
} else {
$dow_class = "weekday";
}
?>
<td class="<?php echo $dow_class; ?>"> </td>
<?php
} // for
?>
</tr>
<?php
} // if
?>
</table>
<div class="month-nav">
<div class="prev-month"><a href="<?php echo get_url('calendar', 'index', gmdate('Ym', $prevMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $prevMonth)))); ?> <?php echo gmdate('Y', $prevMonth); ?></a></div>
<div class="next-month"><a href="<?php echo get_url('calendar', 'index', gmdate('Ym', $nextMonth)); ?>"><?php echo clean(lang(sprintf('month %u', gmdate('m', $nextMonth)))); ?> <?php echo gmdate('Y', $nextMonth); ?></a></div>
</div>
</div>